📄 x100p-ss7.c
字号:
/***************************************************************************** @(#) x100p-ss7.c,v openss7-0_9_2_E(0.9.2.22) 2006/05/08 11:01:18 ----------------------------------------------------------------------------- Copyright (c) 2001-2006 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@openss7.org> 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; version 2 of the License. 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. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS. If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you. If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users). If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any successor regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee. See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2006/05/08 11:01:18 by brian ----------------------------------------------------------------------------- x100p-ss7.c,v Revision 0.9.2.22 2006/05/08 11:01:18 brian - new compilers mishandle postincrement of cast pointers Revision 0.9.2.21 2006/04/24 05:01:02 brian - call interface corrections Revision 0.9.2.20 2006/03/04 13:00:28 brian - FC4 x86_64 gcc 4.0.4 2.6.15 changes *****************************************************************************/#ident "@(#) x100p-ss7.c,v openss7-0_9_2_E(0.9.2.22) 2006/05/08 11:01:18"static char const ident[] = "x100p-ss7.c,v openss7-0_9_2_E(0.9.2.22) 2006/05/08 11:01:18";/* * This is an SL (Signalling Link) kernel module which provides all of the * capabilities of the SLI for the E100P-SS7 and T100P-SS7 cards. This is a * complete SS7 MTP Level 2 OpenSS7 implementation. */#include <sys/os7/compat.h>#ifdef LINUX#include <linux/ioport.h>#include <asm/io.h>#include <asm/dma.h>#include <linux/pci.h>#include <linux/interrupt.h>#endif#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include <ss7/sdti.h>#include <ss7/sdti_ioctl.h>#include <ss7/sli.h>#include <ss7/sli_ioctl.h>#define X100P_DESCRIP "E/T100P-SS7: SS7/SL (Signalling Link) STREAMS DRIVER."#define X100P_EXTRA "Part of the OpenSS7 Stack for Linux Fast-STREAMS."#define X100P_REVISION "OpenSS7 x100p-ss7.c,v openss7-0_9_2_E (0.9.2.22) 2006/05/08 11:01:18"#define X100P_COPYRIGHT "Copyright (c) 1997-2006 OpenSS7 Corporation. All Rights Reserved."#define X100P_DEVICE "Supports the T/E100P-SS7 T1/E1 PCI boards."#define X100P_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define X100P_LICENSE "GPL"#define X100P_BANNER X100P_DESCRIP "\n" \ X100P_EXTRA "\n" \ X100P_REVISION "\n" \ X100P_COPYRIGHT "\n" \ X100P_DEVICE "\n" \ X100P_CONTACT#define X100P_SPLASH X100P_DESCRIP "\n" \ X100P_REVISION#ifdef LINUXMODULE_AUTHOR(X100P_CONTACT);MODULE_DESCRIPTION(X100P_DESCRIP);MODULE_SUPPORTED_DEVICE(X100P_DEVICE);#ifdef MODULE_LICENSEMODULE_LICENSE(X100P_LICENSE);#endif /* MODULE_LICENSE */#if defined MODULE_ALIASMODULE_ALIAS("streams-x100p-ss7");#endif#endif /* LINUX */#ifdef LFS#define X100P_DRV_ID CONFIG_STREAMS_X100P_MODID#define X100P_DRV_NAME CONFIG_STREAMS_X100P_NAME#define X100P_CMAJORS CONFIG_STREAMS_X100P_NMAJORS#define X100P_CMAJOR_0 CONFIG_STREAMS_X100P_MAJOR#define X100P_UNITS CONFIG_STREAMS_X100P_NMINORS#endif/* * ======================================================================= * * STREAMS Definitions * * ======================================================================= */#define DRV_ID X100P_DRV_ID#define DRV_NAME X100P_DRV_NAME#define CMAJORS X100P_CMAJORS#define CMAJOR_0 X100P_CMAJOR_0#define UNITS X100P_UNITS#ifdef MODULE#define DRV_BANNER X100P_BANNER#else /* MODULE */#define DRV_BANNER X100P_SPLASH#endif /* MODULE */STATIC struct module_info xp_minfo = { .mi_idnum = DRV_ID, /* Module ID number */ .mi_idname = DRV_NAME, /* Module name */ .mi_minpsz = 1, /* Min packet size accepted */ .mi_maxpsz = INFPSZ, /* Max packet size accepted */ .mi_hiwat = 1024, /* Hi water mark */ .mi_lowat = 0, /* Lo water mark */};STATIC struct module_stat xp_mstat = { 0, };STATIC int streamscall xp_open(queue_t *, dev_t *, int, int, cred_t *);STATIC int streamscall xp_close(queue_t *, int, cred_t *);STATIC struct qinit xp_rinit = { .qi_putp = ss7_oput, /* Read put (message from below) */ .qi_srvp = ss7_osrv, /* Read queue service */ .qi_qopen = xp_open, /* Each open */ .qi_qclose = xp_close, /* Last close */ .qi_minfo = &xp_minfo, /* Information */ .qi_mstat = &xp_mstat, /* Statistics */};STATIC struct qinit xp_winit = { .qi_putp = ss7_iput, /* Write put (message from above) */ .qi_srvp = ss7_isrv, /* Write queue service */ .qi_minfo = &xp_minfo, /* Information */ .qi_mstat = &xp_mstat, /* Statistics */};STATIC struct streamtab x100pinfo = { .st_rdinit = &xp_rinit, /* Upper read queue */ .st_wrinit = &xp_winit, /* Upper write queue */};/* * ======================================================================== * * Private structure * * ======================================================================== */struct xp;struct sp;struct cd;typedef struct xp_path { uint residue; /* residue bits */ uint rbits; /* number of residue bits */ ushort bcc; /* crc for message */ uint state; /* state */ uint mode; /* path mode */ uint type; /* path frame type */ uint bytes; /* number of whole bytes */ mblk_t *msg; /* message */ mblk_t *nxt; /* message chain block */ mblk_t *cmp; /* compression/repeat message */ uint repeat; /* compression/repeat count */ uint octets; /* octets counted */} xp_path_t;typedef struct xp { STR_DECLARATION (struct xp); /* stream declaration */ struct sp *sp; /* span for this channel */ int chan; /* index (chan) */ int slot; /* 32-bit backplane timeslot */ xp_path_t tx; /* transmit path variables */ xp_path_t rx; /* receive path variables */ lmi_option_t option; /* LMI protocol and variant options */ struct { bufq_t rb; /* received buffer */ bufq_t tb; /* transmission buffer */ bufq_t rtb; /* retransmission buffer */ sl_timers_t timers; /* SL protocol timers */ sl_config_t config; /* SL configuration */ sl_statem_t statem; /* SL state machine */ sl_notify_t notify; /* SL notification options */ sl_stats_t stats; /* SL statistics */ sl_stats_t stamp; /* SL statistics timestamps */ sl_stats_t statsp; /* SL statistics periods */ } sl; struct { bufq_t tb; /* transmission buffer */ sdt_timers_t timers; /* SDT protocol timers */ sdt_config_t config; /* SDT configuration */ sdt_statem_t statem; /* SDT state machine */ sdt_notify_t notify; /* SDT notification options */ sdt_stats_t stats; /* SDT statistics */ sdt_stats_t stamp; /* SDT statistics timestamps */ sdt_stats_t statsp; /* SDT statistics periods */ } sdt; struct { bufq_t tb; /* transmission buffer */ sdl_timers_t timers; /* SDL protocol timers */ sdl_config_t config; /* SDL configuration */ sdl_statem_t statem; /* SDL state machine variables */ sdl_notify_t notify; /* SDL notification options */ sdl_stats_t stats; /* SDL statistics */ sdl_stats_t stamp; /* SDL statistics timestamps */ sdl_stats_t statsp; /* SDL statistics periods */ } sdl;} xp_t;#define XP_PRIV(__q) ((struct xp *)(__q)->q_ptr)STATIC struct xp *xp_alloc_priv(queue_t *, struct xp **, dev_t *, cred_t *);STATIC void xp_free_priv(struct xp *);STATIC struct xp *xp_get(struct xp *);STATIC void xp_put(struct xp *);typedef struct sp { HEAD_DECLARATION (struct sp); /* head declaration */ struct cd *cd; /* card for this span */ struct xp *slots[32]; /* timeslot structures */ volatile ulong recovertime; /* alarm recover time */ ulong iobase; /* span iobase */ int span; /* index (span) */ volatile ulong loopcnt; /* loop command count */ sdl_config_t config; /* span configuration */} sp_t;STATIC struct sp *xp_alloc_sp(struct cd *, uint8_t);STATIC void xp_free_sp(struct sp *);STATIC struct sp *sp_get(struct sp *);STATIC void sp_put(struct sp *);typedef struct cd { HEAD_DECLARATION (struct cd); /* head declaration */ uint frame; /* frame number */ struct sp *spans[1]; /* structures for spans */ uchar *wbuf; /* wr buffer */ uchar *rbuf; /* rd buffer */ uchar *wvir; /* wr dma virtual address */ uchar *rvir; /* rd dma virtual address */ dma_addr_t wdma; /* wr dma physical address */ dma_addr_t rdma; /* rd dma physical address */ volatile int uebno; /* upper elastic buffer number */ volatile int lebno; /* lower elastic buffer number */ volatile int eval_syncsrc; /* need to reevaluate sync src */ volatile int leds; /* leds on the card */ volatile ulong clocksettletime; /* clock settle time */ int card; /* index (card) */ ulong irq; /* card irq */ ulong iobase; /* card iobase */ ulong io_region; /* io region */ ulong io_length; /* io length */ struct tasklet_struct tasklet; /* card tasklet */ sdl_config_t config; /* card configuration */} cd_t;STATIC struct cd *xp_alloc_cd(void);STATIC void xp_free_cd(struct cd *);STATIC struct cd *cd_get(struct cd *);STATIC void cd_put(struct cd *);STATIC struct ss7_bufpool xp_bufpool = { 0, };/* * ------------------------------------------------------------------------ * * Card Structures and Macros * * ------------------------------------------------------------------------ */static const char *xp_t1_framer[] = { "DS2152", "DS21352", "DS21552", "DS21752",};static const char *xp_e1_framer[] = { "DS2154", "DS21354", "DS21554", "DS21754",};#define XP_CNTL 0x00#define XP_OPER 0x01#define XP_AUXC 0x02#define XP_AUXD 0x03#define XP_MASK0 0x04#define XP_MASK1 0x05#define XP_INTSTAT 0x06#define XP_DMAWS 0x08#define XP_DMAWI 0x0c#define XP_DMAWE 0x10#define XP_DMARS 0x18#define XP_DMARI 0x1c#define XP_DMARE 0x20#define XP_CURPOS 0x24#define XP_SERC 0x2d#define XP_FSCDELAY 0x2f#define XP_USERREG 0xc0/* control registers */#define XP_CLOCK 0x0#define XP_LEDTEST 0x1#define XP_VERSION 0x2#define XP_LED0 0x01#define XP_LED1 0x02#define XP_TEST 0x04#define XP_REG 0x78#define XP_CS 0x80#define X100P_SDL_ALARM_SETTLE_TIME 5000 /* allow alarms to settle for 5 seconds */#define X100P_SDL_CLOCK_SETTLE_TIME 100 /* allow clocks to settle for 100 ms *//* control register functions */static inline intcr_inb(struct cd *cd, int reg){ outb(XP_CS | ((reg & 0xf0) >> 1), cd->iobase + XP_AUXD); return inb(cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline voidcr_outb(struct cd *cd, int reg, int val){ outb(XP_CS | ((reg & 0xf0) >> 1), cd->iobase + XP_AUXD); outb(val, cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline intcr_inb_p(struct cd *cd, int reg){ outb_p(XP_CS | ((reg & 0xf0) >> 1), cd->iobase + XP_AUXD); return inb_p(cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline voidcr_outb_p(struct cd *cd, int reg, int val){ outb_p(XP_CS | ((reg & 0xf0) >> 1), cd->iobase + XP_AUXD); outb_p(val, cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}/* framer register functions */static inline intfr_inb(struct cd *cd, int reg){ outb((reg & 0xf0) >> 1, cd->iobase + XP_AUXD); return inb(cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline voidfr_outb(struct cd *cd, int reg, int val){ outb((reg & 0xf0) >> 1, cd->iobase + XP_AUXD); outb(val, cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline intfr_inb_p(struct cd *cd, int reg){ outb_p((reg & 0xf0) >> 1, cd->iobase + XP_AUXD); return inb_p(cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}static inline voidfr_outb_p(struct cd *cd, int reg, int val){ outb_p((reg & 0xf0) >> 1, cd->iobase + XP_AUXD); outb_p(val, cd->iobase + XP_USERREG + ((reg & 0xf) << 2));}/* * Mapping of channels 0-23 for T1, 1-31 for E1 into PCM highway timeslots. */STATIC int xp_t1_tx_chan_map[] = { 2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, 18, 17, 16, 22, 21, 20, 26, 25, 24, 30, 29, 28};STATIC int xp_t1_rx_chan_map[] = { 6, 5, 4, 10, 9, 8, 14, 13, 12, 18, 17, 16, 22, 21, 20, 26, 25, 24, 30, 29, 28, 2, 1, 0};STATIC int xp_e1_tx_chan_map[] = { 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20, 27, 26, 25, 24, 31, 30, 29, 28};STATIC int xp_e1_rx_chan_map[] = { 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20, 27, 26, 25, 24, 31, 30, 29, 28, 3, 2, 1, 0};typedef enum { X100P, X100PSS7,} xp_board_t;/* indexed by xp_board_t above *//* *INDENT-OFF* */static struct { char *name; u32 hw_flags;} xp_board_info[] __devinitdata = { { "X100P", 1 }, { "X100P-SS7", 1 },};/* *INDENT-ON* */STATIC struct pci_device_id xp_pci_tbl[] __devinitdata = { {PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300, 0x6159, PCI_ANY_ID, 0, 0, X100P}, {0,}};STATIC int __devinit xp_probe(struct pci_dev *, const struct pci_device_id *);STATIC void __devexit xp_remove(struct pci_dev *);#ifdef CONFIG_PM#ifndef HAVE_KTYPE_PM_MESSAGE_Ttypedef u32 pm_message_t;#endifSTATIC int xp_suspend(struct pci_dev *pdev, pm_message_t state);STATIC int xp_resume(struct pci_dev *pdev);#endifSTATIC struct pci_driver xp_driver = { .name = DRV_NAME, .probe = xp_probe, .remove = __devexit_p(xp_remove), .id_table = xp_pci_tbl,#ifdef CONFIG_PM .suspend = xp_suspend, .resume = xp_resume,#endif};STATIC int x100p_boards = 0;STATIC struct cd *x100p_cards;#define X100P_EBUFNO (1<<7) /* 32k elastic buffers *//* * ======================================================================== * * PRIMITIVES Sent Upstream * * ======================================================================== *//* * M_ERROR * ----------------------------------- */STATIC intm_error(queue_t *q, struct xp *xp, int err){ mblk_t *mp; if ((mp = ss7_allocb(q, 2, BPRI_MED))) { mp->b_datap->db_type = M_ERROR; *(mp->b_wptr)++ = err < 0 ? -err : err; *(mp->b_wptr)++ = err < 0 ? -err : err; ss7_oput(xp->oq, mp); return (QR_DONE); } rare(); return (-ENOBUFS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -