Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* r3964 linediscipline for linux |
| 2 | * |
| 3 | * ----------------------------------------------------------- |
| 4 | * Copyright by |
| 5 | * Philips Automation Projects |
| 6 | * Kassel (Germany) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * ----------------------------------------------------------- |
| 8 | * This software may be used and distributed according to the terms of |
| 9 | * the GNU General Public License, incorporated herein by reference. |
| 10 | * |
| 11 | * Author: |
| 12 | * L. Haag |
| 13 | * |
| 14 | * $Log: r3964.h,v $ |
Kurt Huwig | 01e33b5 | 2005-12-25 00:13:08 +0100 | [diff] [blame] | 15 | * Revision 1.4 2005/12/21 19:54:24 Kurt Huwig <kurt huwig de> |
| 16 | * Fixed HZ usage on 2.6 kernels |
| 17 | * Removed unnecessary include |
| 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * Revision 1.3 2001/03/18 13:02:24 dwmw2 |
| 20 | * Fix timer usage, use spinlocks properly. |
| 21 | * |
| 22 | * Revision 1.2 2001/03/18 12:53:15 dwmw2 |
| 23 | * Merge changes in 2.4.2 |
| 24 | * |
| 25 | * Revision 1.1.1.1 1998/10/13 16:43:14 dwmw2 |
| 26 | * This'll screw the version control |
| 27 | * |
| 28 | * Revision 1.6 1998/09/30 00:40:38 dwmw2 |
| 29 | * Updated to use kernel's N_R3964 if available |
| 30 | * |
| 31 | * Revision 1.4 1998/04/02 20:29:44 lhaag |
| 32 | * select, blocking, ... |
| 33 | * |
| 34 | * Revision 1.3 1998/02/12 18:58:43 root |
| 35 | * fixed some memory leaks |
| 36 | * calculation of checksum characters |
| 37 | * |
| 38 | * Revision 1.2 1998/02/07 13:03:17 root |
| 39 | * ioctl read_telegram |
| 40 | * |
| 41 | * Revision 1.1 1998/02/06 19:19:43 root |
| 42 | * Initial revision |
| 43 | * |
| 44 | * |
| 45 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifndef __LINUX_N_R3964_H__ |
| 47 | #define __LINUX_N_R3964_H__ |
| 48 | |
Kurt Huwig | 01e33b5 | 2005-12-25 00:13:08 +0100 | [diff] [blame] | 49 | |
| 50 | #include <linux/param.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 51 | #include <uapi/linux/n_r3964.h> |
Kurt Huwig | 01e33b5 | 2005-12-25 00:13:08 +0100 | [diff] [blame] | 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Common ascii handshake characters: |
| 55 | */ |
| 56 | |
| 57 | #define STX 0x02 |
| 58 | #define ETX 0x03 |
| 59 | #define DLE 0x10 |
| 60 | #define NAK 0x15 |
| 61 | |
| 62 | /* |
Kurt Huwig | 01e33b5 | 2005-12-25 00:13:08 +0100 | [diff] [blame] | 63 | * Timeouts (from milliseconds to jiffies) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
| 65 | |
Kurt Huwig | 01e33b5 | 2005-12-25 00:13:08 +0100 | [diff] [blame] | 66 | #define R3964_TO_QVZ ((550)*HZ/1000) |
| 67 | #define R3964_TO_ZVZ ((220)*HZ/1000) |
| 68 | #define R3964_TO_NO_BUF ((400)*HZ/1000) |
| 69 | #define R3964_NO_TX_ROOM ((100)*HZ/1000) |
| 70 | #define R3964_TO_RX_PANIC ((4000)*HZ/1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define R3964_MAX_RETRIES 5 |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | enum { R3964_IDLE, |
| 75 | R3964_TX_REQUEST, R3964_TRANSMITTING, |
| 76 | R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK, |
| 77 | R3964_WAIT_FOR_RX_BUF, |
| 78 | R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * All open file-handles are 'clients' and are stored in a linked list: |
| 83 | */ |
| 84 | |
| 85 | struct r3964_message; |
| 86 | |
| 87 | struct r3964_client_info { |
| 88 | spinlock_t lock; |
Eric W. Biederman | 3cec556 | 2006-12-13 00:35:10 -0800 | [diff] [blame] | 89 | struct pid *pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | unsigned int sig_flags; |
| 91 | |
| 92 | struct r3964_client_info *next; |
| 93 | |
| 94 | struct r3964_message *first_msg; |
| 95 | struct r3964_message *last_msg; |
| 96 | struct r3964_block_header *next_block_to_read; |
| 97 | int msg_count; |
| 98 | }; |
| 99 | |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | struct r3964_block_header; |
| 103 | |
| 104 | /* internal version of client_message: */ |
| 105 | struct r3964_message { |
| 106 | int msg_id; |
| 107 | int arg; |
| 108 | int error_code; |
| 109 | struct r3964_block_header *block; |
| 110 | struct r3964_message *next; |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * Header of received block in rx_buf/tx_buf: |
| 115 | */ |
| 116 | |
| 117 | struct r3964_block_header |
| 118 | { |
| 119 | unsigned int length; /* length in chars without header */ |
| 120 | unsigned char *data; /* usually data is located |
| 121 | immediately behind this struct */ |
| 122 | unsigned int locks; /* only used in rx_buffer */ |
| 123 | |
| 124 | struct r3964_block_header *next; |
| 125 | struct r3964_client_info *owner; /* =NULL in rx_buffer */ |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * If rx_buf hasn't enough space to store R3964_MTU chars, |
| 130 | * we will reject all incoming STX-requests by sending NAK. |
| 131 | */ |
| 132 | |
| 133 | #define RX_BUF_SIZE 4000 |
| 134 | #define TX_BUF_SIZE 4000 |
| 135 | #define R3964_MAX_BLOCKS_IN_RX_QUEUE 100 |
| 136 | |
| 137 | #define R3964_PARITY 0x0001 |
| 138 | #define R3964_FRAME 0x0002 |
| 139 | #define R3964_OVERRUN 0x0004 |
| 140 | #define R3964_UNKNOWN 0x0008 |
| 141 | #define R3964_BREAK 0x0010 |
| 142 | #define R3964_CHECKSUM 0x0020 |
| 143 | #define R3964_ERROR 0x003f |
| 144 | #define R3964_BCC 0x4000 |
| 145 | #define R3964_DEBUG 0x8000 |
| 146 | |
| 147 | |
| 148 | struct r3964_info { |
| 149 | spinlock_t lock; |
| 150 | struct tty_struct *tty; |
| 151 | unsigned char priority; |
| 152 | unsigned char *rx_buf; /* ring buffer */ |
| 153 | unsigned char *tx_buf; |
| 154 | |
| 155 | wait_queue_head_t read_wait; |
| 156 | //struct wait_queue *read_wait; |
| 157 | |
| 158 | struct r3964_block_header *rx_first; |
| 159 | struct r3964_block_header *rx_last; |
| 160 | struct r3964_block_header *tx_first; |
| 161 | struct r3964_block_header *tx_last; |
| 162 | unsigned int tx_position; |
| 163 | unsigned int rx_position; |
| 164 | unsigned char last_rx; |
| 165 | unsigned char bcc; |
| 166 | unsigned int blocks_in_rx_queue; |
| 167 | |
| 168 | |
| 169 | struct r3964_client_info *firstClient; |
| 170 | unsigned int state; |
| 171 | unsigned int flags; |
| 172 | |
| 173 | struct timer_list tmr; |
| 174 | int nRetry; |
| 175 | }; |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #endif |