n_r3964.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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. unsigned char __user * 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. /* FALLTHROUGH */
  513. case R3964_IDLE:
  514. if (c == STX) {
  515. /* Prevent rx_queue from overflow: */
  516. if (pInfo->blocks_in_rx_queue >=
  517. R3964_MAX_BLOCKS_IN_RX_QUEUE) {
  518. TRACE_PE("IDLE - got STX but no space in "
  519. "rx_queue!");
  520. pInfo->state = R3964_WAIT_FOR_RX_BUF;
  521. mod_timer(&pInfo->tmr,
  522. jiffies + R3964_TO_NO_BUF);
  523. break;
  524. }
  525. start_receiving:
  526. /* Ok, start receiving: */
  527. TRACE_PS("IDLE - got STX");
  528. pInfo->rx_position = 0;
  529. pInfo->last_rx = 0;
  530. pInfo->flags &= ~R3964_ERROR;
  531. pInfo->state = R3964_RECEIVING;
  532. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  533. pInfo->nRetry = 0;
  534. put_char(pInfo, DLE);
  535. flush(pInfo);
  536. pInfo->bcc = 0;
  537. }
  538. break;
  539. case R3964_RECEIVING:
  540. if (pInfo->rx_position < RX_BUF_SIZE) {
  541. pInfo->bcc ^= c;
  542. if (c == DLE) {
  543. if (pInfo->last_rx == DLE) {
  544. pInfo->last_rx = 0;
  545. goto char_to_buf;
  546. }
  547. pInfo->last_rx = DLE;
  548. break;
  549. } else if ((c == ETX) && (pInfo->last_rx == DLE)) {
  550. if (pInfo->flags & R3964_BCC) {
  551. pInfo->state = R3964_WAIT_FOR_BCC;
  552. mod_timer(&pInfo->tmr,
  553. jiffies + R3964_TO_ZVZ);
  554. } else {
  555. on_receive_block(pInfo);
  556. }
  557. } else {
  558. pInfo->last_rx = c;
  559. char_to_buf:
  560. pInfo->rx_buf[pInfo->rx_position++] = c;
  561. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  562. }
  563. }
  564. /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
  565. break;
  566. case R3964_WAIT_FOR_BCC:
  567. pInfo->last_rx = c;
  568. on_receive_block(pInfo);
  569. break;
  570. }
  571. }
  572. static void receive_error(struct r3964_info *pInfo, const char flag)
  573. {
  574. switch (flag) {
  575. case TTY_NORMAL:
  576. break;
  577. case TTY_BREAK:
  578. TRACE_PE("received break");
  579. pInfo->flags |= R3964_BREAK;
  580. break;
  581. case TTY_PARITY:
  582. TRACE_PE("parity error");
  583. pInfo->flags |= R3964_PARITY;
  584. break;
  585. case TTY_FRAME:
  586. TRACE_PE("frame error");
  587. pInfo->flags |= R3964_FRAME;
  588. break;
  589. case TTY_OVERRUN:
  590. TRACE_PE("frame overrun");
  591. pInfo->flags |= R3964_OVERRUN;
  592. break;
  593. default:
  594. TRACE_PE("receive_error - unknown flag %d", flag);
  595. pInfo->flags |= R3964_UNKNOWN;
  596. break;
  597. }
  598. }
  599. static void on_timeout(struct timer_list *t)
  600. {
  601. struct r3964_info *pInfo = from_timer(pInfo, t, tmr);
  602. switch (pInfo->state) {
  603. case R3964_TX_REQUEST:
  604. TRACE_PE("TX_REQUEST - timeout");
  605. retry_transmit(pInfo);
  606. break;
  607. case R3964_WAIT_ZVZ_BEFORE_TX_RETRY:
  608. put_char(pInfo, NAK);
  609. flush(pInfo);
  610. retry_transmit(pInfo);
  611. break;
  612. case R3964_WAIT_FOR_TX_ACK:
  613. TRACE_PE("WAIT_FOR_TX_ACK - timeout");
  614. retry_transmit(pInfo);
  615. break;
  616. case R3964_WAIT_FOR_RX_BUF:
  617. TRACE_PE("WAIT_FOR_RX_BUF - timeout");
  618. put_char(pInfo, NAK);
  619. flush(pInfo);
  620. pInfo->state = R3964_IDLE;
  621. break;
  622. case R3964_RECEIVING:
  623. TRACE_PE("RECEIVING - timeout after %d chars",
  624. pInfo->rx_position);
  625. put_char(pInfo, NAK);
  626. flush(pInfo);
  627. pInfo->state = R3964_IDLE;
  628. break;
  629. case R3964_WAIT_FOR_RX_REPEAT:
  630. TRACE_PE("WAIT_FOR_RX_REPEAT - timeout");
  631. pInfo->state = R3964_IDLE;
  632. break;
  633. case R3964_WAIT_FOR_BCC:
  634. TRACE_PE("WAIT_FOR_BCC - timeout");
  635. put_char(pInfo, NAK);
  636. flush(pInfo);
  637. pInfo->state = R3964_IDLE;
  638. break;
  639. }
  640. }
  641. static struct r3964_client_info *findClient(struct r3964_info *pInfo,
  642. struct pid *pid)
  643. {
  644. struct r3964_client_info *pClient;
  645. for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
  646. if (pClient->pid == pid) {
  647. return pClient;
  648. }
  649. }
  650. return NULL;
  651. }
  652. static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
  653. {
  654. struct r3964_client_info *pClient;
  655. struct r3964_client_info **ppClient;
  656. struct r3964_message *pMsg;
  657. if ((arg & R3964_SIG_ALL) == 0) {
  658. /* Remove client from client list */
  659. for (ppClient = &pInfo->firstClient; *ppClient;
  660. ppClient = &(*ppClient)->next) {
  661. pClient = *ppClient;
  662. if (pClient->pid == pid) {
  663. TRACE_PS("removing client %d from client list",
  664. pid_nr(pid));
  665. *ppClient = pClient->next;
  666. while (pClient->msg_count) {
  667. pMsg = remove_msg(pInfo, pClient);
  668. if (pMsg) {
  669. kfree(pMsg);
  670. TRACE_M("enable_signals - msg "
  671. "kfree %p", pMsg);
  672. }
  673. }
  674. put_pid(pClient->pid);
  675. kfree(pClient);
  676. TRACE_M("enable_signals - kfree %p", pClient);
  677. return 0;
  678. }
  679. }
  680. return -EINVAL;
  681. } else {
  682. pClient = findClient(pInfo, pid);
  683. if (pClient) {
  684. /* update signal options */
  685. pClient->sig_flags = arg;
  686. } else {
  687. /* add client to client list */
  688. pClient = kmalloc(sizeof(struct r3964_client_info),
  689. GFP_KERNEL);
  690. TRACE_M("enable_signals - kmalloc %p", pClient);
  691. if (pClient == NULL)
  692. return -ENOMEM;
  693. TRACE_PS("add client %d to client list", pid_nr(pid));
  694. spin_lock_init(&pClient->lock);
  695. pClient->sig_flags = arg;
  696. pClient->pid = get_pid(pid);
  697. pClient->next = pInfo->firstClient;
  698. pClient->first_msg = NULL;
  699. pClient->last_msg = NULL;
  700. pClient->next_block_to_read = NULL;
  701. pClient->msg_count = 0;
  702. pInfo->firstClient = pClient;
  703. }
  704. }
  705. return 0;
  706. }
  707. static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
  708. unsigned char __user * buf)
  709. {
  710. struct r3964_client_info *pClient;
  711. struct r3964_block_header *block;
  712. if (!buf) {
  713. return -EINVAL;
  714. }
  715. pClient = findClient(pInfo, pid);
  716. if (pClient == NULL) {
  717. return -EINVAL;
  718. }
  719. block = pClient->next_block_to_read;
  720. if (!block) {
  721. return 0;
  722. } else {
  723. if (copy_to_user(buf, block->data, block->length))
  724. return -EFAULT;
  725. remove_client_block(pInfo, pClient);
  726. return block->length;
  727. }
  728. return -EINVAL;
  729. }
  730. static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
  731. int error_code, struct r3964_block_header *pBlock)
  732. {
  733. struct r3964_message *pMsg;
  734. unsigned long flags;
  735. if (pClient->msg_count < R3964_MAX_MSG_COUNT - 1) {
  736. queue_the_message:
  737. pMsg = kmalloc(sizeof(struct r3964_message),
  738. error_code ? GFP_ATOMIC : GFP_KERNEL);
  739. TRACE_M("add_msg - kmalloc %p", pMsg);
  740. if (pMsg == NULL) {
  741. return;
  742. }
  743. spin_lock_irqsave(&pClient->lock, flags);
  744. pMsg->msg_id = msg_id;
  745. pMsg->arg = arg;
  746. pMsg->error_code = error_code;
  747. pMsg->block = pBlock;
  748. pMsg->next = NULL;
  749. if (pClient->last_msg == NULL) {
  750. pClient->first_msg = pClient->last_msg = pMsg;
  751. } else {
  752. pClient->last_msg->next = pMsg;
  753. pClient->last_msg = pMsg;
  754. }
  755. pClient->msg_count++;
  756. if (pBlock != NULL) {
  757. pBlock->locks++;
  758. }
  759. spin_unlock_irqrestore(&pClient->lock, flags);
  760. } else {
  761. if ((pClient->last_msg->msg_id == R3964_MSG_ACK)
  762. && (pClient->last_msg->error_code == R3964_OVERFLOW)) {
  763. pClient->last_msg->arg++;
  764. TRACE_PE("add_msg - inc prev OVERFLOW-msg");
  765. } else {
  766. msg_id = R3964_MSG_ACK;
  767. arg = 0;
  768. error_code = R3964_OVERFLOW;
  769. pBlock = NULL;
  770. TRACE_PE("add_msg - queue OVERFLOW-msg");
  771. goto queue_the_message;
  772. }
  773. }
  774. /* Send SIGIO signal to client process: */
  775. if (pClient->sig_flags & R3964_USE_SIGIO) {
  776. kill_pid(pClient->pid, SIGIO, 1);
  777. }
  778. }
  779. static struct r3964_message *remove_msg(struct r3964_info *pInfo,
  780. struct r3964_client_info *pClient)
  781. {
  782. struct r3964_message *pMsg = NULL;
  783. unsigned long flags;
  784. if (pClient->first_msg) {
  785. spin_lock_irqsave(&pClient->lock, flags);
  786. pMsg = pClient->first_msg;
  787. pClient->first_msg = pMsg->next;
  788. if (pClient->first_msg == NULL) {
  789. pClient->last_msg = NULL;
  790. }
  791. pClient->msg_count--;
  792. if (pMsg->block) {
  793. remove_client_block(pInfo, pClient);
  794. pClient->next_block_to_read = pMsg->block;
  795. }
  796. spin_unlock_irqrestore(&pClient->lock, flags);
  797. }
  798. return pMsg;
  799. }
  800. static void remove_client_block(struct r3964_info *pInfo,
  801. struct r3964_client_info *pClient)
  802. {
  803. struct r3964_block_header *block;
  804. TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
  805. block = pClient->next_block_to_read;
  806. if (block) {
  807. block->locks--;
  808. if (block->locks == 0) {
  809. remove_from_rx_queue(pInfo, block);
  810. }
  811. }
  812. pClient->next_block_to_read = NULL;
  813. }
  814. /*************************************************************
  815. * Line discipline routines
  816. *************************************************************/
  817. static int r3964_open(struct tty_struct *tty)
  818. {
  819. struct r3964_info *pInfo;
  820. TRACE_L("open");
  821. TRACE_L("tty=%p, PID=%d, disc_data=%p",
  822. tty, current->pid, tty->disc_data);
  823. pInfo = kmalloc(sizeof(struct r3964_info), GFP_KERNEL);
  824. TRACE_M("r3964_open - info kmalloc %p", pInfo);
  825. if (!pInfo) {
  826. printk(KERN_ERR "r3964: failed to alloc info structure\n");
  827. return -ENOMEM;
  828. }
  829. pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
  830. TRACE_M("r3964_open - rx_buf kmalloc %p", pInfo->rx_buf);
  831. if (!pInfo->rx_buf) {
  832. printk(KERN_ERR "r3964: failed to alloc receive buffer\n");
  833. kfree(pInfo);
  834. TRACE_M("r3964_open - info kfree %p", pInfo);
  835. return -ENOMEM;
  836. }
  837. pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL);
  838. TRACE_M("r3964_open - tx_buf kmalloc %p", pInfo->tx_buf);
  839. if (!pInfo->tx_buf) {
  840. printk(KERN_ERR "r3964: failed to alloc transmit buffer\n");
  841. kfree(pInfo->rx_buf);
  842. TRACE_M("r3964_open - rx_buf kfree %p", pInfo->rx_buf);
  843. kfree(pInfo);
  844. TRACE_M("r3964_open - info kfree %p", pInfo);
  845. return -ENOMEM;
  846. }
  847. spin_lock_init(&pInfo->lock);
  848. mutex_init(&pInfo->read_lock);
  849. pInfo->tty = tty;
  850. pInfo->priority = R3964_MASTER;
  851. pInfo->rx_first = pInfo->rx_last = NULL;
  852. pInfo->tx_first = pInfo->tx_last = NULL;
  853. pInfo->rx_position = 0;
  854. pInfo->tx_position = 0;
  855. pInfo->last_rx = 0;
  856. pInfo->blocks_in_rx_queue = 0;
  857. pInfo->firstClient = NULL;
  858. pInfo->state = R3964_IDLE;
  859. pInfo->flags = R3964_DEBUG;
  860. pInfo->nRetry = 0;
  861. tty->disc_data = pInfo;
  862. tty->receive_room = 65536;
  863. timer_setup(&pInfo->tmr, on_timeout, 0);
  864. return 0;
  865. }
  866. static void r3964_close(struct tty_struct *tty)
  867. {
  868. struct r3964_info *pInfo = tty->disc_data;
  869. struct r3964_client_info *pClient, *pNext;
  870. struct r3964_message *pMsg;
  871. struct r3964_block_header *pHeader, *pNextHeader;
  872. unsigned long flags;
  873. TRACE_L("close");
  874. /*
  875. * Make sure that our task queue isn't activated. If it
  876. * is, take it out of the linked list.
  877. */
  878. del_timer_sync(&pInfo->tmr);
  879. /* Remove client-structs and message queues: */
  880. pClient = pInfo->firstClient;
  881. while (pClient) {
  882. pNext = pClient->next;
  883. while (pClient->msg_count) {
  884. pMsg = remove_msg(pInfo, pClient);
  885. if (pMsg) {
  886. kfree(pMsg);
  887. TRACE_M("r3964_close - msg kfree %p", pMsg);
  888. }
  889. }
  890. put_pid(pClient->pid);
  891. kfree(pClient);
  892. TRACE_M("r3964_close - client kfree %p", pClient);
  893. pClient = pNext;
  894. }
  895. /* Remove jobs from tx_queue: */
  896. spin_lock_irqsave(&pInfo->lock, flags);
  897. pHeader = pInfo->tx_first;
  898. pInfo->tx_first = pInfo->tx_last = NULL;
  899. spin_unlock_irqrestore(&pInfo->lock, flags);
  900. while (pHeader) {
  901. pNextHeader = pHeader->next;
  902. kfree(pHeader);
  903. pHeader = pNextHeader;
  904. }
  905. /* Free buffers: */
  906. kfree(pInfo->rx_buf);
  907. TRACE_M("r3964_close - rx_buf kfree %p", pInfo->rx_buf);
  908. kfree(pInfo->tx_buf);
  909. TRACE_M("r3964_close - tx_buf kfree %p", pInfo->tx_buf);
  910. kfree(pInfo);
  911. TRACE_M("r3964_close - info kfree %p", pInfo);
  912. }
  913. static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
  914. unsigned char __user * buf, size_t nr)
  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. if (copy_to_user(buf, &theMsg, ret)) {
  958. ret = -EFAULT;
  959. goto unlock;
  960. }
  961. TRACE_PS("read - return %d", ret);
  962. goto unlock;
  963. }
  964. ret = -EPERM;
  965. unlock:
  966. mutex_unlock(&pInfo->read_lock);
  967. return ret;
  968. }
  969. static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
  970. const unsigned char *data, size_t count)
  971. {
  972. struct r3964_info *pInfo = tty->disc_data;
  973. struct r3964_block_header *pHeader;
  974. struct r3964_client_info *pClient;
  975. unsigned char *new_data;
  976. TRACE_L("write request, %d characters", count);
  977. /*
  978. * Verify the pointers
  979. */
  980. if (!pInfo)
  981. return -EIO;
  982. /*
  983. * Ensure that the caller does not wish to send too much.
  984. */
  985. if (count > R3964_MTU) {
  986. if (pInfo->flags & R3964_DEBUG) {
  987. TRACE_L(KERN_WARNING "r3964_write: truncating user "
  988. "packet from %u to mtu %d", count, R3964_MTU);
  989. }
  990. count = R3964_MTU;
  991. }
  992. /*
  993. * Allocate a buffer for the data and copy it from the buffer with header prepended
  994. */
  995. new_data = kmalloc(count + sizeof(struct r3964_block_header),
  996. GFP_KERNEL);
  997. TRACE_M("r3964_write - kmalloc %p", new_data);
  998. if (new_data == NULL) {
  999. if (pInfo->flags & R3964_DEBUG) {
  1000. printk(KERN_ERR "r3964_write: no memory\n");
  1001. }
  1002. return -ENOSPC;
  1003. }
  1004. pHeader = (struct r3964_block_header *)new_data;
  1005. pHeader->data = new_data + sizeof(struct r3964_block_header);
  1006. pHeader->length = count;
  1007. pHeader->locks = 0;
  1008. pHeader->owner = NULL;
  1009. pClient = findClient(pInfo, task_pid(current));
  1010. if (pClient) {
  1011. pHeader->owner = pClient;
  1012. }
  1013. memcpy(pHeader->data, data, count); /* We already verified this */
  1014. if (pInfo->flags & R3964_DEBUG) {
  1015. dump_block(pHeader->data, count);
  1016. }
  1017. /*
  1018. * Add buffer to transmit-queue:
  1019. */
  1020. add_tx_queue(pInfo, pHeader);
  1021. trigger_transmit(pInfo);
  1022. return 0;
  1023. }
  1024. static int r3964_ioctl(struct tty_struct *tty, struct file *file,
  1025. unsigned int cmd, unsigned long arg)
  1026. {
  1027. struct r3964_info *pInfo = tty->disc_data;
  1028. if (pInfo == NULL)
  1029. return -EINVAL;
  1030. switch (cmd) {
  1031. case R3964_ENABLE_SIGNALS:
  1032. return enable_signals(pInfo, task_pid(current), arg);
  1033. case R3964_SETPRIORITY:
  1034. if (arg < R3964_MASTER || arg > R3964_SLAVE)
  1035. return -EINVAL;
  1036. pInfo->priority = arg & 0xff;
  1037. return 0;
  1038. case R3964_USE_BCC:
  1039. if (arg)
  1040. pInfo->flags |= R3964_BCC;
  1041. else
  1042. pInfo->flags &= ~R3964_BCC;
  1043. return 0;
  1044. case R3964_READ_TELEGRAM:
  1045. return read_telegram(pInfo, task_pid(current),
  1046. (unsigned char __user *)arg);
  1047. default:
  1048. return -ENOIOCTLCMD;
  1049. }
  1050. }
  1051. #ifdef CONFIG_COMPAT
  1052. static int r3964_compat_ioctl(struct tty_struct *tty, struct file *file,
  1053. unsigned int cmd, unsigned long arg)
  1054. {
  1055. switch (cmd) {
  1056. case R3964_ENABLE_SIGNALS:
  1057. case R3964_SETPRIORITY:
  1058. case R3964_USE_BCC:
  1059. return r3964_ioctl(tty, file, cmd, arg);
  1060. default:
  1061. return -ENOIOCTLCMD;
  1062. }
  1063. }
  1064. #endif
  1065. static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
  1066. {
  1067. TRACE_L("set_termios");
  1068. }
  1069. /* Called without the kernel lock held - fine */
  1070. static __poll_t r3964_poll(struct tty_struct *tty, struct file *file,
  1071. struct poll_table_struct *wait)
  1072. {
  1073. struct r3964_info *pInfo = tty->disc_data;
  1074. struct r3964_client_info *pClient;
  1075. struct r3964_message *pMsg = NULL;
  1076. unsigned long flags;
  1077. __poll_t result = EPOLLOUT;
  1078. TRACE_L("POLL");
  1079. pClient = findClient(pInfo, task_pid(current));
  1080. if (pClient) {
  1081. poll_wait(file, &tty->read_wait, wait);
  1082. spin_lock_irqsave(&pInfo->lock, flags);
  1083. pMsg = pClient->first_msg;
  1084. spin_unlock_irqrestore(&pInfo->lock, flags);
  1085. if (pMsg)
  1086. result |= EPOLLIN | EPOLLRDNORM;
  1087. } else {
  1088. result = -EINVAL;
  1089. }
  1090. return result;
  1091. }
  1092. static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
  1093. char *fp, int count)
  1094. {
  1095. struct r3964_info *pInfo = tty->disc_data;
  1096. const unsigned char *p;
  1097. char *f, flags = TTY_NORMAL;
  1098. int i;
  1099. for (i = count, p = cp, f = fp; i; i--, p++) {
  1100. if (f)
  1101. flags = *f++;
  1102. if (flags == TTY_NORMAL) {
  1103. receive_char(pInfo, *p);
  1104. } else {
  1105. receive_error(pInfo, flags);
  1106. }
  1107. }
  1108. }
  1109. MODULE_LICENSE("GPL");
  1110. MODULE_ALIAS_LDISC(N_R3964);