~xnox/debian/sid/dahdi-linux/nmu-659818

« back to all changes in this revision

Viewing changes to drivers/dahdi/xpp/xbus-core.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell, Tzafrir Cohen, Victor Seva
  • Date: 2009-05-20 07:22:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090520072246-y1ba8ofc81ykgf8z
Tags: 1:2.2.0~dfsg~rc4-1
* New upstream release

[ Tzafrir Cohen ]
* NOT RELEASED YET
* Dropped qozap as wcb4xxp provides that functionality.
* New upstream RC.
* Actually build OpenVox drivers.
* opvxa1200.c: rev. 1.4.12.4 (battery fixes and such)
* Fix '${match}' in udev rules file (hardwire).
* no_firmware_download: Disable downloading a binary kernel module at 
  build time.

[ Victor Seva ]
* fix debian/watch. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#endif
45
45
#include "dahdi_debug.h"
46
46
 
47
 
static const char rcsid[] = "$Id: xbus-core.c 5167 2008-10-29 15:09:11Z tzafrir $";
 
47
static const char rcsid[] = "$Id: xbus-core.c 6408 2009-04-20 10:26:35Z tzafrir $";
48
48
 
49
49
/* Defines */
50
50
#define INITIALIZATION_TIMEOUT  (90*HZ)         /* in jiffies */
61
61
 
62
62
/* Command line parameters */
63
63
extern int debug;
 
64
static DEF_PARM(uint, command_queue_length, 800, 0444, "Maximal command queue length");
64
65
static DEF_PARM(uint, poll_timeout, 1000, 0644, "Timeout (in jiffies) waiting for units to reply");
65
66
static DEF_PARM_BOOL(rx_tasklet, 0, 0644, "Use receive tasklets");
66
67
 
68
69
#ifdef  OLD_PROC
69
70
static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count, int *eof, void *data);
70
71
#endif
71
 
static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, void *priv);
 
72
static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv);
72
73
static void transport_destroy(xbus_t *xbus);
73
74
 
74
75
/* Data structures */
503
504
{
504
505
        xframe_t        *frm;
505
506
        int             ret = 0;
 
507
        int             packno;
506
508
 
507
509
        xbus->command_tick_counter++;
508
 
        frm = xframe_dequeue(&xbus->command_queue);
509
 
        if(frm) {
 
510
        xbus->usec_nosend -= 1000;      /* That's our budget */
 
511
        for(packno = 0; packno < 3; packno++) {
 
512
                if(xbus->usec_nosend > 0)
 
513
                        break;
 
514
                frm = xframe_dequeue(&xbus->command_queue);
 
515
                if(!frm) {
 
516
                        wake_up(&xbus->command_queue_empty);
 
517
                        break;
 
518
                }
510
519
                BUG_ON(frm->xframe_magic != XFRAME_MAGIC);
 
520
                xbus->usec_nosend += frm->usec_towait;
511
521
                ret = really_send_cmd_frame(xbus, frm);
512
522
                if(ret < 0) {
513
523
                        XBUS_ERR(xbus,
515
525
                                ret);
516
526
                        xbus_setstate(xbus, XBUS_STATE_FAIL);
517
527
                }
518
 
        } else
519
 
                wake_up(&xbus->command_queue_empty);
 
528
        }
 
529
        if(xbus->usec_nosend < 0)
 
530
                xbus->usec_nosend = 0;
520
531
        return ret;
521
532
}
522
533
 
717
728
        int                     i;
718
729
        int                     subunits;
719
730
        int                     ret = 0;
 
731
        int                     remaining_ports;
720
732
 
721
733
        proto_table = xproto_get(type);
722
734
        if(!proto_table) {
725
737
                        unit, type);
726
738
                return -EINVAL;
727
739
        }
 
740
        remaining_ports = ports;
728
741
        subunits = (ports + proto_table->ports_per_subunit - 1) /
729
742
                        proto_table->ports_per_subunit;
730
743
        XBUS_DBG(DEVICES, xbus, "CARD %d type=%d.%d ports=%d (%dx%d), %d subunits, port-dir=0x%02X\n",
741
754
        BUG_ON(!xops);
742
755
        xbus->worker->num_units += subunits - 1;
743
756
        for(i = 0; i < subunits; i++) {
 
757
                int     subunit_ports = proto_table->ports_per_subunit;
 
758
 
 
759
                if(subunit_ports > remaining_ports)
 
760
                        subunit_ports = remaining_ports;
 
761
                remaining_ports -= proto_table->ports_per_subunit;
 
762
                if(subunit_ports <= 0) {
 
763
                        XBUS_NOTICE(xbus,
 
764
                                "Subunit XPD=%d%d without ports (%d of %d)\n",
 
765
                                unit,
 
766
                                i,
 
767
                                subunit_ports,
 
768
                                ports);
 
769
                        ret = -ENODEV;
 
770
                        goto out;
 
771
                }
744
772
                if(!XBUS_IS(xbus, RECVD_DESC)) {
745
773
                        XBUS_NOTICE(xbus,
746
774
                                "Cannot create XPD=%d%d in state %s\n",
750
778
                        ret = -ENODEV;
751
779
                        goto out;
752
780
                }
753
 
                XBUS_DBG(DEVICES, xbus, "Creating XPD=%d%d type=%d.%d\n",
 
781
                XBUS_DBG(DEVICES, xbus, "Creating XPD=%d%d type=%d.%d (%d ports)\n",
754
782
                                unit,
755
783
                                i,
756
784
                                type,
757
 
                                subtype);
 
785
                                subtype, subunit_ports);
758
786
                if(!XBUS_IS(xbus, RECVD_DESC)) {
759
787
                        XBUS_ERR(xbus, "Aborting creation -- In bad state %s\n",
760
788
                                xbus_statename(XBUS_STATE(xbus)));
761
789
                        ret = -ENODEV;
762
790
                        goto out;
763
791
                }
764
 
                ret = create_xpd(xbus, proto_table, unit, i, type, subtype, subunits, port_dir);
 
792
                ret = create_xpd(xbus, proto_table, unit, i, type, subtype, subunits, subunit_ports, port_dir);
765
793
                if(ret < 0) {
766
794
                        XBUS_ERR(xbus, "Creation of XPD=%d%d failed %d\n",
767
795
                                unit, i, ret);
813
841
        int     unit;
814
842
        int     subunit;
815
843
        xpd_t   *xpd;
 
844
        struct timeval  time_start;
 
845
        struct timeval  time_end;
 
846
        unsigned long   timediff;
816
847
 
 
848
        do_gettimeofday(&time_start);
817
849
        XBUS_DBG(DEVICES, xbus, "refcount_xbus=%d\n",
818
850
                        refcount_xbus(xbus));
819
851
        for(unit = 0; unit < MAX_UNIT; unit++) {
843
875
                                goto err;
844
876
                }
845
877
        }
 
878
        do_gettimeofday(&time_end);
 
879
        timediff = usec_diff(&time_end, &time_start);
 
880
        timediff /= 1000*100;
 
881
        XBUS_INFO(xbus, "Initialized in %ld.%1ld sec\n", timediff/10, timediff%10);
846
882
        return 0;
847
883
err:
 
884
        xbus_setstate(xbus, XBUS_STATE_FAIL);
848
885
        return -EINVAL;
849
886
}
850
887
 
909
946
         * all others will reach the device before it.
910
947
         */
911
948
        xbus_request_sync(xbus, SYNC_MODE_PLL);
912
 
        elect_syncer("xbus_poll(end)"); /* FIXME: try to do it later */
 
949
        elect_syncer("xbus_populate(end)");     /* FIXME: try to do it later */
913
950
out:
914
951
        XBUS_DBG(DEVICES, xbus, "Leaving\n");
915
952
        wake_up(&worker->wait_for_xpd_initialization);
917
954
        up(&xbus->in_worker);
918
955
        return;
919
956
failed:
 
957
        xbus_setstate(xbus, XBUS_STATE_FAIL);
920
958
        goto out;
921
959
}
922
960
 
1180
1218
 
1181
1219
void xbus_deactivate(xbus_t *xbus, bool is_disconnected)
1182
1220
{
1183
 
        int     i;
1184
 
 
1185
1221
        BUG_ON(!xbus);
1186
1222
        XBUS_INFO(xbus, "[%s] Deactivating\n", xbus->label);
1187
1223
        if(!xbus_setstate(xbus, XBUS_STATE_DEACTIVATING))
1188
1224
                return;
1189
1225
        xbus_request_sync(xbus, SYNC_MODE_NONE);        /* no more ticks */
1190
 
        for(i = 0; i < MAX_XPDS; i++) {
1191
 
                xpd_t *xpd = xpd_of(xbus, i);
1192
 
                if(xpd) {
1193
 
                        xpd_unreg_request(xpd);
1194
 
                }
1195
 
        }
1196
 
        elect_syncer("deactivate");
 
1226
        xbus_request_removal(xbus);
1197
1227
        XBUS_DBG(DEVICES, xbus, "[%s] Waiting for queues\n", xbus->label);
1198
1228
        xbus_command_queue_clean(xbus);
1199
1229
        xbus_command_queue_waitempty(xbus);
1202
1232
        xbus_release_xpds(xbus);
1203
1233
        if(!is_disconnected)
1204
1234
                xbus_setstate(xbus, XBUS_STATE_IDLE);
 
1235
        elect_syncer("deactivate");
1205
1236
}
1206
1237
 
1207
1238
void xbus_disconnect(xbus_t *xbus)
1305
1336
        KZFREE(xbus);
1306
1337
}
1307
1338
 
1308
 
xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, void *priv)
 
1339
xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv)
1309
1340
{
1310
1341
        int                     err;
1311
1342
        xbus_t                  *xbus = NULL;
1319
1350
        }
1320
1351
        snprintf(xbus->busname, XBUS_NAMELEN, "XBUS-%02d", xbus->num);
1321
1352
        XBUS_DBG(DEVICES, xbus, "\n");
1322
 
        transport_init(xbus, ops, max_send_size, priv);
 
1353
        transport_init(xbus, ops, max_send_size, transport_device, priv);
1323
1354
        spin_lock_init(&xbus->lock);
1324
1355
        init_waitqueue_head(&xbus->command_queue_empty);
1325
1356
        init_timer(&xbus->command_timer);
1378
1409
                goto nobus;
1379
1410
        }
1380
1411
#endif
1381
 
        xframe_queue_init(&xbus->command_queue, 10, 500, "command_queue", xbus);
 
1412
        xframe_queue_init(&xbus->command_queue, 10, command_queue_length, "command_queue", xbus);
1382
1413
        xframe_queue_init(&xbus->receive_queue, 10, 50, "receive_queue", xbus);
1383
 
        xframe_queue_init(&xbus->send_pool, 10, 200, "send_pool", xbus);
 
1414
        xframe_queue_init(&xbus->send_pool, 10, 100, "send_pool", xbus);
1384
1415
        xframe_queue_init(&xbus->receive_pool, 10, 50, "receive_pool", xbus);
1385
1416
        xframe_queue_init(&xbus->pcm_tospan, 5, 10, "pcm_tospan", xbus);
1386
1417
        tasklet_init(&xbus->receive_tasklet, receive_tasklet_func, (unsigned long)xbus);
1469
1500
        len += sprintf(page + len, "self_ticking: %d (last_tick at %ld)\n",
1470
1501
                        xbus->self_ticking, xbus->ticker.last_sample.tv.tv_sec);
1471
1502
        len += sprintf(page + len, "command_tick: %d\n", xbus->command_tick_counter);
 
1503
        len += sprintf(page + len, "usec_nosend: %d\n", xbus->usec_nosend);
1472
1504
        len += sprintf(page + len, "xbus: pcm_rx_counter = %d, frag = %d\n",
1473
1505
                atomic_read(&xbus->pcm_rx_counter), xbus->xbus_frag_count);
1474
1506
        len += sprintf(page + len, "max_rx_process = %2ld.%ld ms\n",
1505
1537
 
1506
1538
}
1507
1539
 
 
1540
static bool xpds_done(xbus_t *xbus)
 
1541
{
 
1542
        struct xbus_workqueue   *worker;
 
1543
 
 
1544
        if(XBUS_IS(xbus, FAIL))
 
1545
                return 1;       /* Nothing to wait for */
 
1546
        if(!XBUS_IS(xbus, RECVD_DESC))
 
1547
                return 1;       /* We are not in the initialization phase */
 
1548
        worker = xbus->worker;
 
1549
        if(worker->xpds_init_done)
 
1550
                return 1;       /* All good */
 
1551
        /* Keep waiting */
 
1552
        return 0;
 
1553
}
 
1554
 
1508
1555
int waitfor_xpds(xbus_t *xbus, char *buf)
1509
1556
{
1510
1557
        struct xbus_workqueue   *worker;
1525
1572
                "Waiting for card initialization of %d XPD's max %d seconds\n",
1526
1573
                worker->num_units,
1527
1574
                INITIALIZATION_TIMEOUT/HZ);
1528
 
        /*
1529
 
         * when polling is finished xbus_poll():
1530
 
         *   - Unset worker->is_polling
1531
 
         *   - Sets worker->count_xpds_to_initialize.
1532
 
         * So we wait until polling is finished (is_polling == 0) and:
1533
 
         *   - No poll answers from Astribank (e.g: defective firmware).
1534
 
         *   - Or no units to initialize (e.g: mini-AB with only main card).
1535
 
         *   - Or we finished initializing all existing units.
1536
 
         *   - Or A timeout passed.
1537
 
         */
1538
1575
        ret = wait_event_interruptible_timeout(
1539
1576
                worker->wait_for_xpd_initialization,
1540
 
                !XBUS_IS(xbus, RECVD_DESC) || worker->xpds_init_done,
 
1577
                xpds_done(xbus),
1541
1578
                INITIALIZATION_TIMEOUT);
1542
1579
        if(ret == 0) {
1543
1580
                XBUS_ERR(xbus, "Card Initialization Timeout\n");
1552
1589
                        "Finished initialization of %d XPD's in %d seconds.\n",
1553
1590
                        worker->num_units_initialized,
1554
1591
                        (INITIALIZATION_TIMEOUT - ret)/HZ);
1555
 
        spin_lock_irqsave(&xbus->lock, flags);
1556
 
        len += sprintf(buf, "XPDS_READY: %s: %d/%d\n",
 
1592
        if(XBUS_IS(xbus, FAIL)) {
 
1593
                len += sprintf(buf, "FAILED: %s\n", xbus->busname);
 
1594
        } else {
 
1595
                spin_lock_irqsave(&xbus->lock, flags);
 
1596
                len += sprintf(buf, "XPDS_READY: %s: %d/%d\n",
1557
1597
                        xbus->busname,
1558
1598
                        worker->num_units_initialized, worker->num_units);
1559
 
        spin_unlock_irqrestore(&xbus->lock, flags);
 
1599
                spin_unlock_irqrestore(&xbus->lock, flags);
 
1600
        }
1560
1601
out:
1561
1602
        put_xbus(__FUNCTION__, xbus);   /* from start of waitfor_xpds_show() */
1562
1603
        return len;
1566
1607
static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count, int *eof, void *data)
1567
1608
{
1568
1609
        int                     len = 0;
1569
 
        unsigned long           flags;
1570
1610
        xbus_t                  *xbus = data;
1571
 
        struct xbus_workqueue   *worker;
1572
 
        int                     ret;
1573
1611
 
1574
1612
        if(!xbus)
1575
1613
                goto out;
1709
1747
}
1710
1748
#endif
1711
1749
 
1712
 
static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, void *priv)
 
1750
static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv)
1713
1751
{
1714
1752
        BUG_ON(!xbus);
1715
1753
        BUG_ON(!ops);
1719
1757
        BUG_ON(!ops->free_xframe);
1720
1758
        xbus->transport.ops = ops;
1721
1759
        xbus->transport.max_send_size = max_send_size;
 
1760
        xbus->transport.transport_device = transport_device;
1722
1761
        xbus->transport.priv = priv;
1723
1762
        xbus->transport.xbus_state = XBUS_STATE_START;
1724
1763
        spin_lock_init(&xbus->transport.state_lock);