xpp: fix waitfor_xpds race at startup

* If userspace would run
    modprobe xpp_usb && cat /sys/bus/astribanks/devices/xbus-00/waitfor_xpds
  it would return immediately rather than wait for the Astribank to
  initialize.
* We sometimes managed to read before getting the reply from the
  astribank.
* Now we don't trust unit count at such an early stage.
* Instread we wait for the Astribank to reach a stable state (READY or FAIL)
  before finish waiting for this astribank.

Internal-Issue-ID: Xorcom-1502
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
wcte13xp: Workaround rare nmi on modprobe on select systems

With certain pci controllers that support pci hotplug, during the reset
sequence of the fpga, the host controller can get confused about the state of
the card and throw an nmi.

Known affected systems:
 HP proliant DL160 & DL360p
 Dell poweredge R520
 Super Micro X7SPA-HF

This patch attempts to work around that by removing the fpga reset sequence
from the driver startup, then setting various control registers to known
starting state values.

This patch removes the field upgradeable firmware logic temporarily for the
te133 card to prevent fpga reset.

Signed-off-by: Russ Meyerriecks <rmeyerriecks@digium.com>
xpp: Serialize dahdi registration

xpp: Serialize dahdi registration: Cause races under highly-parallel
workloads (with dahdi_autoreg=0).

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: refactor FXS ring settings

xpp: refactor the FXS module ring settings into separate data structure:

* Update High VBAT initialization in init_card_1_30:
  - Take the value used in set_vm_led_mode() (0x34)
  - Now we don't need to set it over and over again in set_vm_led_mode()
* Create a unified ring_parameters[] array for all ring registers:
  - Columns for 3 ring types (NEON, TRAPEZ, NORMAL)
  - Used by new send_ring_parameters() function
* Now the set_vm_led_mode() simply calls send_ring_parameters()
* This cleanup would allow us to change ring parameters at runtime (by
  updating the values in these tables).

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: FXS: ring/mwi settings: a sysfs interface

A new SysFS interface for FXS modules (XPDs):
* In /sys/bus/xpds/devices/<ll>:<m>:<n>/fxs_ring_registers
* Reading show current register values for NEON/TRAPEZ/NORMAL
* Modify the table via writing: "<column> <reg> <byte> [<byte>]"
* Example:
	echo "NEON 0x33 0x12" > \
		'/sys/bus/xpds/devices/00:0:0/fxs_ring_registers'

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: ring/mwi settings: add to FXS init script

init_card_1_30 (FXS modules init script) can now use the new sysfs
interface to set ring settings.

Currently it only overwrite a single register

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
add a 'location' attribute to sysfs (dahdi_device):

* Our user-space previously used the implicit location from the sysfs
  device path of the "dahdi_device".
* However:
  - Sysfs paths are very limited in length.
  - Low-level driver need more control on the location field.
  - For example, it need to be persistant for span_assignments.
* We now export explicitly the 'location' field which is managed by
  low-level drivers.
* We will use this field as the location in span_assignments.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: Firmware for Astribanks 2.02

Astribank 2.02: a newer model: slight variation of 2.01 (both use E-Main
4). Uses the same USB firmware, has to use a different FPGA firmware as
newer devices cannot be made to work with older 2.01 firmware.

FPGA rev. 11307.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: Firmware for Astribanks 2.02: Makefile

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: USB_FW.202.hex: provide as a symlink

Provide USB_FW.202.hex as a (install-time) symlink to USB_FW.201.hex.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: mark an AB as failed if it gives bad desc

If we fail at handling the device descriptor from the Astribank, mark it
as in state "failed".

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
xpp: Fail loading if no module on first slot

The driver assumes that the first slot is not empty. If this is not the
case, synchronization will not work.

Fail loading if this assertion does not hold.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
dahdi_config: Remove unused NO_DCDC definition.

There are not any drivers in the tree that make reference to this definition
anymore, so it can be removed.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
dahdi: Clear DAHDI_ALARM_NOTOPEN when spans are re-initialized.

This eliminates the need for board drivers to always re-report their alarm
states when spans are unassigned and then reassigned.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
dahdi: Fix placement of '/' in output of /proc/dahdi/x

Fixes strings that look like:
  Span 1: TE2/0/1 "T2XXP (PCI) Card 0 Span 1" CCSHDB3//CRC4 RED

To look like:
  Span 1: TE2/0/1 "T2XXP (PCI) Card 0 Span 1" CCS/HDB3/CRC4 RED

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
dahdi: Work around missing KBUILD_MODNAME

Some older versions of Kbuild will not pass KBUILD_MODNAME to a
compilation unit that is linked to multiple drivers. This change works
around this issue by globally modifing dev_dbg in this case.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
dahdi: Backport try_wait_for_completion() and list_first_entry()

This allows drivers to use the newer interface but build against older
kernels.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
wct4xxp: Print warning in dmesg if span priority is not set correctly.

dahdi_genconf currently does not take into account the number of spans
configured for a particular board. Therefore if you have two dual span cards
installed in the system, it could be possible to have something like this in
/etc/dahdi/system.conf:

  spans=1,1,...
  spans=2,2,...
  spans=3,3,...
  spans=4,4,...

When what you really want is something like this:

  spans=1,1,...
  spans=2,2,...
  spans=3,1,...
  spans=4,2,...

Otherwise, spans 3 and 4 will be configured to not recover the clock from the
span which is most likely NOT what you want.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
wct4xxp: Fix bipolar error insertion test mode.

This change wouldn't affect most people since it's only used by the error
injection code.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
wct4xxp: VPM companding switch print is now debug only.

This print happened when the linemode was changed via sysfs, but it didn't
really add much extra information that a user could act on.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>