From 74856ecf5237acc6f5ca08ce0cefb354316084be Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Thu, 19 Jun 2008 18:13:11 +0000 Subject: Yet another zaptel->dahdi rename. XPP file names this time. git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@4418 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/xpp/Kbuild | 2 +- drivers/dahdi/xpp/README.Astribank | 206 ++++--- drivers/dahdi/xpp/card_bri.c | 36 +- drivers/dahdi/xpp/card_fxo.c | 36 +- drivers/dahdi/xpp/card_fxs.c | 24 +- drivers/dahdi/xpp/card_global.c | 6 +- drivers/dahdi/xpp/card_pri.c | 42 +- drivers/dahdi/xpp/dahdi_debug.c | 91 +++ drivers/dahdi/xpp/dahdi_debug.h | 201 +++++++ drivers/dahdi/xpp/mmapdrv.c | 4 +- drivers/dahdi/xpp/xbus-core.c | 4 +- drivers/dahdi/xpp/xbus-pcm.c | 96 ++-- drivers/dahdi/xpp/xbus-pcm.h | 10 +- drivers/dahdi/xpp/xbus-sysfs.c | 4 +- drivers/dahdi/xpp/xframe_queue.c | 2 +- drivers/dahdi/xpp/xpd.h | 4 +- drivers/dahdi/xpp/xpp.conf | 2 +- drivers/dahdi/xpp/xpp_dahdi.c | 1075 +++++++++++++++++++++++++++++++++++ drivers/dahdi/xpp/xpp_dahdi.h | 53 ++ drivers/dahdi/xpp/xpp_usb.c | 4 +- drivers/dahdi/xpp/xpp_zap.c | 1087 ------------------------------------ drivers/dahdi/xpp/xpp_zap.h | 53 -- drivers/dahdi/xpp/xproto.c | 8 +- drivers/dahdi/xpp/xproto.h | 4 +- drivers/dahdi/xpp/zap_debug.c | 91 --- drivers/dahdi/xpp/zap_debug.h | 201 ------- 26 files changed, 1663 insertions(+), 1683 deletions(-) create mode 100644 drivers/dahdi/xpp/dahdi_debug.c create mode 100644 drivers/dahdi/xpp/dahdi_debug.h create mode 100644 drivers/dahdi/xpp/xpp_dahdi.c create mode 100644 drivers/dahdi/xpp/xpp_dahdi.h delete mode 100644 drivers/dahdi/xpp/xpp_zap.c delete mode 100644 drivers/dahdi/xpp/xpp_zap.h delete mode 100644 drivers/dahdi/xpp/zap_debug.c delete mode 100644 drivers/dahdi/xpp/zap_debug.h (limited to 'drivers') diff --git a/drivers/dahdi/xpp/Kbuild b/drivers/dahdi/xpp/Kbuild index 6d4db4c..52c095b 100644 --- a/drivers/dahdi/xpp/Kbuild +++ b/drivers/dahdi/xpp/Kbuild @@ -25,7 +25,7 @@ ifneq (,$(filter y m,$(CONFIG_BF537))) obj-$(DAHDI_BUILD_ALL)$(CONFIG_XPP_MMAP) += xpp_mmap.o endif -xpp-objs += xbus-core.o xbus-sysfs.o xbus-pcm.o xframe_queue.o xpp_zap.o xproto.o card_global.o zap_debug.o +xpp-objs += xbus-core.o xbus-sysfs.o xbus-pcm.o xframe_queue.o xpp_dahdi.o xproto.o card_global.o dahdi_debug.o xpd_fxs-objs += card_fxs.o xpd_fxo-objs += card_fxo.o xpd_bri-objs += card_bri.o diff --git a/drivers/dahdi/xpp/README.Astribank b/drivers/dahdi/xpp/README.Astribank index af43eb1..0104dea 100644 --- a/drivers/dahdi/xpp/README.Astribank +++ b/drivers/dahdi/xpp/README.Astribank @@ -3,7 +3,7 @@ Xorcom Astribank Documentation Xorcom Team $Revision$, $Date$ -This file documents the Zaptel drivers for the Xorcom Channel Bank. +This file documents the Dahdi drivers for the Xorcom Channel Bank. The drivers reside in a separate subdirectory, kernel/xpp/ . It is generally a more technical document than the @@ -15,34 +15,26 @@ http://zaptel.tzafrir.org.il/README.Astribank.html[] Building and Installation ------------------------- Building and installation is basically like the normal procedure of -installing Zaptel with some additions. +installing Dahdi with some additions. Building drivers ~~~~~~~~~~~~~~~~ -Apart from the standard Zaptel build requirements, you also need libusb +Apart from the standard Dahdi build requirements, you also need libusb development headers to build the fpga_load firmware loader. This is typically the package libusb-dev on Debian (and derivatives like Ubuntu) or libusb-devel on RedHat (and derivatives like CentOS/Trixbox). -On Zaptel 1.2 you will need to run the following extra step to build the -user space utilities, apart from the standard 'make; make install': - - make -C xpp/utils install - -Though this should be done automatically on Zaptel >= 1.4.1 . - - Sample Configurations --------------------- We generally recommend to generate the configuration by using utility -genzaptelconf or zapconf which are included with Zaptel. Nevertheless, +genzaptelconf or zapconf which are included with Dahdi. Nevertheless, the following can serve as reference configurations for a system where Astribank devices are used. -Zaptel Init Configuration File +Dahdi Init Configuration File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The zaptel init.d script, genzaptelconf and the XPD init scripts uses the +The dahdi init.d script, genzaptelconf and the XPD init scripts uses the parameters located in file /etc/default/zaptel (on Debian) or /etc/sysconfig/zaptel (on RedHats). There is a number of useful parameters that may be defined there: @@ -60,14 +52,14 @@ that may be defined there: # Equivalent to the parameter opermode to the module wctdm: country-specific # settings to the FXO lines. For a complete list of possible values, see -# /usr/share/zaptel/init_fxo_mode . +# /usr/share/dahdi/init_fxo_mode . #opermode=FRANCE # xpp_sync runs with the value of 'XPP_SYNC' as its parameter to set the # synchronization source. The default is 'auto' that selects the best -# Astribank. 'ZAPTEL' gets synchronization from the Zaptel sync master +# Astribank. 'DAHDI' gets synchronization from the Dahdi sync master # span. Or a specific XBUS number. -#XPP_SYNC=ZAPTEL +#XPP_SYNC=DAHDI # Disables hot-plug firmware loading #XPP_HOTPLUG_DISABLED=yes @@ -87,7 +79,7 @@ that may be defined there: # ' ----------------------------------------------------------- -/etc/zaptel.conf +/etc/dahdi.conf ~~~~~~~~~~~~~~~~ Astribank 8 @@ -307,7 +299,7 @@ Sample dialplan (extensions.conf) for all the above: ----------------------------------------------------------- [phones-zap] -; 6001 will dial to channel 1, 6020, to Zaptel channel 20, etc. +; 6001 will dial to channel 1, 6020, to Dahdi channel 20, etc. exten => _6XXX,1,Dial(ZAP/${EXTEN:1}) ; Useful for debugging trunks. Will potentially allow users to ; bypass context limitations. @@ -335,7 +327,7 @@ include => astbank-test [from-pstn] ; Calls from the PSTN enter here. Redirect calls to an IVR ; or a default extension in the s context here. In this case we -; redirect calls to Zaptel channel 1: +; redirect calls to Dahdi channel 1: exten => s,1,Dial(Zap/1) ; Alternatively, the following will redirect you to the demo IVR @@ -364,7 +356,7 @@ exten => s,n,Set(ZAP_CHAN=${CUT(ZAP_CHAN,/,2)}) ; configuration below. ;exten => s,n,Set(INPUT_NUM=$[${ZAP_CHAN}-11)]) ; The sample below just logs the signal. -exten => s,n,NoOp(Got signal from Zaptel Channel ${ZAP_CHAN}) +exten => s,n,NoOp(Got signal from Dahdi Channel ${ZAP_CHAN}) ; Alternatively: ;exten => s,n,System(run something) @@ -385,14 +377,14 @@ lsusb Test ~~~~~~~~~~ Check USB level status. You can use one of the following utilities for it: - zaptel_hardware -v + dahdi_hardware -v or lsusb | grep e4e4 - Look for the USB Product ID (the second number after e4e4). - If you see *11x2* (e.g: 1152)- the FPGA firmware has been loaded. Move on. - zaptel_hardware will also show you some more details if the driver + dahdi_hardware will also show you some more details if the driver is loaded while the lsusb will just list the device. - If it shows something as product ID *11x0* - the USB firmware is not loaded. Maybe you need to run fxload. Or maybe just unplug and plug again @@ -401,46 +393,46 @@ Check USB level status. You can use one of the following utilities for it: and not the FPGA firmware is loaded. If this is still the case after a while - either the firmware loading has failed or you don't have fpga_load. Make sure you have libusb-dev(el) installed when - building Zaptel. After you have installed it, you may need to re-run + building Dahdi. After you have installed it, you may need to re-run ./configure . - It should list all of your Astribank devices. If it doesn't (for more than period of time needed for the initial firmware loading) - Check that the Astribank is connected indeed. -Zaptel Registration +Dahdi Registration ~~~~~~~~~~~~~~~~~~~ -Check if the Astribank spans are registered in Zaptel +Check if the Astribank spans are registered in Dahdi - zt_registration + dahdi_registration - This should give useful results after the drivers have identified and your devices are initialized. - It should list all Astribank XPDs. For each of them it should write "on" or "off". If the registration status is "off", then it means that - the span has not been registered in Zaptel and therefore can not be used + the span has not been registered in Dahdi and therefore can not be used yet. -- Registration is normally done as part of `/etc/init.d/zaptel start`. +- Registration is normally done as part of `/etc/init.d/dahdi start`. If you want to register the spans manually, then run command: - `zt_registration on` . + `dahdi_registration on` . - Disabling of the automatic Astribank spans registration give you full - control on the order of Zaptel spans. See the module parameter + control on the order of Dahdi spans. See the module parameter **zap_autoreg** for the further details. -Zaptel Level Information +Dahdi Level Information ~~~~~~~~~~~~~~~~~~~~~~~~ -You can get some information regarding Zaptel channels by running one of the +You can get some information regarding Dahdi channels by running one of the following commands: - lszaptel + lsdahdi or - cat /proc/zaptel/* + cat /proc/dahdi/* -- Those two are almost the same. The lszaptel produced more correctly sorted +- Those two are almost the same. The lsdahdi produced more correctly sorted output if you have more than 10 spans, and also make the output listing looks a little bit nicer. -- You can see if your Zaptel spans and channels were loaded, if +- You can see if your Dahdi spans and channels were loaded, if they were configured by ztcfg and if they are in use (typically by Asterisk). For example: @@ -449,7 +441,7 @@ following commands: 42 FXS - When a channel has been configured with *ztcfg* (that applies - /etc/zaptel.conf), you will see an extra column for the signalling + /etc/dahdi.conf), you will see an extra column for the signalling type of the channel. The same channel after it has been configured: 42 FXS FXOKS @@ -511,7 +503,7 @@ it: .Fix: Move that process from that directory, or close the file it uses from -under /proc/xpp and reload the zaptel / xpp drivers. +under /proc/xpp and reload the dahdi / xpp drivers. Bad Firmware Version @@ -529,14 +521,14 @@ to a The protocol version supported by the firmware will typically be the same one as in the device initialization scripts installed to -/usr/share/zaptel . Hence if this version installed -`/usr/share/zaptel/init_card_3_29` it will probably include firmware of +/usr/share/dahdi . Hence if this version installed +`/usr/share/dahdi/init_card_3_29` it will probably include firmware of protocol version 29. .Fix: Reset the firmware: - /usr/share/zaptel/xpp_fxloader reset + /usr/share/dahdi/xpp_fxloader reset Or disconnect the Astribank from the power and reocnnect. On some older versions of the USB firmware resetting the firmware (or any operation of @@ -565,7 +557,7 @@ BRI Layer 1 Down With the BRI module only, and not in the middle of an active call, you notice that suddenly the line goes down. The LED of the port stops blinking, layer1 not listed as "active" in the bri_info file in -/proc/xpp, and the span is in RED alarm in Zaptel. +/proc/xpp, and the span is in RED alarm in Dahdi. You may also see an error message such as: @@ -609,7 +601,7 @@ many of our programs read configuration from there: either from The problem is what to do if both of those exist. Selecting an arbitrary one can lead to unexpected results. Likewise sourcing both of them. Therefore we prefer to fail in a noisy and expected way. In the future -we will probably me to reading configuration from a file under /etc/zaptel . +we will probably me to reading configuration from a file under /etc/dahdi . .Fix: Remove one of those two. There should be no reason to have both on the @@ -639,7 +631,7 @@ initilization to end. .Fix: Reset the firmware of the Astribank by either: - /usr/share/zaptel/xpp_fxloader reset + /usr/share/dahdi/xpp_fxloader reset or disconnecting it from the power and reconnecting it. @@ -697,17 +689,17 @@ For each port there are two optional parameters that define its behavior: Each port in the PRI module can be configured either as E1 or T1. The -port type defaults to E1 and can be changed to T1 in the Zaptel Init +port type defaults to E1 and can be changed to T1 in the Dahdi Init Configuration File. The Astribank xpp driver uses that information for correct hardware -initialization that is performed before the Zaptel span registration +initialization that is performed before the Dahdi span registration process takes place. Because of that, xpp driver can't use the -information from file zaptel.conf. +information from file dahdi.conf. -Another parameter that also can be defined in the Zaptel Init +Another parameter that also can be defined in the Dahdi Init Configuration File is the function group TE (CPE) or NT (Network). This -parameter is used for (a) building correct Zaptel & Asterisk +parameter is used for (a) building correct Dahdi & Asterisk configuration by genzaptelconf and (b) control RJ-45 sockets LEDs for better visual port control: @@ -724,7 +716,7 @@ NT:: To set them to a non-default value, you should use the variable XPP_PRI_SETUP in the -xref:_zaptel_init_configuration_file[Zaptel Init Configuration File] +xref:dahdi_init_configuration_file[Dahdi Init Configuration File] (/etc/sysconfig/zaptel on Redhats, /etc/default/zaptel on Debians). This value is a whitespace-separated list of conditions. When a port is initialized it checks those conditions and uses the first one that @@ -790,18 +782,18 @@ Device Startup ~~~~~~~~~~~~~~ This section describes in great depth the initialization of the Xorcom Astribank. Normally it would not be really needed, as the standard -installation of Zaptel should put everything in place. +installation of Dahdi should put everything in place. Terminology ^^^^^^^^^^^ There are some technical terms that are used in this document and in the -driver / zaptel. +driver / dahdi. span: -Zaptel breaks the channels it knows about to logical units called +Dahdi breaks the channels it knows about to logical units called "spans". A port in a E1/T1/ISDN card is usually a span. An whole analog card is also a "span". You can see the list of spans as the list -of files under /proc/zaptel directory or in output of the zttool +of files under /proc/dahdi directory or in output of the zttool utility. XBUS: @@ -809,13 +801,13 @@ A funny way to call an Astribank device. XPD: Basically this is a logical unit of the Astribank. It will be registered in -Zaptel as a single span. This can be either an analog (FXS or FXO) +Dahdi as a single span. This can be either an analog (FXS or FXO) module or a single port in case of a BRI module. Loading Firmware ^^^^^^^^^^^^^^^^ -Normally this is done using the script /usr/share/zaptel/xpp_fxloader. +Normally this is done using the script /usr/share/dahdi/xpp_fxloader. If it works fine, you don't need to bother reading this section. Once the firmware is loaded the USB Vendor ID and Product ID of the Astribank became to be e4e4 11x2, and now the driver can pick it up. @@ -825,8 +817,8 @@ is lsusb. The output of lsusb should show you if the device is connected if its firmware is loaded. The firmware files are named *.hex. They are presented in the text -hexadecimal format The files are copied from xpp/utils to /usr/share/zaptel -folder during the Zaptel installation. +hexadecimal format The files are copied from xpp/utils to /usr/share/dahdi +folder during the Dahdi installation. The Astribank needs a firmware loaded into it. Without the firmware, the device will appear in lsusb with Vendor ID e4e4 and Product ID 1130. @@ -837,7 +829,7 @@ completed the Vendor ID is e4e4 and the Product ID is 1131. You can use the following command in order to load the "USB" firmware manually: - fxload -t fx2 -D /proc/bus/usb/MMM/NNN -I /usr/share/zaptel/USB_FW.hex + fxload -t fx2 -D /proc/bus/usb/MMM/NNN -I /usr/share/dahdi/USB_FW.hex where, @@ -858,12 +850,12 @@ disconnects and then connects again itself with USB Product ID 1131 In the second stage, the "FPGA" firmware is loaded. The second-stage firmware loading is performed by using program fpga_load, which is built in the directory xpp/utils and then copied to folder -/usr/sbin during Zaptel installation. +/usr/sbin during Dahdi installation. The command syntax is similar to the syntax of fxload. You can use the following command in order to load the FPGA firmware manually: - fpga_load -D /proc/bus/usb/MMM/NNN -I /usr/share/zaptel/FPGA_1151.hex + fpga_load -D /proc/bus/usb/MMM/NNN -I /usr/share/dahdi/FPGA_1151.hex Please note, that NNN value differs from that that was used for the fxload command due to the fact that device has "reconnected" itself @@ -911,7 +903,7 @@ then the firmware should be loaded automatically. In order to get udev to automatically load the firmware into the Astribank, the configuration file xpp.rules should be copied into folder /etc/udev/rules.d and the script xpp_fxloader should be copied into folder /etc/hotplug/usb/ . -This is done by 'make -C xpp/utils install' during Zaptel installation. +This is done by 'make -C xpp/utils install' during Dahdi installation. File xpp.rules instructs the udevd daemon to run xpp_fxloader script with the option "udev" and with the Astribank USB ID obtained from the @@ -927,11 +919,11 @@ Newer versions of the USB firmware can now be reset using 'fpga_load -r'. Also you can try the following: - /usr/share/zaptel/xpp_fxloader reset + /usr/share/dahdi/xpp_fxloader reset # if asterisk was running: you may need to stop/restart it now. # if there are some "disconnected" spans in /proc/xpp/xbuses # wait a while, until you see the 1152 IDs again, and then: - /etc/init.d/zaptel start + /etc/init.d/dahdi start # and start/restart asterisk. @@ -953,7 +945,7 @@ Now to the ugly details: The driver of the Astribank is composed of several modules: -* xpp - the basic module, that communicates with Zaptel and provides +* xpp - the basic module, that communicates with Dahdi and provides some common services to other modules. * xpd_fxs - the module for controlling FXS modules. * xpd_fxo - the module for controlling FXO modules. @@ -971,7 +963,7 @@ Vendor-ID/Product-ID of the device will be e4e4/1132 . The handler for that combination is listed as the kernel module xpp_usb. Therefore, the system runs 'modprobe xpp_usb' if that module is not already loaded. -The module xpp_usb depends on the zaptel and xpp modules. Both of them +The module xpp_usb depends on the dahdi and xpp modules. Both of them are loaded before xpp_usb. As usual, parameters and rules form /etc/modprobe.conf and/or from /etc/modprobe.d/* will be applied to the module. @@ -990,8 +982,8 @@ Device Initializations Scripts The chips in the device need to be initialized. This requires sending a bunch of values to certain registers in those chips. We decided that hardwiring those values in the driver code is not a good idea. -Before registering a XPD as a span in Zaptel, we run an initialization -script: /usr/share/zaptel/init_card_N_MM ( +Before registering a XPD as a span in Dahdi, we run an initialization +script: /usr/share/dahdi/init_card_N_MM ( where, * N - is 3 for an FXS span and 4 for an FXO span, and 6 or 7 for BRI. @@ -1004,75 +996,75 @@ If because of some reasons this fails (the script is not in the place, or the file doesn't have the executable permissions), then you will get an error message in the logs and the XPD will then be removed (you won't see directory for that XPD under the corresponding /proc/xpp/XBUS-* directory) and will not -be registered in Zaptel. +be registered in Dahdi. As the XPD is initialized, you'll see the green LEDs of the ports steadily turn on and later off ("a train of lights"). This is a bit slower than the -faster "blinking" when the XPDs register as Zaptel spans. The initialization +faster "blinking" when the XPDs register as Dahdi spans. The initialization of an FXS XPD may take a few seconds. -Registering in Zaptel +Registering in Dahdi ^^^^^^^^^^^^^^^^^^^^^ -The XPDs will not automatically register as Zaptel spans. This is +The XPDs will not automatically register as Dahdi spans. This is intended to allow you to set the registration order (and hence the order -of Zaptel spans and channels) among multiple Astribank devices, -or between an Astribank and a different Zaptel device. +of Dahdi spans and channels) among multiple Astribank devices, +or between an Astribank and a different Dahdi device. -When the XPD registers to Zaptel, all the green LEDs will be lit for a +When the XPD registers to Dahdi, all the green LEDs will be lit for a short while. -Spans are normally registered with the utility zt_registration. Simply -running 'zt_registration' shows the available XPDs and whether or not +Spans are normally registered with the utility dahdi_registration. Simply +running 'dahdi_registration' shows the available XPDs and whether or not they are registered. To register: - zt_registration on + dahdi_registration on For a system with several spans you'll see a "fast train of lights". -If you have multiple Astribank devices, zt_registration will register +If you have multiple Astribank devices, dahdi_registration will register them by the order of the "connector" field. This means that as long as the same Astribank is connected to the same port, the order of plugging is not important.. -zt_registration checks if a span is registered or tries to register a -span using the file /proc/xpp/XBUS-nn/XPD-mm/zt_registration . Reading +dahdi_registration checks if a span is registered or tries to register a +span using the file /proc/xpp/XBUS-nn/XPD-mm/dahdi_registration . Reading from that file returns 0 if the span is unregisters or 1 if it is registered. You can register a span or ask to unregister it by writing 1 (register) or 0 (unregister) to that file. Registration should generally always succeed. Unregistration may fail if a span is in use. -You may choose to register the XPDs in Zaptel automatically. This may +You may choose to register the XPDs in Dahdi automatically. This may make the startup sequence a bit simpler, but is generally not recommended on a system with more than one Astribank or an Astribank and -a different Zaptel device. This behavior may be defined by setting +a different Dahdi device. This behavior may be defined by setting parameter zap_autoreg in the modprobe configuration file (A file under /etc/modprobe.d or /etc/modprobe.conf): options xpp zap_autoreg=1 -Zaptel And Above +Dahdi And Above ^^^^^^^^^^^^^^^^ -From here you get a standard Zaptel span. It still needs to be +From here you get a standard Dahdi span. It still needs to be configured by ztcfg and used by a program such as Asterisk like any -other Zaptel device. In order for you to get a dial-tone in a phone +other Dahdi device. In order for you to get a dial-tone in a phone connected to the FXS port or a fully synchronized BRI port (layer 2 activated, as signalled by a more steady blink) you will actually need -both the span configured by Zaptel and the channels configured in +both the span configured by Dahdi and the channels configured in Asterisk. -You should generally refer to the general Zaptel documentation on how to +You should generally refer to the general Dahdi documentation on how to configure those levels. e.g, the README file in the top-level directory, and http://voip-info.org/wiki/view/Asterisk+config+zapata.conf[] -Zaptel now includes a utility called genzaptelconf (written as a big -ugly shell script) to configure Zaptel automatically as good as +Dahdi now includes a utility called genzaptelconf (written as a big +ugly shell script) to configure Dahdi automatically as good as possible. For analog channels it works quite well (because, IMHO, the -"configuration" level on Zaptel should be optional there - there are +"configuration" level on Dahdi should be optional there - there are already sane defaults). For digital spans - BRI and PRI , it may take some tuning. @@ -1088,7 +1080,7 @@ are many other debugging details that are exposed through the procfs interface. Also note that those details are subject to changes. Generally the -recommended stable interface are the Zaptel-perl utilities from the +recommended stable interface are the Dahdi-perl utilities from the xpp/utils directory. @@ -1114,15 +1106,15 @@ Possible values are: :: Make the Astribank XBUS- the sync source for other Astribanks. -ZAPTEL:: - Make the Astribanks synchronize with the Zaptel timing master span. +DAHDI:: + Make the Astribanks synchronize with the Dahdi timing master span. You probably need this to get faxes from a non-Astribank adapter to an Astribank. Though you'll normally use xpp_sync(8) for that. For each Astribank device there is folder /proc/xpp/XBUS-nn and for each device -module (span in the terms of Zaptel) there is folder /proc/XBUS-nn/XPD-mm. +module (span in the terms of Dahdi) there is folder /proc/XBUS-nn/XPD-mm. /proc/xpp/XBUS-nn/waitfor_xpds @@ -1136,23 +1128,23 @@ reading from this file returns immediately: XPDS_READY: XBUS-00: 3/3 -/proc/xpp/XBUS-nn/XPD-mm/zt_registration +/proc/xpp/XBUS-nn/XPD-mm/dahdi_registration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ is a read/write file. Reading from it gives 0 if the span is unregistered, or the span number if it is registered. -Writing to it allows manual registration / unregistration from Zaptel: +Writing to it allows manual registration / unregistration from Dahdi: writing 1 registers a span (if it wasn't already registered) and writing 0 attempts to unregister it (if it is registered. Span unregistration will fail if some channels from the span are used (e.g: by Asterisk). -A more convenient interface to this is the command zt_registration that +A more convenient interface to this is the command dahdi_registration that registers or unregisters all the spans at once with a predefined order, and this is what you should normally use. Alternatively you can use the parameter zap_autoreg to register spans automatically. But this is only recommended on a system with a single -Astribank and no other Zaptel device. +Astribank and no other Dahdi device. /proc/xpp/XBUS-nn/XPD-mm/summary @@ -1216,7 +1208,7 @@ the contents of the channel that is supposed to be the D channel. Writing to this file can be used to change the type of the device. The device type can only be changed when the XPD is not registered as a -Zaptel span. The value is a whitespace-separated list of values that can +Dahdi span. The value is a whitespace-separated list of values that can be of: E1:: @@ -1248,7 +1240,7 @@ NOLOCALLOOP:: Normally those are set by the PRI initialization script . See the definition of XPP_PRI_SETUP in -xref:_zaptel_init_configuration_file[the sample Zaptel init +xref:dahdi_init_configuration_file[the sample Dahdi init configuration file] . @@ -1264,7 +1256,7 @@ for each Astribank (such as its connector string). On each time an Astribank is initialized or destroyed a udev event is generated. The rules from our sample udev rules file (xpp/utils/xpp.rules) -make that event run the script /usr/share/zaptel/astribank_hook with the +make that event run the script /usr/share/dahdi/astribank_hook with the parameter 'add' or 'remove', if such script exists. An example script that just adjusts the Astribank sync settings is included in xpp/utils. @@ -1296,13 +1288,13 @@ description line for the parameter in the "modinfo" command output. zap_autoreg (xpp):: Register spans automatically (1) or not (0). Default: 0. Setting it simplifies operations with a single Astribank and no other - Zaptel hardware. However if you have such systems, automatic + Dahdi hardware. However if you have such systems, automatic registration can cause the order of spans to be unpredictable. - The standard startup scripts use 'zt_registration on' instead of this. + The standard startup scripts use 'dahdi_registration on' instead of this. initdir (xpp):: This is the directory containing the initialization scripts. - The default is /usr/share/zaptel . + The default is /usr/share/dahdi . Setting this value could be useful if that location is inconvenient for you. rx_tasklet (xpp):: @@ -1322,7 +1314,7 @@ debug (all modules):: * 4 - LEDS - Anything related to the LEDs status control. The driver produces a lot of messages when the option is enabled. * 8 - SYNC - Synchronization related messages. - * 16 - SIGNAL - Zaptel signalling related messages. + * 16 - SIGNAL - Dahdi signalling related messages. * 32 - PROC - Messages related to the procfs interface. * 64 - REGS - Reading and writing to chip registers. Tends to flood logs. diff --git a/drivers/dahdi/xpp/card_bri.c b/drivers/dahdi/xpp/card_bri.c index b737b7b..150e754 100644 --- a/drivers/dahdi/xpp/card_bri.c +++ b/drivers/dahdi/xpp/card_bri.c @@ -28,9 +28,9 @@ #include #include "xpd.h" #include "xproto.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "card_bri.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xbus-core.h" static const char rcsid[] = "$Id$"; @@ -39,7 +39,7 @@ static const char rcsid[] = "$Id$"; #error CONFIG_ZAPATA_BRI_DCHANS is not defined #endif -static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ +static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ static DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)"); static DEF_PARM_BOOL(nt_keepalive, 1, 0644, "Force BRI_NT to keep trying connection"); @@ -505,7 +505,7 @@ static int rx_dchan(xpd_t *xpd, reg_cmd_t *regcmd) if(debug) dump_dchan_packet(xpd, 0, dchan_buf, idx /* - 3 */); /* Print checksum? */ /* - * Tell Zaptel that we received idx-1 bytes. They include the data and a 2-byte checksum. + * Tell Dahdi that we received idx-1 bytes. They include the data and a 2-byte checksum. * The last byte (that we don't pass on) is 0 if the checksum is correct. If it were wrong, * we would drop the packet in the "if(dchan_buf[idx-1])" above. */ @@ -655,7 +655,7 @@ static int BRI_card_remove(xbus_t *xbus, xpd_t *xpd) return 0; } -static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) +static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct BRI_priv_data *priv; @@ -737,7 +737,7 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) return 0; } -static int BRI_card_zaptel_postregistration(xpd_t *xpd, bool on) +static int BRI_card_dahdi_postregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct BRI_priv_data *priv; @@ -956,7 +956,7 @@ static int BRI_card_close(xpd_t *xpd, lineno_t pos) } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int bri_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc) { @@ -999,8 +999,8 @@ static int bri_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc) /* * Set signalling type (if appropriate) - * Called from zaptel with spinlock held on chan. Must not call back - * zaptel functions. + * Called from dahdi with spinlock held on chan. Must not call back + * dahdi functions. */ static int bri_chanconfig(struct dahdi_chan *chan, int sigtype) { @@ -1012,7 +1012,7 @@ static int bri_chanconfig(struct dahdi_chan *chan, int sigtype) } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int bri_startup(struct dahdi_span *span) { @@ -1024,7 +1024,7 @@ static int bri_startup(struct dahdi_span *span) priv = xpd->priv; BUG_ON(!priv); if(!TRANSPORT_RUNNING(xpd->xbus)) { - XPD_DBG(GENERAL, xpd, "Startup called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Startup called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "STARTUP\n"); @@ -1034,10 +1034,10 @@ static int bri_startup(struct dahdi_span *span) dchan = &span->chans[2]; span->flags |= DAHDI_FLAG_RUNNING; /* - * Zaptel (wrongly) assume that D-Channel need HDLC decoding - * and during zaptel registration override our flags. + * Dahdi (wrongly) assume that D-Channel need HDLC decoding + * and during dahdi registration override our flags. * - * Don't Get Mad, Get Even: Now we override zaptel :-) + * Don't Get Mad, Get Even: Now we override dahdi :-) */ dchan->flags |= DAHDI_FLAG_BRIDCHAN; dchan->flags &= ~DAHDI_FLAG_HDLC; @@ -1046,7 +1046,7 @@ static int bri_startup(struct dahdi_span *span) } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int bri_shutdown(struct dahdi_span *span) { @@ -1057,7 +1057,7 @@ static int bri_shutdown(struct dahdi_span *span) priv = xpd->priv; BUG_ON(!priv); if(!TRANSPORT_RUNNING(xpd->xbus)) { - XPD_DBG(GENERAL, xpd, "Shutdown called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Shutdown called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); @@ -1391,8 +1391,8 @@ static xproto_table_t PROTO_TABLE(BRI) = { .card_new = BRI_card_new, .card_init = BRI_card_init, .card_remove = BRI_card_remove, - .card_zaptel_preregistration = BRI_card_zaptel_preregistration, - .card_zaptel_postregistration = BRI_card_zaptel_postregistration, + .card_dahdi_preregistration = BRI_card_dahdi_preregistration, + .card_dahdi_postregistration = BRI_card_dahdi_postregistration, .card_hooksig = BRI_card_hooksig, .card_tick = BRI_card_tick, .card_pcm_fromspan = BRI_card_pcm_fromspan, diff --git a/drivers/dahdi/xpp/card_fxo.c b/drivers/dahdi/xpp/card_fxo.c index 9ab2bbe..d7e1510 100644 --- a/drivers/dahdi/xpp/card_fxo.c +++ b/drivers/dahdi/xpp/card_fxo.c @@ -26,9 +26,9 @@ #include #include "xpd.h" #include "xproto.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "card_fxo.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xbus-core.h" static const char rcsid[] = "$Id$"; @@ -97,7 +97,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in #ifdef WITH_METERING static int proc_xpd_metering_read(char *page, char **start, off_t off, int count, int *eof, void *data); #endif -static void zap_report_battery(xpd_t *xpd, lineno_t chan); +static void dahdi_report_battery(xpd_t *xpd, lineno_t chan); #define PROC_REGISTER_FNAME "slics" #define PROC_FXO_INFO_FNAME "fxo_info" @@ -261,7 +261,7 @@ static void handle_fxo_leds(xpd_t *xpd) spin_unlock_irqrestore(&xpd->lock, flags); } -static void update_zap_ring(xpd_t *xpd, int pos, bool on) +static void update_dahdi_ring(xpd_t *xpd, int pos, bool on) { dahdi_rxsig_t rxsig; @@ -289,7 +289,7 @@ static void update_zap_ring(xpd_t *xpd, int pos, bool on) dahdi_hooksig(&xpd->chans[pos], rxsig); } -static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_zap) +static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi) { struct FXO_priv_data *priv; @@ -305,15 +305,15 @@ static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_zap) LINE_DBG(SIGNAL, xpd, pos, "START\n"); xpd->ringing[pos] = 1; MARK_BLINK(priv, pos, LED_GREEN, LED_BLINK_RING); - if(update_zap) - update_zap_ring(xpd, pos, on); + if(update_dahdi) + update_dahdi_ring(xpd, pos, on); } else if(!on && xpd->ringing[pos]) { LINE_DBG(SIGNAL, xpd, pos, "STOP\n"); xpd->ringing[pos] = 0; if(IS_BLINKING(priv, pos, LED_GREEN)) MARK_BLINK(priv, pos, LED_GREEN, 0); - if(update_zap) - update_zap_ring(xpd, pos, on); + if(update_dahdi) + update_dahdi_ring(xpd, pos, on); } } @@ -494,7 +494,7 @@ static int FXO_card_remove(xbus_t *xbus, xpd_t *xpd) return 0; } -static int FXO_card_zaptel_preregistration(xpd_t *xpd, bool on) +static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct FXO_priv_data *priv; @@ -527,7 +527,7 @@ static int FXO_card_zaptel_preregistration(xpd_t *xpd, bool on) return 0; } -static int FXO_card_zaptel_postregistration(xpd_t *xpd, bool on) +static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct FXO_priv_data *priv; @@ -540,7 +540,7 @@ static int FXO_card_zaptel_postregistration(xpd_t *xpd, bool on) BUG_ON(!priv); XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); for_each_line(xpd, i) { - zap_report_battery(xpd, i); + dahdi_report_battery(xpd, i); MARK_OFF(priv, i, LED_GREEN); msleep(2); MARK_OFF(priv, i, LED_RED); @@ -577,7 +577,7 @@ static int FXO_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, dahdi_txsig_t txs return ret; } -static void zap_report_battery(xpd_t *xpd, lineno_t chan) +static void dahdi_report_battery(xpd_t *xpd, lineno_t chan) { struct FXO_priv_data *priv; @@ -856,7 +856,7 @@ static void update_battery_voltage(xpd_t *xpd, byte data_low, xportno_t portno) LINE_DBG(SIGNAL, xpd, portno, "BATTERY OFF voltage=%d\n", data_low); priv->battery[portno] = BATTERY_OFF; if(SPAN_REGISTERED(xpd)) - zap_report_battery(xpd, portno); + dahdi_report_battery(xpd, portno); priv->polarity[portno] = POL_UNKNOWN; /* What's the polarity ? */ priv->power[portno] = POWER_UNKNOWN; /* What's the current ? */ /* @@ -872,7 +872,7 @@ static void update_battery_voltage(xpd_t *xpd, byte data_low, xportno_t portno) LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n", data_low); priv->battery[portno] = BATTERY_ON; if(SPAN_REGISTERED(xpd)) - zap_report_battery(xpd, portno); + dahdi_report_battery(xpd, portno); } } #if 0 @@ -923,7 +923,7 @@ static void update_battery_voltage(xpd_t *xpd, byte data_low, xportno_t portno) LINE_DBG(SIGNAL, xpd, portno, "Polarity changed to %s\n", polname); /* - * Inform zaptel/Asterisk: + * Inform dahdi/Asterisk: * 1. Maybe used for hangup detection during offhook * 2. In some countries used to report caller-id during onhook * but before first ring. @@ -1066,8 +1066,8 @@ static xproto_table_t PROTO_TABLE(FXO) = { .card_new = FXO_card_new, .card_init = FXO_card_init, .card_remove = FXO_card_remove, - .card_zaptel_preregistration = FXO_card_zaptel_preregistration, - .card_zaptel_postregistration = FXO_card_zaptel_postregistration, + .card_dahdi_preregistration = FXO_card_dahdi_preregistration, + .card_dahdi_postregistration = FXO_card_dahdi_postregistration, .card_hooksig = FXO_card_hooksig, .card_tick = FXO_card_tick, .card_pcm_fromspan = generic_card_pcm_fromspan, diff --git a/drivers/dahdi/xpp/card_fxs.c b/drivers/dahdi/xpp/card_fxs.c index 055f89e..d17571b 100644 --- a/drivers/dahdi/xpp/card_fxs.c +++ b/drivers/dahdi/xpp/card_fxs.c @@ -26,14 +26,14 @@ #include #include "xpd.h" #include "xproto.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "card_fxo.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xbus-core.h" static const char rcsid[] = "$Id$"; -static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ +static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ static DEF_PARM_BOOL(reversepolarity, 0, 0644, "Reverse Line Polarity"); static DEF_PARM_BOOL(vmwineon, 0, 0644, "Indicate voicemail to a neon lamp"); static DEF_PARM_BOOL(dtmf_detection, 1, 0644, "Do DTMF detection in hardware"); @@ -130,8 +130,8 @@ struct FXS_priv_data { xpp_line_t search_fsk_pattern; xpp_line_t found_fsk_pattern; xpp_line_t update_offhook_state; - xpp_line_t want_dtmf_events; /* what zaptel want */ - xpp_line_t want_dtmf_mute; /* what zaptel want */ + xpp_line_t want_dtmf_events; /* what dahdi want */ + xpp_line_t want_dtmf_mute; /* what dahdi want */ int led_counter[NUM_LEDS][CHANNELS_PERXPD]; int ohttimer[CHANNELS_PERXPD]; #define OHT_TIMER 6000 /* How long after RING to retain OHT */ @@ -465,7 +465,7 @@ static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd) return 0; } -static int FXS_card_zaptel_preregistration(xpd_t *xpd, bool on) +static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct FXS_priv_data *priv; @@ -506,7 +506,7 @@ static int FXS_card_zaptel_preregistration(xpd_t *xpd, bool on) return 0; } -static int FXS_card_zaptel_postregistration(xpd_t *xpd, bool on) +static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct FXS_priv_data *priv; @@ -894,9 +894,9 @@ static int FXS_card_open(xpd_t *xpd, lineno_t chan) else LINE_DBG(SIGNAL, xpd, chan, "is onhook\n"); /* - * Delegate updating zaptel to FXS_card_tick(): + * Delegate updating dahdi to FXS_card_tick(): * The problem is that dahdi_hooksig() is spinlocking the channel and - * we are called by zaptel with the spinlock already held on the + * we are called by dahdi with the spinlock already held on the * same channel. */ BIT_SET(priv->update_offhook_state, chan); @@ -1065,7 +1065,7 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd) if(!IS_SET(priv->update_offhook_state, i)) continue; /* - * Update zaptel with current state of line. + * Update dahdi with current state of line. */ if(IS_SET(xpd->offhook, i)) { update_line_status(xpd, i, 1); @@ -1312,8 +1312,8 @@ static xproto_table_t PROTO_TABLE(FXS) = { .card_new = FXS_card_new, .card_init = FXS_card_init, .card_remove = FXS_card_remove, - .card_zaptel_preregistration = FXS_card_zaptel_preregistration, - .card_zaptel_postregistration = FXS_card_zaptel_postregistration, + .card_dahdi_preregistration = FXS_card_dahdi_preregistration, + .card_dahdi_postregistration = FXS_card_dahdi_postregistration, .card_hooksig = FXS_card_hooksig, .card_tick = FXS_card_tick, .card_pcm_fromspan = generic_card_pcm_fromspan, diff --git a/drivers/dahdi/xpp/card_global.c b/drivers/dahdi/xpp/card_global.c index 7a3d101..4bc577f 100644 --- a/drivers/dahdi/xpp/card_global.c +++ b/drivers/dahdi/xpp/card_global.c @@ -24,15 +24,15 @@ #include #include "xdefs.h" #include "xpd.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "xproto.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xbus-core.h" #include "parport_debug.h" static const char rcsid[] = "$Id$"; -DEF_PARM(charp,initdir, "/usr/share/zaptel", 0644, "The directory of card initialization scripts"); +DEF_PARM(charp,initdir, "/usr/share/dahdi", 0644, "The directory of card initialization scripts"); #define CHIP_REGISTERS "chipregs" diff --git a/drivers/dahdi/xpp/card_pri.c b/drivers/dahdi/xpp/card_pri.c index 8b920bf..e1670a0 100644 --- a/drivers/dahdi/xpp/card_pri.c +++ b/drivers/dahdi/xpp/card_pri.c @@ -28,15 +28,15 @@ #include #include "xpd.h" #include "xproto.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "card_pri.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xpd.h" #include "xbus-core.h" static const char rcsid[] = "$Id$"; -static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ +static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ static DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)"); #define PRI_LINES_BITMASK BITMASK(31) @@ -474,7 +474,7 @@ static int set_pri_proto(xpd_t *xpd, enum pri_protocol set_proto) return 0; } -static void zap_update_syncsrc(xpd_t *xpd) +static void dahdi_update_syncsrc(xpd_t *xpd) { struct PRI_priv_data *priv; xpd_t *subxpd; @@ -562,18 +562,18 @@ static void set_clocking(xpd_t *xpd) priv->clock_source = 0; } } - zap_update_syncsrc(xpd); + dahdi_update_syncsrc(xpd); put_xbus(xbus); } /* - * Normally set by the timing parameter in zaptel.conf + * Normally set by the timing parameter in dahdi.conf * If this is called by ztcfg, than it's too late to change - * zaptel sync priority (we are already registered) + * dahdi sync priority (we are already registered) * There are two workarounds to mitigate this problem: * 1. So we set *our* sync master at least. * 2. And we try to call it with a sane default from set_nt() - * which is called before zaptel registration. + * which is called before dahdi registration. */ static int set_master_mode(const char *msg, xpd_t *xpd) { @@ -779,7 +779,7 @@ bad_lineconfig: } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int pri_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc) @@ -796,7 +796,7 @@ static int pri_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc) return -EINVAL; } /* - * FIXME: lc->name is unused by ztcfg and zaptel... + * FIXME: lc->name is unused by ztcfg and dahdi... * We currently ignore it also. */ XPD_DBG(GENERAL, xpd, "[%s] lbo=%d lineconfig=0x%X sync=%d\n", @@ -813,8 +813,8 @@ static int pri_spanconfig(struct dahdi_span *span, struct dahdi_lineconfig *lc) /* * Set signalling type (if appropriate) - * Called from zaptel with spinlock held on chan. Must not call back - * zaptel functions. + * Called from dahdi with spinlock held on chan. Must not call back + * dahdi functions. */ static int pri_chanconfig(struct dahdi_chan *chan, int sigtype) { @@ -898,7 +898,7 @@ static int PRI_card_remove(xbus_t *xbus, xpd_t *xpd) return 0; } -static int PRI_card_zaptel_preregistration(xpd_t *xpd, bool on) +static int PRI_card_dahdi_preregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct PRI_priv_data *priv; @@ -947,7 +947,7 @@ static int PRI_card_zaptel_preregistration(xpd_t *xpd, bool on) return 0; } -static int PRI_card_zaptel_postregistration(xpd_t *xpd, bool on) +static int PRI_card_dahdi_postregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct PRI_priv_data *priv; @@ -957,7 +957,7 @@ static int PRI_card_zaptel_postregistration(xpd_t *xpd, bool on) priv = xpd->priv; BUG_ON(!xbus); XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); - zap_update_syncsrc(xpd); + dahdi_update_syncsrc(xpd); return(0); } @@ -1124,7 +1124,7 @@ static int PRI_card_close(xpd_t *xpd, lineno_t pos) } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int pri_startup(struct dahdi_span *span) { @@ -1135,7 +1135,7 @@ static int pri_startup(struct dahdi_span *span) priv = xpd->priv; BUG_ON(!priv); if(!TRANSPORT_RUNNING(xpd->xbus)) { - XPD_DBG(GENERAL, xpd, "Startup called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Startup called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "STARTUP\n"); @@ -1145,7 +1145,7 @@ static int pri_startup(struct dahdi_span *span) } /* - * Called only for 'span' keyword in /etc/zaptel.conf + * Called only for 'span' keyword in /etc/dahdi.conf */ static int pri_shutdown(struct dahdi_span *span) { @@ -1156,7 +1156,7 @@ static int pri_shutdown(struct dahdi_span *span) priv = xpd->priv; BUG_ON(!priv); if(!TRANSPORT_RUNNING(xpd->xbus)) { - XPD_DBG(GENERAL, xpd, "Shutdown called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Shutdown called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); @@ -1437,8 +1437,8 @@ static xproto_table_t PROTO_TABLE(PRI) = { .card_new = PRI_card_new, .card_init = PRI_card_init, .card_remove = PRI_card_remove, - .card_zaptel_preregistration = PRI_card_zaptel_preregistration, - .card_zaptel_postregistration = PRI_card_zaptel_postregistration, + .card_dahdi_preregistration = PRI_card_dahdi_preregistration, + .card_dahdi_postregistration = PRI_card_dahdi_postregistration, .card_hooksig = PRI_card_hooksig, .card_tick = PRI_card_tick, .card_pcm_fromspan = PRI_card_pcm_fromspan, diff --git a/drivers/dahdi/xpp/dahdi_debug.c b/drivers/dahdi/xpp/dahdi_debug.c new file mode 100644 index 0000000..0e0261d --- /dev/null +++ b/drivers/dahdi/xpp/dahdi_debug.c @@ -0,0 +1,91 @@ +/* + * Written by Oron Peled + * Copyright (C) 2004-2006, Xorcom + * + * All rights reserved. + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +# warning "This module is tested only with 2.6 kernels" +#endif + +#include +#include +#include +#include +#include "dahdi_debug.h" +#include "xdefs.h" + +static const char rcsid[] = "$Id$"; + +#define P_(x) [ x ] = { .value = x, .name = #x, } +static struct { + int value; + char *name; +} poll_names[] = { + P_(POLLIN), + P_(POLLPRI), + P_(POLLOUT), + P_(POLLERR), + P_(POLLHUP), + P_(POLLNVAL), + P_(POLLRDNORM), + P_(POLLRDBAND), + P_(POLLWRNORM), + P_(POLLWRBAND), + P_(POLLMSG), + P_(POLLREMOVE) +}; +#undef P_ + +void dump_poll(int debug, const char *msg, int poll) +{ + int i; + + for(i = 0; i < ARRAY_SIZE(poll_names); i++) { + if(poll & poll_names[i].value) + DBG(GENERAL, "%s: %s\n", msg, poll_names[i].name); + } +} + +void alarm2str(int alarm, char *buf, int buflen) +{ + char *p = buf; + int left = buflen; + int i; + int n; + + if(!alarm) { + snprintf(buf, buflen, "NONE"); + return; + } + memset(buf, 0, buflen); + for(i = 0; i < 8; i++) { + if(left && (alarm & BIT(i))) { + n = snprintf(p, left, "%s,", alarmbit2str(i)); + p += n; + left -= n; + } + } + if(p > buf) /* kill last comma */ + *(p - 1) = '\0'; +} + +EXPORT_SYMBOL(dump_poll); +EXPORT_SYMBOL(alarm2str); diff --git a/drivers/dahdi/xpp/dahdi_debug.h b/drivers/dahdi/xpp/dahdi_debug.h new file mode 100644 index 0000000..753fa1a --- /dev/null +++ b/drivers/dahdi/xpp/dahdi_debug.h @@ -0,0 +1,201 @@ +#ifndef DAHDI_DEBUG_H +#define DAHDI_DEBUG_H +/* + * Written by Oron Peled + * Copyright (C) 2004-2006, Xorcom + * + * All rights reserved. + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include /* for dahdi_* defs */ + +/* Debugging Macros */ + +#define PRINTK(level, category, fmt, ...) \ + printk(KERN_ ## level "%s%s-%s: " fmt, #level, category, THIS_MODULE->name, ## __VA_ARGS__) + +#define XBUS_PRINTK(level, category, xbus, fmt, ...) \ + printk(KERN_ ## level "%s%s-%s: %s: " fmt, #level, \ + category, THIS_MODULE->name, (xbus)->busname, ## __VA_ARGS__) + +#define XPD_PRINTK(level, category, xpd, fmt, ...) \ + printk(KERN_ ## level "%s%s-%s: %s/%s: " fmt, #level, \ + category, THIS_MODULE->name, (xpd)->xbus->busname, (xpd)->xpdname, ## __VA_ARGS__) + +#define LINE_PRINTK(level, category, xpd, pos, fmt, ...) \ + printk(KERN_ ## level "%s%s-%s: %s/%s/%d: " fmt, #level, \ + category, THIS_MODULE->name, (xpd)->xbus->busname, (xpd)->xpdname, (pos), ## __VA_ARGS__) + +#define PORT_PRINTK(level, category, xbus, unit, port, fmt, ...) \ + printk(KERN_ ## level "%s%s-%s: %s UNIT=%d PORT=%d: " fmt, #level, \ + category, THIS_MODULE->name, (xbus)->busname, (unit), (port), ## __VA_ARGS__) + +#define DBG(bits, fmt, ...) \ + ((void)((debug & (DBG_ ## bits)) && PRINTK(DEBUG, "-" #bits, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define INFO(fmt, ...) PRINTK(INFO, "", fmt, ## __VA_ARGS__) +#define NOTICE(fmt, ...) PRINTK(NOTICE, "", fmt, ## __VA_ARGS__) +#define WARNING(fmt, ...) PRINTK(WARNING, "", fmt, ## __VA_ARGS__) +#define ERR(fmt, ...) PRINTK(ERR, "", fmt, ## __VA_ARGS__) + +#define XBUS_DBG(bits, xbus, fmt, ...) \ + ((void)((debug & (DBG_ ## bits)) && XBUS_PRINTK(DEBUG, "-" #bits, xbus, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define XBUS_INFO(xbus, fmt, ...) XBUS_PRINTK(INFO, "", xbus, fmt, ## __VA_ARGS__) +#define XBUS_NOTICE(xbus, fmt, ...) XBUS_PRINTK(NOTICE, "", xbus, fmt, ## __VA_ARGS__) +#define XBUS_ERR(xbus, fmt, ...) XBUS_PRINTK(ERR, "", xbus, fmt, ## __VA_ARGS__) + +#define XPD_DBG(bits, xpd, fmt, ...) \ + ((void)((debug & (DBG_ ## bits)) && XPD_PRINTK(DEBUG, "-" #bits, xpd, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define XPD_INFO(xpd, fmt, ...) XPD_PRINTK(INFO, "", xpd, fmt, ## __VA_ARGS__) +#define XPD_NOTICE(xpd, fmt, ...) XPD_PRINTK(NOTICE, "", xpd, fmt, ## __VA_ARGS__) +#define XPD_WARNING(xpd, fmt, ...) XPD_PRINTK(WARNING, "", xpd, fmt, ## __VA_ARGS__) +#define XPD_ERR(xpd, fmt, ...) XPD_PRINTK(ERR, "", xpd, fmt, ## __VA_ARGS__) + +#define LINE_DBG(bits, xpd, pos, fmt, ...) \ + ((void)((debug & (DBG_ ## bits)) && LINE_PRINTK(DEBUG, "-" #bits, xpd, pos, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define LINE_NOTICE(xpd, pos, fmt, ...) LINE_PRINTK(NOTICE, "", xpd, pos, fmt, ## __VA_ARGS__) +#define LINE_ERR(xpd, pos, fmt, ...) LINE_PRINTK(ERR, "", xpd, pos, fmt, ## __VA_ARGS__) + +#define PORT_DBG(bits, xbus, unit, port, fmt, ...) \ + ((void)((debug & (DBG_ ## bits)) && PORT_PRINTK(DEBUG, "-" #bits, \ + xbus, unit, port, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define PORT_NOTICE(xbus, unit, port, fmt, ...) PORT_PRINTK(NOTICE, "", xbus, unit, port, fmt, ## __VA_ARGS__) +#define PORT_ERR(xbus, unit, port, fmt, ...) PORT_PRINTK(ERR, "", xbus, unit, port, fmt, ## __VA_ARGS__) + +/* + * Bits for debug + */ +#define DBG_GENERAL BIT(0) +#define DBG_PCM BIT(1) +#define DBG_LEDS BIT(2) +#define DBG_SYNC BIT(3) +#define DBG_SIGNAL BIT(4) +#define DBG_PROC BIT(5) +#define DBG_REGS BIT(6) +#define DBG_DEVICES BIT(7) /* instantiation/destruction etc. */ +#define DBG_COMMANDS BIT(8) /* All commands */ +#define DBG_ANY (~0) + +void dump_poll(int debug, const char *msg, int poll); + +static inline char *rxsig2str(dahdi_rxsig_t sig) +{ + switch(sig) { + case DAHDI_RXSIG_ONHOOK: return "ONHOOK"; + case DAHDI_RXSIG_OFFHOOK: return "OFFHOOK"; + case DAHDI_RXSIG_START: return "START"; + case DAHDI_RXSIG_RING: return "RING"; + case DAHDI_RXSIG_INITIAL: return "INITIAL"; + } + return "Unknown rxsig"; +} + +static inline char *txsig2str(dahdi_txsig_t sig) +{ + switch(sig) { + case DAHDI_TXSIG_ONHOOK: return "TXSIG_ONHOOK"; + case DAHDI_TXSIG_OFFHOOK: return "TXSIG_OFFHOOK"; + case DAHDI_TXSIG_START: return "TXSIG_START"; + case DAHDI_TXSIG_KEWL: return "TXSIG_KEWL"; /* Drop battery if possible */ + } + return "Unknown txsig"; +} + +static inline char *event2str(int event) +{ + switch(event) { + case DAHDI_EVENT_NONE: return "NONE"; + case DAHDI_EVENT_ONHOOK: return "ONHOOK"; + case DAHDI_EVENT_RINGOFFHOOK: return "RINGOFFHOOK"; + case DAHDI_EVENT_WINKFLASH: return "WINKFLASH"; + case DAHDI_EVENT_ALARM: return "ALARM"; + case DAHDI_EVENT_NOALARM: return "NOALARM"; + case DAHDI_EVENT_ABORT: return "ABORT"; + case DAHDI_EVENT_OVERRUN: return "OVERRUN"; + case DAHDI_EVENT_BADFCS: return "BADFCS"; + case DAHDI_EVENT_DIALCOMPLETE: return "DIALCOMPLETE"; + case DAHDI_EVENT_RINGERON: return "RINGERON"; + case DAHDI_EVENT_RINGEROFF: return "RINGEROFF"; + case DAHDI_EVENT_HOOKCOMPLETE: return "HOOKCOMPLETE"; + case DAHDI_EVENT_BITSCHANGED: return "BITSCHANGED"; + case DAHDI_EVENT_PULSE_START: return "PULSE_START"; + case DAHDI_EVENT_TIMER_EXPIRED: return "TIMER_EXPIRED"; + case DAHDI_EVENT_TIMER_PING: return "TIMER_PING"; + case DAHDI_EVENT_POLARITY: return "POLARITY"; + } + return "Unknown event"; +} + +static inline char *hookstate2str(int hookstate) +{ + switch(hookstate) { + case DAHDI_ONHOOK: return "DAHDI_ONHOOK"; + case DAHDI_START: return "DAHDI_START"; + case DAHDI_OFFHOOK: return "DAHDI_OFFHOOK"; + case DAHDI_WINK: return "DAHDI_WINK"; + case DAHDI_FLASH: return "DAHDI_FLASH"; + case DAHDI_RING: return "DAHDI_RING"; + case DAHDI_RINGOFF: return "DAHDI_RINGOFF"; + } + return "Unknown hookstate"; +} + +/* From dahdi-base.c */ +static inline char *sig2str(int sig) +{ + switch (sig) { + case DAHDI_SIG_FXSLS: return "FXSLS"; + case DAHDI_SIG_FXSKS: return "FXSKS"; + case DAHDI_SIG_FXSGS: return "FXSGS"; + case DAHDI_SIG_FXOLS: return "FXOLS"; + case DAHDI_SIG_FXOKS: return "FXOKS"; + case DAHDI_SIG_FXOGS: return "FXOGS"; + case DAHDI_SIG_EM: return "E&M"; + case DAHDI_SIG_EM_E1: return "E&M-E1"; + case DAHDI_SIG_CLEAR: return "Clear"; + case DAHDI_SIG_HDLCRAW: return "HDLCRAW"; + case DAHDI_SIG_HDLCFCS: return "HDLCFCS"; + case DAHDI_SIG_HDLCNET: return "HDLCNET"; + case DAHDI_SIG_SLAVE: return "Slave"; + case DAHDI_SIG_CAS: return "CAS"; + case DAHDI_SIG_DACS: return "DACS"; + case DAHDI_SIG_DACS_RBS: return "DACS+RBS"; + case DAHDI_SIG_SF: return "SF (ToneOnly)"; + case DAHDI_SIG_NONE: + break; + } + return "Unconfigured"; +} + +static inline char *alarmbit2str(int alarmbit) +{ + /* from dahdi/kernel.h */ + switch(1 << alarmbit) { + case DAHDI_ALARM_NONE: return "NONE"; + case DAHDI_ALARM_RECOVER: return "RECOVER"; + case DAHDI_ALARM_LOOPBACK: return "LOOPBACK"; + case DAHDI_ALARM_YELLOW: return "YELLOW"; + case DAHDI_ALARM_RED: return "RED"; + case DAHDI_ALARM_BLUE: return "BLUE"; + case DAHDI_ALARM_NOTOPEN: return "NOTOPEN"; + } + return "UNKNOWN"; +} + +void alarm2str(int alarm, char *buf, int buflen); + +#endif /* DAHDI_DEBUG_H */ diff --git a/drivers/dahdi/xpp/mmapdrv.c b/drivers/dahdi/xpp/mmapdrv.c index d63ca12..c3ce708 100644 --- a/drivers/dahdi/xpp/mmapdrv.c +++ b/drivers/dahdi/xpp/mmapdrv.c @@ -13,7 +13,7 @@ #include #include "mmapbus.h" #include "xbus-core.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include "xdefs.h" #include "xproto.h" #include "xframe_queue.h" @@ -526,7 +526,7 @@ static int __init xpp_mmap_init(void) ret = -ENOMEM; goto fail_cache; } - /* interface with Zaptel */ + /* interface with Dahdi */ global_xbus = xbus_new(&xmmap_ops, XFRAME_DATASIZE, NULL); if (!global_xbus) { ret = -ENOMEM; diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c index 26c31f5..21f9c45 100644 --- a/drivers/dahdi/xpp/xbus-core.c +++ b/drivers/dahdi/xpp/xbus-core.c @@ -36,13 +36,13 @@ #include #include /* for msleep() to debug */ #include "xpd.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "xbus-core.h" #include "card_global.h" #ifdef XPP_DEBUGFS #include "xpp_log.h" #endif -#include "zap_debug.h" +#include "dahdi_debug.h" static const char rcsid[] = "$Id$"; diff --git a/drivers/dahdi/xpp/xbus-pcm.c b/drivers/dahdi/xpp/xbus-pcm.c index 8f1b294..5f6ed8d 100644 --- a/drivers/dahdi/xpp/xbus-pcm.c +++ b/drivers/dahdi/xpp/xbus-pcm.c @@ -29,8 +29,8 @@ #include #include "xbus-pcm.h" #include "xbus-core.h" -#include "xpp_zap.h" -#include "zap_debug.h" +#include "xpp_dahdi.h" +#include "dahdi_debug.h" #include "parport_debug.h" static const char rcsid[] = "$Id$"; @@ -38,7 +38,7 @@ static const char rcsid[] = "$Id$"; extern int debug; #ifdef XPP_EC_CHUNK #include "supress/ec_xpp.h" -DEF_PARM_BOOL(xpp_ec, 0, 0444, "Do we use our own (1) or Zaptel's (0) echo canceller"); +DEF_PARM_BOOL(xpp_ec, 0, 0444, "Do we use our own (1) or Dahdi's (0) echo canceller"); #endif #ifdef OPTIMIZE_CHANMUTE static DEF_PARM_BOOL(optimize_chanmute, 1, 0644, "Optimize by muting inactive channels"); @@ -53,14 +53,14 @@ static DEF_PARM_BOOL(disable_pll_sync, 0, 0644, "Disable automatic adjustment of static xbus_t *syncer; /* current syncer */ static atomic_t xpp_tick_counter = ATOMIC_INIT(0); -static struct xpp_ticker zaptel_ticker; +static struct xpp_ticker dahdi_ticker; /* * The ref_ticker points to the current referece tick source. - * I.e: one of our AB or zaptel_ticker + * I.e: one of our AB or dahdi_ticker */ static struct xpp_ticker *ref_ticker = NULL; static spinlock_t ref_ticker_lock = SPIN_LOCK_UNLOCKED; -static bool force_zaptel_sync = 0; /* from "/proc/xpp/sync" */ +static bool force_dahdi_sync = 0; /* from "/proc/xpp/sync" */ static xbus_t *global_ticker; static struct xpp_ticker global_ticks_series; @@ -76,8 +76,8 @@ static struct xpp_ticker global_ticks_series; #define SYNC_ADJ_QUICK 1000 #define SYNC_ADJ_SLOW 10000 -#ifdef ZAPTEL_SYNC_TICK -static unsigned int zaptel_tick_count = 0; +#ifdef DAHDI_SYNC_TICK +static unsigned int dahdi_tick_count = 0; #endif /*------------------------- SYNC Handling --------------------------*/ @@ -431,40 +431,40 @@ static void global_tick(void) xpp_ticker_step(&global_ticks_series, &now); } -#ifdef ZAPTEL_SYNC_TICK -int zaptel_sync_tick(struct dahdi_span *span, int is_master) +#ifdef DAHDI_SYNC_TICK +int dahdi_sync_tick(struct dahdi_span *span, int is_master) { xpd_t *xpd = span->pvt; static int redundant_ticks; /* for extra spans */ struct timeval now; - if(!force_zaptel_sync) + if(!force_dahdi_sync) goto noop; do_gettimeofday(&now); BUG_ON(!xpd); /* - * Detect if any of our spans is zaptel sync master + * Detect if any of our spans is dahdi sync master */ if(is_master) { static int rate_limit; if(xpd->xbus != syncer && ((rate_limit % 1003) == 0)) { XPD_ERR(xpd, - "Zaptel master, but syncer=%s\n", + "Dahdi master, but syncer=%s\n", xpd->xbus->busname); } if((rate_limit % 5003) == 0) - XPD_NOTICE(xpd, "Zaptel master: ignore ZAPTEL sync\n"); + XPD_NOTICE(xpd, "Dahdi master: ignore DAHDI sync\n"); rate_limit++; goto noop; } - /* Now we know for sure someone else is zaptel sync master */ + /* Now we know for sure someone else is dahdi sync master */ if(syncer) { static int rate_limit; if((rate_limit++ % 5003) == 0) XBUS_DBG(SYNC, syncer, - "Already a syncer, ignore ZAPTEL sync\n"); + "Already a syncer, ignore DAHDI sync\n"); goto noop; } /* ignore duplicate calls from all our registered spans */ @@ -473,27 +473,27 @@ int zaptel_sync_tick(struct dahdi_span *span, int is_master) static int rate_limit; if((rate_limit++ % 1003) < 16) - XPD_NOTICE(xpd, "boop (%d)\n", zaptel_tick_count); + XPD_NOTICE(xpd, "boop (%d)\n", dahdi_tick_count); #endif goto noop; } - xpp_ticker_step(&zaptel_ticker, &now); - zaptel_tick_count++; + xpp_ticker_step(&dahdi_ticker, &now); + dahdi_tick_count++; //flip_parport_bit(1); return 0; noop: - return 0; /* No auto sync from zaptel */ + return 0; /* No auto sync from dahdi */ } #endif /* * called from elect_syncer() * if new_syncer is NULL, than we move all to SYNC_MODE_PLL - * for ZAPTEL sync. + * for DAHDI sync. */ static void update_sync_master(xbus_t *new_syncer) { - const char *msg = (force_zaptel_sync) ? "ZAPTEL" : "NO-SYNC"; + const char *msg = (force_dahdi_sync) ? "DAHDI" : "NO-SYNC"; int i; unsigned long flags; @@ -511,12 +511,12 @@ static void update_sync_master(xbus_t *new_syncer) if(new_syncer) { XBUS_DBG(SYNC, new_syncer, "pcm_rx_counter=%d\n", atomic_read(&new_syncer->pcm_rx_counter)); - force_zaptel_sync = 0; + force_dahdi_sync = 0; ref_ticker = &new_syncer->ticker; xbus_drift_clear(new_syncer); /* Clean new data */ xbus_request_sync(new_syncer, SYNC_MODE_AB); - } else if(force_zaptel_sync) { - ref_ticker = &zaptel_ticker; + } else if(force_dahdi_sync) { + ref_ticker = &dahdi_ticker; } else { ref_ticker = NULL; } @@ -652,7 +652,7 @@ void fill_beep(u_char *buf, int num, int duration) #ifdef XPP_EC_CHUNK /* - * Taken from zaptel.c + * Taken from dahdi.c */ static inline void xpp_ec_chunk(struct dahdi_chan *chan, unsigned char *rxchunk, const unsigned char *txchunk) { @@ -724,7 +724,7 @@ int xpp_echocan(struct dahdi_chan *chan, int len) { #ifdef XPP_EC_CHUNK if(len == 0) { /* shut down */ - /* zaptel calls this also during channel initialization */ + /* dahdi calls this also during channel initialization */ if(chan->ec) { xpp_echo_can_free(chan->ec); } @@ -969,7 +969,7 @@ static void xbus_tick(xbus_t *xbus) bool sent_sync_bit = 0; /* - * Update zaptel + * Update dahdi */ for(i = 0; i < MAX_XPDS; i++) { xpd = xpd_of(xbus, i); @@ -1089,7 +1089,7 @@ static void do_tick(xbus_t *xbus, const struct timeval *tv_received) xbus_command_queue_tick(xbus); if(global_ticker == xbus) - global_tick(); /* called from here or zaptel_sync_tick() */ + global_tick(); /* called from here or dahdi_sync_tick() */ spin_lock_irqsave(&ref_ticker_lock, flags); xpp_drift_step(xbus, tv_received); spin_unlock_irqrestore(&ref_ticker_lock, flags); @@ -1131,27 +1131,27 @@ static int proc_sync_read(char *page, char **start, off_t off, int count, int *e do_gettimeofday(&now); len += sprintf(page + len, "# To modify sync source write into this file:\n"); - len += sprintf(page + len, "# ZAPTEL - Another zaptel device provide sync\n"); + len += sprintf(page + len, "# DAHDI - Another dahdi device provide sync\n"); len += sprintf(page + len, "# SYNC=nn - XBUS-nn provide sync\n"); len += sprintf(page + len, "# QUERY=nn - Query XBUS-nn for sync information (DEBUG)\n"); if(!syncer) { - if(force_zaptel_sync) - len += sprintf(page + len, "ZAPTEL\n"); + if(force_dahdi_sync) + len += sprintf(page + len, "DAHDI\n"); else len += sprintf(page + len, "NO-SYNC\n"); } else len += sprintf(page + len, "SYNC=%02d\n", syncer->num); -#ifdef ZAPTEL_SYNC_TICK - if(force_zaptel_sync) { +#ifdef DAHDI_SYNC_TICK + if(force_dahdi_sync) { len += sprintf(page + len, - "Zaptel Reference Sync (%d registered spans):\n", + "Dahdi Reference Sync (%d registered spans):\n", total_registered_spans()); - len += sprintf(page + len, "\tzaptel_tick: #%d\n", zaptel_tick_count); - len += sprintf(page + len, "\ttick - zaptel_tick = %d\n", - counter - zaptel_tick_count); + len += sprintf(page + len, "\tdahdi_tick: #%d\n", dahdi_tick_count); + len += sprintf(page + len, "\ttick - dahdi_tick = %d\n", + counter - dahdi_tick_count); } else { len += sprintf(page + len, - "Zaptel Reference Sync Not activated\n"); + "Dahdi Reference Sync Not activated\n"); } #endif usec = usec_diff(&now, &global_ticks_series.last_sample.tv); @@ -1185,9 +1185,9 @@ static int proc_sync_write(struct file *file, const char __user *buffer, unsigne if(copy_from_user(buf, buffer, count)) return -EFAULT; buf[count] = '\0'; - if(strncmp("ZAPTEL", buf, 6) == 0) { - DBG(SYNC, "ZAPTEL\n"); - force_zaptel_sync=1; + if(strncmp("DAHDI", buf, 6) == 0) { + DBG(SYNC, "DAHDI\n"); + force_dahdi_sync=1; update_sync_master(NULL); } else if(sscanf(buf, "SYNC=%d", &xbus_num) == 1) { DBG(SYNC, "SYNC=%d\n", xbus_num); @@ -1254,13 +1254,13 @@ int xbus_pcm_init(struct proc_dir_entry *toplevel) INFO("FEATURE: with XPP_EC_CHUNK\n"); else INFO("FEATURE: without XPP_EC_CHUNK\n"); -#ifdef ZAPTEL_SYNC_TICK - INFO("FEATURE: with sync_tick() from ZAPTEL\n"); +#ifdef DAHDI_SYNC_TICK + INFO("FEATURE: with sync_tick() from DAHDI\n"); #else - INFO("FEATURE: without sync_tick() from ZAPTEL\n"); + INFO("FEATURE: without sync_tick() from DAHDI\n"); #endif xpp_ticker_init(&global_ticks_series); - xpp_ticker_init(&zaptel_ticker); + xpp_ticker_init(&dahdi_ticker); #ifdef CONFIG_PROC_FS top = toplevel; ent = create_proc_entry(PROC_SYNC, 0644, top); @@ -1289,8 +1289,8 @@ EXPORT_SYMBOL(xbus_request_sync); EXPORT_SYMBOL(got_new_syncer); EXPORT_SYMBOL(elect_syncer); EXPORT_SYMBOL(xpp_echocan); -#ifdef ZAPTEL_SYNC_TICK -EXPORT_SYMBOL(zaptel_sync_tick); +#ifdef DAHDI_SYNC_TICK +EXPORT_SYMBOL(dahdi_sync_tick); #endif EXPORT_SYMBOL(__pcm_recompute); EXPORT_SYMBOL(pcm_recompute); diff --git a/drivers/dahdi/xpp/xbus-pcm.h b/drivers/dahdi/xpp/xbus-pcm.h index 9d4e771..3995bdc 100644 --- a/drivers/dahdi/xpp/xbus-pcm.h +++ b/drivers/dahdi/xpp/xbus-pcm.h @@ -53,9 +53,9 @@ struct xpp_timestamp { * A ticker encapsulates the timing information of some * abstract tick source. The following tickers are used: * - Each xbus has an embedded ticker. - * - There is one global zaptel_ticker to represent ticks - * of external zaptel card (in case we want to sync - * from other zaptel devices). + * - There is one global dahdi_ticker to represent ticks + * of external dahdi card (in case we want to sync + * from other dahdi devices). */ struct xpp_ticker { /* for rate calculation */ int count; @@ -113,8 +113,8 @@ int xbus_command_queue_tick(xbus_t *xbus); void xbus_reset_counters(xbus_t *xbus); void elect_syncer(const char *msg); int xpp_echocan(struct dahdi_chan *chan, int len); -#ifdef ZAPTEL_SYNC_TICK -int zaptel_sync_tick(struct dahdi_span *span, int is_master); +#ifdef DAHDI_SYNC_TICK +int dahdi_sync_tick(struct dahdi_span *span, int is_master); #endif #ifdef XPP_EC_CHUNK diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c index 87a58f1..c00ee64 100644 --- a/drivers/dahdi/xpp/xbus-sysfs.c +++ b/drivers/dahdi/xpp/xbus-sysfs.c @@ -36,12 +36,12 @@ #include #include /* for msleep() to debug */ #include "xpd.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "xbus-core.h" #ifdef XPP_DEBUGFS #include "xpp_log.h" #endif -#include "zap_debug.h" +#include "dahdi_debug.h" static const char rcsid[] = "$Id$"; diff --git a/drivers/dahdi/xpp/xframe_queue.c b/drivers/dahdi/xpp/xframe_queue.c index 7d9c098..261740e 100644 --- a/drivers/dahdi/xpp/xframe_queue.c +++ b/drivers/dahdi/xpp/xframe_queue.c @@ -1,6 +1,6 @@ #include "xframe_queue.h" #include "xbus-core.h" -#include "zap_debug.h" +#include "dahdi_debug.h" extern int debug; diff --git a/drivers/dahdi/xpp/xpd.h b/drivers/dahdi/xpp/xpd.h index 506a935..e800e43 100644 --- a/drivers/dahdi/xpp/xpd.h +++ b/drivers/dahdi/xpp/xpd.h @@ -154,7 +154,7 @@ struct xpd { xpp_line_t digital_outputs; /* 0 - no, 1 - yes */ xpp_line_t digital_inputs; /* 0 - no, 1 - yes */ xpp_line_t digital_signalling; /* BRI signalling channels */ - uint timing_priority; /* from 'span' directives in zapata.conf */ + uint timing_priority; /* from 'span' directives in chan_dahdi.conf */ /* maintained by card drivers */ uint pcm_len; /* allocation length of PCM packet (dynamic) */ @@ -167,7 +167,7 @@ struct xpd { xbus_t *xbus; /* The XBUS we are connected to */ spinlock_t lock; - atomic_t dahdi_registered; /* Am I fully registered with zaptel */ + atomic_t dahdi_registered; /* Am I fully registered with dahdi */ atomic_t open_counter; /* Number of open channels */ int flags; diff --git a/drivers/dahdi/xpp/xpp.conf b/drivers/dahdi/xpp/xpp.conf index 2629a3c..0bb3097 100644 --- a/drivers/dahdi/xpp/xpp.conf +++ b/drivers/dahdi/xpp/xpp.conf @@ -1,4 +1,4 @@ -# A local replacement for /etc/default/zaptel +# A local replacement for /etc/dahdi/defaults #INIT_FXS_SKIP_CALIB=1 DEBUG_INIT_FXS=0 diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c new file mode 100644 index 0000000..8ee23f7 --- /dev/null +++ b/drivers/dahdi/xpp/xpp_dahdi.c @@ -0,0 +1,1075 @@ +/* + * Written by Oron Peled + * Copyright (C) 2004, Xorcom + * + * Derived from ztdummy + * + * Copyright (C) 2002, Hermes Softlab + * Copyright (C) 2004, Digium, Inc. + * + * All rights reserved. + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +# warning "This module is tested only with 2.6 kernels" +#endif + +#include +#include +#include +#include +#include +#include /* for udelay */ +#include +#include +#include +#include "xbus-core.h" +#include "xproto.h" +#include "xpp_dahdi.h" +#include "parport_debug.h" + +static const char rcsid[] = "$Id$"; + +#ifdef CONFIG_PROC_FS +struct proc_dir_entry *xpp_proc_toplevel = NULL; +#define PROC_DIR "xpp" +#define PROC_XPD_ZTREGISTER "dahdi_registration" +#define PROC_XPD_BLINK "blink" +#define PROC_XPD_SUMMARY "summary" +#endif + +#define MAX_QUEUE_LEN 10000 +#define DELAY_UNTIL_DIALTONE 3000 + +DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); +static DEF_PARM_BOOL(dahdi_autoreg, 0, 0644, "Register spans automatically (1) or not (0)"); +static DEF_PARM_BOOL(prefmaster, 0, 0644, "Do we want to be dahdi preferred sync master"); +// DEF_ARRAY(int, pcmtx, 4, 0, "Forced PCM values to transmit"); + +#include "dahdi_debug.h" + +#ifdef DEBUG_SYNC_PARPORT +/* + * Use parallel port to sample our PCM sync and diagnose quality and + * potential problems. A logic analizer or a scope should be connected + * to the data bits of the parallel port. + * + * Array parameter: Choose the two xbuses Id's to sample. + * This can be changed on runtime as well. Example: + * echo "3,5" > /sys/module/xpp/parameters/parport_xbuses + */ +static int parport_xbuses[2] = { 0, 1 }; +unsigned int parport_xbuses_num_values; +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9) +module_param_array(parport_xbuses, int, &parport_xbuses_num_values, 0577); +#else +module_param_array(parport_xbuses, int, parport_xbuses_num_values, 0577); +#endif +MODULE_PARM_DESC(parport_xbuses, "Id's of xbuses to sample (1-2)"); + +/* + * Flip a single bit in the parallel port: + * - The bit number is either bitnum0 or bitnum1 + * - Bit is selected by xbus number from parport_xbuses[] + */ +void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1) +{ + int num = xbus->num; + + if(num == parport_xbuses[0]) + flip_parport_bit(bitnum0); + if(num == parport_xbuses[1]) + flip_parport_bit(bitnum1); +} +EXPORT_SYMBOL(xbus_flip_bit); +#endif + +static atomic_t num_registered_spans = ATOMIC_INIT(0); + +int total_registered_spans(void) +{ + return atomic_read(&num_registered_spans); +} + +static int dahdi_register_xpd(xpd_t *xpd); +static int dahdi_unregister_xpd(xpd_t *xpd); +static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data); +static int proc_xpd_blink_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_xpd_blink_write(struct file *file, const char __user *buffer, unsigned long count, void *data); + +/*------------------------- XPD Management -------------------------*/ + +static void xpd_proc_remove(xbus_t *xbus, xpd_t *xpd) +{ +#ifdef CONFIG_PROC_FS + if(xpd->proc_xpd_dir) { + chip_proc_remove(xbus, xpd); + if(xpd->proc_xpd_summary) { + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_SUMMARY); + remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir); + xpd->proc_xpd_summary = NULL; + } + if(xpd->proc_xpd_ztregister) { + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_ZTREGISTER); + remove_proc_entry(PROC_XPD_ZTREGISTER, xpd->proc_xpd_dir); + xpd->proc_xpd_ztregister = NULL; + } + if(xpd->proc_xpd_blink) { + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_BLINK); + remove_proc_entry(PROC_XPD_BLINK, xpd->proc_xpd_dir); + xpd->proc_xpd_blink = NULL; + } + XPD_DBG(PROC, xpd, "Removing %s/%s proc directory\n", + xbus->busname, xpd->xpdname); + remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir); + xpd->proc_xpd_dir = NULL; + } +#endif +} + +static int xpd_proc_create(xbus_t *xbus, xpd_t *xpd) +{ +#ifdef CONFIG_PROC_FS + XPD_DBG(PROC, xpd, "Creating proc directory\n"); + xpd->proc_xpd_dir = proc_mkdir(xpd->xpdname, xbus->proc_xbus_dir); + if(!xpd->proc_xpd_dir) { + XPD_ERR(xpd, "Failed to create proc directory\n"); + goto err; + } + xpd->proc_xpd_summary = create_proc_read_entry(PROC_XPD_SUMMARY, 0444, xpd->proc_xpd_dir, + xpd_read_proc, xpd); + if(!xpd->proc_xpd_summary) { + XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_SUMMARY); + goto err; + } + xpd->proc_xpd_summary->owner = THIS_MODULE; + xpd->proc_xpd_ztregister = create_proc_entry(PROC_XPD_ZTREGISTER, 0644, xpd->proc_xpd_dir); + if (!xpd->proc_xpd_ztregister) { + XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_ZTREGISTER); + goto err; + } + xpd->proc_xpd_ztregister->owner = THIS_MODULE; + xpd->proc_xpd_ztregister->data = xpd; + xpd->proc_xpd_ztregister->read_proc = proc_xpd_ztregister_read; + xpd->proc_xpd_ztregister->write_proc = proc_xpd_ztregister_write; + xpd->proc_xpd_blink = create_proc_entry(PROC_XPD_BLINK, 0644, xpd->proc_xpd_dir); + if (!xpd->proc_xpd_blink) { + XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_BLINK); + goto err; + } + xpd->proc_xpd_blink->owner = THIS_MODULE; + xpd->proc_xpd_blink->data = xpd; + xpd->proc_xpd_blink->read_proc = proc_xpd_blink_read; + xpd->proc_xpd_blink->write_proc = proc_xpd_blink_write; + if(chip_proc_create(xbus, xpd) < 0) + goto err; +#endif + return 0; +err: + xpd_proc_remove(xbus, xpd); + return -EFAULT; +} + +void xpd_free(xpd_t *xpd) +{ + xbus_t *xbus = NULL; + + if(!xpd) + return; + if(xpd->xproto) + xproto_put(xpd->xproto); /* was taken in xpd_alloc() */ + xpd->xproto = NULL; + xbus = xpd->xbus; + if(!xbus) + return; + XPD_DBG(DEVICES, xpd, "\n"); + xpd_proc_remove(xbus, xpd); + xbus_unregister_xpd(xbus, xpd); + KZFREE(xpd); +} + + +__must_check int xpd_common_init(xbus_t *xbus, xpd_t *xpd, int unit, int subunit, int subtype, int subunits) +{ + int ret; + + MKADDR(&xpd->addr, unit, subunit); + xpd->xbus_idx = XPD_IDX(unit,subunit); + snprintf(xpd->xpdname, XPD_NAMELEN, "XPD-%1d%1d", unit, subunit); + xpd->subtype = subtype; + xpd->subunits = subunits; + xpd->offhook = 0; + + /* For USB-1 disable some channels */ + if(MAX_SEND_SIZE(xbus) < RPACKET_SIZE(GLOBAL, PCM_WRITE)) { + xpp_line_t no_pcm; + + no_pcm = 0x7F | xpd->digital_outputs | xpd->digital_inputs; + xpd->no_pcm = no_pcm; + XBUS_NOTICE(xbus, "max xframe size = %d, disabling some PCM channels. no_pcm=0x%04X\n", + MAX_SEND_SIZE(xbus), xpd->no_pcm); + } + if((ret = xpd_proc_create(xbus, xpd)) < 0) + return ret; + xbus_register_xpd(xbus, xpd); + return 0; +} + +/* + * Synchronous part of XPD detection. + * Called from xbus_poll() + */ +int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, + int unit, + int subunit, + byte type, + byte subtype, + int subunits, + byte port_dir) +{ + xpd_t *xpd = NULL; + bool to_phone; + int ret = -EINVAL; + + BUG_ON(type == XPD_TYPE_NOMODULE); + to_phone = BIT(subunit) & port_dir; + BUG_ON(!xbus); + xpd = xpd_byaddr(xbus, unit, subunit); + if(xpd) { + XPD_NOTICE(xpd, "XPD at %d%d already exists\n", + unit, subunit); + goto out; + } + xpd = proto_table->xops.card_new(xbus, unit, subunit, proto_table, subtype, subunits, to_phone); + if(!xpd) { + XBUS_NOTICE(xbus, "card_new(%d,%d,%d,%d,%d) failed. Ignored.\n", + unit, subunit, proto_table->type, subtype, to_phone); + goto err; + } +out: + return 0; +err: + if(xpd) + xpd_free(xpd); + return ret; +} + +void xpd_post_init(xpd_t *xpd) +{ + XPD_DBG(DEVICES, xpd, "\n"); + if(dahdi_autoreg) + dahdi_register_xpd(xpd); +} + +#ifdef CONFIG_PROC_FS + +/** + * Prints a general procfs entry for the bus, under xpp/BUSNAME/summary + * @page TODO: figure out procfs + * @start TODO: figure out procfs + * @off TODO: figure out procfs + * @count TODO: figure out procfs + * @eof TODO: figure out procfs + * @data an xbus_t pointer with the bus data. + */ +static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) +{ + int len = 0; + xpd_t *xpd = data; + xbus_t *xbus; + int i; + + if(!xpd) + goto out; + + xbus = xpd->xbus; + len += sprintf(page + len, "%s (%s, card %s, span %d)\n" + "timing_priority: %d\n" + "timer_count: %d span->mainttimer=%d\n" + , + xpd->xpdname, xpd->type_name, + (xpd->card_present) ? "present" : "missing", + (SPAN_REGISTERED(xpd)) ? xpd->span.spanno : 0, + xpd->timing_priority, + xpd->timer_count, xpd->span.mainttimer + ); + len += sprintf(page + len, "Address: U=%d S=%d\n", xpd->addr.unit, xpd->addr.subunit); + len += sprintf(page + len, "Subunits: %d\n", xpd->subunits); + len += sprintf(page + len, "Type: %d.%d\n\n", xpd->type, xpd->subtype); + len += sprintf(page + len, "pcm_len=%d\n\n", xpd->pcm_len); + len += sprintf(page + len, "wanted_pcm_mask=0x%04X\n\n", xpd->wanted_pcm_mask); + len += sprintf(page + len, "mute_dtmf=0x%04X\n\n", xpd->mute_dtmf); + len += sprintf(page + len, "STATES:"); + len += sprintf(page + len, "\n\t%-17s: ", "output_relays"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->digital_outputs, i)); + } + len += sprintf(page + len, "\n\t%-17s: ", "input_relays"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->digital_inputs, i)); + } + len += sprintf(page + len, "\n\t%-17s: ", "offhook"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->offhook, i)); + } + len += sprintf(page + len, "\n\t%-17s: ", "cid_on"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->cid_on, i)); + } + len += sprintf(page + len, "\n\t%-17s: ", "msg_waiting"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->msg_waiting, i)); + } + len += sprintf(page + len, "\n\t%-17s: ", "ringing"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", xpd->ringing[i]); + } + len += sprintf(page + len, "\n\t%-17s: ", "no_pcm"); + for_each_line(xpd, i) { + len += sprintf(page + len, "%d ", IS_SET(xpd->no_pcm, i)); + } +#if 1 + if(SPAN_REGISTERED(xpd)) { + len += sprintf(page + len, "\nPCM:\n | [readchunk] | [writechunk] | W D"); + for_each_line(xpd, i) { + struct dahdi_chan *chans = xpd->span.chans; + byte rchunk[DAHDI_CHUNKSIZE]; + byte wchunk[DAHDI_CHUNKSIZE]; + byte *rp; + byte *wp; + int j; + + if(IS_SET(xpd->digital_outputs, i)) + continue; + if(IS_SET(xpd->digital_inputs, i)) + continue; + if(IS_SET(xpd->digital_signalling, i)) + continue; + rp = chans[i].readchunk; + wp = chans[i].writechunk; + memcpy(rchunk, rp, DAHDI_CHUNKSIZE); + memcpy(wchunk, wp, DAHDI_CHUNKSIZE); + len += sprintf(page + len, "\n port %2d> | ", i); + for(j = 0; j < DAHDI_CHUNKSIZE; j++) { + len += sprintf(page + len, "%02X ", rchunk[j]); + } + len += sprintf(page + len, " | "); + for(j = 0; j < DAHDI_CHUNKSIZE; j++) { + len += sprintf(page + len, "%02X ", wchunk[j]); + } + len += sprintf(page + len, " | %c", + (IS_SET(xpd->wanted_pcm_mask, i))?'+':' '); + len += sprintf(page + len, " %c", + (IS_SET(xpd->mute_dtmf, i))?'-':' '); + } + } +#endif +#if 0 + if(SPAN_REGISTERED(xpd)) { + len += sprintf(page + len, "\nSignalling:\n"); + for_each_line(xpd, i) { + struct dahdi_chan *chan = &xpd->span.chans[i]; + len += sprintf(page + len, "\t%2d> sigcap=0x%04X sig=0x%04X\n", i, chan->sigcap, chan->sig); + } + } +#endif + len += sprintf(page + len, "\nCOUNTERS:\n"); + for(i = 0; i < XPD_COUNTER_MAX; i++) { + len += sprintf(page + len, "\t\t%-20s = %d\n", + xpd_counters[i].name, xpd->counters[i]); + } + len += sprintf(page + len, "<-- len=%d\n", len); +out: + if (len <= off+count) + *eof = 1; + *start = page + off; + len -= off; + if (len > count) + len = count; + if (len < 0) + len = 0; + return len; + +} + +#endif + +/* + * xpd_alloc - Allocator for new XPD's + * + */ +xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channels) +{ + xpd_t *xpd = NULL; + size_t alloc_size = sizeof(xpd_t) + privsize; + int type = proto_table->type; + + BUG_ON(!proto_table); + DBG(DEVICES, "type=%d channels=%d (alloc_size=%zd)\n", + type, channels, alloc_size); + if(channels > CHANNELS_PERXPD) { + ERR("%s: type=%d: too many channels %d\n", + __FUNCTION__, type, channels); + goto err; + } + + if((xpd = KZALLOC(alloc_size, GFP_KERNEL)) == NULL) { + ERR("%s: type=%d: Unable to allocate memory\n", + __FUNCTION__, type); + goto err; + } + xpd->priv = (byte *)xpd + sizeof(xpd_t); + spin_lock_init(&xpd->lock); + xpd->xbus = NULL; + xpd->xbus_idx = -1; + xpd->channels = channels; + xpd->chans = NULL; + xpd->card_present = 0; + xpd->offhook = 0x0; /* ONHOOK */ + xpd->type = proto_table->type; + xpd->xproto = proto_table; + xpd->xops = &proto_table->xops; + xpd->digital_outputs = 0; + xpd->digital_inputs = 0; + + atomic_set(&xpd->dahdi_registered, 0); + atomic_set(&xpd->open_counter, 0); + + xpd->chans = kmalloc(sizeof(struct dahdi_chan)*xpd->channels, GFP_KERNEL); + if (xpd->chans == NULL) { + ERR("%s: Unable to allocate channels\n", __FUNCTION__); + goto err; + } + xproto_get(type); /* will be returned in xpd_free() */ + return xpd; +err: + if(xpd) { + if(xpd->chans) + kfree((void *)xpd->chans); + kfree(xpd); + } + return NULL; +} + +/* FIXME: this should be removed once digium patch their dahdi.h + * I simply wish to avoid changing dahdi.h in the xpp patches. + */ +#ifndef DAHDI_EVENT_REMOVED +#define DAHDI_EVENT_REMOVED (20) +#endif + +void xpd_disconnect(xpd_t *xpd) +{ + unsigned long flags; + + BUG_ON(!xpd); + + spin_lock_irqsave(&xpd->lock, flags); + XPD_DBG(DEVICES, xpd, "(%p)\n", xpd->xproto); + if(!xpd->card_present) /* Multiple reports */ + goto out; + xpd->card_present = 0; + if(SPAN_REGISTERED(xpd)) { + int i; + + update_xpd_status(xpd, DAHDI_ALARM_NOTOPEN); + /* TODO: Should this be done before releasing the spinlock? */ + XPD_DBG(DEVICES, xpd, "Queuing DAHDI_EVENT_REMOVED on all channels to ask user to release them\n"); + for (i=0; ispan.channels; i++) + dahdi_qevent_lock(&xpd->chans[i],DAHDI_EVENT_REMOVED); + } +out: + spin_unlock_irqrestore(&xpd->lock, flags); +} + +void xpd_remove(xpd_t *xpd) +{ + xbus_t *xbus; + + BUG_ON(!xpd); + xbus = xpd->xbus; + XPD_INFO(xpd, "Remove\n"); + dahdi_unregister_xpd(xpd); + CALL_XMETHOD(card_remove, xbus, xpd); + xpd_free(xpd); +} + +void update_xpd_status(xpd_t *xpd, int alarm_flag) +{ + struct dahdi_span *span = &xpd->span; + + if(!SPAN_REGISTERED(xpd)) { + // XPD_NOTICE(xpd, "%s: XPD is not registered. Skipping.\n", __FUNCTION__); + return; + } + switch (alarm_flag) { + case DAHDI_ALARM_NONE: + xpd->last_response = jiffies; + break; + default: + // Nothing + break; + } + if(span->alarms == alarm_flag) + return; + span->alarms = alarm_flag; + dahdi_alarm_notify(span); + XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n", xpd->span.name, alarm_flag); +} + +void update_line_status(xpd_t *xpd, int pos, bool to_offhook) +{ + dahdi_rxsig_t rxsig; + + BUG_ON(!xpd); + if(to_offhook) { + BIT_SET(xpd->offhook, pos); + rxsig = DAHDI_RXSIG_OFFHOOK; + } else { + BIT_CLR(xpd->offhook, pos); + BIT_CLR(xpd->cid_on, pos); + rxsig = DAHDI_RXSIG_ONHOOK; + /* + * To prevent latest PCM to stay in buffers + * indefinitely, mark this channel for a + * single silence transmittion. + * + * This bit will be cleared on the next tick. + */ + BIT_SET(xpd->silence_pcm, pos); + } + /* + * We should not spinlock before calling dahdi_hooksig() as + * it may call back into our xpp_hooksig() and cause + * a nested spinlock scenario + */ + LINE_DBG(SIGNAL, xpd, pos, "rxsig=%s\n", (rxsig == DAHDI_RXSIG_ONHOOK) ? "ONHOOK" : "OFFHOOK"); + if(SPAN_REGISTERED(xpd)) + dahdi_hooksig(&xpd->chans[pos], rxsig); +} + +#ifdef CONFIG_PROC_FS +static int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data) +{ + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + + BUG_ON(!xpd); + spin_lock_irqsave(&xpd->lock, flags); + + len += sprintf(page + len, "%d\n", SPAN_REGISTERED(xpd) ? xpd->span.spanno : 0); + spin_unlock_irqrestore(&xpd->lock, flags); + if (len <= off+count) + *eof = 1; + *start = page + off; + len -= off; + if (len > count) + len = count; + if (len < 0) + len = 0; + return len; +} + +static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data) +{ + xpd_t *xpd = data; + char buf[MAX_PROC_WRITE]; + int dahdi_reg; + int ret; + + BUG_ON(!xpd); + if(count >= MAX_PROC_WRITE) + return -EINVAL; + if(copy_from_user(buf, buffer, count)) + return -EFAULT; + buf[count] = '\0'; + ret = sscanf(buf, "%d", &dahdi_reg); + if(ret != 1) + return -EINVAL; + XPD_DBG(GENERAL, xpd, "%s\n", (dahdi_reg) ? "register" : "unregister"); + if(dahdi_reg) + ret = dahdi_register_xpd(xpd); + else + ret = dahdi_unregister_xpd(xpd); + return (ret < 0) ? ret : count; +} + +static int proc_xpd_blink_read(char *page, char **start, off_t off, int count, int *eof, void *data) +{ + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + + BUG_ON(!xpd); + spin_lock_irqsave(&xpd->lock, flags); + + len += sprintf(page + len, "%d\n", xpd->blink_mode); + spin_unlock_irqrestore(&xpd->lock, flags); + if (len <= off+count) + *eof = 1; + *start = page + off; + len -= off; + if (len > count) + len = count; + if (len < 0) + len = 0; + return len; +} + +static int proc_xpd_blink_write(struct file *file, const char __user *buffer, unsigned long count, void *data) +{ + xpd_t *xpd = data; + char buf[MAX_PROC_WRITE]; + char *endp; + unsigned blink; + + + BUG_ON(!xpd); + if(count >= MAX_PROC_WRITE) + return -EINVAL; + if(copy_from_user(buf, buffer, count)) + return -EFAULT; + buf[count] = '\0'; + if(count > 0 && buf[count-1] == '\n') /* chomp */ + buf[count-1] = '\0'; + blink = simple_strtoul(buf, &endp, 0); + if(*endp != '\0' || blink > 0xFFFF) + return -EINVAL; + XPD_DBG(GENERAL, xpd, "BLINK channels: 0x%X\n", blink); + xpd->blink_mode = blink; + return count; +} + +#endif + + +#define XPP_MAX_LEN 512 + +/*------------------------- Dahdi Interfaces -----------------------*/ + + +/* + * Called from dahdi with spinlock held on chan. Must not call back + * dahdi functions. + */ +int xpp_open(struct dahdi_chan *chan) +{ +#if 0 + xpd_t *xpd = chan->pvt; + xbus_t *xbus = xpd->xbus; + int pos = chan->chanpos - 1; + unsigned long flags; +#else + xpd_t *xpd; + xbus_t *xbus; + int pos; + unsigned long flags; + + if (!chan) { + NOTICE("open called on a null chan\n"); + return -EINVAL; + } + xpd = chan->pvt; + if (!xpd) { + NOTICE("open called on a chan with no pvt (xpd)\n"); + return -EINVAL; + } + xbus = xpd->xbus; + if (!xbus) { + NOTICE("open called on a chan with no xbus\n"); + return -EINVAL; + } + pos = chan->chanpos - 1; +#endif + + spin_lock_irqsave(&xbus->lock, flags); + atomic_inc(&xbus->xbus_ref_count); + atomic_inc(&xpd->open_counter); + if(IS_SET(xpd->digital_signalling, pos)) /* D-chan offhook */ + BIT_SET(xpd->offhook, pos); + DBG(DEVICES, "chan=%d (xbus_ref_count=%d)\n", + pos, atomic_read(&xbus->xbus_ref_count)); + spin_unlock_irqrestore(&xbus->lock, flags); + if(xpd->xops->card_open) + xpd->xops->card_open(xpd, pos); + return 0; +} + +int xpp_close(struct dahdi_chan *chan) +{ + xpd_t *xpd = chan->pvt; + xbus_t *xbus = xpd->xbus; + int pos = chan->chanpos - 1; + unsigned long flags; + + spin_lock_irqsave(&xbus->lock, flags); + atomic_dec(&xpd->open_counter); + if(IS_SET(xpd->digital_signalling, pos)) /* D-chan onhook */ + BIT_CLR(xpd->offhook, pos); + spin_unlock_irqrestore(&xbus->lock, flags); + if(xpd->xops->card_close) + xpd->xops->card_close(xpd, pos); + XPD_DBG(GENERAL, xpd, "pid=%d: chan=%d (xbus_ref_count=%d)\n", + current->pid, pos, atomic_read(&xbus->xbus_ref_count)); + if(atomic_dec_and_test(&xbus->xbus_ref_count)) + xbus_remove(xbus); + return 0; +} + +void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd) +{ + XPD_NOTICE(xpd, "%s: Bad ioctl\n", msg); + XPD_NOTICE(xpd, "ENOTTY: chan=%d cmd=0x%x\n", pos, cmd); + XPD_NOTICE(xpd, " IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd)); + XPD_NOTICE(xpd, " IOC_DIR=0x%02X\n", _IOC_DIR(cmd)); + XPD_NOTICE(xpd, " IOC_NR=%d\n", _IOC_NR(cmd)); + XPD_NOTICE(xpd, " IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd)); +} + +int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg) +{ + xpd_t *xpd = chan->pvt; + int pos = chan->chanpos - 1; + + if(!xpd) { + ERR("%s: channel in pos %d, was already closed. Ignore.\n", + __FUNCTION__, pos); + return -ENODEV; + } + switch (cmd) { + default: + /* Some span-specific commands before we give up: */ + if (xpd->xops->card_ioctl != NULL) { + return xpd->xops->card_ioctl(xpd, pos, cmd, arg); + } + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + return -ENOTTY; + } + return 0; +} + +static int xpp_hooksig(struct dahdi_chan *chan, dahdi_txsig_t txsig) +{ + xpd_t *xpd = chan->pvt; + xbus_t *xbus; + int pos = chan->chanpos - 1; + + if(!xpd) { + ERR("%s: channel in pos %d, was already closed. Ignore.\n", + __FUNCTION__, pos); + return -ENODEV; + } + xbus = xpd->xbus; + BUG_ON(!xbus); + DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); + return CALL_XMETHOD(card_hooksig, xbus, xpd, pos, txsig); +} + +/* Req: Set the requested chunk size. This is the unit in which you must + report results for conferencing, etc */ +int xpp_setchunksize(struct dahdi_span *span, int chunksize); + +/* Enable maintenance modes */ +int xpp_maint(struct dahdi_span *span, int cmd) +{ + xpd_t *xpd = span->pvt; + int ret = 0; +#if 0 + char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG"; +#endif + + DBG(GENERAL, "span->mainttimer=%d\n", span->mainttimer); + switch(cmd) { + case DAHDI_MAINT_NONE: + printk("XXX Turn off local and remote loops XXX\n"); + break; + case DAHDI_MAINT_LOCALLOOP: + printk("XXX Turn on local loopback XXX\n"); + break; + case DAHDI_MAINT_REMOTELOOP: + printk("XXX Turn on remote loopback XXX\n"); + break; + case DAHDI_MAINT_LOOPUP: + printk("XXX Send loopup code XXX\n"); + // CALL_XMETHOD(LOOPBACK_AX, xpd->xbus, xpd, loopback_data, ARRAY_SIZE(loopback_data)); + break; + case DAHDI_MAINT_LOOPDOWN: + printk("XXX Send loopdown code XXX\n"); + break; + case DAHDI_MAINT_LOOPSTOP: + printk("XXX Stop sending loop codes XXX\n"); + break; + default: + ERR("XPP: Unknown maint command: %d\n", cmd); + ret = -EINVAL; + break; + } + if (span->mainttimer || span->maintstat) + update_xpd_status(xpd, DAHDI_ALARM_LOOPBACK); + return ret; +} + +#ifdef CONFIG_DAHDI_WATCHDOG +/* + * If the watchdog detects no received data, it will call the + * watchdog routine + */ +static int xpp_watchdog(struct dahdi_span *span, int cause) +{ + static int rate_limit = 0; + + if((rate_limit++ % 1000) == 0) + DBG(GENERAL, "\n"); + return 0; +} +#endif + +/** + * Unregister an xpd from dahdi and release related resources + * @xpd The xpd to be unregistered + * @returns 0 on success, errno otherwise + * + * Checks that nobody holds an open channel. + * + * Called by: + * - User action through /proc + * - During xpd_remove() + */ +static int dahdi_unregister_xpd(xpd_t *xpd) +{ + unsigned long flags; + + BUG_ON(!xpd); + spin_lock_irqsave(&xpd->lock, flags); + + if(!SPAN_REGISTERED(xpd)) { + XPD_NOTICE(xpd, "Already unregistered\n"); + spin_unlock_irqrestore(&xpd->lock, flags); + return -EIDRM; + } + update_xpd_status(xpd, DAHDI_ALARM_NOTOPEN); + if(atomic_read(&xpd->open_counter)) { + XPD_NOTICE(xpd, "Busy (open_counter=%d). Skipping.\n", atomic_read(&xpd->open_counter)); + spin_unlock_irqrestore(&xpd->lock, flags); + return -EBUSY; + } + mdelay(2); // FIXME: This is to give chance for transmit/receiveprep to finish. + spin_unlock_irqrestore(&xpd->lock, flags); + if(xpd->card_present) + xpd->xops->card_dahdi_preregistration(xpd, 0); + atomic_dec(&xpd->dahdi_registered); + atomic_dec(&num_registered_spans); + dahdi_unregister(&xpd->span); + if(xpd->card_present) + xpd->xops->card_dahdi_postregistration(xpd, 0); + return 0; +} + +static int dahdi_register_xpd(xpd_t *xpd) +{ + struct dahdi_span *span; + xbus_t *xbus; + int cn; + const xops_t *xops; + + BUG_ON(!xpd); + xops = xpd->xops; + xbus = xpd->xbus; + + if (SPAN_REGISTERED(xpd)) { + XPD_ERR(xpd, "Already registered\n"); + return -EEXIST; + } + cn = xpd->channels; + XPD_DBG(DEVICES, xpd, "Initializing span: %d channels.\n", cn); + memset(xpd->chans, 0, sizeof(struct dahdi_chan)*cn); + memset(&xpd->span, 0, sizeof(struct dahdi_span)); + + span = &xpd->span; + snprintf(span->name, MAX_SPANNAME, "%s/%s", xbus->busname, xpd->xpdname); + span->deflaw = DAHDI_LAW_MULAW; /* default, may be overriden by card_* drivers */ + init_waitqueue_head(&span->maintq); + span->pvt = xpd; + span->channels = cn; + span->chans = xpd->chans; + + span->open = xpp_open; + span->close = xpp_close; + span->flags = DAHDI_FLAG_RBS; + span->hooksig = xpp_hooksig; /* Only with RBS bits */ + span->ioctl = xpp_ioctl; + span->maint = xpp_maint; +#ifdef DAHDI_SPANSTAT_V2 + /* + * This actually describe the dahdi_spaninfo version 3 + * A bunch of unrelated data exported via a modified ioctl() + * What a bummer... + */ + span->manufacturer = "Xorcom Inc."; /* OK, that's obvious */ + /* span->spantype = "...."; set in card_dahdi_preregistration() */ + /* + * Yes, this basically duplicates information available + * from the description field. If some more is needed + * why not add it there? + * OK, let's add to the kernel more useless info. + */ + snprintf(span->devicetype, sizeof(span->devicetype) - 1, + "Astribank: Unit %x Subunit %x: %s", + XBUS_UNIT(xpd->xbus_idx), XBUS_SUBUNIT(xpd->xbus_idx), + xpd->type_name); + /* + * location is the only usefull new data item. + * For our devices it was available for ages via: + * - The legacy "/proc/xpp/XBUS-??/summary" (CONNECTOR=...) + * - The same info in "/proc/xpp/xbuses" + * - The modern "/sys/bus/astribanks/devices/xbus-??/connector" attribute + * So let's also export it via the newfangled "location" field. + */ + snprintf(span->location, sizeof(span->location) - 1, "%s", xbus->location); + /* + * Who said a span and irq have 1-1 relationship? + * Also exporting this low-level detail isn't too wise. + * No irq's for you today! + */ + span->irq = 0; +#endif +#ifdef DAHDI_SYNC_TICK + span->sync_tick = dahdi_sync_tick; +#endif + if (xpp_ec) + span->echocan = xpp_echocan; +#ifdef CONFIG_DAHDI_WATCHDOG + span->watchdog = xpp_watchdog; +#endif + + snprintf(xpd->span.desc, MAX_SPANDESC, "Xorcom XPD #%02d/%1d%1d: %s", + xbus->num, xpd->addr.unit, xpd->addr.subunit, xpd->type_name); + XPD_DBG(GENERAL, xpd, "Registering span '%s'\n", xpd->span.desc); + xpd->xops->card_dahdi_preregistration(xpd, 1); + if(dahdi_register(&xpd->span, prefmaster)) { + XPD_ERR(xpd, "Failed to dahdi_register span\n"); + return -ENODEV; + } + atomic_inc(&num_registered_spans); + atomic_inc(&xpd->dahdi_registered); + xpd->xops->card_dahdi_postregistration(xpd, 1); + /* + * Update dahdi about our state + */ +#if 0 + /* + * FIXME: since asterisk didn't open the channel yet, the report + * is discarded anyway. OTOH, we cannot report in xpp_open or + * xpp_chanconfig since dahdi call them with a spinlock on the channel + * and dahdi_hooksig tries to acquire the same spinlock, resulting in + * double spinlock deadlock (we are lucky that RH/Fedora kernel are + * compiled with spinlock debugging).... tough. + */ + for_each_line(xpd, cn) { + struct dahdi_chan *chans = xpd->span.chans; + + if(IS_SET(xpd->offhook, cn)) { + LINE_NOTICE(xpd, cn, "Report OFFHOOK to dahdi\n"); + dahdi_hooksig(&chans[cn], DAHDI_RXSIG_OFFHOOK); + } + } +#endif + return 0; +} + +/*------------------------- Initialization -------------------------*/ + +static void do_cleanup(void) +{ +#ifdef CONFIG_PROC_FS + if(xpp_proc_toplevel) { + DBG(GENERAL, "Removing '%s' from proc\n", PROC_DIR); + remove_proc_entry(PROC_DIR, NULL); + xpp_proc_toplevel = NULL; + } +#endif +} + +static int __init xpp_dahdi_init(void) +{ + int ret = 0; + + INFO("revision %s MAX_XPDS=%d (%d*%d)\n", XPP_VERSION, + MAX_XPDS, MAX_UNIT, MAX_SUBUNIT); +#ifdef CONFIG_ZAPATA_BRI_DCHANS + INFO("FEATURE: with BRISTUFF support\n"); +#else + INFO("FEATURE: without BRISTUFF support\n"); +#endif +#ifdef CONFIG_PROC_FS + xpp_proc_toplevel = proc_mkdir(PROC_DIR, NULL); + if(!xpp_proc_toplevel) { + ret = -EIO; + goto err; + } +#endif + ret = xbus_core_init(); + if(ret) { + ERR("xbus_core_init failed (%d)\n", ret); + goto err; + } + ret = xbus_pcm_init(xpp_proc_toplevel); + if(ret) { + ERR("xbus_pcm_init failed (%d)\n", ret); + xbus_core_shutdown(); + goto err; + } + return 0; +err: + do_cleanup(); + return ret; +} + +static void __exit xpp_dahdi_cleanup(void) +{ + xbus_pcm_shutdown(); + xbus_core_shutdown(); + do_cleanup(); +} + +EXPORT_SYMBOL(debug); +EXPORT_SYMBOL(xpd_common_init); +EXPORT_SYMBOL(create_xpd); +EXPORT_SYMBOL(xpd_post_init); +EXPORT_SYMBOL(xpd_alloc); +EXPORT_SYMBOL(xpd_free); +EXPORT_SYMBOL(xpd_disconnect); +EXPORT_SYMBOL(update_xpd_status); +EXPORT_SYMBOL(update_line_status); +EXPORT_SYMBOL(xpp_open); +EXPORT_SYMBOL(xpp_close); +EXPORT_SYMBOL(xpp_ioctl); +EXPORT_SYMBOL(xpp_maint); +EXPORT_SYMBOL(report_bad_ioctl); + +MODULE_DESCRIPTION("XPP Dahdi Driver"); +MODULE_AUTHOR("Oron Peled "); +MODULE_LICENSE("GPL"); +MODULE_VERSION(XPP_VERSION); + +module_init(xpp_dahdi_init); +module_exit(xpp_dahdi_cleanup); diff --git a/drivers/dahdi/xpp/xpp_dahdi.h b/drivers/dahdi/xpp/xpp_dahdi.h new file mode 100644 index 0000000..74a12c8 --- /dev/null +++ b/drivers/dahdi/xpp/xpp_dahdi.h @@ -0,0 +1,53 @@ +#ifndef XPP_DAHDI_H +#define XPP_DAHDI_H +/* + * Written by Oron Peled + * Copyright (C) 2004-2006, Xorcom + * + * All rights reserved. + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "xpd.h" +#include "xproto.h" + +void xpd_disconnect(xpd_t *xpd); +int xpd_common_init(xbus_t *xbus, xpd_t *xpd, int unit, int subunit, int subtype, int subunits); +int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, + int unit, int subunit, byte type, byte subtype, int subunits, byte port_dir); +void xpd_post_init(xpd_t *xpd); +xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channels); +void xpd_free(xpd_t *xpd); +void xpd_remove(xpd_t *xpd); +void update_xpd_status(xpd_t *xpd, int alarm_flag); +void update_line_status(xpd_t *xpd, int pos, bool good); +int xpp_open(struct dahdi_chan *chan); +int xpp_close(struct dahdi_chan *chan); +int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg); +int xpp_maint(struct dahdi_span *span, int cmd); +void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd); +int total_registered_spans(void); + +#ifdef CONFIG_PROC_FS +#include + +extern struct proc_dir_entry *xpp_proc_toplevel; +#endif + +#define SPAN_REGISTERED(xpd) atomic_read(&(xpd)->dahdi_registered) + +#endif /* XPP_DAHDI_H */ diff --git a/drivers/dahdi/xpp/xpp_usb.c b/drivers/dahdi/xpp/xpp_usb.c index 2b633c6..a64a50c 100644 --- a/drivers/dahdi/xpp/xpp_usb.c +++ b/drivers/dahdi/xpp/xpp_usb.c @@ -45,12 +45,12 @@ static const char rcsid[] = "$Id$"; -static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ +static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ static DEF_PARM(int, usb1, 0, 0644, "Allow using USB 1.1 interfaces"); static DEF_PARM(uint, tx_sluggish, 2000, 0644, "A sluggish transmit (usec)"); static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggish to drop a PCM frame"); -#include "zap_debug.h" +#include "dahdi_debug.h" #define XUSB_PRINTK(level, xusb, fmt, ...) \ diff --git a/drivers/dahdi/xpp/xpp_zap.c b/drivers/dahdi/xpp/xpp_zap.c deleted file mode 100644 index 12ffeb8..0000000 --- a/drivers/dahdi/xpp/xpp_zap.c +++ /dev/null @@ -1,1087 +0,0 @@ -/* - * Written by Oron Peled - * Copyright (C) 2004, Xorcom - * - * Derived from ztdummy - * - * Copyright (C) 2002, Hermes Softlab - * Copyright (C) 2004, Digium, Inc. - * - * All rights reserved. - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -#include - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -# warning "This module is tested only with 2.6 kernels" -#endif - -#include -#include -#include -#include -#include -#include /* for udelay */ -#include -#include -#include -#include "xbus-core.h" -#include "xproto.h" -#include "xpp_zap.h" -#include "parport_debug.h" - -static const char rcsid[] = "$Id$"; - -#ifdef CONFIG_PROC_FS -struct proc_dir_entry *xpp_proc_toplevel = NULL; -#define PROC_DIR "xpp" -#define PROC_XPD_ZTREGISTER "dahdi_registration" -#define PROC_XPD_BLINK "blink" -#define PROC_XPD_SUMMARY "summary" -#endif - -#define MAX_QUEUE_LEN 10000 -#define DELAY_UNTIL_DIALTONE 3000 - -DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); -static DEF_PARM_BOOL(zap_autoreg, 0, 0644, "Register spans automatically (1) or not (0)"); -static DEF_PARM_BOOL(prefmaster, 0, 0644, "Do we want to be zaptel preferred sync master"); -// DEF_ARRAY(int, pcmtx, 4, 0, "Forced PCM values to transmit"); - -#include "zap_debug.h" - -#ifdef DEBUG_SYNC_PARPORT -/* - * Use parallel port to sample our PCM sync and diagnose quality and - * potential problems. A logic analizer or a scope should be connected - * to the data bits of the parallel port. - * - * Array parameter: Choose the two xbuses Id's to sample. - * This can be changed on runtime as well. Example: - * echo "3,5" > /sys/module/xpp/parameters/parport_xbuses - */ -static int parport_xbuses[2] = { 0, 1 }; -unsigned int parport_xbuses_num_values; -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9) -module_param_array(parport_xbuses, int, &parport_xbuses_num_values, 0577); -#else -module_param_array(parport_xbuses, int, parport_xbuses_num_values, 0577); -#endif -MODULE_PARM_DESC(parport_xbuses, "Id's of xbuses to sample (1-2)"); - -/* - * Flip a single bit in the parallel port: - * - The bit number is either bitnum0 or bitnum1 - * - Bit is selected by xbus number from parport_xbuses[] - */ -void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1) -{ - int num = xbus->num; - - if(num == parport_xbuses[0]) - flip_parport_bit(bitnum0); - if(num == parport_xbuses[1]) - flip_parport_bit(bitnum1); -} -EXPORT_SYMBOL(xbus_flip_bit); -#endif - -static atomic_t num_registered_spans = ATOMIC_INIT(0); - -int total_registered_spans(void) -{ - return atomic_read(&num_registered_spans); -} - -static int zaptel_register_xpd(xpd_t *xpd); -static int zaptel_unregister_xpd(xpd_t *xpd); -static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data); -static int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data); -static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data); -static int proc_xpd_blink_read(char *page, char **start, off_t off, int count, int *eof, void *data); -static int proc_xpd_blink_write(struct file *file, const char __user *buffer, unsigned long count, void *data); - -/*------------------------- XPD Management -------------------------*/ - -static void xpd_proc_remove(xbus_t *xbus, xpd_t *xpd) -{ -#ifdef CONFIG_PROC_FS - if(xpd->proc_xpd_dir) { - chip_proc_remove(xbus, xpd); - if(xpd->proc_xpd_summary) { - XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_SUMMARY); - remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir); - xpd->proc_xpd_summary = NULL; - } - if(xpd->proc_xpd_ztregister) { - XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_ZTREGISTER); - remove_proc_entry(PROC_XPD_ZTREGISTER, xpd->proc_xpd_dir); - xpd->proc_xpd_ztregister = NULL; - } - if(xpd->proc_xpd_blink) { - XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_BLINK); - remove_proc_entry(PROC_XPD_BLINK, xpd->proc_xpd_dir); - xpd->proc_xpd_blink = NULL; - } - XPD_DBG(PROC, xpd, "Removing %s/%s proc directory\n", - xbus->busname, xpd->xpdname); - remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir); - xpd->proc_xpd_dir = NULL; - } -#endif -} - -static int xpd_proc_create(xbus_t *xbus, xpd_t *xpd) -{ -#ifdef CONFIG_PROC_FS - XPD_DBG(PROC, xpd, "Creating proc directory\n"); - xpd->proc_xpd_dir = proc_mkdir(xpd->xpdname, xbus->proc_xbus_dir); - if(!xpd->proc_xpd_dir) { - XPD_ERR(xpd, "Failed to create proc directory\n"); - goto err; - } - xpd->proc_xpd_summary = create_proc_read_entry(PROC_XPD_SUMMARY, 0444, xpd->proc_xpd_dir, - xpd_read_proc, xpd); - if(!xpd->proc_xpd_summary) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_SUMMARY); - goto err; - } - xpd->proc_xpd_summary->owner = THIS_MODULE; - xpd->proc_xpd_ztregister = create_proc_entry(PROC_XPD_ZTREGISTER, 0644, xpd->proc_xpd_dir); - if (!xpd->proc_xpd_ztregister) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_ZTREGISTER); - goto err; - } - xpd->proc_xpd_ztregister->owner = THIS_MODULE; - xpd->proc_xpd_ztregister->data = xpd; - xpd->proc_xpd_ztregister->read_proc = proc_xpd_ztregister_read; - xpd->proc_xpd_ztregister->write_proc = proc_xpd_ztregister_write; - xpd->proc_xpd_blink = create_proc_entry(PROC_XPD_BLINK, 0644, xpd->proc_xpd_dir); - if (!xpd->proc_xpd_blink) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_BLINK); - goto err; - } - xpd->proc_xpd_blink->owner = THIS_MODULE; - xpd->proc_xpd_blink->data = xpd; - xpd->proc_xpd_blink->read_proc = proc_xpd_blink_read; - xpd->proc_xpd_blink->write_proc = proc_xpd_blink_write; - if(chip_proc_create(xbus, xpd) < 0) - goto err; -#endif - return 0; -err: - xpd_proc_remove(xbus, xpd); - return -EFAULT; -} - -void xpd_free(xpd_t *xpd) -{ - xbus_t *xbus = NULL; - - if(!xpd) - return; - if(xpd->xproto) - xproto_put(xpd->xproto); /* was taken in xpd_alloc() */ - xpd->xproto = NULL; - xbus = xpd->xbus; - if(!xbus) - return; - XPD_DBG(DEVICES, xpd, "\n"); - xpd_proc_remove(xbus, xpd); - xbus_unregister_xpd(xbus, xpd); - KZFREE(xpd); -} - - -__must_check int xpd_common_init(xbus_t *xbus, xpd_t *xpd, int unit, int subunit, int subtype, int subunits) -{ - int ret; - - MKADDR(&xpd->addr, unit, subunit); - xpd->xbus_idx = XPD_IDX(unit,subunit); - snprintf(xpd->xpdname, XPD_NAMELEN, "XPD-%1d%1d", unit, subunit); - xpd->subtype = subtype; - xpd->subunits = subunits; - xpd->offhook = 0; - - /* For USB-1 disable some channels */ - if(MAX_SEND_SIZE(xbus) < RPACKET_SIZE(GLOBAL, PCM_WRITE)) { - xpp_line_t no_pcm; - - no_pcm = 0x7F | xpd->digital_outputs | xpd->digital_inputs; - xpd->no_pcm = no_pcm; - XBUS_NOTICE(xbus, "max xframe size = %d, disabling some PCM channels. no_pcm=0x%04X\n", - MAX_SEND_SIZE(xbus), xpd->no_pcm); - } - if((ret = xpd_proc_create(xbus, xpd)) < 0) - return ret; - xbus_register_xpd(xbus, xpd); - return 0; -} - -/* - * Synchronous part of XPD detection. - * Called from xbus_poll() - */ -int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, - int unit, - int subunit, - byte type, - byte subtype, - int subunits, - byte port_dir) -{ - xpd_t *xpd = NULL; - bool to_phone; - int ret = -EINVAL; - - BUG_ON(type == XPD_TYPE_NOMODULE); - to_phone = BIT(subunit) & port_dir; - BUG_ON(!xbus); - xpd = xpd_byaddr(xbus, unit, subunit); - if(xpd) { - XPD_NOTICE(xpd, "XPD at %d%d already exists\n", - unit, subunit); - goto out; - } - xpd = proto_table->xops.card_new(xbus, unit, subunit, proto_table, subtype, subunits, to_phone); - if(!xpd) { - XBUS_NOTICE(xbus, "card_new(%d,%d,%d,%d,%d) failed. Ignored.\n", - unit, subunit, proto_table->type, subtype, to_phone); - goto err; - } -out: - return 0; -err: - if(xpd) - xpd_free(xpd); - return ret; -} - -void xpd_post_init(xpd_t *xpd) -{ - XPD_DBG(DEVICES, xpd, "\n"); - if(zap_autoreg) - zaptel_register_xpd(xpd); -} - -#ifdef CONFIG_PROC_FS - -/** - * Prints a general procfs entry for the bus, under xpp/BUSNAME/summary - * @page TODO: figure out procfs - * @start TODO: figure out procfs - * @off TODO: figure out procfs - * @count TODO: figure out procfs - * @eof TODO: figure out procfs - * @data an xbus_t pointer with the bus data. - */ -static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) -{ - int len = 0; - xpd_t *xpd = data; - xbus_t *xbus; - int i; - - if(!xpd) - goto out; - - xbus = xpd->xbus; - len += sprintf(page + len, "%s (%s, card %s, span %d)\n" - "timing_priority: %d\n" - "timer_count: %d span->mainttimer=%d\n" - , - xpd->xpdname, xpd->type_name, - (xpd->card_present) ? "present" : "missing", - (SPAN_REGISTERED(xpd)) ? xpd->span.spanno : 0, - xpd->timing_priority, - xpd->timer_count, xpd->span.mainttimer - ); - len += sprintf(page + len, "Address: U=%d S=%d\n", xpd->addr.unit, xpd->addr.subunit); - len += sprintf(page + len, "Subunits: %d\n", xpd->subunits); - len += sprintf(page + len, "Type: %d.%d\n\n", xpd->type, xpd->subtype); - len += sprintf(page + len, "pcm_len=%d\n\n", xpd->pcm_len); - len += sprintf(page + len, "wanted_pcm_mask=0x%04X\n\n", xpd->wanted_pcm_mask); - len += sprintf(page + len, "mute_dtmf=0x%04X\n\n", xpd->mute_dtmf); - len += sprintf(page + len, "STATES:"); - len += sprintf(page + len, "\n\t%-17s: ", "output_relays"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->digital_outputs, i)); - } - len += sprintf(page + len, "\n\t%-17s: ", "input_relays"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->digital_inputs, i)); - } - len += sprintf(page + len, "\n\t%-17s: ", "offhook"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->offhook, i)); - } - len += sprintf(page + len, "\n\t%-17s: ", "cid_on"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->cid_on, i)); - } - len += sprintf(page + len, "\n\t%-17s: ", "msg_waiting"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->msg_waiting, i)); - } - len += sprintf(page + len, "\n\t%-17s: ", "ringing"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", xpd->ringing[i]); - } - len += sprintf(page + len, "\n\t%-17s: ", "no_pcm"); - for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(xpd->no_pcm, i)); - } -#if 1 - if(SPAN_REGISTERED(xpd)) { - len += sprintf(page + len, "\nPCM:\n | [readchunk] | [writechunk] | W D"); - for_each_line(xpd, i) { - struct dahdi_chan *chans = xpd->span.chans; - byte rchunk[DAHDI_CHUNKSIZE]; - byte wchunk[DAHDI_CHUNKSIZE]; - byte *rp; - byte *wp; - int j; - - if(IS_SET(xpd->digital_outputs, i)) - continue; - if(IS_SET(xpd->digital_inputs, i)) - continue; - if(IS_SET(xpd->digital_signalling, i)) - continue; - rp = chans[i].readchunk; - wp = chans[i].writechunk; - memcpy(rchunk, rp, DAHDI_CHUNKSIZE); - memcpy(wchunk, wp, DAHDI_CHUNKSIZE); - len += sprintf(page + len, "\n port %2d> | ", i); - for(j = 0; j < DAHDI_CHUNKSIZE; j++) { - len += sprintf(page + len, "%02X ", rchunk[j]); - } - len += sprintf(page + len, " | "); - for(j = 0; j < DAHDI_CHUNKSIZE; j++) { - len += sprintf(page + len, "%02X ", wchunk[j]); - } - len += sprintf(page + len, " | %c", - (IS_SET(xpd->wanted_pcm_mask, i))?'+':' '); - len += sprintf(page + len, " %c", - (IS_SET(xpd->mute_dtmf, i))?'-':' '); - } - } -#endif -#if 0 - if(SPAN_REGISTERED(xpd)) { - len += sprintf(page + len, "\nSignalling:\n"); - for_each_line(xpd, i) { - struct dahdi_chan *chan = &xpd->span.chans[i]; - len += sprintf(page + len, "\t%2d> sigcap=0x%04X sig=0x%04X\n", i, chan->sigcap, chan->sig); - } - } -#endif - len += sprintf(page + len, "\nCOUNTERS:\n"); - for(i = 0; i < XPD_COUNTER_MAX; i++) { - len += sprintf(page + len, "\t\t%-20s = %d\n", - xpd_counters[i].name, xpd->counters[i]); - } - len += sprintf(page + len, "<-- len=%d\n", len); -out: - if (len <= off+count) - *eof = 1; - *start = page + off; - len -= off; - if (len > count) - len = count; - if (len < 0) - len = 0; - return len; - -} - -#endif - -/* - * xpd_alloc - Allocator for new XPD's - * - */ -xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channels) -{ - xpd_t *xpd = NULL; - size_t alloc_size = sizeof(xpd_t) + privsize; - int type = proto_table->type; - - BUG_ON(!proto_table); - DBG(DEVICES, "type=%d channels=%d (alloc_size=%zd)\n", - type, channels, alloc_size); - if(channels > CHANNELS_PERXPD) { - ERR("%s: type=%d: too many channels %d\n", - __FUNCTION__, type, channels); - goto err; - } - - if((xpd = KZALLOC(alloc_size, GFP_KERNEL)) == NULL) { - ERR("%s: type=%d: Unable to allocate memory\n", - __FUNCTION__, type); - goto err; - } - xpd->priv = (byte *)xpd + sizeof(xpd_t); - spin_lock_init(&xpd->lock); - xpd->xbus = NULL; - xpd->xbus_idx = -1; - xpd->channels = channels; - xpd->chans = NULL; - xpd->card_present = 0; - xpd->offhook = 0x0; /* ONHOOK */ - xpd->type = proto_table->type; - xpd->xproto = proto_table; - xpd->xops = &proto_table->xops; - xpd->digital_outputs = 0; - xpd->digital_inputs = 0; - - atomic_set(&xpd->dahdi_registered, 0); - atomic_set(&xpd->open_counter, 0); - - xpd->chans = kmalloc(sizeof(struct dahdi_chan)*xpd->channels, GFP_KERNEL); - if (xpd->chans == NULL) { - ERR("%s: Unable to allocate channels\n", __FUNCTION__); - goto err; - } - xproto_get(type); /* will be returned in xpd_free() */ - return xpd; -err: - if(xpd) { - if(xpd->chans) - kfree((void *)xpd->chans); - kfree(xpd); - } - return NULL; -} - -/* FIXME: this should be removed once digium patch their zaptel.h - * I simply wish to avoid changing zaptel.h in the xpp patches. - */ -#ifndef DAHDI_EVENT_REMOVED -#define DAHDI_EVENT_REMOVED (20) -#endif - -void xpd_disconnect(xpd_t *xpd) -{ - unsigned long flags; - - BUG_ON(!xpd); - - spin_lock_irqsave(&xpd->lock, flags); - XPD_DBG(DEVICES, xpd, "(%p)\n", xpd->xproto); - if(!xpd->card_present) /* Multiple reports */ - goto out; - xpd->card_present = 0; - if(SPAN_REGISTERED(xpd)) { - int i; - - update_xpd_status(xpd, DAHDI_ALARM_NOTOPEN); - /* TODO: Should this be done before releasing the spinlock? */ - XPD_DBG(DEVICES, xpd, "Queuing DAHDI_EVENT_REMOVED on all channels to ask user to release them\n"); - for (i=0; ispan.channels; i++) - dahdi_qevent_lock(&xpd->chans[i],DAHDI_EVENT_REMOVED); - } -out: - spin_unlock_irqrestore(&xpd->lock, flags); -} - -void xpd_remove(xpd_t *xpd) -{ - xbus_t *xbus; - - BUG_ON(!xpd); - xbus = xpd->xbus; - XPD_INFO(xpd, "Remove\n"); - zaptel_unregister_xpd(xpd); - CALL_XMETHOD(card_remove, xbus, xpd); - xpd_free(xpd); -} - -void update_xpd_status(xpd_t *xpd, int alarm_flag) -{ - struct dahdi_span *span = &xpd->span; - - if(!SPAN_REGISTERED(xpd)) { - // XPD_NOTICE(xpd, "%s: XPD is not registered. Skipping.\n", __FUNCTION__); - return; - } - switch (alarm_flag) { - case DAHDI_ALARM_NONE: - xpd->last_response = jiffies; - break; - default: - // Nothing - break; - } - if(span->alarms == alarm_flag) - return; - span->alarms = alarm_flag; - dahdi_alarm_notify(span); - XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n", xpd->span.name, alarm_flag); -} - -void update_line_status(xpd_t *xpd, int pos, bool to_offhook) -{ - dahdi_rxsig_t rxsig; - - BUG_ON(!xpd); - if(to_offhook) { - BIT_SET(xpd->offhook, pos); - rxsig = DAHDI_RXSIG_OFFHOOK; - } else { - BIT_CLR(xpd->offhook, pos); - BIT_CLR(xpd->cid_on, pos); - rxsig = DAHDI_RXSIG_ONHOOK; - /* - * To prevent latest PCM to stay in buffers - * indefinitely, mark this channel for a - * single silence transmittion. - * - * This bit will be cleared on the next tick. - */ - BIT_SET(xpd->silence_pcm, pos); - } - /* - * We should not spinlock before calling dahdi_hooksig() as - * it may call back into our xpp_hooksig() and cause - * a nested spinlock scenario - */ - LINE_DBG(SIGNAL, xpd, pos, "rxsig=%s\n", (rxsig == DAHDI_RXSIG_ONHOOK) ? "ONHOOK" : "OFFHOOK"); - if(SPAN_REGISTERED(xpd)) - dahdi_hooksig(&xpd->chans[pos], rxsig); -} - -#ifdef CONFIG_PROC_FS -static int proc_xpd_ztregister_read(char *page, char **start, off_t off, int count, int *eof, void *data) -{ - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - - BUG_ON(!xpd); - spin_lock_irqsave(&xpd->lock, flags); - - len += sprintf(page + len, "%d\n", SPAN_REGISTERED(xpd) ? xpd->span.spanno : 0); - spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) - *eof = 1; - *start = page + off; - len -= off; - if (len > count) - len = count; - if (len < 0) - len = 0; - return len; -} - -static int proc_xpd_ztregister_write(struct file *file, const char __user *buffer, unsigned long count, void *data) -{ - xpd_t *xpd = data; - char buf[MAX_PROC_WRITE]; - int dahdi_reg; - int ret; - - BUG_ON(!xpd); - if(count >= MAX_PROC_WRITE) - return -EINVAL; - if(copy_from_user(buf, buffer, count)) - return -EFAULT; - buf[count] = '\0'; - ret = sscanf(buf, "%d", &dahdi_reg); - if(ret != 1) - return -EINVAL; - XPD_DBG(GENERAL, xpd, "%s\n", (dahdi_reg) ? "register" : "unregister"); - if(dahdi_reg) - ret = zaptel_register_xpd(xpd); - else - ret = zaptel_unregister_xpd(xpd); - return (ret < 0) ? ret : count; -} - -static int proc_xpd_blink_read(char *page, char **start, off_t off, int count, int *eof, void *data) -{ - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - - BUG_ON(!xpd); - spin_lock_irqsave(&xpd->lock, flags); - - len += sprintf(page + len, "%d\n", xpd->blink_mode); - spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) - *eof = 1; - *start = page + off; - len -= off; - if (len > count) - len = count; - if (len < 0) - len = 0; - return len; -} - -static int proc_xpd_blink_write(struct file *file, const char __user *buffer, unsigned long count, void *data) -{ - xpd_t *xpd = data; - char buf[MAX_PROC_WRITE]; - char *endp; - unsigned blink; - - - BUG_ON(!xpd); - if(count >= MAX_PROC_WRITE) - return -EINVAL; - if(copy_from_user(buf, buffer, count)) - return -EFAULT; - buf[count] = '\0'; - if(count > 0 && buf[count-1] == '\n') /* chomp */ - buf[count-1] = '\0'; - blink = simple_strtoul(buf, &endp, 0); - if(*endp != '\0' || blink > 0xFFFF) - return -EINVAL; - XPD_DBG(GENERAL, xpd, "BLINK channels: 0x%X\n", blink); - xpd->blink_mode = blink; - return count; -} - -#endif - - -#define XPP_MAX_LEN 512 - -/*------------------------- Zaptel Interfaces ----------------------*/ - - -/* - * Called from zaptel with spinlock held on chan. Must not call back - * zaptel functions. - */ -int xpp_open(struct dahdi_chan *chan) -{ -#if 0 - xpd_t *xpd = chan->pvt; - xbus_t *xbus = xpd->xbus; - int pos = chan->chanpos - 1; - unsigned long flags; -#else - xpd_t *xpd; - xbus_t *xbus; - int pos; - unsigned long flags; - - if (!chan) { - NOTICE("open called on a null chan\n"); - return -EINVAL; - } - xpd = chan->pvt; - if (!xpd) { - NOTICE("open called on a chan with no pvt (xpd)\n"); - return -EINVAL; - } - xbus = xpd->xbus; - if (!xbus) { - NOTICE("open called on a chan with no xbus\n"); - return -EINVAL; - } - pos = chan->chanpos - 1; -#endif - - spin_lock_irqsave(&xbus->lock, flags); - atomic_inc(&xbus->xbus_ref_count); - atomic_inc(&xpd->open_counter); - if(IS_SET(xpd->digital_signalling, pos)) /* D-chan offhook */ - BIT_SET(xpd->offhook, pos); - DBG(DEVICES, "chan=%d (xbus_ref_count=%d)\n", - pos, atomic_read(&xbus->xbus_ref_count)); - spin_unlock_irqrestore(&xbus->lock, flags); - if(xpd->xops->card_open) - xpd->xops->card_open(xpd, pos); - return 0; -} - -int xpp_close(struct dahdi_chan *chan) -{ - xpd_t *xpd = chan->pvt; - xbus_t *xbus = xpd->xbus; - int pos = chan->chanpos - 1; - unsigned long flags; - - spin_lock_irqsave(&xbus->lock, flags); - atomic_dec(&xpd->open_counter); - if(IS_SET(xpd->digital_signalling, pos)) /* D-chan onhook */ - BIT_CLR(xpd->offhook, pos); - spin_unlock_irqrestore(&xbus->lock, flags); - if(xpd->xops->card_close) - xpd->xops->card_close(xpd, pos); - XPD_DBG(GENERAL, xpd, "pid=%d: chan=%d (xbus_ref_count=%d)\n", - current->pid, pos, atomic_read(&xbus->xbus_ref_count)); - if(atomic_dec_and_test(&xbus->xbus_ref_count)) - xbus_remove(xbus); - return 0; -} - -void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd) -{ - XPD_NOTICE(xpd, "%s: Bad ioctl\n", msg); - XPD_NOTICE(xpd, "ENOTTY: chan=%d cmd=0x%x\n", pos, cmd); - XPD_NOTICE(xpd, " IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd)); - XPD_NOTICE(xpd, " IOC_DIR=0x%02X\n", _IOC_DIR(cmd)); - XPD_NOTICE(xpd, " IOC_NR=%d\n", _IOC_NR(cmd)); - XPD_NOTICE(xpd, " IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd)); -} - -int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg) -{ - xpd_t *xpd = chan->pvt; - int pos = chan->chanpos - 1; - - if(!xpd) { - ERR("%s: channel in pos %d, was already closed. Ignore.\n", - __FUNCTION__, pos); - return -ENODEV; - } - switch (cmd) { - default: - /* Some span-specific commands before we give up: */ - if (xpd->xops->card_ioctl != NULL) { - return xpd->xops->card_ioctl(xpd, pos, cmd, arg); - } - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); - return -ENOTTY; - } - return 0; -} - -static int xpp_hooksig(struct dahdi_chan *chan, dahdi_txsig_t txsig) -{ - xpd_t *xpd = chan->pvt; - xbus_t *xbus; - int pos = chan->chanpos - 1; - - if(!xpd) { - ERR("%s: channel in pos %d, was already closed. Ignore.\n", - __FUNCTION__, pos); - return -ENODEV; - } - xbus = xpd->xbus; - BUG_ON(!xbus); - DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); - return CALL_XMETHOD(card_hooksig, xbus, xpd, pos, txsig); -} - -/* Req: Set the requested chunk size. This is the unit in which you must - report results for conferencing, etc */ -int xpp_setchunksize(struct dahdi_span *span, int chunksize); - -/* Enable maintenance modes */ -int xpp_maint(struct dahdi_span *span, int cmd) -{ - xpd_t *xpd = span->pvt; - int ret = 0; -#if 0 - char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG"; -#endif - - DBG(GENERAL, "span->mainttimer=%d\n", span->mainttimer); - switch(cmd) { - case DAHDI_MAINT_NONE: - printk("XXX Turn off local and remote loops XXX\n"); - break; - case DAHDI_MAINT_LOCALLOOP: - printk("XXX Turn on local loopback XXX\n"); - break; - case DAHDI_MAINT_REMOTELOOP: - printk("XXX Turn on remote loopback XXX\n"); - break; - case DAHDI_MAINT_LOOPUP: - printk("XXX Send loopup code XXX\n"); - // CALL_XMETHOD(LOOPBACK_AX, xpd->xbus, xpd, loopback_data, ARRAY_SIZE(loopback_data)); - break; - case DAHDI_MAINT_LOOPDOWN: - printk("XXX Send loopdown code XXX\n"); - break; - case DAHDI_MAINT_LOOPSTOP: - printk("XXX Stop sending loop codes XXX\n"); - break; - default: - ERR("XPP: Unknown maint command: %d\n", cmd); - ret = -EINVAL; - break; - } - if (span->mainttimer || span->maintstat) - update_xpd_status(xpd, DAHDI_ALARM_LOOPBACK); - return ret; -} - -#ifdef CONFIG_ZAPTEL_WATCHDOG -/* - * If the watchdog detects no received data, it will call the - * watchdog routine - */ -static int xpp_watchdog(struct dahdi_span *span, int cause) -{ - static int rate_limit = 0; - - if((rate_limit++ % 1000) == 0) - DBG(GENERAL, "\n"); - return 0; -} -#endif - -/** - * Unregister an xpd from zaptel and release related resources - * @xpd The xpd to be unregistered - * @returns 0 on success, errno otherwise - * - * Checks that nobody holds an open channel. - * - * Called by: - * - User action through /proc - * - During xpd_remove() - */ -static int zaptel_unregister_xpd(xpd_t *xpd) -{ - unsigned long flags; - - BUG_ON(!xpd); - spin_lock_irqsave(&xpd->lock, flags); - - if(!SPAN_REGISTERED(xpd)) { - XPD_NOTICE(xpd, "Already unregistered\n"); - spin_unlock_irqrestore(&xpd->lock, flags); - return -EIDRM; - } - update_xpd_status(xpd, DAHDI_ALARM_NOTOPEN); - if(atomic_read(&xpd->open_counter)) { - XPD_NOTICE(xpd, "Busy (open_counter=%d). Skipping.\n", atomic_read(&xpd->open_counter)); - spin_unlock_irqrestore(&xpd->lock, flags); - return -EBUSY; - } - mdelay(2); // FIXME: This is to give chance for transmit/receiveprep to finish. - spin_unlock_irqrestore(&xpd->lock, flags); - if(xpd->card_present) - xpd->xops->card_zaptel_preregistration(xpd, 0); - atomic_dec(&xpd->dahdi_registered); - atomic_dec(&num_registered_spans); - dahdi_unregister(&xpd->span); - if(xpd->card_present) - xpd->xops->card_zaptel_postregistration(xpd, 0); - return 0; -} - -static int zaptel_register_xpd(xpd_t *xpd) -{ - struct dahdi_span *span; - xbus_t *xbus; - int cn; - const xops_t *xops; - - BUG_ON(!xpd); - xops = xpd->xops; - xbus = xpd->xbus; - - if (SPAN_REGISTERED(xpd)) { - XPD_ERR(xpd, "Already registered\n"); - return -EEXIST; - } - cn = xpd->channels; - XPD_DBG(DEVICES, xpd, "Initializing span: %d channels.\n", cn); - memset(xpd->chans, 0, sizeof(struct dahdi_chan)*cn); - memset(&xpd->span, 0, sizeof(struct dahdi_span)); - - span = &xpd->span; - snprintf(span->name, MAX_SPANNAME, "%s/%s", xbus->busname, xpd->xpdname); - span->deflaw = DAHDI_LAW_MULAW; /* default, may be overriden by card_* drivers */ - init_waitqueue_head(&span->maintq); - span->pvt = xpd; - span->channels = cn; - span->chans = xpd->chans; - - span->open = xpp_open; - span->close = xpp_close; - span->flags = DAHDI_FLAG_RBS; - span->hooksig = xpp_hooksig; /* Only with RBS bits */ - span->ioctl = xpp_ioctl; - span->maint = xpp_maint; -#ifdef DAHDI_SPANSTAT_V2 - /* - * This actually describe the dahdi_spaninfo version 3 - * A bunch of unrelated data exported via a modified ioctl() - * What a bummer... - */ - span->manufacturer = "Xorcom Inc."; /* OK, that's obvious */ - /* span->spantype = "...."; set in card_zaptel_preregistration() */ - /* - * Yes, this basically duplicates information available - * from the description field. If some more is needed - * why not add it there? - * OK, let's add to the kernel more useless info. - */ - snprintf(span->devicetype, sizeof(span->devicetype) - 1, - "Astribank: Unit %x Subunit %x: %s", - XBUS_UNIT(xpd->xbus_idx), XBUS_SUBUNIT(xpd->xbus_idx), - xpd->type_name); - /* - * location is the only usefull new data item. - * For our devices it was available for ages via: - * - The legacy "/proc/xpp/XBUS-??/summary" (CONNECTOR=...) - * - The same info in "/proc/xpp/xbuses" - * - The modern "/sys/bus/astribanks/devices/xbus-??/connector" attribute - * So let's also export it via the newfangled "location" field. - */ - snprintf(span->location, sizeof(span->location) - 1, "%s", xbus->location); - /* - * Who said a span and irq have 1-1 relationship? - * Also exporting this low-level detail isn't too wise. - * No irq's for you today! - */ - span->irq = 0; -#endif -#ifdef ZAPTEL_SYNC_TICK - span->sync_tick = zaptel_sync_tick; -#endif - if (xpp_ec) - span->echocan = xpp_echocan; -#ifdef CONFIG_ZAPTEL_WATCHDOG - span->watchdog = xpp_watchdog; -#endif - - snprintf(xpd->span.desc, MAX_SPANDESC, "Xorcom XPD #%02d/%1d%1d: %s", - xbus->num, xpd->addr.unit, xpd->addr.subunit, xpd->type_name); - XPD_DBG(GENERAL, xpd, "Registering span '%s'\n", xpd->span.desc); - xpd->xops->card_zaptel_preregistration(xpd, 1); - if(dahdi_register(&xpd->span, prefmaster)) { - XPD_ERR(xpd, "Failed to dahdi_register span\n"); - return -ENODEV; - } - atomic_inc(&num_registered_spans); - atomic_inc(&xpd->dahdi_registered); - xpd->xops->card_zaptel_postregistration(xpd, 1); - /* - * Update zaptel about our state - */ -#if 0 - /* - * FIXME: since asterisk didn't open the channel yet, the report - * is discarded anyway. OTOH, we cannot report in xpp_open or - * xpp_chanconfig since zaptel call them with a spinlock on the channel - * and dahdi_hooksig tries to acquire the same spinlock, resulting in - * double spinlock deadlock (we are lucky that RH/Fedora kernel are - * compiled with spinlock debugging).... tough. - */ - for_each_line(xpd, cn) { - struct dahdi_chan *chans = xpd->span.chans; - - if(IS_SET(xpd->offhook, cn)) { - LINE_NOTICE(xpd, cn, "Report OFFHOOK to zaptel\n"); - dahdi_hooksig(&chans[cn], DAHDI_RXSIG_OFFHOOK); - } - } -#endif - return 0; -} - -/*------------------------- Proc debugging interface ---------------*/ - -#ifdef CONFIG_PROC_FS - -#if 0 -static int xpp_zap_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data) -{ -} -#endif - -#endif - -/*------------------------- Initialization -------------------------*/ - -static void do_cleanup(void) -{ -#ifdef CONFIG_PROC_FS - if(xpp_proc_toplevel) { - DBG(GENERAL, "Removing '%s' from proc\n", PROC_DIR); - remove_proc_entry(PROC_DIR, NULL); - xpp_proc_toplevel = NULL; - } -#endif -} - -static int __init xpp_zap_init(void) -{ - int ret = 0; - - INFO("revision %s MAX_XPDS=%d (%d*%d)\n", XPP_VERSION, - MAX_XPDS, MAX_UNIT, MAX_SUBUNIT); -#ifdef CONFIG_ZAPATA_BRI_DCHANS - INFO("FEATURE: with BRISTUFF support\n"); -#else - INFO("FEATURE: without BRISTUFF support\n"); -#endif -#ifdef CONFIG_PROC_FS - xpp_proc_toplevel = proc_mkdir(PROC_DIR, NULL); - if(!xpp_proc_toplevel) { - ret = -EIO; - goto err; - } -#endif - ret = xbus_core_init(); - if(ret) { - ERR("xbus_core_init failed (%d)\n", ret); - goto err; - } - ret = xbus_pcm_init(xpp_proc_toplevel); - if(ret) { - ERR("xbus_pcm_init failed (%d)\n", ret); - xbus_core_shutdown(); - goto err; - } - return 0; -err: - do_cleanup(); - return ret; -} - -static void __exit xpp_zap_cleanup(void) -{ - xbus_pcm_shutdown(); - xbus_core_shutdown(); - do_cleanup(); -} - -EXPORT_SYMBOL(debug); -EXPORT_SYMBOL(xpd_common_init); -EXPORT_SYMBOL(create_xpd); -EXPORT_SYMBOL(xpd_post_init); -EXPORT_SYMBOL(xpd_alloc); -EXPORT_SYMBOL(xpd_free); -EXPORT_SYMBOL(xpd_disconnect); -EXPORT_SYMBOL(update_xpd_status); -EXPORT_SYMBOL(update_line_status); -EXPORT_SYMBOL(xpp_open); -EXPORT_SYMBOL(xpp_close); -EXPORT_SYMBOL(xpp_ioctl); -EXPORT_SYMBOL(xpp_maint); -EXPORT_SYMBOL(report_bad_ioctl); - -MODULE_DESCRIPTION("XPP Zaptel Driver"); -MODULE_AUTHOR("Oron Peled "); -MODULE_LICENSE("GPL"); -MODULE_VERSION(XPP_VERSION); - -module_init(xpp_zap_init); -module_exit(xpp_zap_cleanup); diff --git a/drivers/dahdi/xpp/xpp_zap.h b/drivers/dahdi/xpp/xpp_zap.h deleted file mode 100644 index c6585af..0000000 --- a/drivers/dahdi/xpp/xpp_zap.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef XPP_ZAP_H -#define XPP_ZAP_H -/* - * Written by Oron Peled - * Copyright (C) 2004-2006, Xorcom - * - * All rights reserved. - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include "xpd.h" -#include "xproto.h" - -void xpd_disconnect(xpd_t *xpd); -int xpd_common_init(xbus_t *xbus, xpd_t *xpd, int unit, int subunit, int subtype, int subunits); -int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, - int unit, int subunit, byte type, byte subtype, int subunits, byte port_dir); -void xpd_post_init(xpd_t *xpd); -xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channels); -void xpd_free(xpd_t *xpd); -void xpd_remove(xpd_t *xpd); -void update_xpd_status(xpd_t *xpd, int alarm_flag); -void update_line_status(xpd_t *xpd, int pos, bool good); -int xpp_open(struct dahdi_chan *chan); -int xpp_close(struct dahdi_chan *chan); -int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg); -int xpp_maint(struct dahdi_span *span, int cmd); -void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd); -int total_registered_spans(void); - -#ifdef CONFIG_PROC_FS -#include - -extern struct proc_dir_entry *xpp_proc_toplevel; -#endif - -#define SPAN_REGISTERED(xpd) atomic_read(&(xpd)->dahdi_registered) - -#endif /* XPP_ZAP_H */ diff --git a/drivers/dahdi/xpp/xproto.c b/drivers/dahdi/xpp/xproto.c index c3aa34e..72686e3 100644 --- a/drivers/dahdi/xpp/xproto.c +++ b/drivers/dahdi/xpp/xproto.c @@ -22,9 +22,9 @@ #include "xpd.h" #include "xproto.h" -#include "xpp_zap.h" +#include "xpp_dahdi.h" #include "xbus-core.h" -#include "zap_debug.h" +#include "dahdi_debug.h" #include #include @@ -437,8 +437,8 @@ int xproto_register(const xproto_table_t *proto_table) CHECK_XOP(card_tick); CHECK_XOP(card_pcm_fromspan); CHECK_XOP(card_pcm_tospan); - CHECK_XOP(card_zaptel_preregistration); - CHECK_XOP(card_zaptel_postregistration); + CHECK_XOP(card_dahdi_preregistration); + CHECK_XOP(card_dahdi_postregistration); CHECK_XOP(card_hooksig); // CHECK_XOP(card_ioctl); // optional method -- call after testing CHECK_XOP(card_register_reply); diff --git a/drivers/dahdi/xpp/xproto.h b/drivers/dahdi/xpp/xproto.h index 760b0a3..9a0726e 100644 --- a/drivers/dahdi/xpp/xproto.h +++ b/drivers/dahdi/xpp/xproto.h @@ -223,8 +223,8 @@ struct xops { int (*card_tick)(xbus_t *xbus, xpd_t *xpd); void (*card_pcm_fromspan)(xbus_t *xbus, xpd_t *xpd, xpp_line_t lines, xpacket_t *pack); void (*card_pcm_tospan)(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack); - int (*card_zaptel_preregistration)(xpd_t *xpd, bool on); - int (*card_zaptel_postregistration)(xpd_t *xpd, bool on); + int (*card_dahdi_preregistration)(xpd_t *xpd, bool on); + int (*card_dahdi_postregistration)(xpd_t *xpd, bool on); int (*card_hooksig)(xbus_t *xbus, xpd_t *xpd, int pos, dahdi_txsig_t txsig); int (*card_ioctl)(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg); int (*card_open)(xpd_t *xpd, lineno_t pos); diff --git a/drivers/dahdi/xpp/zap_debug.c b/drivers/dahdi/xpp/zap_debug.c deleted file mode 100644 index 08f684e..0000000 --- a/drivers/dahdi/xpp/zap_debug.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Written by Oron Peled - * Copyright (C) 2004-2006, Xorcom - * - * All rights reserved. - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -#include - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -# warning "This module is tested only with 2.6 kernels" -#endif - -#include -#include -#include -#include -#include "zap_debug.h" -#include "xdefs.h" - -static const char rcsid[] = "$Id$"; - -#define P_(x) [ x ] = { .value = x, .name = #x, } -static struct { - int value; - char *name; -} poll_names[] = { - P_(POLLIN), - P_(POLLPRI), - P_(POLLOUT), - P_(POLLERR), - P_(POLLHUP), - P_(POLLNVAL), - P_(POLLRDNORM), - P_(POLLRDBAND), - P_(POLLWRNORM), - P_(POLLWRBAND), - P_(POLLMSG), - P_(POLLREMOVE) -}; -#undef P_ - -void dump_poll(int debug, const char *msg, int poll) -{ - int i; - - for(i = 0; i < ARRAY_SIZE(poll_names); i++) { - if(poll & poll_names[i].value) - DBG(GENERAL, "%s: %s\n", msg, poll_names[i].name); - } -} - -void alarm2str(int alarm, char *buf, int buflen) -{ - char *p = buf; - int left = buflen; - int i; - int n; - - if(!alarm) { - snprintf(buf, buflen, "NONE"); - return; - } - memset(buf, 0, buflen); - for(i = 0; i < 8; i++) { - if(left && (alarm & BIT(i))) { - n = snprintf(p, left, "%s,", alarmbit2str(i)); - p += n; - left -= n; - } - } - if(p > buf) /* kill last comma */ - *(p - 1) = '\0'; -} - -EXPORT_SYMBOL(dump_poll); -EXPORT_SYMBOL(alarm2str); diff --git a/drivers/dahdi/xpp/zap_debug.h b/drivers/dahdi/xpp/zap_debug.h deleted file mode 100644 index 2911828..0000000 --- a/drivers/dahdi/xpp/zap_debug.h +++ /dev/null @@ -1,201 +0,0 @@ -#ifndef ZAP_DEBUG_H -#define ZAP_DEBUG_H -/* - * Written by Oron Peled - * Copyright (C) 2004-2006, Xorcom - * - * All rights reserved. - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include /* for zt_* defs */ - -/* Debugging Macros */ - -#define PRINTK(level, category, fmt, ...) \ - printk(KERN_ ## level "%s%s-%s: " fmt, #level, category, THIS_MODULE->name, ## __VA_ARGS__) - -#define XBUS_PRINTK(level, category, xbus, fmt, ...) \ - printk(KERN_ ## level "%s%s-%s: %s: " fmt, #level, \ - category, THIS_MODULE->name, (xbus)->busname, ## __VA_ARGS__) - -#define XPD_PRINTK(level, category, xpd, fmt, ...) \ - printk(KERN_ ## level "%s%s-%s: %s/%s: " fmt, #level, \ - category, THIS_MODULE->name, (xpd)->xbus->busname, (xpd)->xpdname, ## __VA_ARGS__) - -#define LINE_PRINTK(level, category, xpd, pos, fmt, ...) \ - printk(KERN_ ## level "%s%s-%s: %s/%s/%d: " fmt, #level, \ - category, THIS_MODULE->name, (xpd)->xbus->busname, (xpd)->xpdname, (pos), ## __VA_ARGS__) - -#define PORT_PRINTK(level, category, xbus, unit, port, fmt, ...) \ - printk(KERN_ ## level "%s%s-%s: %s UNIT=%d PORT=%d: " fmt, #level, \ - category, THIS_MODULE->name, (xbus)->busname, (unit), (port), ## __VA_ARGS__) - -#define DBG(bits, fmt, ...) \ - ((void)((debug & (DBG_ ## bits)) && PRINTK(DEBUG, "-" #bits, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) -#define INFO(fmt, ...) PRINTK(INFO, "", fmt, ## __VA_ARGS__) -#define NOTICE(fmt, ...) PRINTK(NOTICE, "", fmt, ## __VA_ARGS__) -#define WARNING(fmt, ...) PRINTK(WARNING, "", fmt, ## __VA_ARGS__) -#define ERR(fmt, ...) PRINTK(ERR, "", fmt, ## __VA_ARGS__) - -#define XBUS_DBG(bits, xbus, fmt, ...) \ - ((void)((debug & (DBG_ ## bits)) && XBUS_PRINTK(DEBUG, "-" #bits, xbus, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) -#define XBUS_INFO(xbus, fmt, ...) XBUS_PRINTK(INFO, "", xbus, fmt, ## __VA_ARGS__) -#define XBUS_NOTICE(xbus, fmt, ...) XBUS_PRINTK(NOTICE, "", xbus, fmt, ## __VA_ARGS__) -#define XBUS_ERR(xbus, fmt, ...) XBUS_PRINTK(ERR, "", xbus, fmt, ## __VA_ARGS__) - -#define XPD_DBG(bits, xpd, fmt, ...) \ - ((void)((debug & (DBG_ ## bits)) && XPD_PRINTK(DEBUG, "-" #bits, xpd, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) -#define XPD_INFO(xpd, fmt, ...) XPD_PRINTK(INFO, "", xpd, fmt, ## __VA_ARGS__) -#define XPD_NOTICE(xpd, fmt, ...) XPD_PRINTK(NOTICE, "", xpd, fmt, ## __VA_ARGS__) -#define XPD_WARNING(xpd, fmt, ...) XPD_PRINTK(WARNING, "", xpd, fmt, ## __VA_ARGS__) -#define XPD_ERR(xpd, fmt, ...) XPD_PRINTK(ERR, "", xpd, fmt, ## __VA_ARGS__) - -#define LINE_DBG(bits, xpd, pos, fmt, ...) \ - ((void)((debug & (DBG_ ## bits)) && LINE_PRINTK(DEBUG, "-" #bits, xpd, pos, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) -#define LINE_NOTICE(xpd, pos, fmt, ...) LINE_PRINTK(NOTICE, "", xpd, pos, fmt, ## __VA_ARGS__) -#define LINE_ERR(xpd, pos, fmt, ...) LINE_PRINTK(ERR, "", xpd, pos, fmt, ## __VA_ARGS__) - -#define PORT_DBG(bits, xbus, unit, port, fmt, ...) \ - ((void)((debug & (DBG_ ## bits)) && PORT_PRINTK(DEBUG, "-" #bits, \ - xbus, unit, port, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) -#define PORT_NOTICE(xbus, unit, port, fmt, ...) PORT_PRINTK(NOTICE, "", xbus, unit, port, fmt, ## __VA_ARGS__) -#define PORT_ERR(xbus, unit, port, fmt, ...) PORT_PRINTK(ERR, "", xbus, unit, port, fmt, ## __VA_ARGS__) - -/* - * Bits for debug - */ -#define DBG_GENERAL BIT(0) -#define DBG_PCM BIT(1) -#define DBG_LEDS BIT(2) -#define DBG_SYNC BIT(3) -#define DBG_SIGNAL BIT(4) -#define DBG_PROC BIT(5) -#define DBG_REGS BIT(6) -#define DBG_DEVICES BIT(7) /* instantiation/destruction etc. */ -#define DBG_COMMANDS BIT(8) /* All commands */ -#define DBG_ANY (~0) - -void dump_poll(int debug, const char *msg, int poll); - -static inline char *rxsig2str(dahdi_rxsig_t sig) -{ - switch(sig) { - case DAHDI_RXSIG_ONHOOK: return "ONHOOK"; - case DAHDI_RXSIG_OFFHOOK: return "OFFHOOK"; - case DAHDI_RXSIG_START: return "START"; - case DAHDI_RXSIG_RING: return "RING"; - case DAHDI_RXSIG_INITIAL: return "INITIAL"; - } - return "Unknown rxsig"; -} - -static inline char *txsig2str(dahdi_txsig_t sig) -{ - switch(sig) { - case DAHDI_TXSIG_ONHOOK: return "TXSIG_ONHOOK"; - case DAHDI_TXSIG_OFFHOOK: return "TXSIG_OFFHOOK"; - case DAHDI_TXSIG_START: return "TXSIG_START"; - case DAHDI_TXSIG_KEWL: return "TXSIG_KEWL"; /* Drop battery if possible */ - } - return "Unknown txsig"; -} - -static inline char *event2str(int event) -{ - switch(event) { - case DAHDI_EVENT_NONE: return "NONE"; - case DAHDI_EVENT_ONHOOK: return "ONHOOK"; - case DAHDI_EVENT_RINGOFFHOOK: return "RINGOFFHOOK"; - case DAHDI_EVENT_WINKFLASH: return "WINKFLASH"; - case DAHDI_EVENT_ALARM: return "ALARM"; - case DAHDI_EVENT_NOALARM: return "NOALARM"; - case DAHDI_EVENT_ABORT: return "ABORT"; - case DAHDI_EVENT_OVERRUN: return "OVERRUN"; - case DAHDI_EVENT_BADFCS: return "BADFCS"; - case DAHDI_EVENT_DIALCOMPLETE: return "DIALCOMPLETE"; - case DAHDI_EVENT_RINGERON: return "RINGERON"; - case DAHDI_EVENT_RINGEROFF: return "RINGEROFF"; - case DAHDI_EVENT_HOOKCOMPLETE: return "HOOKCOMPLETE"; - case DAHDI_EVENT_BITSCHANGED: return "BITSCHANGED"; - case DAHDI_EVENT_PULSE_START: return "PULSE_START"; - case DAHDI_EVENT_TIMER_EXPIRED: return "TIMER_EXPIRED"; - case DAHDI_EVENT_TIMER_PING: return "TIMER_PING"; - case DAHDI_EVENT_POLARITY: return "POLARITY"; - } - return "Unknown event"; -} - -static inline char *hookstate2str(int hookstate) -{ - switch(hookstate) { - case DAHDI_ONHOOK: return "DAHDI_ONHOOK"; - case DAHDI_START: return "DAHDI_START"; - case DAHDI_OFFHOOK: return "DAHDI_OFFHOOK"; - case DAHDI_WINK: return "DAHDI_WINK"; - case DAHDI_FLASH: return "DAHDI_FLASH"; - case DAHDI_RING: return "DAHDI_RING"; - case DAHDI_RINGOFF: return "DAHDI_RINGOFF"; - } - return "Unknown hookstate"; -} - -/* From zaptel.c */ -static inline char *sig2str(int sig) -{ - switch (sig) { - case DAHDI_SIG_FXSLS: return "FXSLS"; - case DAHDI_SIG_FXSKS: return "FXSKS"; - case DAHDI_SIG_FXSGS: return "FXSGS"; - case DAHDI_SIG_FXOLS: return "FXOLS"; - case DAHDI_SIG_FXOKS: return "FXOKS"; - case DAHDI_SIG_FXOGS: return "FXOGS"; - case DAHDI_SIG_EM: return "E&M"; - case DAHDI_SIG_EM_E1: return "E&M-E1"; - case DAHDI_SIG_CLEAR: return "Clear"; - case DAHDI_SIG_HDLCRAW: return "HDLCRAW"; - case DAHDI_SIG_HDLCFCS: return "HDLCFCS"; - case DAHDI_SIG_HDLCNET: return "HDLCNET"; - case DAHDI_SIG_SLAVE: return "Slave"; - case DAHDI_SIG_CAS: return "CAS"; - case DAHDI_SIG_DACS: return "DACS"; - case DAHDI_SIG_DACS_RBS: return "DACS+RBS"; - case DAHDI_SIG_SF: return "SF (ToneOnly)"; - case DAHDI_SIG_NONE: - break; - } - return "Unconfigured"; -} - -static inline char *alarmbit2str(int alarmbit) -{ - /* from dahdi/kernel.h */ - switch(1 << alarmbit) { - case DAHDI_ALARM_NONE: return "NONE"; - case DAHDI_ALARM_RECOVER: return "RECOVER"; - case DAHDI_ALARM_LOOPBACK: return "LOOPBACK"; - case DAHDI_ALARM_YELLOW: return "YELLOW"; - case DAHDI_ALARM_RED: return "RED"; - case DAHDI_ALARM_BLUE: return "BLUE"; - case DAHDI_ALARM_NOTOPEN: return "NOTOPEN"; - } - return "UNKNOWN"; -} - -void alarm2str(int alarm, char *buf, int buflen); - -#endif /* ZAP_DEBUG_H */ -- cgit v1.2.3