summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2002-07-17 19:19:06 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2002-07-17 19:19:06 +0000
commit4df431b0eafadb55bb322f213470ae81dedc69c2 (patch)
treefda3f7ef656a7d81a566b32a97b5dd7cac953af7
parenta72deaedf7713a2b101e72007ebff0c6cf64230a (diff)
Version 0.3.0 from FTP
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@93 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rwxr-xr-xztdummy.c190
-rwxr-xr-xztdummy.h133
2 files changed, 323 insertions, 0 deletions
diff --git a/ztdummy.c b/ztdummy.c
new file mode 100755
index 0000000..021b12d
--- /dev/null
+++ b/ztdummy.c
@@ -0,0 +1,190 @@
+/*
+ * Dummy Zaptel Driver for Zapata Telephony interface
+ *
+ * Required: usb-uhci module and kernel > 2.4.4
+ *
+ * Written by Robert Pleh <robert.pleh@hermes.si>
+ *
+ * Copyright (C) 2002, Hermes Softlab
+ *
+ * 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 <asm/io.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/usb.h>
+#include <linux/errno.h>
+#include <asm/io.h>
+#ifdef STANDALONE_ZAPATA
+#include "zaptel.h"
+#else
+#include <linux/zaptel.h>
+#endif
+#include "ztdummy.h"
+
+
+#ifndef LINUX_VERSION_CODE
+# include <linux/version.h>
+#endif
+
+#ifndef VERSION_CODE
+# define VERSION_CODE(vers,rel,seq) ( ((vers)<<16) | ((rel)<<8) | (seq) )
+#endif
+
+
+#if LINUX_VERSION_CODE < VERSION_CODE(2,4,5)
+# error "This kernel is too old: not supported by this file"
+#endif
+
+
+
+static struct ztdummy *ztd;
+static uhci_desc_t *td;
+static uhci_t *s;
+static int check_int = 0;
+
+
+static int debug = 0;
+static int monitor = 0;
+
+/* exported kernel symbols */
+extern int insert_td (uhci_t *s, uhci_desc_t *qh, uhci_desc_t* new, int flags);
+extern int alloc_td (uhci_t *s, uhci_desc_t ** new, int flags);
+extern int insert_td_horizontal (uhci_t *s, uhci_desc_t *td, uhci_desc_t* new);
+extern int unlink_td (uhci_t *s, uhci_desc_t *element, int phys_unlink);
+extern void fill_td (uhci_desc_t *td, int status, int info, __u32 buffer);
+extern void uhci_interrupt (int irq, void *__uhci, struct pt_regs *regs);
+extern int delete_desc (uhci_t *s, uhci_desc_t *element);
+extern uhci_t **uhci_devices;
+
+
+static void ztdummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ unsigned short status;
+ unsigned int io_addr = s->io_addr;
+
+ status = inw (io_addr + USBSTS);
+ if (status != 0) { /* interrupt from our USB port */
+ zt_receive(&ztd->span);
+ zt_transmit(&ztd->span);
+ if (monitor && (check_int==0)) { /* for testing if interrupt gets triggered*/
+ check_int = 1;
+ printk("ztdummy: interrupt triggered \n");
+ }
+ }
+ return;
+}
+
+static int ztdummy_initialize(struct ztdummy *ztd)
+{
+ /* Zapata stuff */
+ sprintf(ztd->span.name, "ZTDUMMY/1");
+ sprintf(ztd->span.desc, "%s %d\n", ztd->span.name, 1);
+ sprintf(ztd->chan.name, "ZTDUMMY/%d/%d", 1, 0);
+ ztd->chan.chanpos = 1;
+ ztd->span.chans = &ztd->chan;
+ ztd->span.channels = 0; /* no channels on our span */
+ ztd->span.deflaw = ZT_LAW_MULAW;
+ init_waitqueue_head(&ztd->span.maintq);
+ ztd->span.pvt = ztd;
+ ztd->chan.pvt = ztd;
+ if (zt_register(&ztd->span, 0)) {
+ return -1;
+ }
+ return 0;
+}
+
+
+
+
+int init_module(void)
+{
+ int irq;
+ spinlock_t mylock = SPIN_LOCK_UNLOCKED;
+
+ if (uhci_devices==NULL){
+ printk ("ztdummy: Uhci_devices pointer error.\n");
+ return -ENODEV;
+ }
+ s=*uhci_devices; /* uhci device */
+ if (s==NULL){
+ printk ("ztdummy: No uhci_device found.\n");
+ return -ENODEV;
+ }
+
+ ztd = kmalloc(sizeof(struct ztdummy), GFP_KERNEL);
+ if (ztd == NULL) {
+ printk("ztdummy: Unable to allocate memory\n");
+ return -ENOMEM;
+ }
+ memset(ztd, 0x0, sizeof(struct ztdummy));
+
+ if (ztdummy_initialize(ztd)) {
+ printk("ztdummy: Unable to intialize zaptel driver\n");
+ kfree(ztd);
+ return -ENODEV;
+ }
+
+ irq=s->irq;
+ spin_lock_irq(&mylock);
+ free_irq(s->irq, s); /* remove uhci_interrupt temporaly */
+ if (request_irq (irq, ztdummy_interrupt, SA_SHIRQ, "ztdummy", ztd)) {
+ spin_unlock_irq(&mylock);
+ err("Our request_irq %d failed!",irq);
+ kfree(ztd);
+ return -EIO;
+ } /* we add our handler first, to assure, that our handler gets called first */
+ if (request_irq (irq, uhci_interrupt, SA_SHIRQ, "usb-uhci", s)) {
+ spin_unlock_irq(&mylock);
+ err("Original request_irq %d failed!",irq);
+ }
+ spin_unlock_irq(&mylock);
+ /* add td to usb host controller interrupt queue */
+ alloc_td(s, &td, 0);
+ fill_td(td, TD_CTRL_IOC, 0, 0);
+ insert_td_horizontal(s, s->int_chain[0], td); /* use int_chain[0] to get 1ms interrupts */
+ if (debug)
+ printk("ztdummy: init() finished\n");
+ return 0;
+}
+
+
+void cleanup_module(void)
+{
+ zt_unregister(&ztd->span);
+ free_irq(s->irq, ztd); /* disable interrupts */
+ kfree(ztd);
+ unlink_td (s, td, 1); /* unlink and delete td */
+ delete_desc (s, td);
+ if (debug)
+ printk("ztdummy: cleanup() finished\n");
+}
+
+
+
+MODULE_PARM(debug, "i");
+MODULE_PARM(monitor, "i");
+MODULE_DESCRIPTION("Dummy Zaptel Driver");
+MODULE_AUTHOR("Robert Pleh <robert.pleh@hermes.si>");
+#ifdef MODULE_LICENSE
+MODULE_LICENSE("GPL");
+#endif
+
+
diff --git a/ztdummy.h b/ztdummy.h
new file mode 100755
index 0000000..2f1c102
--- /dev/null
+++ b/ztdummy.h
@@ -0,0 +1,133 @@
+/*
+ * Dummy Zaptel Driver for Zapata Telephony interface
+ *
+ * Written by Robert Pleh <robert.pleh@hermes.si>
+ *
+ * Copyright (C) 2002, Hermes Softlab
+ *
+ * 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.
+ *
+ *
+*/
+
+struct ztdummy {
+ struct zt_span span;
+ struct zt_chan chan;
+};
+
+
+/* Uhci definitions and structures - from file usb-uhci.h */
+#define TD_CTRL_IOC (1 << 24) /* Interrupt on Complete */
+#define USBSTS 2
+
+typedef enum {
+ TD_TYPE, QH_TYPE
+} uhci_desc_type_t;
+
+typedef struct {
+ __u32 link;
+ __u32 status;
+ __u32 info;
+ __u32 buffer;
+} uhci_td_t, *puhci_td_t;
+
+
+typedef struct {
+ __u32 head;
+ __u32 element; /* Queue element pointer */
+} uhci_qh_t, *puhci_qh_t;
+
+typedef struct {
+ union {
+ uhci_td_t td;
+ uhci_qh_t qh;
+ } hw;
+ uhci_desc_type_t type;
+ dma_addr_t dma_addr;
+ struct list_head horizontal;
+ struct list_head vertical;
+ struct list_head desc_list;
+ int last_used;
+} uhci_desc_t, *puhci_desc_t;
+
+typedef struct {
+ struct list_head desc_list; // list pointer to all corresponding TDs/QHs associated with this request
+ dma_addr_t setup_packet_dma;
+ dma_addr_t transfer_buffer_dma;
+ unsigned long started;
+ urb_t *next_queued_urb; // next queued urb for this EP
+ urb_t *prev_queued_urb;
+ uhci_desc_t *bottom_qh;
+ uhci_desc_t *next_qh; // next helper QH
+ char use_loop;
+ char flags;
+} urb_priv_t, *purb_priv_t;
+
+struct virt_root_hub {
+ int devnum; /* Address of Root Hub endpoint */
+ void *urb;
+ void *int_addr;
+ int send;
+ int interval;
+ int numports;
+ int c_p_r[8];
+ struct timer_list rh_int_timer;
+};
+
+typedef struct uhci {
+ int irq;
+ unsigned int io_addr;
+ unsigned int io_size;
+ unsigned int maxports;
+ int running;
+
+ int apm_state;
+
+ struct uhci *next; // chain of uhci device contexts
+
+ struct list_head urb_list; // list of all pending urbs
+
+ spinlock_t urb_list_lock; // lock to keep consistency
+
+ int unlink_urb_done;
+ atomic_t avoid_bulk;
+
+ struct usb_bus *bus; // our bus
+
+ __u32 *framelist;
+ dma_addr_t framelist_dma;
+ uhci_desc_t **iso_td;
+ uhci_desc_t *int_chain[8];
+ uhci_desc_t *ls_control_chain;
+ uhci_desc_t *control_chain;
+ uhci_desc_t *bulk_chain;
+ uhci_desc_t *chain_end;
+ uhci_desc_t *td1ms;
+ uhci_desc_t *td32ms;
+ struct list_head free_desc;
+ spinlock_t qh_lock;
+ spinlock_t td_lock;
+ struct virt_root_hub rh; //private data of the virtual root hub
+ int loop_usage; // URBs using bandwidth reclamation
+
+ struct list_head urb_unlinked; // list of all unlinked urbs
+ long timeout_check;
+ int timeout_urbs;
+ struct pci_dev *uhci_pci;
+ struct pci_pool *desc_pool;
+ long last_error_time; // last error output in uhci_interrupt()
+} uhci_t, *puhci_t;