kernel.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. /*
  2. * DAHDI Telephony Interface
  3. *
  4. * Written by Mark Spencer <markster@digium.com>
  5. * Based on previous works, designs, and architectures conceived and
  6. * written by Jim Dixon <jim@lambdatel.com>.
  7. *
  8. * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
  9. * Copyright (C) 2001 - 2012 Digium, Inc.
  10. *
  11. * All rights reserved.
  12. *
  13. */
  14. /*
  15. * See http://www.asterisk.org for more information about
  16. * the Asterisk project. Please do not directly contact
  17. * any of the maintainers of this project for assistance;
  18. * the project provides a web site, mailing lists and IRC
  19. * channels for your use.
  20. *
  21. * This program is free software, distributed under the terms of
  22. * the GNU General Public License Version 2 as published by the
  23. * Free Software Foundation. See the LICENSE file included with
  24. * this program for more details.
  25. */
  26. /*!
  27. * \file
  28. * \brief DAHDI kernel interface definitions
  29. */
  30. #ifndef _DAHDI_KERNEL_H
  31. #define _DAHDI_KERNEL_H
  32. #include <dahdi/user.h>
  33. #include <dahdi/fasthdlc.h>
  34. #include <dahdi/dahdi_config.h>
  35. #include <linux/version.h>
  36. #include <linux/fs.h>
  37. #include <linux/device.h>
  38. #include <linux/cdev.h>
  39. #include <linux/module.h>
  40. #include <linux/ioctl.h>
  41. #ifdef CONFIG_DAHDI_NET
  42. #include <linux/hdlc.h>
  43. #endif
  44. #ifdef CONFIG_DAHDI_PPP
  45. #include <linux/ppp_channel.h>
  46. #include <linux/skbuff.h>
  47. #include <linux/interrupt.h>
  48. #endif
  49. #include <linux/device.h>
  50. #include <linux/sysfs.h>
  51. #include <linux/poll.h>
  52. #define dahdi_pci_module pci_register_driver
  53. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
  54. #define DAHDI_IRQ_HANDLER(a) static irqreturn_t a(int irq, void *dev_id)
  55. #else
  56. #define DAHDI_IRQ_HANDLER(a) static irqreturn_t a(int irq, void *dev_id, struct pt_regs *regs)
  57. #endif
  58. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  59. #ifdef CONFIG_PCI
  60. #include <linux/pci-aspm.h>
  61. #endif
  62. #endif
  63. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
  64. #define HAVE_NET_DEVICE_OPS
  65. #endif
  66. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
  67. # ifdef RHEL_RELEASE_VERSION
  68. # if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5, 6)
  69. #define dev_name(dev) ((dev)->bus_id)
  70. #define dev_set_name(dev, format, ...) \
  71. snprintf((dev)->bus_id, BUS_ID_SIZE, format, ## __VA_ARGS__)
  72. # else
  73. #define dev_set_name(dev, format, ...) \
  74. do { \
  75. kobject_set_name(&(dev)->kobj, format, ## __VA_ARGS__); \
  76. snprintf((dev)->bus_id, BUS_ID_SIZE, \
  77. kobject_name(&(dev)->kobj)); \
  78. } while (0)
  79. # endif
  80. # else
  81. #define dev_name(dev) ((dev)->bus_id)
  82. #define dev_set_name(dev, format, ...) \
  83. snprintf((dev)->bus_id, BUS_ID_SIZE, format, ## __VA_ARGS__)
  84. # endif
  85. #endif
  86. /* __dev* were removed in 3.8. They still have effect in 2.6.18. */
  87. #ifndef __devinit
  88. # define __devinit
  89. # define __devinitdata
  90. # define __devexit
  91. # define __devexit_p(x) x
  92. #endif
  93. /*! Default chunk size for conferences and such -- static right now, might make
  94. variable sometime. 8 samples = 1 ms = most frequent service interval possible
  95. for a USB device */
  96. #define DAHDI_CHUNKSIZE 8
  97. #define DAHDI_MIN_CHUNKSIZE DAHDI_CHUNKSIZE
  98. #define DAHDI_DEFAULT_CHUNKSIZE DAHDI_CHUNKSIZE
  99. #define DAHDI_MAX_CHUNKSIZE DAHDI_CHUNKSIZE
  100. #define DAHDI_CB_SIZE (1 << 3)
  101. /* DAHDI operates at 8Khz by default */
  102. #define DAHDI_MS_TO_SAMPLES(ms) ((ms) * 8)
  103. #define DAHDI_MSECS_PER_CHUNK (DAHDI_CHUNKSIZE/DAHDI_MS_TO_SAMPLES(1))
  104. #define RING_DEBOUNCE_TIME 2000 /*!< 2000 ms ring debounce time */
  105. typedef struct
  106. {
  107. int32_t gain;
  108. int32_t a1;
  109. int32_t a2;
  110. int32_t b1;
  111. int32_t b2;
  112. int32_t z1;
  113. int32_t z2;
  114. } biquad2_state_t;
  115. typedef struct
  116. {
  117. biquad2_state_t notch;
  118. int notch_level;
  119. int channel_level;
  120. int tone_present;
  121. int tone_cycle_duration;
  122. int good_cycles;
  123. int hit;
  124. } echo_can_disable_detector_state_t;
  125. struct sf_detect_state {
  126. long x1;
  127. long x2;
  128. long y1;
  129. long y2;
  130. long e1;
  131. long e2;
  132. int samps;
  133. int lastdetect;
  134. };
  135. struct dahdi_tone_state {
  136. int v1_1;
  137. int v2_1;
  138. int v3_1;
  139. int v1_2;
  140. int v2_2;
  141. int v3_2;
  142. int modulate;
  143. };
  144. /*! \brief Conference queue structure */
  145. struct confq {
  146. u_char buffer[DAHDI_CHUNKSIZE * DAHDI_CB_SIZE];
  147. u_char *buf[DAHDI_CB_SIZE];
  148. int inbuf;
  149. int outbuf;
  150. };
  151. struct dahdi_chan;
  152. struct dahdi_echocan_state;
  153. /*! Features a DAHDI echo canceler (software or hardware) can provide to the DAHDI core. */
  154. struct dahdi_echocan_features {
  155. /*! Able to detect CED tone (2100 Hz with phase reversals) in the transmit direction.
  156. * If the echocan can detect this tone, it may report it it as an event (see
  157. * the events.CED_tx_detected field of dahdi_echocan_state), and if it will automatically
  158. * disable itself or its non-linear processor, then the NLP_automatic feature flag should also
  159. * be set so that the DAHDI core doesn't bother trying to do so.
  160. */
  161. u32 CED_tx_detect:1;
  162. /*! Able to detect CED tone (2100 Hz with phase reversals) in the receive direction.
  163. * If the echocan can detect this tone, it may report it it as an event (see
  164. * the events.CED_rx_detected field of dahdi_echocan_state), and if it will automatically
  165. * disable itself or its non-linear processor, then the NLP_automatic flag feature should also
  166. * be set so that the DAHDI core doesn't bother trying to do so.
  167. */
  168. u32 CED_rx_detect:1;
  169. /*! Able to detect CNG tone (1100 Hz) in the transmit direction. */
  170. u32 CNG_tx_detect:1;
  171. /*! Able to detect CNG tone (1100 Hz) in the receive direction. */
  172. u32 CNG_rx_detect:1;
  173. /*! If the echocan's NLP can be enabled and disabled without requiring destruction
  174. * and recreation of the state structure, this feature flag should be set and the
  175. * echocan_NLP_toggle field of the dahdi_echocan_ops structure should be filled with a
  176. * pointer to the function to perform that operation.
  177. */
  178. u32 NLP_toggle:1;
  179. /*! If the echocan will automatically disable itself (or even just its NLP) based on
  180. * detection of a CED tone in either direction, this feature flag should be set (along
  181. * with the tone detection feature flags).
  182. */
  183. u32 NLP_automatic:1;
  184. };
  185. /*! Operations (methods) that can be performed on a DAHDI echo canceler instance (state
  186. * structure) after it has been created, by either a software or hardware echo canceller.
  187. * The echo canceler must populate the owner field of the dahdi_echocan_state structure
  188. * with a pointer to the relevant operations structure for that instance.
  189. */
  190. struct dahdi_echocan_ops {
  191. /*! \brief Free an echocan state structure.
  192. * \param[in,out] ec Pointer to the state structure to free.
  193. *
  194. * \return Nothing.
  195. */
  196. void (*echocan_free)(struct dahdi_chan *chan, struct dahdi_echocan_state *ec);
  197. /*! \brief Process an array of audio samples through the echocan.
  198. * \param[in,out] ec Pointer to the state structure.
  199. * \param[in,out] isig The receive direction data (will be modified).
  200. * \param[in] iref The transmit direction data.
  201. * \param[in] size The number of elements in the isig and iref arrays.
  202. *
  203. * Note: This function can also return events in the events field of the
  204. * dahdi_echocan_state structure. If it can do so, then the echocan does
  205. * not need to provide the echocan_events function.
  206. *
  207. * \return Nothing.
  208. */
  209. void (*echocan_process)(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size);
  210. /*! \brief Retrieve events from the echocan.
  211. * \param[in,out] ec Pointer to the state structure.
  212. *
  213. *
  214. * If any events have occurred, the events field of the dahdi_echocan_state
  215. * structure should be updated to include them.
  216. *
  217. * \return Nothing.
  218. */
  219. void (*echocan_events)(struct dahdi_echocan_state *ec);
  220. /*! \brief Feed a sample (and its position) for echocan training.
  221. * \param[in,out] ec Pointer to the state structure.
  222. * \param[in] pos The tap position to be 'trained'.
  223. * \param[in] val The receive direction sample for the specified tap position.
  224. *
  225. * \retval Zero if training should continue.
  226. * \retval Non-zero if training is complete.
  227. */
  228. int (*echocan_traintap)(struct dahdi_echocan_state *ec, int pos, short val);
  229. /*! \brief Enable or disable non-linear processing (NLP) in the echocan.
  230. * \param[in,out] ec Pointer to the state structure.
  231. * \param[in] enable Zero to disable, non-zero to enable.
  232. *
  233. * \return Nothing.
  234. */
  235. void (*echocan_NLP_toggle)(struct dahdi_echocan_state *ec, unsigned int enable);
  236. #ifdef CONFIG_DAHDI_ECHOCAN_PROCESS_TX
  237. /*! \brief Process an array of TX audio samples.
  238. *
  239. * \return Nothing.
  240. */
  241. void (*echocan_process_tx)(struct dahdi_echocan_state *ec,
  242. short *tx, u32 size);
  243. #endif
  244. };
  245. /*! A factory for creating instances of software echo cancelers to be used on DAHDI channels. */
  246. struct dahdi_echocan_factory {
  247. /*! Get the name of the factory. */
  248. const char *(*get_name)(const struct dahdi_chan *chan);
  249. /*! Pointer to the module that owns this factory; the module's reference count will be
  250. * incremented/decremented by the DAHDI core as needed.
  251. */
  252. struct module *owner;
  253. /*! \brief Function to create an instance of the echocan.
  254. * \param[in] ecp Structure defining parameters to be used for the instance creation.
  255. * \param[in] p Pointer to the beginning of an (optional) array of user-defined parameters.
  256. * \param[out] ec Pointer to the state structure that is created, if any.
  257. *
  258. * \retval Zero on success.
  259. * \retval Non-zero on failure (return value will be returned to userspace so it should be a
  260. * standard error number).
  261. */
  262. int (*echocan_create)(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp,
  263. struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec);
  264. };
  265. /*! \brief Register an echo canceler factory with the DAHDI core.
  266. * \param[in] ec Pointer to the dahdi_echocan_factory structure to be registered.
  267. *
  268. * \retval Zero on success.
  269. * \retval Non-zero on failure (return value will be a standard error number).
  270. */
  271. int dahdi_register_echocan_factory(const struct dahdi_echocan_factory *ec);
  272. /*! \brief Unregister a previously-registered echo canceler factory from the DAHDI core.
  273. * \param[in] ec Pointer to the dahdi_echocan_factory structure to be unregistered.
  274. *
  275. * \return Nothing.
  276. */
  277. void dahdi_unregister_echocan_factory(const struct dahdi_echocan_factory *ec);
  278. enum dahdi_echocan_mode {
  279. __ECHO_MODE_MUTE = 1 << 8,
  280. ECHO_MODE_IDLE = 0,
  281. ECHO_MODE_PRETRAINING = 1 | __ECHO_MODE_MUTE,
  282. ECHO_MODE_STARTTRAINING = 2 | __ECHO_MODE_MUTE,
  283. ECHO_MODE_AWAITINGECHO = 3 | __ECHO_MODE_MUTE,
  284. ECHO_MODE_TRAINING = 4 | __ECHO_MODE_MUTE,
  285. ECHO_MODE_ACTIVE = 5,
  286. ECHO_MODE_FAX = 6,
  287. };
  288. /*! An instance of a DAHDI echo canceler (software or hardware). */
  289. struct dahdi_echocan_state {
  290. /*! Pointer to a dahdi_echocan_ops structure of operations that can be
  291. * performed on this instance.
  292. */
  293. const struct dahdi_echocan_ops *ops;
  294. /*! State data used by the DAHDI core's CED detector for the transmit
  295. * direction, if needed.
  296. */
  297. echo_can_disable_detector_state_t txecdis;
  298. /*! State data used by the DAHDI core's CED detector for the receive
  299. * direction, if needed.
  300. */
  301. echo_can_disable_detector_state_t rxecdis;
  302. /*! Features offered by the echo canceler that provided this instance. */
  303. struct dahdi_echocan_features features;
  304. struct {
  305. /*! The mode the echocan is currently in. */
  306. enum dahdi_echocan_mode mode;
  307. /*! The last tap position that was fed to the echocan's training function. */
  308. u32 last_train_tap;
  309. /*! How many samples to wait before beginning the training operation. */
  310. u32 pretrain_timer;
  311. } status;
  312. /*! This structure contains event flags, allowing the echocan to report
  313. * events that occurred as it processed the transmit and receive streams
  314. * of samples. Each call to the echocan_process operation for this
  315. * instance may report events, so the structure should be cleared before
  316. * calling that operation.
  317. */
  318. union dahdi_echocan_events {
  319. u32 all;
  320. struct {
  321. /*! CED tone was detected in the transmit direction. If the
  322. * echocan automatically disables its NLP when this occurs,
  323. * it must also signal the NLP_auto_disabled event during the *same*
  324. * call to echocan_process that reports the CED detection.
  325. */
  326. u32 CED_tx_detected:1;
  327. /*! CED tone was detected in the receive direction. If the
  328. * echocan automatically disables its NLP when this occurs,
  329. * it must also signal the NLP_auto_disabled event during the *same*
  330. * call to echocan_process that reports the CED detection.
  331. */
  332. u32 CED_rx_detected:1;
  333. /*! CNG tone was detected in the transmit direction. */
  334. u32 CNG_tx_detected:1;
  335. /*! CNG tone was detected in the receive direction. */
  336. u32 CNG_rx_detected:1;
  337. /*! The echocan disabled its NLP automatically.
  338. */
  339. u32 NLP_auto_disabled:1;
  340. /*! The echocan enabled its NLP automatically.
  341. */
  342. u32 NLP_auto_enabled:1;
  343. } bit;
  344. } events;
  345. };
  346. struct dahdi_chan {
  347. #ifdef CONFIG_DAHDI_NET
  348. /*! \note Must be first */
  349. struct dahdi_hdlc *hdlcnetdev;
  350. #endif
  351. #ifdef CONFIG_DAHDI_PPP
  352. struct ppp_channel *ppp;
  353. struct tasklet_struct ppp_calls;
  354. int do_ppp_wakeup;
  355. int do_ppp_error;
  356. struct sk_buff_head ppp_rq;
  357. #endif
  358. #ifdef BUFFER_DEBUG
  359. int statcount;
  360. int lastnumbufs;
  361. #endif
  362. spinlock_t lock;
  363. struct mutex mutex;
  364. char name[40];
  365. /* Specified by DAHDI */
  366. /*! \brief DAHDI channel number */
  367. int channo;
  368. int chanpos;
  369. unsigned long flags;
  370. long rxp1;
  371. long rxp2;
  372. long rxp3;
  373. int txtone;
  374. int tx_v2;
  375. int tx_v3;
  376. int v1_1;
  377. int v2_1;
  378. int v3_1;
  379. int toneflags;
  380. struct sf_detect_state rd;
  381. struct dahdi_chan *master; /*!< Our Master channel (could be us) */
  382. /*! \brief Next slave (if appropriate) */
  383. struct dahdi_chan *nextslave;
  384. u_char *writechunk; /*!< Actual place to write to */
  385. u_char swritechunk[DAHDI_MAX_CHUNKSIZE]; /*!< Buffer to be written */
  386. u_char *readchunk; /*!< Actual place to read from */
  387. u_char sreadchunk[DAHDI_MAX_CHUNKSIZE]; /*!< Preallocated static area */
  388. short *readchunkpreec;
  389. /* Channel from which to read when DACSed. */
  390. struct dahdi_chan *dacs_chan;
  391. /*! Pointer to tx and rx gain tables */
  392. const u_char *rxgain;
  393. const u_char *txgain;
  394. /* Specified by driver, readable by DAHDI */
  395. void *pvt; /*!< Private channel data */
  396. struct file *file; /*!< File structure */
  397. #ifdef CONFIG_DAHDI_MIRROR
  398. struct dahdi_chan *rxmirror; /*!< channel we mirror reads to */
  399. struct dahdi_chan *txmirror; /*!< channel we mirror writes to */
  400. struct dahdi_chan *srcmirror; /*!< channel we mirror from */
  401. #endif /* CONFIG_DAHDI_MIRROR */
  402. struct dahdi_span *span; /*!< Span we're a member of */
  403. int sig; /*!< Signalling */
  404. int sigcap; /*!< Capability for signalling */
  405. __u32 chan_alarms; /*!< alarms status */
  406. wait_queue_head_t waitq;
  407. /* Used only by DAHDI -- NO DRIVER SERVICEABLE PARTS BELOW */
  408. /* Buffer declarations */
  409. u_char *readbuf[DAHDI_MAX_NUM_BUFS]; /*!< read buffer */
  410. int inreadbuf;
  411. int outreadbuf;
  412. u_char *writebuf[DAHDI_MAX_NUM_BUFS]; /*!< write buffers */
  413. int inwritebuf;
  414. int outwritebuf;
  415. int blocksize; /*!< Block size */
  416. int eventinidx; /*!< out index in event buf (circular) */
  417. int eventoutidx; /*!< in index in event buf (circular) */
  418. unsigned int eventbuf[DAHDI_MAX_EVENTSIZE]; /*!< event circ. buffer */
  419. int readn[DAHDI_MAX_NUM_BUFS]; /*!< # of bytes ready in read buf */
  420. int readidx[DAHDI_MAX_NUM_BUFS]; /*!< current read pointer */
  421. int writen[DAHDI_MAX_NUM_BUFS]; /*!< # of bytes ready in write buf */
  422. int writeidx[DAHDI_MAX_NUM_BUFS]; /*!< current write pointer */
  423. int numbufs; /*!< How many buffers in channel */
  424. int txbufpolicy; /*!< Buffer policy */
  425. int txdisable; /*!< Disable transmitter */
  426. /* Tone zone stuff */
  427. struct dahdi_zone *curzone; /*!< Zone for selecting tones */
  428. struct dahdi_tone *curtone; /*!< Current tone we're playing (if any) */
  429. int tonep; /*!< Current position in tone */
  430. struct dahdi_tone_state ts; /*!< Tone state */
  431. /* Pulse dial stuff */
  432. int pdialcount; /*!< pulse dial count */
  433. /*! Ring cadence */
  434. int ringcadence[DAHDI_MAX_CADENCE];
  435. int firstcadencepos; /*!< Where to restart ring cadence */
  436. /* Digit string dialing stuff */
  437. int digitmode; /*!< What kind of tones are we sending? */
  438. char txdialbuf[DAHDI_MAX_DTMF_BUF];
  439. int dialing;
  440. int afterdialingtimer;
  441. int cadencepos; /*!< Where in the cadence we are */
  442. /* I/O Mask */
  443. unsigned int iomask; /*! I/O Mux signal mask */
  444. /* HDLC state machines */
  445. struct fasthdlc_state txhdlc;
  446. struct fasthdlc_state rxhdlc;
  447. int infcs;
  448. /* Conferencing stuff */
  449. int confna; /*! conference number (alias) */
  450. int _confn; /*! Actual conference number */
  451. int confmode; /*! conference mode */
  452. int confmute; /*! conference mute mode */
  453. struct dahdi_chan *conf_chan;
  454. /* Incoming and outgoing conference chunk queues for
  455. communicating between DAHDI master time and
  456. other boards */
  457. struct confq confin;
  458. struct confq confout;
  459. short getlin[DAHDI_MAX_CHUNKSIZE]; /*!< Last transmitted samples */
  460. unsigned char getraw[DAHDI_MAX_CHUNKSIZE]; /*!< Last received raw data */
  461. short putlin[DAHDI_MAX_CHUNKSIZE]; /*!< Last received samples */
  462. unsigned char putraw[DAHDI_MAX_CHUNKSIZE]; /*!< Last received raw data */
  463. short conflast[DAHDI_MAX_CHUNKSIZE]; /*!< Last conference sample -- base part of channel */
  464. short conflast1[DAHDI_MAX_CHUNKSIZE]; /*!< Last conference sample -- pseudo part of channel */
  465. short conflast2[DAHDI_MAX_CHUNKSIZE]; /*!< Previous last conference sample -- pseudo part of channel */
  466. /*! The echo canceler module that should be used to create an
  467. instance when this channel needs one */
  468. const struct dahdi_echocan_factory *ec_factory;
  469. /*! The echo canceler module that owns the instance currently
  470. on this channel, if one is present */
  471. const struct dahdi_echocan_factory *ec_current;
  472. /*! The state data of the echo canceler instance in use */
  473. struct dahdi_echocan_state *ec_state;
  474. /* RBS timings */
  475. int prewinktime; /*!< pre-wink time (ms) */
  476. int preflashtime; /*!< pre-flash time (ms) */
  477. int winktime; /*!< wink time (ms) */
  478. int flashtime; /*!< flash time (ms) */
  479. int starttime; /*!< start time (ms) */
  480. int rxwinktime; /*!< rx wink time (ms) */
  481. int rxflashtime; /*!< rx flash time (ms) */
  482. int debouncetime; /*!< FXS GS sig debounce time (ms) */
  483. int pulsebreaktime; /*!< pulse line open time (ms) */
  484. int pulsemaketime; /*!< pulse line closed time (ms) */
  485. int pulseaftertime; /*!< pulse time between digits (ms) */
  486. /*! RING debounce timer */
  487. int ringdebtimer;
  488. /*! RING trailing detector to make sure a RING is really over */
  489. int ringtrailer;
  490. /* PULSE digit receiver stuff */
  491. int pulsecount;
  492. int pulsetimer;
  493. /* RBS timers */
  494. int itimerset; /*!< what the itimer was set to last */
  495. int itimer;
  496. int otimer;
  497. /* RBS state */
  498. int gotgs;
  499. int txstate;
  500. int rxsig;
  501. int txsig;
  502. int rxsigstate;
  503. /* non-RBS rx state */
  504. int rxhooksig;
  505. int txhooksig;
  506. int kewlonhook;
  507. /*! Idle signalling if CAS signalling */
  508. int idlebits;
  509. int deflaw; /*! 1 = mulaw, 2=alaw, 0=undefined */
  510. short *xlaw;
  511. #ifdef OPTIMIZE_CHANMUTE
  512. int chanmute; /*!< no need for PCM data */
  513. #endif
  514. #ifdef CONFIG_CALC_XLAW
  515. unsigned char (*lineartoxlaw)(short a);
  516. #else
  517. unsigned char *lin2x;
  518. #endif
  519. struct device chan_device; /*!< Kernel object for this chan */
  520. #define dev_to_chan(dev) container_of(dev, struct dahdi_chan, chan_device)
  521. };
  522. #ifdef CONFIG_DAHDI_NET
  523. struct dahdi_hdlc {
  524. struct net_device *netdev;
  525. struct dahdi_chan *chan;
  526. };
  527. #endif
  528. /*! Define the maximum block size */
  529. #define DAHDI_MAX_BLOCKSIZE 8192
  530. #define DAHDI_DEFAULT_WINKTIME 150 /*!< 150 ms default wink time */
  531. #define DAHDI_DEFAULT_FLASHTIME 750 /*!< 750 ms default flash time */
  532. #define DAHDI_DEFAULT_PREWINKTIME 50 /*!< 50 ms before wink */
  533. #define DAHDI_DEFAULT_PREFLASHTIME 50 /*!< 50 ms before flash */
  534. #define DAHDI_DEFAULT_STARTTIME 1500 /*!< 1500 ms of start */
  535. #define DAHDI_DEFAULT_RINGTIME 2000 /*!< 2000 ms of ring on (start, FXO) */
  536. #if 0
  537. #define DAHDI_DEFAULT_RXWINKTIME 250 /*!< 250ms longest rx wink */
  538. #endif
  539. #define DAHDI_DEFAULT_RXWINKTIME 300 /*!< 300ms longest rx wink (to work with the Atlas) */
  540. #define DAHDI_DEFAULT_RXFLASHTIME 1250 /*!< 1250ms longest rx flash */
  541. #define DAHDI_DEFAULT_DEBOUNCETIME 600 /*!< 600ms of FXS GS signalling debounce */
  542. #define DAHDI_DEFAULT_PULSEMAKETIME 50 /*!< 50 ms of line closed when dial pulsing */
  543. #define DAHDI_DEFAULT_PULSEBREAKTIME 50 /*!< 50 ms of line open when dial pulsing */
  544. #define DAHDI_DEFAULT_PULSEAFTERTIME 750 /*!< 750ms between dial pulse digits */
  545. #define DAHDI_MINPULSETIME (15 * 8) /*!< 15 ms minimum */
  546. #ifdef SHORT_FLASH_TIME
  547. #define DAHDI_MAXPULSETIME (80 * 8) /*!< we need 80 ms, not 200ms, as we have a short flash */
  548. #else
  549. #define DAHDI_MAXPULSETIME (200 * 8) /*!< 200 ms maximum */
  550. #endif
  551. #define DAHDI_PULSETIMEOUT ((DAHDI_MAXPULSETIME / 8) + 50)
  552. #define DAHDI_RINGTRAILER (50 * 8) /*!< Don't consider a ring "over" until it's been gone at least this
  553. much time */
  554. #define DAHDI_LOOPCODE_TIME 10000 /*!< send loop codes for 10 secs */
  555. #define DAHDI_ALARMSETTLE_TIME 5000 /*!< allow alarms to settle for 5 secs */
  556. #define DAHDI_AFTERSTART_TIME 500 /*!< 500ms after start */
  557. #define DAHDI_RINGOFFTIME 4000 /*!< Turn off ringer for 4000 ms */
  558. #define DAHDI_KEWLTIME 500 /*!< 500ms for kewl pulse */
  559. #define DAHDI_AFTERKEWLTIME 300 /*!< 300ms after kewl pulse */
  560. #define DAHDI_MAX_PRETRAINING 1000 /*!< 1000ms max pretraining time */
  561. #ifdef FXSFLASH
  562. #define DAHDI_FXSFLASHMINTIME 450 /*!< min 450ms */
  563. #define DAHDI_FXSFLASHMAXTIME 550 /*!< max 550ms */
  564. #endif
  565. struct dahdi_chardev {
  566. const char *name;
  567. __u8 minor;
  568. };
  569. int dahdi_register_chardev(struct dahdi_chardev *dev);
  570. int dahdi_unregister_chardev(struct dahdi_chardev *dev);
  571. /*! \brief defines for transmit signalling */
  572. enum dahdi_txsig {
  573. DAHDI_TXSIG_ONHOOK, /*!< On hook */
  574. DAHDI_TXSIG_OFFHOOK, /*!< Off hook */
  575. DAHDI_TXSIG_START, /*!< Start / Ring */
  576. DAHDI_TXSIG_KEWL, /*!< Drop battery if possible */
  577. /*! Leave this as the last entry */
  578. DAHDI_TXSIG_TOTAL,
  579. };
  580. enum dahdi_rxsig {
  581. DAHDI_RXSIG_ONHOOK,
  582. DAHDI_RXSIG_OFFHOOK,
  583. DAHDI_RXSIG_START,
  584. DAHDI_RXSIG_RING,
  585. DAHDI_RXSIG_INITIAL
  586. };
  587. enum {
  588. /* Span flags */
  589. DAHDI_FLAGBIT_REGISTERED= 0,
  590. DAHDI_FLAGBIT_RUNNING = 1,
  591. DAHDI_FLAGBIT_RBS = 12, /*!< Span uses RBS signalling */
  592. /* Channel flags */
  593. DAHDI_FLAGBIT_DTMFDECODE= 2, /*!< Channel supports native DTMF decode */
  594. DAHDI_FLAGBIT_MFDECODE = 3, /*!< Channel supports native MFr2 decode */
  595. DAHDI_FLAGBIT_ECHOCANCEL= 4, /*!< Channel supports native echo cancellation */
  596. DAHDI_FLAGBIT_HDLC = 5, /*!< Perform HDLC */
  597. #ifdef CONFIG_DAHDI_NET
  598. DAHDI_FLAGBIT_NETDEV = 6, /*!< Send to network */
  599. #endif
  600. DAHDI_FLAGBIT_CLEAR = 8, /*!< Clear channel */
  601. DAHDI_FLAGBIT_AUDIO = 9, /*!< Audio mode channel */
  602. DAHDI_FLAGBIT_OPEN = 10, /*!< Channel is open */
  603. DAHDI_FLAGBIT_FCS = 11, /*!< Calculate FCS */
  604. /* Reserve 12 for uniqueness with span flags */
  605. DAHDI_FLAGBIT_LINEAR = 13, /*!< Talk to user space in linear */
  606. DAHDI_FLAGBIT_PPP = 14, /*!< PPP is available */
  607. DAHDI_FLAGBIT_T1PPP = 15,
  608. DAHDI_FLAGBIT_SIGFREEZE = 16, /*!< Freeze signalling */
  609. DAHDI_FLAGBIT_NOSTDTXRX = 17, /*!< Do NOT do standard transmit and receive on every interrupt */
  610. DAHDI_FLAGBIT_LOOPED = 18, /*!< Loopback the receive data from the channel to the transmit */
  611. DAHDI_FLAGBIT_MTP2 = 19, /*!< Repeats last message in buffer and also discards repeating messages sent to us */
  612. DAHDI_FLAGBIT_HDLC56 = 20, /*!< Sets the given channel (if in HDLC mode) to use 56K HDLC instead of 64K */
  613. DAHDI_FLAGBIT_BUFEVENTS = 21, /*!< Report buffer events */
  614. DAHDI_FLAGBIT_TXUNDERRUN = 22, /*!< Transmit underrun condition */
  615. DAHDI_FLAGBIT_RXOVERRUN = 23, /*!< Receive overrun condition */
  616. DAHDI_FLAGBIT_DEVFILE = 25, /*!< Channel has a sysfs dev file */
  617. };
  618. #ifdef CONFIG_DAHDI_NET
  619. /**
  620. * have_netdev() - Return true if a channel has an associated network device.
  621. * @chan: Then channel to check.
  622. *
  623. */
  624. static inline int dahdi_have_netdev(const struct dahdi_chan *chan)
  625. {
  626. return test_bit(DAHDI_FLAGBIT_NETDEV, &chan->flags);
  627. }
  628. #else
  629. static inline int dahdi_have_netdev(const struct dahdi_chan *chan) { return 0; }
  630. #endif
  631. struct dahdi_count {
  632. u32 fe; /*!< Framing error counter */
  633. u32 cv; /*!< Coding violations counter */
  634. u32 bpv; /*!< Bipolar Violation counter */
  635. u32 crc4; /*!< CRC4 error counter */
  636. u32 ebit; /*!< current E-bit error count */
  637. u32 fas; /*!< current FAS error count */
  638. u32 be; /*!< current bit error count */
  639. u32 prbs; /*!< current PRBS detected pattern */
  640. u32 errsec; /*!< errored seconds */
  641. u32 timingslips; /*!< Clock slips */
  642. };
  643. /* map flagbits to flag masks */
  644. #define DAHDI_FLAG(x) (1 << (DAHDI_FLAGBIT_ ## x))
  645. /*! This is a redefinition of the flags from above to allow use of the
  646. * legacy drivers that do not use the kernel atomic bit testing and
  647. * changing routines.
  648. *
  649. * See the above descriptions for DAHDI_FLAGBIT_.... for documentation
  650. * about function. */
  651. /* Span flags */
  652. #define DAHDI_FLAG_REGISTERED DAHDI_FLAG(REGISTERED)
  653. #define DAHDI_FLAG_RUNNING DAHDI_FLAG(RUNNING)
  654. #define DAHDI_FLAG_RBS DAHDI_FLAG(RBS)
  655. /* Channel flags */
  656. #define DAHDI_FLAG_DTMFDECODE DAHDI_FLAG(DTMFDECODE)
  657. #define DAHDI_FLAG_MFDECODE DAHDI_FLAG(MFDECODE)
  658. #define DAHDI_FLAG_ECHOCANCEL DAHDI_FLAG(ECHOCANCEL)
  659. #define DAHDI_FLAG_HDLC DAHDI_FLAG(HDLC)
  660. /* #define DAHDI_FLAG_NETDEV DAHDI_FLAG(NETDEV) */
  661. #define DAHDI_FLAG_CLEAR DAHDI_FLAG(CLEAR)
  662. #define DAHDI_FLAG_AUDIO DAHDI_FLAG(AUDIO)
  663. #define DAHDI_FLAG_OPEN DAHDI_FLAG(OPEN)
  664. #define DAHDI_FLAG_FCS DAHDI_FLAG(FCS)
  665. /* Reserve 12 for uniqueness with span flags */
  666. #define DAHDI_FLAG_LINEAR DAHDI_FLAG(LINEAR)
  667. #define DAHDI_FLAG_PPP DAHDI_FLAG(PPP)
  668. #define DAHDI_FLAG_T1PPP DAHDI_FLAG(T1PPP)
  669. #define DAHDI_FLAG_SIGFREEZE DAHDI_FLAG(SIGFREEZE)
  670. #define DAHDI_FLAG_NOSTDTXRX DAHDI_FLAG(NOSTDTXRX)
  671. #define DAHDI_FLAG_LOOPED DAHDI_FLAG(LOOPED)
  672. #define DAHDI_FLAG_MTP2 DAHDI_FLAG(MTP2)
  673. #define DAHDI_FLAG_HDLC56 DAHDI_FLAG(HDLC56)
  674. #define DAHDI_FLAG_BUFEVENTS DAHDI_FLAG(BUFEVENTS)
  675. #define DAHDI_FLAG_TXUNDERRUN DAHDI_FLAG(TXUNDERRUN)
  676. #define DAHDI_FLAG_RXOVERRUN DAHDI_FLAG(RXOVERRUN)
  677. enum spantypes {
  678. SPANTYPE_INVALID = 0,
  679. SPANTYPE_ANALOG_FXS,
  680. SPANTYPE_ANALOG_FXO,
  681. SPANTYPE_ANALOG_MIXED,
  682. SPANTYPE_DIGITAL_E1,
  683. SPANTYPE_DIGITAL_T1,
  684. SPANTYPE_DIGITAL_J1,
  685. SPANTYPE_DIGITAL_BRI_NT,
  686. SPANTYPE_DIGITAL_BRI_TE,
  687. SPANTYPE_DIGITAL_BRI_SOFT,
  688. SPANTYPE_DIGITAL_DYNAMIC,
  689. };
  690. const char *dahdi_spantype2str(enum spantypes st);
  691. enum spantypes dahdi_str2spantype(const char *name);
  692. const char *dahdi_lineconfig_bit_name(int lineconfig_bit);
  693. ssize_t lineconfig_str(int lineconfig, char buf[], size_t size);
  694. struct file;
  695. struct dahdi_span_ops {
  696. struct module *owner; /*!< Which module is exporting this span. */
  697. /* ==== Span Callback Operations ==== */
  698. /*! Req: Set the requested chunk size. This is the unit in which you must
  699. report results for conferencing, etc */
  700. int (*setchunksize)(struct dahdi_span *span, int chunksize);
  701. /*! Opt: Configure the span (if appropriate) */
  702. int (*spanconfig)(struct file *file, struct dahdi_span *span,
  703. struct dahdi_lineconfig *lc);
  704. /*! Opt: Start the span */
  705. int (*startup)(struct file *file, struct dahdi_span *span);
  706. /*! Opt: Shutdown the span */
  707. int (*shutdown)(struct dahdi_span *span);
  708. /*! Opt: Enable maintenance modes */
  709. int (*maint)(struct dahdi_span *span, int mode);
  710. #ifdef DAHDI_SYNC_TICK
  711. /*! Opt: send sync to spans. Called in hard_irq context with chan_lock
  712. * held.*/
  713. void (*sync_tick)(struct dahdi_span *span, int is_master);
  714. #endif
  715. /* ==== Channel Callback Operations ==== */
  716. /*! Opt: Set signalling type (if appropriate) */
  717. int (*chanconfig)(struct file *file, struct dahdi_chan *chan,
  718. int sigtype);
  719. /*! Opt: Prepare a channel for I/O */
  720. int (*open)(struct dahdi_chan *chan);
  721. /*! Opt: Close channel for I/O */
  722. int (*close)(struct dahdi_chan *chan);
  723. /*! Opt: IOCTL */
  724. int (*ioctl)(struct dahdi_chan *chan, unsigned int cmd, unsigned long data);
  725. /* Okay, now we get to the signalling. You have several options: */
  726. /* Option 1: If you're a T1 like interface, you can just provide a
  727. rbsbits function and we'll assert robbed bits for you. Be sure to
  728. set the DAHDI_FLAG_RBS in this case. */
  729. /*! Opt: If the span uses A/B bits, set them here */
  730. int (*rbsbits)(struct dahdi_chan *chan, int bits);
  731. /*! Option 2: If you don't know about sig bits, but do have their
  732. equivalents (i.e. you can disconnect battery, detect off hook,
  733. generate ring, etc directly) then you can just specify a
  734. sethook function, and we'll call you with appropriate hook states
  735. to set. Still set the DAHDI_FLAG_RBS in this case as well */
  736. int (*hooksig)(struct dahdi_chan *chan, enum dahdi_txsig hookstate);
  737. /*! Option 3: If you can't use sig bits, you can write a function
  738. which handles the individual hook states */
  739. int (*sethook)(struct dahdi_chan *chan, int hookstate);
  740. /*! Opt: Used to tell an onboard HDLC controller that there is data ready to transmit */
  741. void (*hdlc_hard_xmit)(struct dahdi_chan *chan);
  742. /*! If the watchdog detects no received data, it will call the
  743. watchdog routine */
  744. int (*watchdog)(struct dahdi_span *span, int cause);
  745. #ifdef DAHDI_AUDIO_NOTIFY
  746. /*! Opt: audio is used, don't optimize out */
  747. int (*audio_notify)(struct dahdi_chan *chan, int yes);
  748. #endif
  749. /*! Opt: Enable preechocan stream from inline HW echocanceler. */
  750. int (*enable_hw_preechocan)(struct dahdi_chan *chan);
  751. /*! Opt: Disable preechocan stream from inline HW echocanceler. */
  752. void (*disable_hw_preechocan)(struct dahdi_chan *chan);
  753. /*! Opt: Dacs the contents of chan2 into chan1 if possible */
  754. int (*dacs)(struct dahdi_chan *chan1, struct dahdi_chan *chan2);
  755. /*! Opt: Provide echo cancellation on a channel */
  756. int (*echocan_create)(struct dahdi_chan *chan,
  757. struct dahdi_echocanparams *ecp,
  758. struct dahdi_echocanparam *p,
  759. struct dahdi_echocan_state **ec);
  760. /*! Opt: Provide the name of the echo canceller on a channel */
  761. const char *(*echocan_name)(const struct dahdi_chan *chan);
  762. /*! When using "assigned spans", this function is called back when this
  763. * span has been assigned with the system. */
  764. void (*assigned)(struct dahdi_span *span);
  765. /*! Called when the spantype / linemode is changed before the span is
  766. * assigned a number. */
  767. int (*set_spantype)(struct dahdi_span *span, enum spantypes st);
  768. };
  769. /**
  770. * dahdi_device - Represents a device that can contain one or more spans.
  771. *
  772. * @spans: List of child spans.
  773. * @manufacturer: Device manufacturer.
  774. * @location: The location of this device. This should not change if
  775. * the device is replaced (e.g: in the same PCI slot)
  776. * @hardware_id: The hardware_id of this device (NULL for devices without
  777. * a hardware_id). This should not change if the device is
  778. * relocated to a different location (e.g: different PCI slot)
  779. * @devicetype: What type of device this is.
  780. * @irqmisses: Count of "interrupt misses" for this device.
  781. *
  782. */
  783. struct dahdi_device {
  784. struct list_head spans;
  785. const char *manufacturer;
  786. const char *location;
  787. const char *hardware_id;
  788. const char *devicetype;
  789. struct device dev;
  790. unsigned int irqmisses;
  791. struct timespec registration_time;
  792. };
  793. struct dahdi_span {
  794. spinlock_t lock;
  795. char name[40]; /*!< Span name */
  796. char desc[80]; /*!< Span description */
  797. enum spantypes spantype; /*!< span type */
  798. int deflaw; /*!< Default law (DAHDI_MULAW or DAHDI_ALAW) */
  799. int alarms; /*!< Pending alarms on span */
  800. unsigned long flags;
  801. u8 cannot_provide_timing:1;
  802. int lbo; /*!< Span Line-Buildout */
  803. int lineconfig; /*!< Span line configuration */
  804. int linecompat; /*!< Span line compatibility (0 for
  805. analog spans)*/
  806. int channels; /*!< Number of channels in span */
  807. int txlevel; /*!< Tx level */
  808. int rxlevel; /*!< Rx level */
  809. int syncsrc; /*!< current sync src (gets copied here) */
  810. struct dahdi_count count; /*!< Performance and Error counters */
  811. int maintstat; /*!< Maintenance state */
  812. int mainttimer; /*!< Maintenance timer */
  813. struct dahdi_chan **chans; /*!< Member channel structures */
  814. const struct dahdi_span_ops *ops; /*!< span callbacks. */
  815. /* Used by DAHDI only -- no user servicable parts inside */
  816. int spanno; /*!< Span number for DAHDI */
  817. int offset; /*!< Offset within a given card */
  818. int lastalarms; /*!< Previous alarms */
  819. #ifdef CONFIG_DAHDI_WATCHDOG
  820. int watchcounter;
  821. int watchstate;
  822. #endif
  823. #ifdef CONFIG_PROC_FS
  824. struct proc_dir_entry *proc_entry;
  825. #endif
  826. struct list_head spans_node;
  827. struct dahdi_device *parent;
  828. struct list_head device_node;
  829. struct device *span_device;
  830. };
  831. struct dahdi_transcoder_channel {
  832. void *pvt;
  833. struct dahdi_transcoder *parent;
  834. wait_queue_head_t ready;
  835. __u32 built_fmts;
  836. #define DAHDI_TC_FLAG_BUSY 1
  837. #define DAHDI_TC_FLAG_CHAN_BUILT 2
  838. #define DAHDI_TC_FLAG_NONBLOCK 3
  839. #define DAHDI_TC_FLAG_DATA_WAITING 4
  840. unsigned long flags;
  841. u32 dstfmt;
  842. u32 srcfmt;
  843. };
  844. int dahdi_is_sync_master(const struct dahdi_span *span);
  845. struct dahdi_span *get_master_span(void);
  846. void set_master_span(int spanno);
  847. static inline int
  848. dahdi_tc_is_built(struct dahdi_transcoder_channel *dtc) {
  849. return test_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  850. }
  851. static inline void
  852. dahdi_tc_set_built(struct dahdi_transcoder_channel *dtc) {
  853. set_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  854. }
  855. static inline void
  856. dahdi_tc_clear_built(struct dahdi_transcoder_channel *dtc) {
  857. clear_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  858. }
  859. static inline int
  860. dahdi_tc_is_nonblock(struct dahdi_transcoder_channel *dtc) {
  861. return test_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  862. }
  863. static inline void
  864. dahdi_tc_set_nonblock(struct dahdi_transcoder_channel *dtc) {
  865. set_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  866. }
  867. static inline void
  868. dahdi_tc_clear_nonblock(struct dahdi_transcoder_channel *dtc) {
  869. clear_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  870. }
  871. static inline int
  872. dahdi_tc_is_data_waiting(struct dahdi_transcoder_channel *dtc) {
  873. return test_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  874. }
  875. static inline int
  876. dahdi_tc_is_busy(struct dahdi_transcoder_channel *dtc) {
  877. return test_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  878. }
  879. static inline void
  880. dahdi_tc_set_busy(struct dahdi_transcoder_channel *dtc) {
  881. set_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  882. }
  883. static inline void
  884. dahdi_tc_clear_busy(struct dahdi_transcoder_channel *dtc) {
  885. clear_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  886. }
  887. static inline void
  888. dahdi_tc_set_data_waiting(struct dahdi_transcoder_channel *dtc) {
  889. set_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  890. }
  891. static inline void
  892. dahdi_tc_clear_data_waiting(struct dahdi_transcoder_channel *dtc) {
  893. clear_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  894. }
  895. struct dahdi_transcoder {
  896. struct list_head active_list_node;
  897. struct list_head registration_list_node;
  898. char name[80];
  899. int numchannels;
  900. unsigned int srcfmts;
  901. unsigned int dstfmts;
  902. struct file_operations fops;
  903. int (*allocate)(struct dahdi_transcoder_channel *channel);
  904. int (*release)(struct dahdi_transcoder_channel *channel);
  905. /* Transcoder channels */
  906. struct dahdi_transcoder_channel channels[0];
  907. };
  908. #define DAHDI_WATCHDOG_NOINTS (1 << 0)
  909. #define DAHDI_WATCHDOG_INIT 1000
  910. #define DAHDI_WATCHSTATE_UNKNOWN 0
  911. #define DAHDI_WATCHSTATE_OK 1
  912. #define DAHDI_WATCHSTATE_RECOVERING 2
  913. #define DAHDI_WATCHSTATE_FAILED 3
  914. struct dahdi_dynamic {
  915. char addr[40];
  916. char dname[20];
  917. int err;
  918. struct kref kref;
  919. long rxjif;
  920. unsigned short txcnt;
  921. unsigned short rxcnt;
  922. struct dahdi_device *ddev;
  923. struct dahdi_span span;
  924. struct dahdi_chan *chans[256];
  925. struct dahdi_dynamic_driver *driver;
  926. void *pvt;
  927. int timing;
  928. int master;
  929. unsigned char *msgbuf;
  930. struct device *dev;
  931. struct list_head list;
  932. };
  933. struct dahdi_dynamic_driver {
  934. /*! Driver name (e.g. Eth) */
  935. const char *name;
  936. /*! Driver description */
  937. const char *desc;
  938. /*! Create a new transmission pipe */
  939. int (*create)(struct dahdi_dynamic *d, const char *address);
  940. /*! Destroy a created transmission pipe */
  941. void (*destroy)(struct dahdi_dynamic *d);
  942. /*! Transmit a given message */
  943. void (*transmit)(struct dahdi_dynamic *d, u8 *msg, size_t msglen);
  944. /*! Flush any pending messages */
  945. int (*flush)(void);
  946. struct list_head list;
  947. struct module *owner;
  948. /*! Numberic id of next device created by this driver. */
  949. unsigned int id;
  950. };
  951. /*! \brief Receive a dynamic span message */
  952. void dahdi_dynamic_receive(struct dahdi_span *span, unsigned char *msg, int msglen);
  953. /*! \brief Register a dynamic driver */
  954. int dahdi_dynamic_register_driver(struct dahdi_dynamic_driver *driver);
  955. /*! \brief Unregister a dynamic driver */
  956. void dahdi_dynamic_unregister_driver(struct dahdi_dynamic_driver *driver);
  957. int _dahdi_receive(struct dahdi_span *span);
  958. /*! Receive on a span. The DAHDI interface will handle all the calculations for
  959. all member channels of the span, pulling the data from the readchunk buffer */
  960. static inline int dahdi_receive(struct dahdi_span *span)
  961. {
  962. unsigned long flags;
  963. int ret;
  964. local_irq_save(flags);
  965. ret = _dahdi_receive(span);
  966. local_irq_restore(flags);
  967. return ret;
  968. }
  969. int _dahdi_transmit(struct dahdi_span *span);
  970. /*! Prepare writechunk buffers on all channels for this span */
  971. static inline int dahdi_transmit(struct dahdi_span *span)
  972. {
  973. unsigned long flags;
  974. int ret;
  975. local_irq_save(flags);
  976. ret = _dahdi_transmit(span);
  977. local_irq_restore(flags);
  978. return ret;
  979. }
  980. static inline int dahdi_is_digital_span(const struct dahdi_span *s)
  981. {
  982. return (s->linecompat > 0);
  983. }
  984. static inline int dahdi_is_t1_span(const struct dahdi_span *s)
  985. {
  986. return (s->linecompat & (DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF |
  987. DAHDI_CONFIG_B8ZS)) > 0;
  988. }
  989. static inline int dahdi_is_e1_span(const struct dahdi_span *s)
  990. {
  991. return dahdi_is_digital_span(s) && !dahdi_is_t1_span(s);
  992. }
  993. /*! Abort the buffer currently being receive with event "event" */
  994. void dahdi_hdlc_abort(struct dahdi_chan *ss, int event);
  995. /*! Indicate to DAHDI that the end of frame was received and rotate buffers */
  996. void dahdi_hdlc_finish(struct dahdi_chan *ss);
  997. /*! Put a chunk of data into the current receive buffer */
  998. void dahdi_hdlc_putbuf(struct dahdi_chan *ss, unsigned char *rxb, int bytes);
  999. /*! Get a chunk of data from the current transmit buffer. Returns -1 if no data
  1000. * is left to send, 0 if there is data remaining in the current message to be sent
  1001. * and 1 if the currently transmitted message is now done */
  1002. int dahdi_hdlc_getbuf(struct dahdi_chan *ss, unsigned char *bufptr, unsigned int *size);
  1003. /*! Register a device. Returns 0 on success, -1 on failure. */
  1004. struct dahdi_device *dahdi_create_device(void);
  1005. int dahdi_register_device(struct dahdi_device *ddev, struct device *parent);
  1006. void dahdi_unregister_device(struct dahdi_device *ddev);
  1007. void dahdi_free_device(struct dahdi_device *ddev);
  1008. void dahdi_init_span(struct dahdi_span *span);
  1009. /*! Allocate / free memory for a transcoder */
  1010. struct dahdi_transcoder *dahdi_transcoder_alloc(int numchans);
  1011. void dahdi_transcoder_free(struct dahdi_transcoder *ztc);
  1012. /*! \brief Register a transcoder */
  1013. int dahdi_transcoder_register(struct dahdi_transcoder *tc);
  1014. /*! \brief Unregister a transcoder */
  1015. int dahdi_transcoder_unregister(struct dahdi_transcoder *tc);
  1016. /*! \brief Alert a transcoder */
  1017. int dahdi_transcoder_alert(struct dahdi_transcoder_channel *ztc);
  1018. /*! \brief Gives a name to an LBO */
  1019. const char *dahdi_lboname(int lbo);
  1020. /*! \brief Tell DAHDI about changes in received rbs bits */
  1021. void dahdi_rbsbits(struct dahdi_chan *chan, int bits);
  1022. /*! \brief Tell DAHDI abou changes in received signalling */
  1023. void dahdi_hooksig(struct dahdi_chan *chan, enum dahdi_rxsig rxsig);
  1024. /*! \brief Queue an event on a channel */
  1025. void dahdi_qevent_nolock(struct dahdi_chan *chan, int event);
  1026. /*! \brief Queue an event on a channel, locking it first */
  1027. void dahdi_qevent_lock(struct dahdi_chan *chan, int event);
  1028. /*! \brief Notify a change possible change in alarm status on a channel */
  1029. void dahdi_alarm_channel(struct dahdi_chan *chan, int alarms);
  1030. /*! \brief Notify a change possible change in alarm status on a span */
  1031. void dahdi_alarm_notify(struct dahdi_span *span);
  1032. /*! \brief Initialize a tone state */
  1033. void dahdi_init_tone_state(struct dahdi_tone_state *ts, struct dahdi_tone *zt);
  1034. /*! \brief Get a given MF tone struct, suitable for dahdi_tone_nextsample. */
  1035. struct dahdi_tone *dahdi_mf_tone(const struct dahdi_chan *chan, char digit, int digitmode);
  1036. /*! \brief Convert signalling bits to human readable string */
  1037. const char *sigstr(int sig);
  1038. /*! \brief Convert alarm bits to human readable string */
  1039. int fill_alarm_string(char *buf, int count, int alarms);
  1040. /* Echo cancel a receive and transmit chunk for a given channel. This
  1041. should be called by the low-level driver as close to the interface
  1042. as possible. ECHO CANCELLATION IS NO LONGER AUTOMATICALLY DONE
  1043. AT THE DAHDI LEVEL. dahdi_ec_chunk will not echo cancel if it should
  1044. not be doing so. rxchunk is modified in-place */
  1045. void __dahdi_ec_chunk(struct dahdi_chan *ss, u8 *rxchunk,
  1046. const u8 *preecchunk, const u8 *txchunk);
  1047. static inline void _dahdi_ec_chunk(struct dahdi_chan *chan,
  1048. u8 *rxchunk, const u8 *txchunk)
  1049. {
  1050. __dahdi_ec_chunk(chan, rxchunk, rxchunk, txchunk);
  1051. }
  1052. static inline void dahdi_ec_chunk(struct dahdi_chan *ss, unsigned char *rxchunk,
  1053. const unsigned char *txchunk)
  1054. {
  1055. unsigned long flags;
  1056. local_irq_save(flags);
  1057. _dahdi_ec_chunk(ss, rxchunk, txchunk);
  1058. local_irq_restore(flags);
  1059. }
  1060. void _dahdi_ec_span(struct dahdi_span *span);
  1061. static inline void dahdi_ec_span(struct dahdi_span *span)
  1062. {
  1063. unsigned long flags;
  1064. local_irq_save(flags);
  1065. _dahdi_ec_span(span);
  1066. local_irq_restore(flags);
  1067. }
  1068. extern struct file_operations *dahdi_transcode_fops;
  1069. int dahdi_get_auto_assign_spans(void);
  1070. /* Don't use these directly -- they're not guaranteed to
  1071. be there. */
  1072. extern short __dahdi_mulaw[256];
  1073. extern short __dahdi_alaw[256];
  1074. #ifdef CONFIG_CALC_XLAW
  1075. u_char __dahdi_lineartoulaw(short a);
  1076. u_char __dahdi_lineartoalaw(short a);
  1077. #else
  1078. extern u_char __dahdi_lin2mu[16384];
  1079. extern u_char __dahdi_lin2a[16384];
  1080. #endif
  1081. struct dahdi_dynamic_ops {
  1082. struct module *owner;
  1083. int (*ioctl)(unsigned int cmd, unsigned long data);
  1084. };
  1085. /*! \brief Used by dynamic DAHDI -- don't use directly */
  1086. void dahdi_set_dynamic_ops(const struct dahdi_dynamic_ops *ops);
  1087. /*! \brief Used by DAHDI HPEC module -- don't use directly */
  1088. void dahdi_set_hpec_ioctl(int (*func)(unsigned int cmd, unsigned long data));
  1089. /*! \brief Used privately by DAHDI. Avoid touching directly */
  1090. struct dahdi_tone {
  1091. int fac1;
  1092. int init_v2_1;
  1093. int init_v3_1;
  1094. int fac2;
  1095. int init_v2_2;
  1096. int init_v3_2;
  1097. int tonesamples; /*!< How long to play this tone before
  1098. going to the next (in samples) */
  1099. struct dahdi_tone *next; /* Next tone in this sequence */
  1100. int modulate;
  1101. };
  1102. static inline short dahdi_tone_nextsample(struct dahdi_tone_state *ts, struct dahdi_tone *zt)
  1103. {
  1104. /* follow the curves, return the sum */
  1105. int p;
  1106. ts->v1_1 = ts->v2_1;
  1107. ts->v2_1 = ts->v3_1;
  1108. ts->v3_1 = (zt->fac1 * ts->v2_1 >> 15) - ts->v1_1;
  1109. ts->v1_2 = ts->v2_2;
  1110. ts->v2_2 = ts->v3_2;
  1111. ts->v3_2 = (zt->fac2 * ts->v2_2 >> 15) - ts->v1_2;
  1112. /* Return top 16 bits */
  1113. if (!ts->modulate) return ts->v3_1 + ts->v3_2;
  1114. /* we are modulating */
  1115. p = ts->v3_2 - 32768;
  1116. if (p < 0) p = -p;
  1117. p = ((p * 9) / 10) + 1;
  1118. return (ts->v3_1 * p) >> 15;
  1119. }
  1120. static inline short dahdi_txtone_nextsample(struct dahdi_chan *ss)
  1121. {
  1122. /* follow the curves, return the sum */
  1123. ss->v1_1 = ss->v2_1;
  1124. ss->v2_1 = ss->v3_1;
  1125. ss->v3_1 = (ss->txtone * ss->v2_1 >> 15) - ss->v1_1;
  1126. return ss->v3_1;
  1127. }
  1128. /* These are the right functions to use. */
  1129. #define DAHDI_MULAW(a) (__dahdi_mulaw[(a)])
  1130. #define DAHDI_ALAW(a) (__dahdi_alaw[(a)])
  1131. #define DAHDI_XLAW(a,c) (c->xlaw[(a)])
  1132. #ifdef CONFIG_CALC_XLAW
  1133. #define DAHDI_LIN2MU(a) (__dahdi_lineartoulaw((a)))
  1134. #define DAHDI_LIN2A(a) (__dahdi_lineartoalaw((a)))
  1135. #define DAHDI_LIN2X(a,c) ((c)->lineartoxlaw((a)))
  1136. #else
  1137. /* Use tables */
  1138. #define DAHDI_LIN2MU(a) (__dahdi_lin2mu[((unsigned short)(a)) >> 2])
  1139. #define DAHDI_LIN2A(a) (__dahdi_lin2a[((unsigned short)(a)) >> 2])
  1140. /* Manipulate as appropriate for x-law */
  1141. #define DAHDI_LIN2X(a,c) ((c)->lin2x[((unsigned short)(a)) >> 2])
  1142. #endif /* CONFIG_CALC_XLAW */
  1143. /* Data formats for capabilities and frames alike (from Asterisk) */
  1144. /*! G.723.1 compression */
  1145. #define DAHDI_FORMAT_G723_1 (1 << 0)
  1146. /*! GSM compression */
  1147. #define DAHDI_FORMAT_GSM (1 << 1)
  1148. /*! Raw mu-law data (G.711) */
  1149. #define DAHDI_FORMAT_ULAW (1 << 2)
  1150. /*! Raw A-law data (G.711) */
  1151. #define DAHDI_FORMAT_ALAW (1 << 3)
  1152. /*! ADPCM (G.726, 32kbps) */
  1153. #define DAHDI_FORMAT_G726 (1 << 4)
  1154. /*! ADPCM (IMA) */
  1155. #define DAHDI_FORMAT_ADPCM (1 << 5)
  1156. /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
  1157. #define DAHDI_FORMAT_SLINEAR (1 << 6)
  1158. /*! LPC10, 180 samples/frame */
  1159. #define DAHDI_FORMAT_LPC10 (1 << 7)
  1160. /*! G.729A audio */
  1161. #define DAHDI_FORMAT_G729A (1 << 8)
  1162. /*! SpeeX Free Compression */
  1163. #define DAHDI_FORMAT_SPEEX (1 << 9)
  1164. /*! iLBC Free Compression */
  1165. #define DAHDI_FORMAT_ILBC (1 << 10)
  1166. /*! Maximum audio format */
  1167. #define DAHDI_FORMAT_MAX_AUDIO (1 << 15)
  1168. /*! Maximum audio mask */
  1169. #define DAHDI_FORMAT_AUDIO_MASK ((1 << 16) - 1)
  1170. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
  1171. /* DAHDI only was using the xxx_clear_bit variants. */
  1172. #ifndef smp_mb__before_atomic
  1173. #define smp_mb__before_atomic smp_mb__before_clear_bit
  1174. #endif
  1175. #ifndef smp_mb__after_atomic
  1176. #define smp_mb__after_atomic smp_mb__after_clear_bit
  1177. #endif
  1178. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  1179. #ifdef RHEL_RELEASE_VERSION
  1180. #if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6, 5)
  1181. #ifdef CONFIG_PROC_FS
  1182. #include <linux/proc_fs.h>
  1183. static inline void *PDE_DATA(const struct inode *inode)
  1184. {
  1185. return PDE(inode)->data;
  1186. }
  1187. #endif
  1188. #endif
  1189. #else
  1190. #ifdef CONFIG_PROC_FS
  1191. #include <linux/proc_fs.h>
  1192. static inline void *PDE_DATA(const struct inode *inode)
  1193. {
  1194. return PDE(inode)->data;
  1195. }
  1196. #endif
  1197. #endif
  1198. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
  1199. #define KERN_CONT ""
  1200. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
  1201. # ifndef RHEL_RELEASE_VERSION
  1202. /* I'm not sure which 5.x release this was backported into. */
  1203. static inline int try_wait_for_completion(struct completion *x)
  1204. {
  1205. unsigned long flags;
  1206. int ret = 1;
  1207. spin_lock_irqsave(&x->wait.lock, flags);
  1208. if (!x->done)
  1209. ret = 0;
  1210. else
  1211. x->done--;
  1212. spin_unlock_irqrestore(&x->wait.lock, flags);
  1213. return ret;
  1214. }
  1215. #endif
  1216. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
  1217. #ifdef CONFIG_PROC_FS
  1218. #include <linux/proc_fs.h>
  1219. static inline struct proc_dir_entry *proc_create_data(const char *name,
  1220. mode_t mode,
  1221. struct proc_dir_entry *parent,
  1222. const struct file_operations *proc_fops,
  1223. void *data)
  1224. {
  1225. struct proc_dir_entry *pde = create_proc_entry(name, mode, parent);
  1226. if (!pde)
  1227. return NULL;
  1228. pde->proc_fops = proc_fops;
  1229. pde->data = data;
  1230. return pde;
  1231. }
  1232. #endif /* CONFIG_PROC_FS */
  1233. #ifndef clamp
  1234. #define clamp(x, low, high) min(max(low, x), high)
  1235. #endif
  1236. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
  1237. /* Some distributions backported fatal_signal_pending so we'll use a macro to
  1238. * override the inline function definition. */
  1239. #define fatal_signal_pending(p) \
  1240. (signal_pending((p)) && sigismember(&(p)->pending.signal, SIGKILL))
  1241. #ifdef CONFIG_PCI
  1242. #ifndef PCIE_LINK_STATE_L0S
  1243. #define PCIE_LINK_STATE_L0S 1
  1244. #define PCIE_LINK_STATE_L1 2
  1245. #define PCIE_LINK_STATE_CLKPM 4
  1246. #endif
  1247. #define pci_disable_link_state dahdi_pci_disable_link_state
  1248. void dahdi_pci_disable_link_state(struct pci_dev *pdev, int state);
  1249. #endif /* CONFIG_PCI */
  1250. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22)
  1251. #define list_first_entry(ptr, type, member) \
  1252. list_entry((ptr)->next, type, member)
  1253. #define strncasecmp strnicmp
  1254. #ifndef __packed
  1255. #define __packed __attribute__((packed))
  1256. #endif
  1257. #include <linux/ctype.h>
  1258. /* A define of 'clamp_val' happened to be added in the patch
  1259. * linux-2.6-sata-prep-work-for-rhel5-3.patch kernel-2.6.spec that also
  1260. * backported support for strcasecmp to some later RHEL/Centos kernels.
  1261. * If you have an older kernel that breaks because strcasecmp is already
  1262. * defined, somebody out-smarted us. In that case, replace the line below
  1263. * with '#if 0' to get the code building, and file a bug report at
  1264. * https://issues.asterisk.org/ .
  1265. */
  1266. #ifndef clamp_val
  1267. static inline int strcasecmp(const char *s1, const char *s2)
  1268. {
  1269. int c1, c2;
  1270. do {
  1271. c1 = tolower(*s1++);
  1272. c2 = tolower(*s2++);
  1273. } while (c1 == c2 && c1 != 0);
  1274. return c1 - c2;
  1275. }
  1276. #endif /* clamp_val */
  1277. #endif /* 2.6.22 */
  1278. #endif /* 2.6.25 */
  1279. #endif /* 2.6.26 */
  1280. #endif /* 2.6.27 */
  1281. #endif /* 2.6.31 */
  1282. #endif /* 3.10.0 */
  1283. #endif /* 3.16.0 */
  1284. #ifndef DEFINE_SPINLOCK
  1285. #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
  1286. #endif
  1287. #ifndef DEFINE_SEMAPHORE
  1288. #define DEFINE_SEMAPHORE(name) \
  1289. struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
  1290. #endif
  1291. #ifndef DEFINE_MUTEX
  1292. struct mutex {
  1293. struct semaphore sem;
  1294. };
  1295. #define DEFINE_MUTEX(name) \
  1296. struct mutex name = { \
  1297. .sem = __SEMAPHORE_INITIALIZER((name).sem, 1), \
  1298. }
  1299. #define mutex_lock(_x) down(&(_x)->sem)
  1300. #define mutex_unlock(_x) up(&(_x)->sem)
  1301. #define mutex_init(_x) sema_init(&(_x)->sem, 1)
  1302. #endif
  1303. #ifndef DEFINE_PCI_DEVICE_TABLE
  1304. #define DEFINE_PCI_DEVICE_TABLE(_x) \
  1305. const struct pci_device_id _x[] __devinitdata
  1306. #endif
  1307. #ifndef DMA_BIT_MASK
  1308. #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
  1309. #endif
  1310. /* WARN_ONCE first showed up in the kernel in 2.6.27 but it may have been
  1311. * backported. */
  1312. #ifndef WARN_ONCE
  1313. #define WARN_ONCE(condition, format...) WARN_ON_ONCE(condition)
  1314. #endif
  1315. #define DAHDI_CTL 0
  1316. #define DAHDI_TRANSCODE 250
  1317. #define DAHDI_TIMER 253
  1318. #define DAHDI_CHANNEL 254
  1319. #define DAHDI_PSEUDO 255
  1320. /* prink-wrapper macros */
  1321. #define module_printk(level, fmt, args...) \
  1322. printk(level "%s: " fmt, THIS_MODULE->name, ## args)
  1323. #define DAHDI_PRINTK(level, category, fmt, ...) \
  1324. printk(KERN_ ## level "%s%s-%s: " fmt, #level, category, \
  1325. THIS_MODULE->name, ## __VA_ARGS__)
  1326. #define span_printk(level, category, span, fmt, ...) \
  1327. printk(KERN_ ## level "%s%s-%s: span-%d: " fmt, #level, \
  1328. category, THIS_MODULE->name, (span)->spanno, ## __VA_ARGS__)
  1329. #define chan_printk(level, category, chan, fmt, ...) \
  1330. printk(KERN_ ## level "%s%s-%s: chan-%d: " fmt, #level, \
  1331. category, THIS_MODULE->name, (chan)->channo, ## __VA_ARGS__)
  1332. #define dahdi_err(fmt, ...) DAHDI_PRINTK(ERR, "", fmt, ## __VA_ARGS__)
  1333. #define span_info(span, fmt, ...) span_printk(INFO, "", span, fmt, \
  1334. ## __VA_ARGS__)
  1335. #define span_notice(span, fmt, ...) span_printk(NOTICE, "", span, fmt, \
  1336. ## __VA_ARGS__)
  1337. #define span_err(span, fmt, ...) span_printk(ERR, "", span, fmt, \
  1338. ## __VA_ARGS__)
  1339. #define chan_notice(chan, fmt, ...) chan_printk(NOTICE, "", chan, fmt, \
  1340. ## __VA_ARGS__)
  1341. #define chan_err(chan, fmt, ...) chan_printk(ERR, "", chan, fmt, \
  1342. ## __VA_ARGS__)
  1343. #ifndef pr_fmt
  1344. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  1345. #endif
  1346. #ifndef pr_err
  1347. #define pr_err(fmt, ...) \
  1348. printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  1349. #endif
  1350. #ifndef pr_warning
  1351. #define pr_warning(fmt, ...) \
  1352. printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  1353. #endif
  1354. #ifndef pr_warn
  1355. #define pr_warn pr_warning
  1356. #endif
  1357. #ifndef pr_notice
  1358. #define pr_notice(fmt, ...) \
  1359. printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  1360. #endif
  1361. #ifndef pr_info
  1362. #define pr_info(fmt, ...) \
  1363. printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  1364. #endif
  1365. /* If KBUILD_MODNAME is not defined in a compilation unit, then the dev_dbg
  1366. * macro will not work properly. */
  1367. #ifndef KBUILD_MODNAME
  1368. #undef dev_dbg
  1369. #ifdef DEBUG
  1370. #define dev_dbg dev_info
  1371. #else
  1372. #define dev_dbg(...) do { } while (0)
  1373. #endif
  1374. #endif
  1375. /* The dbg_* ones use a magical variable 'debug' and the user should be
  1376. * aware of that.
  1377. */
  1378. #ifdef DAHDI_PRINK_MACROS_USE_debug
  1379. #ifndef BIT /* added in 2.6.24 */
  1380. #define BIT(i) (1UL << (i))
  1381. #endif
  1382. /* Standard debug bit values. Any module may define others. They must
  1383. * be of the form DAHDI_DBG_*
  1384. */
  1385. #define DAHDI_DBG_GENERAL BIT(0)
  1386. #define DAHDI_DBG_ASSIGN BIT(1)
  1387. #define DAHDI_DBG_DEVICES BIT(7) /* instantiation/destruction etc. */
  1388. #define dahdi_dbg(bits, fmt, ...) \
  1389. ((void)((debug & (DAHDI_DBG_ ## bits)) && DAHDI_PRINTK(DEBUG, \
  1390. "-" #bits, "%s: " fmt, __func__, ## __VA_ARGS__)))
  1391. #define span_dbg(bits, span, fmt, ...) \
  1392. ((void)((debug & (DAHDI_DBG_ ## bits)) && \
  1393. span_printk(DEBUG, "-" #bits, span, "%s: " \
  1394. fmt, __func__, ## __VA_ARGS__)))
  1395. #define chan_dbg(bits, chan, fmt, ...) \
  1396. ((void)((debug & (DAHDI_DBG_ ## bits)) && \
  1397. chan_printk(DEBUG, "-" #bits, chan, \
  1398. "%s: " fmt, __func__, ## __VA_ARGS__)))
  1399. #define dahdi_dev_dbg(bits, dev, fmt, ...) \
  1400. do { if (debug & (DAHDI_DBG_ ## bits)) { \
  1401. dev_printk(KERN_DEBUG, dev, \
  1402. "DBG-%s(%s): " fmt, #bits, __func__, ## __VA_ARGS__); \
  1403. } } while (0)
  1404. #endif /* DAHDI_PRINK_MACROS_USE_debug */
  1405. #endif /* _DAHDI_KERNEL_H */