kernel.h 51 KB

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