n_r3964.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /* r3964 linediscipline for linux
  3. *
  4. * -----------------------------------------------------------
  5. * Copyright by
  6. * Philips Automation Projects
  7. * Kassel (Germany)
  8. * -----------------------------------------------------------
  9. * Author:
  10. * L. Haag
  11. *
  12. * $Log: n_r3964.c,v $
  13. * Revision 1.10 2001/03/18 13:02:24 dwmw2
  14. * Fix timer usage, use spinlocks properly.
  15. *
  16. * Revision 1.9 2001/03/18 12:52:14 dwmw2
  17. * Merge changes in 2.4.2
  18. *
  19. * Revision 1.8 2000/03/23 14:14:54 dwmw2
  20. * Fix race in sleeping in r3964_read()
  21. *
  22. * Revision 1.7 1999/28/08 11:41:50 dwmw2
  23. * Port to 2.3 kernel
  24. *
  25. * Revision 1.6 1998/09/30 00:40:40 dwmw2
  26. * Fixed compilation on 2.0.x kernels
  27. * Updated to newly registered tty-ldisc number 9
  28. *
  29. * Revision 1.5 1998/09/04 21:57:36 dwmw2
  30. * Signal handling bug fixes, port to 2.1.x.
  31. *
  32. * Revision 1.4 1998/04/02 20:26:59 lhaag
  33. * select, blocking, ...
  34. *
  35. * Revision 1.3 1998/02/12 18:58:43 root
  36. * fixed some memory leaks
  37. * calculation of checksum characters
  38. *
  39. * Revision 1.2 1998/02/07 13:03:34 root
  40. * ioctl read_telegram
  41. *
  42. * Revision 1.1 1998/02/06 19:21:03 root
  43. * Initial revision
  44. *
  45. *
  46. */
  47. #include <linux/module.h>
  48. #include <linux/kernel.h>
  49. #include <linux/sched.h>
  50. #include <linux/types.h>
  51. #include <linux/fcntl.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/ptrace.h>
  54. #include <linux/ioport.h>
  55. #include <linux/in.h>
  56. #include <linux/slab.h>
  57. #include <linux/tty.h>
  58. #include <linux/errno.h>
  59. #include <linux/string.h> /* used in new tty drivers */
  60. #include <linux/signal.h> /* used in new tty drivers */
  61. #include <linux/ioctl.h>
  62. #include <linux/n_r3964.h>
  63. #include <linux/poll.h>
  64. #include <linux/init.h>
  65. #include <linux/uaccess.h>
  66. /*#define DEBUG_QUEUE*/
  67. /* Log successful handshake and protocol operations */
  68. /*#define DEBUG_PROTO_S*/
  69. /* Log handshake and protocol errors: */
  70. /*#define DEBUG_PROTO_E*/
  71. /* Log Linediscipline operations (open, close, read, write...): */
  72. /*#define DEBUG_LDISC*/
  73. /* Log module and memory operations (init, cleanup; kmalloc, kfree): */
  74. /*#define DEBUG_MODUL*/
  75. /* Macro helpers for debug output: */
  76. #define TRACE(format, args...) printk("r3964: " format "\n" , ## args)
  77. #ifdef DEBUG_MODUL
  78. #define TRACE_M(format, args...) printk("r3964: " format "\n" , ## args)
  79. #else
  80. #define TRACE_M(fmt, arg...) do {} while (0)
  81. #endif
  82. #ifdef DEBUG_PROTO_S
  83. #define TRACE_PS(format, args...) printk("r3964: " format "\n" , ## args)
  84. #else
  85. #define TRACE_PS(fmt, arg...) do {} while (0)
  86. #endif
  87. #ifdef DEBUG_PROTO_E
  88. #define TRACE_PE(format, args...) printk("r3964: " format "\n" , ## args)
  89. #else
  90. #define TRACE_PE(fmt, arg...) do {} while (0)
  91. #endif
  92. #ifdef DEBUG_LDISC
  93. #define TRACE_L(format, args...) printk("r3964: " format "\n" , ## args)
  94. #else
  95. #define TRACE_L(fmt, arg...) do {} while (0)
  96. #endif
  97. #ifdef DEBUG_QUEUE
  98. #define TRACE_Q(format, args...) printk("r3964: " format "\n" , ## args)
  99. #else
  100. #define TRACE_Q(fmt, arg...) do {} while (0)
  101. #endif
  102. static void add_tx_queue(struct r3964_info *, struct r3964_block_header *);
  103. static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code);
  104. static void put_char(struct r3964_info *pInfo, unsigned char ch);
  105. static void trigger_transmit(struct r3964_info *pInfo);
  106. static void retry_transmit(struct r3964_info *pInfo);
  107. static void transmit_block(struct r3964_info *pInfo);
  108. static void receive_char(struct r3964_info *pInfo, const unsigned char c);
  109. static void receive_error(struct r3964_info *pInfo, const char flag);
  110. static void on_timeout(struct timer_list *t);
  111. static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg);
  112. static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
  113. unsigned char __user * buf);
  114. static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
  115. int error_code, struct r3964_block_header *pBlock);
  116. static struct r3964_message *remove_msg(struct r3964_info *pInfo,
  117. struct r3964_client_info *pClient);
  118. static void remove_client_block(struct r3964_info *pInfo,
  119. struct r3964_client_info *pClient);
  120. static int r3964_open(struct tty_struct *tty);
  121. static void r3964_close(struct tty_struct *tty);
  122. static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
  123. void *cookie, unsigned char *buf, size_t nr);
  124. static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
  125. const unsigned char *buf, size_t nr);
  126. static int r3964_ioctl(struct tty_struct *tty, struct file *file,
  127. unsigned int cmd, unsigned long arg);
  128. #ifdef CONFIG_COMPAT
  129. static int r3964_compat_ioctl(struct tty_struct *tty, struct file *file,
  130. unsigned int cmd, unsigned long arg);
  131. #endif
  132. static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old);
  133. static __poll_t r3964_poll(struct tty_struct *tty, struct file *file,
  134. struct poll_table_struct *wait);
  135. static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
  136. char *fp, int count);
  137. static struct tty_ldisc_ops tty_ldisc_N_R3964 = {
  138. .owner = THIS_MODULE,
  139. .magic = TTY_LDISC_MAGIC,
  140. .name = "R3964",
  141. .open = r3964_open,
  142. .close = r3964_close,
  143. .read = r3964_read,
  144. .write = r3964_write,
  145. .ioctl = r3964_ioctl,
  146. #ifdef CONFIG_COMPAT
  147. .compat_ioctl = r3964_compat_ioctl,
  148. #endif
  149. .set_termios = r3964_set_termios,
  150. .poll = r3964_poll,
  151. .receive_buf = r3964_receive_buf,
  152. };
  153. static void dump_block(const unsigned char *block, unsigned int length)
  154. {
  155. unsigned int i, j;
  156. char linebuf[16 * 3 + 1];
  157. for (i = 0; i < length; i += 16) {
  158. for (j = 0; (j < 16) && (j + i < length); j++) {
  159. sprintf(linebuf + 3 * j, "%02x ", block[i + j]);
  160. }
  161. linebuf[3 * j] = '\0';
  162. TRACE_PS("%s", linebuf);
  163. }
  164. }
  165. /*************************************************************
  166. * Driver initialisation
  167. *************************************************************/
  168. /*************************************************************
  169. * Module support routines
  170. *************************************************************/
  171. static void __exit r3964_exit(void)
  172. {
  173. int status;
  174. TRACE_M("cleanup_module()");
  175. status = tty_unregister_ldisc(N_R3964);
  176. if (status != 0) {
  177. printk(KERN_ERR "r3964: error unregistering linediscipline: "
  178. "%d\n", status);
  179. } else {
  180. TRACE_L("linediscipline successfully unregistered");
  181. }
  182. }
  183. static int __init r3964_init(void)
  184. {
  185. int status;
  186. printk("r3964: Philips r3964 Driver $Revision: 1.10 $\n");
  187. /*
  188. * Register the tty line discipline
  189. */
  190. status = tty_register_ldisc(N_R3964, &tty_ldisc_N_R3964);
  191. if (status == 0) {
  192. TRACE_L("line discipline %d registered", N_R3964);
  193. TRACE_L("flags=%x num=%x", tty_ldisc_N_R3964.flags,
  194. tty_ldisc_N_R3964.num);
  195. TRACE_L("open=%p", tty_ldisc_N_R3964.open);
  196. TRACE_L("tty_ldisc_N_R3964 = %p", &tty_ldisc_N_R3964);
  197. } else {
  198. printk(KERN_ERR "r3964: error registering line discipline: "
  199. "%d\n", status);
  200. }
  201. return status;
  202. }
  203. module_init(r3964_init);
  204. module_exit(r3964_exit);
  205. /*************************************************************
  206. * Protocol implementation routines
  207. *************************************************************/
  208. static void add_tx_queue(struct r3964_info *pInfo,
  209. struct r3964_block_header *pHeader)
  210. {
  211. unsigned long flags;
  212. spin_lock_irqsave(&pInfo->lock, flags);
  213. pHeader->next = NULL;
  214. if (pInfo->tx_last == NULL) {
  215. pInfo->tx_first = pInfo->tx_last = pHeader;
  216. } else {
  217. pInfo->tx_last->next = pHeader;
  218. pInfo->tx_last = pHeader;
  219. }
  220. spin_unlock_irqrestore(&pInfo->lock, flags);
  221. TRACE_Q("add_tx_queue %p, length %d, tx_first = %p",
  222. pHeader, pHeader->length, pInfo->tx_first);
  223. }
  224. static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code)
  225. {
  226. struct r3964_block_header *pHeader;
  227. unsigned long flags;
  228. #ifdef DEBUG_QUEUE
  229. struct r3964_block_header *pDump;
  230. #endif
  231. pHeader = pInfo->tx_first;
  232. if (pHeader == NULL)
  233. return;
  234. #ifdef DEBUG_QUEUE
  235. printk("r3964: remove_from_tx_queue: %p, length %u - ",
  236. pHeader, pHeader->length);
  237. for (pDump = pHeader; pDump; pDump = pDump->next)
  238. printk("%p ", pDump);
  239. printk("\n");
  240. #endif
  241. if (pHeader->owner) {
  242. if (error_code) {
  243. add_msg(pHeader->owner, R3964_MSG_ACK, 0,
  244. error_code, NULL);
  245. } else {
  246. add_msg(pHeader->owner, R3964_MSG_ACK, pHeader->length,
  247. error_code, NULL);
  248. }
  249. wake_up_interruptible(&pInfo->tty->read_wait);
  250. }
  251. spin_lock_irqsave(&pInfo->lock, flags);
  252. pInfo->tx_first = pHeader->next;
  253. if (pInfo->tx_first == NULL) {
  254. pInfo->tx_last = NULL;
  255. }
  256. spin_unlock_irqrestore(&pInfo->lock, flags);
  257. kfree(pHeader);
  258. TRACE_M("remove_from_tx_queue - kfree %p", pHeader);
  259. TRACE_Q("remove_from_tx_queue: tx_first = %p, tx_last = %p",
  260. pInfo->tx_first, pInfo->tx_last);
  261. }
  262. static void add_rx_queue(struct r3964_info *pInfo,
  263. struct r3964_block_header *pHeader)
  264. {
  265. unsigned long flags;
  266. spin_lock_irqsave(&pInfo->lock, flags);
  267. pHeader->next = NULL;
  268. if (pInfo->rx_last == NULL) {
  269. pInfo->rx_first = pInfo->rx_last = pHeader;
  270. } else {
  271. pInfo->rx_last->next = pHeader;
  272. pInfo->rx_last = pHeader;
  273. }
  274. pInfo->blocks_in_rx_queue++;
  275. spin_unlock_irqrestore(&pInfo->lock, flags);
  276. TRACE_Q("add_rx_queue: %p, length = %d, rx_first = %p, count = %d",
  277. pHeader, pHeader->length,
  278. pInfo->rx_first, pInfo->blocks_in_rx_queue);
  279. }
  280. static void remove_from_rx_queue(struct r3964_info *pInfo,
  281. struct r3964_block_header *pHeader)
  282. {
  283. unsigned long flags;
  284. struct r3964_block_header *pFind;
  285. if (pHeader == NULL)
  286. return;
  287. TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
  288. pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
  289. TRACE_Q("remove_from_rx_queue: %p, length %u",
  290. pHeader, pHeader->length);
  291. spin_lock_irqsave(&pInfo->lock, flags);
  292. if (pInfo->rx_first == pHeader) {
  293. /* Remove the first block in the linked list: */
  294. pInfo->rx_first = pHeader->next;
  295. if (pInfo->rx_first == NULL) {
  296. pInfo->rx_last = NULL;
  297. }
  298. pInfo->blocks_in_rx_queue--;
  299. } else {
  300. /* Find block to remove: */
  301. for (pFind = pInfo->rx_first; pFind; pFind = pFind->next) {
  302. if (pFind->next == pHeader) {
  303. /* Got it. */
  304. pFind->next = pHeader->next;
  305. pInfo->blocks_in_rx_queue--;
  306. if (pFind->next == NULL) {
  307. /* Oh, removed the last one! */
  308. pInfo->rx_last = pFind;
  309. }
  310. break;
  311. }
  312. }
  313. }
  314. spin_unlock_irqrestore(&pInfo->lock, flags);
  315. kfree(pHeader);
  316. TRACE_M("remove_from_rx_queue - kfree %p", pHeader);
  317. TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
  318. pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
  319. }
  320. static void put_char(struct r3964_info *pInfo, unsigned char ch)
  321. {
  322. struct tty_struct *tty = pInfo->tty;
  323. /* FIXME: put_char should not be called from an IRQ */
  324. tty_put_char(tty, ch);
  325. pInfo->bcc ^= ch;
  326. }
  327. static void flush(struct r3964_info *pInfo)
  328. {
  329. struct tty_struct *tty = pInfo->tty;
  330. if (tty == NULL || tty->ops->flush_chars == NULL)
  331. return;
  332. tty->ops->flush_chars(tty);
  333. }
  334. static void trigger_transmit(struct r3964_info *pInfo)
  335. {
  336. unsigned long flags;
  337. spin_lock_irqsave(&pInfo->lock, flags);
  338. if ((pInfo->state == R3964_IDLE) && (pInfo->tx_first != NULL)) {
  339. pInfo->state = R3964_TX_REQUEST;
  340. pInfo->nRetry = 0;
  341. pInfo->flags &= ~R3964_ERROR;
  342. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  343. spin_unlock_irqrestore(&pInfo->lock, flags);
  344. TRACE_PS("trigger_transmit - sent STX");
  345. put_char(pInfo, STX);
  346. flush(pInfo);
  347. pInfo->bcc = 0;
  348. } else {
  349. spin_unlock_irqrestore(&pInfo->lock, flags);
  350. }
  351. }
  352. static void retry_transmit(struct r3964_info *pInfo)
  353. {
  354. if (pInfo->nRetry < R3964_MAX_RETRIES) {
  355. TRACE_PE("transmission failed. Retry #%d", pInfo->nRetry);
  356. pInfo->bcc = 0;
  357. put_char(pInfo, STX);
  358. flush(pInfo);
  359. pInfo->state = R3964_TX_REQUEST;
  360. pInfo->nRetry++;
  361. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  362. } else {
  363. TRACE_PE("transmission failed after %d retries",
  364. R3964_MAX_RETRIES);
  365. remove_from_tx_queue(pInfo, R3964_TX_FAIL);
  366. put_char(pInfo, NAK);
  367. flush(pInfo);
  368. pInfo->state = R3964_IDLE;
  369. trigger_transmit(pInfo);
  370. }
  371. }
  372. static void transmit_block(struct r3964_info *pInfo)
  373. {
  374. struct tty_struct *tty = pInfo->tty;
  375. struct r3964_block_header *pBlock = pInfo->tx_first;
  376. int room = 0;
  377. if (tty == NULL || pBlock == NULL) {
  378. return;
  379. }
  380. room = tty_write_room(tty);
  381. TRACE_PS("transmit_block %p, room %d, length %d",
  382. pBlock, room, pBlock->length);
  383. while (pInfo->tx_position < pBlock->length) {
  384. if (room < 2)
  385. break;
  386. if (pBlock->data[pInfo->tx_position] == DLE) {
  387. /* send additional DLE char: */
  388. put_char(pInfo, DLE);
  389. }
  390. put_char(pInfo, pBlock->data[pInfo->tx_position++]);
  391. room--;
  392. }
  393. if ((pInfo->tx_position == pBlock->length) && (room >= 3)) {
  394. put_char(pInfo, DLE);
  395. put_char(pInfo, ETX);
  396. if (pInfo->flags & R3964_BCC) {
  397. put_char(pInfo, pInfo->bcc);
  398. }
  399. pInfo->state = R3964_WAIT_FOR_TX_ACK;
  400. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  401. }
  402. flush(pInfo);
  403. }
  404. static void on_receive_block(struct r3964_info *pInfo)
  405. {
  406. unsigned int length;
  407. struct r3964_client_info *pClient;
  408. struct r3964_block_header *pBlock;
  409. length = pInfo->rx_position;
  410. /* compare byte checksum characters: */
  411. if (pInfo->flags & R3964_BCC) {
  412. if (pInfo->bcc != pInfo->last_rx) {
  413. TRACE_PE("checksum error - got %x but expected %x",
  414. pInfo->last_rx, pInfo->bcc);
  415. pInfo->flags |= R3964_CHECKSUM;
  416. }
  417. }
  418. /* check for errors (parity, overrun,...): */
  419. if (pInfo->flags & R3964_ERROR) {
  420. TRACE_PE("on_receive_block - transmission failed error %x",
  421. pInfo->flags & R3964_ERROR);
  422. put_char(pInfo, NAK);
  423. flush(pInfo);
  424. if (pInfo->nRetry < R3964_MAX_RETRIES) {
  425. pInfo->state = R3964_WAIT_FOR_RX_REPEAT;
  426. pInfo->nRetry++;
  427. mod_timer(&pInfo->tmr, jiffies + R3964_TO_RX_PANIC);
  428. } else {
  429. TRACE_PE("on_receive_block - failed after max retries");
  430. pInfo->state = R3964_IDLE;
  431. }
  432. return;
  433. }
  434. /* received block; submit DLE: */
  435. put_char(pInfo, DLE);
  436. flush(pInfo);
  437. del_timer_sync(&pInfo->tmr);
  438. TRACE_PS(" rx success: got %d chars", length);
  439. /* prepare struct r3964_block_header: */
  440. pBlock = kmalloc(length + sizeof(struct r3964_block_header),
  441. GFP_KERNEL);
  442. TRACE_M("on_receive_block - kmalloc %p", pBlock);
  443. if (pBlock == NULL)
  444. return;
  445. pBlock->length = length;
  446. pBlock->data = ((unsigned char *)pBlock) +
  447. sizeof(struct r3964_block_header);
  448. pBlock->locks = 0;
  449. pBlock->next = NULL;
  450. pBlock->owner = NULL;
  451. memcpy(pBlock->data, pInfo->rx_buf, length);
  452. /* queue block into rx_queue: */
  453. add_rx_queue(pInfo, pBlock);
  454. /* notify attached client processes: */
  455. for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
  456. if (pClient->sig_flags & R3964_SIG_DATA) {
  457. add_msg(pClient, R3964_MSG_DATA, length, R3964_OK,
  458. pBlock);
  459. }
  460. }
  461. wake_up_interruptible(&pInfo->tty->read_wait);
  462. pInfo->state = R3964_IDLE;
  463. trigger_transmit(pInfo);
  464. }
  465. static void receive_char(struct r3964_info *pInfo, const unsigned char c)
  466. {
  467. switch (pInfo->state) {
  468. case R3964_TX_REQUEST:
  469. if (c == DLE) {
  470. TRACE_PS("TX_REQUEST - got DLE");
  471. pInfo->state = R3964_TRANSMITTING;
  472. pInfo->tx_position = 0;
  473. transmit_block(pInfo);
  474. } else if (c == STX) {
  475. if (pInfo->nRetry == 0) {
  476. TRACE_PE("TX_REQUEST - init conflict");
  477. if (pInfo->priority == R3964_SLAVE) {
  478. goto start_receiving;
  479. }
  480. } else {
  481. TRACE_PE("TX_REQUEST - secondary init "
  482. "conflict!? Switching to SLAVE mode "
  483. "for next rx.");
  484. goto start_receiving;
  485. }
  486. } else {
  487. TRACE_PE("TX_REQUEST - char != DLE: %x", c);
  488. retry_transmit(pInfo);
  489. }
  490. break;
  491. case R3964_TRANSMITTING:
  492. if (c == NAK) {
  493. TRACE_PE("TRANSMITTING - got NAK");
  494. retry_transmit(pInfo);
  495. } else {
  496. TRACE_PE("TRANSMITTING - got invalid char");
  497. pInfo->state = R3964_WAIT_ZVZ_BEFORE_TX_RETRY;
  498. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  499. }
  500. break;
  501. case R3964_WAIT_FOR_TX_ACK:
  502. if (c == DLE) {
  503. TRACE_PS("WAIT_FOR_TX_ACK - got DLE");
  504. remove_from_tx_queue(pInfo, R3964_OK);
  505. pInfo->state = R3964_IDLE;
  506. trigger_transmit(pInfo);
  507. } else {
  508. retry_transmit(pInfo);
  509. }
  510. break;
  511. case R3964_WAIT_FOR_RX_REPEAT:
  512. case R3964_IDLE:
  513. if (c == STX) {
  514. /* Prevent rx_queue from overflow: */
  515. if (pInfo->blocks_in_rx_queue >=
  516. R3964_MAX_BLOCKS_IN_RX_QUEUE) {
  517. TRACE_PE("IDLE - got STX but no space in "
  518. "rx_queue!");
  519. pInfo->state = R3964_WAIT_FOR_RX_BUF;
  520. mod_timer(&pInfo->tmr,
  521. jiffies + R3964_TO_NO_BUF);
  522. break;
  523. }
  524. start_receiving:
  525. /* Ok, start receiving: */
  526. TRACE_PS("IDLE - got STX");
  527. pInfo->rx_position = 0;
  528. pInfo->last_rx = 0;
  529. pInfo->flags &= ~R3964_ERROR;
  530. pInfo->state = R3964_RECEIVING;
  531. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  532. pInfo->nRetry = 0;
  533. put_char(pInfo, DLE);
  534. flush(pInfo);
  535. pInfo->bcc = 0;
  536. }
  537. break;
  538. case R3964_RECEIVING:
  539. if (pInfo->rx_position < RX_BUF_SIZE) {
  540. pInfo->bcc ^= c;
  541. if (c == DLE) {
  542. if (pInfo->last_rx == DLE) {
  543. pInfo->last_rx = 0;
  544. goto char_to_buf;
  545. }
  546. pInfo->last_rx = DLE;
  547. break;
  548. } else if ((c == ETX) && (pInfo->last_rx == DLE)) {
  549. if (pInfo->flags & R3964_BCC) {
  550. pInfo->state = R3964_WAIT_FOR_BCC;
  551. mod_timer(&pInfo->tmr,
  552. jiffies + R3964_TO_ZVZ);
  553. } else {
  554. on_receive_block(pInfo);
  555. }
  556. } else {
  557. pInfo->last_rx = c;
  558. char_to_buf:
  559. pInfo->rx_buf[pInfo->rx_position++] = c;
  560. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  561. }
  562. }
  563. /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
  564. break;
  565. case R3964_WAIT_FOR_BCC:
  566. pInfo->last_rx = c;
  567. on_receive_block(pInfo);
  568. break;
  569. }
  570. }
  571. static void receive_error(struct r3964_info *pInfo, const char flag)
  572. {
  573. switch (flag) {
  574. case TTY_NORMAL:
  575. break;
  576. case TTY_BREAK:
  577. TRACE_PE("received break");
  578. pInfo->flags |= R3964_BREAK;
  579. break;
  580. case TTY_PARITY:
  581. TRACE_PE("parity error");
  582. pInfo->flags |= R3964_PARITY;
  583. break;
  584. case TTY_FRAME:
  585. TRACE_PE("frame error");
  586. pInfo->flags |= R3964_FRAME;
  587. break;
  588. case TTY_OVERRUN:
  589. TRACE_PE("frame overrun");
  590. pInfo->flags |= R3964_OVERRUN;
  591. break;
  592. default:
  593. TRACE_PE("receive_error - unknown flag %d", flag);
  594. pInfo->flags |= R3964_UNKNOWN;
  595. break;
  596. }
  597. }
  598. static void on_timeout(struct timer_list *t)
  599. {
  600. struct r3964_info *pInfo = from_timer(pInfo, t, tmr);
  601. switch (pInfo->state) {
  602. case R3964_TX_REQUEST:
  603. TRACE_PE("TX_REQUEST - timeout");
  604. retry_transmit(pInfo);
  605. break;
  606. case R3964_WAIT_ZVZ_BEFORE_TX_RETRY:
  607. put_char(pInfo, NAK);
  608. flush(pInfo);
  609. retry_transmit(pInfo);
  610. break;
  611. case R3964_WAIT_FOR_TX_ACK:
  612. TRACE_PE("WAIT_FOR_TX_ACK - timeout");
  613. retry_transmit(pInfo);
  614. break;
  615. case R3964_WAIT_FOR_RX_BUF:
  616. TRACE_PE("WAIT_FOR_RX_BUF - timeout");
  617. put_char(pInfo, NAK);
  618. flush(pInfo);
  619. pInfo->state = R3964_IDLE;
  620. break;
  621. case R3964_RECEIVING:
  622. TRACE_PE("RECEIVING - timeout after %d chars",
  623. pInfo->rx_position);
  624. put_char(pInfo, NAK);
  625. flush(pInfo);
  626. pInfo->state = R3964_IDLE;
  627. break;
  628. case R3964_WAIT_FOR_RX_REPEAT:
  629. TRACE_PE("WAIT_FOR_RX_REPEAT - timeout");
  630. pInfo->state = R3964_IDLE;
  631. break;
  632. case R3964_WAIT_FOR_BCC:
  633. TRACE_PE("WAIT_FOR_BCC - timeout");
  634. put_char(pInfo, NAK);
  635. flush(pInfo);
  636. pInfo->state = R3964_IDLE;
  637. break;
  638. }
  639. }
  640. static struct r3964_client_info *findClient(struct r3964_info *pInfo,
  641. struct pid *pid)
  642. {
  643. struct r3964_client_info *pClient;
  644. for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
  645. if (pClient->pid == pid) {
  646. return pClient;
  647. }
  648. }
  649. return NULL;
  650. }
  651. static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
  652. {
  653. struct r3964_client_info *pClient;
  654. struct r3964_client_info **ppClient;
  655. struct r3964_message *pMsg;
  656. if ((arg & R3964_SIG_ALL) == 0) {
  657. /* Remove client from client list */
  658. for (ppClient = &pInfo->firstClient; *ppClient;
  659. ppClient = &(*ppClient)->next) {
  660. pClient = *ppClient;
  661. if (pClient->pid == pid) {
  662. TRACE_PS("removing client %d from client list",
  663. pid_nr(pid));
  664. *ppClient = pClient->next;
  665. while (pClient->msg_count) {
  666. pMsg = remove_msg(pInfo, pClient);
  667. if (pMsg) {
  668. kfree(pMsg);
  669. TRACE_M("enable_signals - msg "
  670. "kfree %p", pMsg);
  671. }
  672. }
  673. put_pid(pClient->pid);
  674. kfree(pClient);
  675. TRACE_M("enable_signals - kfree %p", pClient);
  676. return 0;
  677. }
  678. }
  679. return -EINVAL;
  680. } else {
  681. pClient = findClient(pInfo, pid);
  682. if (pClient) {
  683. /* update signal options */
  684. pClient->sig_flags = arg;
  685. } else {
  686. /* add client to client list */
  687. pClient = kmalloc(sizeof(struct r3964_client_info),
  688. GFP_KERNEL);
  689. TRACE_M("enable_signals - kmalloc %p", pClient);
  690. if (pClient == NULL)
  691. return -ENOMEM;
  692. TRACE_PS("add client %d to client list", pid_nr(pid));
  693. spin_lock_init(&pClient->lock);
  694. pClient->sig_flags = arg;
  695. pClient->pid = get_pid(pid);
  696. pClient->next = pInfo->firstClient;
  697. pClient->first_msg = NULL;
  698. pClient->last_msg = NULL;
  699. pClient->next_block_to_read = NULL;
  700. pClient->msg_count = 0;
  701. pInfo->firstClient = pClient;
  702. }
  703. }
  704. return 0;
  705. }
  706. static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
  707. unsigned char __user * buf)
  708. {
  709. struct r3964_client_info *pClient;
  710. struct r3964_block_header *block;
  711. if (!buf) {
  712. return -EINVAL;
  713. }
  714. pClient = findClient(pInfo, pid);
  715. if (pClient == NULL) {
  716. return -EINVAL;
  717. }
  718. block = pClient->next_block_to_read;
  719. if (!block) {
  720. return 0;
  721. } else {
  722. if (copy_to_user(buf, block->data, block->length))
  723. return -EFAULT;
  724. remove_client_block(pInfo, pClient);
  725. return block->length;
  726. }
  727. return -EINVAL;
  728. }
  729. static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
  730. int error_code, struct r3964_block_header *pBlock)
  731. {
  732. struct r3964_message *pMsg;
  733. unsigned long flags;
  734. if (pClient->msg_count < R3964_MAX_MSG_COUNT - 1) {
  735. queue_the_message:
  736. pMsg = kmalloc(sizeof(struct r3964_message),
  737. error_code ? GFP_ATOMIC : GFP_KERNEL);
  738. TRACE_M("add_msg - kmalloc %p", pMsg);
  739. if (pMsg == NULL) {
  740. return;
  741. }
  742. spin_lock_irqsave(&pClient->lock, flags);
  743. pMsg->msg_id = msg_id;
  744. pMsg->arg = arg;
  745. pMsg->error_code = error_code;
  746. pMsg->block = pBlock;
  747. pMsg->next = NULL;
  748. if (pClient->last_msg == NULL) {
  749. pClient->first_msg = pClient->last_msg = pMsg;
  750. } else {
  751. pClient->last_msg->next = pMsg;
  752. pClient->last_msg = pMsg;
  753. }
  754. pClient->msg_count++;
  755. if (pBlock != NULL) {
  756. pBlock->locks++;
  757. }
  758. spin_unlock_irqrestore(&pClient->lock, flags);
  759. } else {
  760. if ((pClient->last_msg->msg_id == R3964_MSG_ACK)
  761. && (pClient->last_msg->error_code == R3964_OVERFLOW)) {
  762. pClient->last_msg->arg++;
  763. TRACE_PE("add_msg - inc prev OVERFLOW-msg");
  764. } else {
  765. msg_id = R3964_MSG_ACK;
  766. arg = 0;
  767. error_code = R3964_OVERFLOW;
  768. pBlock = NULL;
  769. TRACE_PE("add_msg - queue OVERFLOW-msg");
  770. goto queue_the_message;
  771. }
  772. }
  773. /* Send SIGIO signal to client process: */
  774. if (pClient->sig_flags & R3964_USE_SIGIO) {
  775. kill_pid(pClient->pid, SIGIO, 1);
  776. }
  777. }
  778. static struct r3964_message *remove_msg(struct r3964_info *pInfo,
  779. struct r3964_client_info *pClient)
  780. {
  781. struct r3964_message *pMsg = NULL;
  782. unsigned long flags;
  783. if (pClient->first_msg) {
  784. spin_lock_irqsave(&pClient->lock, flags);
  785. pMsg = pClient->first_msg;
  786. pClient->first_msg = pMsg->next;
  787. if (pClient->first_msg == NULL) {
  788. pClient->last_msg = NULL;
  789. }
  790. pClient->msg_count--;
  791. if (pMsg->block) {
  792. remove_client_block(pInfo, pClient);
  793. pClient->next_block_to_read = pMsg->block;
  794. }
  795. spin_unlock_irqrestore(&pClient->lock, flags);
  796. }
  797. return pMsg;
  798. }
  799. static void remove_client_block(struct r3964_info *pInfo,
  800. struct r3964_client_info *pClient)
  801. {
  802. struct r3964_block_header *block;
  803. TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
  804. block = pClient->next_block_to_read;
  805. if (block) {
  806. block->locks--;
  807. if (block->locks == 0) {
  808. remove_from_rx_queue(pInfo, block);
  809. }
  810. }
  811. pClient->next_block_to_read = NULL;
  812. }
  813. /*************************************************************
  814. * Line discipline routines
  815. *************************************************************/
  816. static int r3964_open(struct tty_struct *tty)
  817. {
  818. struct r3964_info *pInfo;
  819. TRACE_L("open");
  820. TRACE_L("tty=%p, PID=%d, disc_data=%p",
  821. tty, current->pid, tty->disc_data);
  822. pInfo = kmalloc(sizeof(struct r3964_info), GFP_KERNEL);
  823. TRACE_M("r3964_open - info kmalloc %p", pInfo);
  824. if (!pInfo) {
  825. printk(KERN_ERR "r3964: failed to alloc info structure\n");
  826. return -ENOMEM;
  827. }
  828. pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
  829. TRACE_M("r3964_open - rx_buf kmalloc %p", pInfo->rx_buf);
  830. if (!pInfo->rx_buf) {
  831. printk(KERN_ERR "r3964: failed to alloc receive buffer\n");
  832. kfree(pInfo);
  833. TRACE_M("r3964_open - info kfree %p", pInfo);
  834. return -ENOMEM;
  835. }
  836. pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL);
  837. TRACE_M("r3964_open - tx_buf kmalloc %p", pInfo->tx_buf);
  838. if (!pInfo->tx_buf) {
  839. printk(KERN_ERR "r3964: failed to alloc transmit buffer\n");
  840. kfree(pInfo->rx_buf);
  841. TRACE_M("r3964_open - rx_buf kfree %p", pInfo->rx_buf);
  842. kfree(pInfo);
  843. TRACE_M("r3964_open - info kfree %p", pInfo);
  844. return -ENOMEM;
  845. }
  846. spin_lock_init(&pInfo->lock);
  847. mutex_init(&pInfo->read_lock);
  848. pInfo->tty = tty;
  849. pInfo->priority = R3964_MASTER;
  850. pInfo->rx_first = pInfo->rx_last = NULL;
  851. pInfo->tx_first = pInfo->tx_last = NULL;
  852. pInfo->rx_position = 0;
  853. pInfo->tx_position = 0;
  854. pInfo->last_rx = 0;
  855. pInfo->blocks_in_rx_queue = 0;
  856. pInfo->firstClient = NULL;
  857. pInfo->state = R3964_IDLE;
  858. pInfo->flags = R3964_DEBUG;
  859. pInfo->nRetry = 0;
  860. tty->disc_data = pInfo;
  861. tty->receive_room = 65536;
  862. timer_setup(&pInfo->tmr, on_timeout, 0);
  863. return 0;
  864. }
  865. static void r3964_close(struct tty_struct *tty)
  866. {
  867. struct r3964_info *pInfo = tty->disc_data;
  868. struct r3964_client_info *pClient, *pNext;
  869. struct r3964_message *pMsg;
  870. struct r3964_block_header *pHeader, *pNextHeader;
  871. unsigned long flags;
  872. TRACE_L("close");
  873. /*
  874. * Make sure that our task queue isn't activated. If it
  875. * is, take it out of the linked list.
  876. */
  877. del_timer_sync(&pInfo->tmr);
  878. /* Remove client-structs and message queues: */
  879. pClient = pInfo->firstClient;
  880. while (pClient) {
  881. pNext = pClient->next;
  882. while (pClient->msg_count) {
  883. pMsg = remove_msg(pInfo, pClient);
  884. if (pMsg) {
  885. kfree(pMsg);
  886. TRACE_M("r3964_close - msg kfree %p", pMsg);
  887. }
  888. }
  889. put_pid(pClient->pid);
  890. kfree(pClient);
  891. TRACE_M("r3964_close - client kfree %p", pClient);
  892. pClient = pNext;
  893. }
  894. /* Remove jobs from tx_queue: */
  895. spin_lock_irqsave(&pInfo->lock, flags);
  896. pHeader = pInfo->tx_first;
  897. pInfo->tx_first = pInfo->tx_last = NULL;
  898. spin_unlock_irqrestore(&pInfo->lock, flags);
  899. while (pHeader) {
  900. pNextHeader = pHeader->next;
  901. kfree(pHeader);
  902. pHeader = pNextHeader;
  903. }
  904. /* Free buffers: */
  905. kfree(pInfo->rx_buf);
  906. TRACE_M("r3964_close - rx_buf kfree %p", pInfo->rx_buf);
  907. kfree(pInfo->tx_buf);
  908. TRACE_M("r3964_close - tx_buf kfree %p", pInfo->tx_buf);
  909. kfree(pInfo);
  910. TRACE_M("r3964_close - info kfree %p", pInfo);
  911. }
  912. static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
  913. unsigned char *kbuf, size_t nr,
  914. void **cookie, unsigned long offset)
  915. {
  916. struct r3964_info *pInfo = tty->disc_data;
  917. struct r3964_client_info *pClient;
  918. struct r3964_message *pMsg;
  919. struct r3964_client_message theMsg;
  920. int ret;
  921. TRACE_L("read()");
  922. /*
  923. * Internal serialization of reads.
  924. */
  925. if (file->f_flags & O_NONBLOCK) {
  926. if (!mutex_trylock(&pInfo->read_lock))
  927. return -EAGAIN;
  928. } else {
  929. if (mutex_lock_interruptible(&pInfo->read_lock))
  930. return -ERESTARTSYS;
  931. }
  932. pClient = findClient(pInfo, task_pid(current));
  933. if (pClient) {
  934. pMsg = remove_msg(pInfo, pClient);
  935. if (pMsg == NULL) {
  936. /* no messages available. */
  937. if (tty_io_nonblock(tty, file)) {
  938. ret = -EAGAIN;
  939. goto unlock;
  940. }
  941. /* block until there is a message: */
  942. wait_event_interruptible(tty->read_wait,
  943. (pMsg = remove_msg(pInfo, pClient)));
  944. }
  945. /* If we still haven't got a message, we must have been signalled */
  946. if (!pMsg) {
  947. ret = -EINTR;
  948. goto unlock;
  949. }
  950. /* deliver msg to client process: */
  951. theMsg.msg_id = pMsg->msg_id;
  952. theMsg.arg = pMsg->arg;
  953. theMsg.error_code = pMsg->error_code;
  954. ret = sizeof(struct r3964_client_message);
  955. kfree(pMsg);
  956. TRACE_M("r3964_read - msg kfree %p", pMsg);
  957. memcpy(kbuf, &theMsg, ret);
  958. TRACE_PS("read - return %d", ret);
  959. goto unlock;
  960. }
  961. ret = -EPERM;
  962. unlock:
  963. mutex_unlock(&pInfo->read_lock);
  964. return ret;
  965. }
  966. static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
  967. const unsigned char *data, size_t count)
  968. {
  969. struct r3964_info *pInfo = tty->disc_data;
  970. struct r3964_block_header *pHeader;
  971. struct r3964_client_info *pClient;
  972. unsigned char *new_data;
  973. TRACE_L("write request, %d characters", count);
  974. /*
  975. * Verify the pointers
  976. */
  977. if (!pInfo)
  978. return -EIO;
  979. /*
  980. * Ensure that the caller does not wish to send too much.
  981. */
  982. if (count > R3964_MTU) {
  983. if (pInfo->flags & R3964_DEBUG) {
  984. TRACE_L(KERN_WARNING "r3964_write: truncating user "
  985. "packet from %u to mtu %d", count, R3964_MTU);
  986. }
  987. count = R3964_MTU;
  988. }
  989. /*
  990. * Allocate a buffer for the data and copy it from the buffer with header prepended
  991. */
  992. new_data = kmalloc(count + sizeof(struct r3964_block_header),
  993. GFP_KERNEL);
  994. TRACE_M("r3964_write - kmalloc %p", new_data);
  995. if (new_data == NULL) {
  996. if (pInfo->flags & R3964_DEBUG) {
  997. printk(KERN_ERR "r3964_write: no memory\n");
  998. }
  999. return -ENOSPC;
  1000. }
  1001. pHeader = (struct r3964_block_header *)new_data;
  1002. pHeader->data = new_data + sizeof(struct r3964_block_header);
  1003. pHeader->length = count;
  1004. pHeader->locks = 0;
  1005. pHeader->owner = NULL;
  1006. pClient = findClient(pInfo, task_pid(current));
  1007. if (pClient) {
  1008. pHeader->owner = pClient;
  1009. }
  1010. memcpy(pHeader->data, data, count); /* We already verified this */
  1011. if (pInfo->flags & R3964_DEBUG) {
  1012. dump_block(pHeader->data, count);
  1013. }
  1014. /*
  1015. * Add buffer to transmit-queue:
  1016. */
  1017. add_tx_queue(pInfo, pHeader);
  1018. trigger_transmit(pInfo);
  1019. return 0;
  1020. }
  1021. static int r3964_ioctl(struct tty_struct *tty, struct file *file,
  1022. unsigned int cmd, unsigned long arg)
  1023. {
  1024. struct r3964_info *pInfo = tty->disc_data;
  1025. if (pInfo == NULL)
  1026. return -EINVAL;
  1027. switch (cmd) {
  1028. case R3964_ENABLE_SIGNALS:
  1029. return enable_signals(pInfo, task_pid(current), arg);
  1030. case R3964_SETPRIORITY:
  1031. if (arg < R3964_MASTER || arg > R3964_SLAVE)
  1032. return -EINVAL;
  1033. pInfo->priority = arg & 0xff;
  1034. return 0;
  1035. case R3964_USE_BCC:
  1036. if (arg)
  1037. pInfo->flags |= R3964_BCC;
  1038. else
  1039. pInfo->flags &= ~R3964_BCC;
  1040. return 0;
  1041. case R3964_READ_TELEGRAM:
  1042. return read_telegram(pInfo, task_pid(current),
  1043. (unsigned char __user *)arg);
  1044. default:
  1045. return -ENOIOCTLCMD;
  1046. }
  1047. }
  1048. #ifdef CONFIG_COMPAT
  1049. static int r3964_compat_ioctl(struct tty_struct *tty, struct file *file,
  1050. unsigned int cmd, unsigned long arg)
  1051. {
  1052. switch (cmd) {
  1053. case R3964_ENABLE_SIGNALS:
  1054. case R3964_SETPRIORITY:
  1055. case R3964_USE_BCC:
  1056. return r3964_ioctl(tty, file, cmd, arg);
  1057. default:
  1058. return -ENOIOCTLCMD;
  1059. }
  1060. }
  1061. #endif
  1062. static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
  1063. {
  1064. TRACE_L("set_termios");
  1065. }
  1066. /* Called without the kernel lock held - fine */
  1067. static __poll_t r3964_poll(struct tty_struct *tty, struct file *file,
  1068. struct poll_table_struct *wait)
  1069. {
  1070. struct r3964_info *pInfo = tty->disc_data;
  1071. struct r3964_client_info *pClient;
  1072. struct r3964_message *pMsg = NULL;
  1073. unsigned long flags;
  1074. __poll_t result = EPOLLOUT;
  1075. TRACE_L("POLL");
  1076. pClient = findClient(pInfo, task_pid(current));
  1077. if (pClient) {
  1078. poll_wait(file, &tty->read_wait, wait);
  1079. spin_lock_irqsave(&pInfo->lock, flags);
  1080. pMsg = pClient->first_msg;
  1081. spin_unlock_irqrestore(&pInfo->lock, flags);
  1082. if (pMsg)
  1083. result |= EPOLLIN | EPOLLRDNORM;
  1084. } else {
  1085. result = -EINVAL;
  1086. }
  1087. return result;
  1088. }
  1089. static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
  1090. char *fp, int count)
  1091. {
  1092. struct r3964_info *pInfo = tty->disc_data;
  1093. const unsigned char *p;
  1094. char *f, flags = TTY_NORMAL;
  1095. int i;
  1096. for (i = count, p = cp, f = fp; i; i--, p++) {
  1097. if (f)
  1098. flags = *f++;
  1099. if (flags == TTY_NORMAL) {
  1100. receive_char(pInfo, *p);
  1101. } else {
  1102. receive_error(pInfo, flags);
  1103. }
  1104. }
  1105. }
  1106. MODULE_LICENSE("GPL");
  1107. MODULE_ALIAS_LDISC(N_R3964);