diff options
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r-- | drivers/char/moxa.c | 927 |
1 files changed, 305 insertions, 622 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index f391a24a1b4..7dbaee8d940 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -11,15 +11,6 @@ | |||
11 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | 14 | */ |
24 | 15 | ||
25 | /* | 16 | /* |
@@ -55,36 +46,20 @@ | |||
55 | #include <asm/io.h> | 46 | #include <asm/io.h> |
56 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
57 | 48 | ||
58 | #define MOXA_VERSION "5.1k" | 49 | #define MOXA_VERSION "5.1k" |
59 | 50 | ||
60 | #define MOXAMAJOR 172 | 51 | #define MOXAMAJOR 172 |
61 | #define MOXACUMAJOR 173 | 52 | #define MOXACUMAJOR 173 |
62 | 53 | ||
63 | #define put_to_user(arg1, arg2) put_user(arg1, (unsigned long *)arg2) | 54 | #define MAX_BOARDS 4 /* Don't change this value */ |
64 | #define get_from_user(arg1, arg2) get_user(arg1, (unsigned int *)arg2) | ||
65 | |||
66 | #define MAX_BOARDS 4 /* Don't change this value */ | ||
67 | #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ | 55 | #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ |
68 | #define MAX_PORTS 128 /* Don't change this value */ | 56 | #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) |
69 | 57 | ||
70 | /* | 58 | /* |
71 | * Define the Moxa PCI vendor and device IDs. | 59 | * Define the Moxa PCI vendor and device IDs. |
72 | */ | 60 | */ |
73 | #define MOXA_BUS_TYPE_ISA 0 | 61 | #define MOXA_BUS_TYPE_ISA 0 |
74 | #define MOXA_BUS_TYPE_PCI 1 | 62 | #define MOXA_BUS_TYPE_PCI 1 |
75 | |||
76 | #ifndef PCI_VENDOR_ID_MOXA | ||
77 | #define PCI_VENDOR_ID_MOXA 0x1393 | ||
78 | #endif | ||
79 | #ifndef PCI_DEVICE_ID_CP204J | ||
80 | #define PCI_DEVICE_ID_CP204J 0x2040 | ||
81 | #endif | ||
82 | #ifndef PCI_DEVICE_ID_C218 | ||
83 | #define PCI_DEVICE_ID_C218 0x2180 | ||
84 | #endif | ||
85 | #ifndef PCI_DEVICE_ID_C320 | ||
86 | #define PCI_DEVICE_ID_C320 0x3200 | ||
87 | #endif | ||
88 | 63 | ||
89 | enum { | 64 | enum { |
90 | MOXA_BOARD_C218_PCI = 1, | 65 | MOXA_BOARD_C218_PCI = 1, |
@@ -105,47 +80,56 @@ static char *moxa_brdname[] = | |||
105 | 80 | ||
106 | #ifdef CONFIG_PCI | 81 | #ifdef CONFIG_PCI |
107 | static struct pci_device_id moxa_pcibrds[] = { | 82 | static struct pci_device_id moxa_pcibrds[] = { |
108 | { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_C218, PCI_ANY_ID, PCI_ANY_ID, | 83 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218), |
109 | 0, 0, MOXA_BOARD_C218_PCI }, | 84 | .driver_data = MOXA_BOARD_C218_PCI }, |
110 | { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_C320, PCI_ANY_ID, PCI_ANY_ID, | 85 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320), |
111 | 0, 0, MOXA_BOARD_C320_PCI }, | 86 | .driver_data = MOXA_BOARD_C320_PCI }, |
112 | { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_CP204J, PCI_ANY_ID, PCI_ANY_ID, | 87 | { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J), |
113 | 0, 0, MOXA_BOARD_CP204J }, | 88 | .driver_data = MOXA_BOARD_CP204J }, |
114 | { 0 } | 89 | { 0 } |
115 | }; | 90 | }; |
116 | MODULE_DEVICE_TABLE(pci, moxa_pcibrds); | 91 | MODULE_DEVICE_TABLE(pci, moxa_pcibrds); |
117 | #endif /* CONFIG_PCI */ | 92 | #endif /* CONFIG_PCI */ |
118 | 93 | ||
119 | typedef struct _moxa_isa_board_conf { | 94 | struct moxa_isa_board_conf { |
120 | int boardType; | 95 | int boardType; |
121 | int numPorts; | 96 | int numPorts; |
122 | unsigned long baseAddr; | 97 | unsigned long baseAddr; |
123 | } moxa_isa_board_conf; | 98 | }; |
124 | 99 | ||
125 | static moxa_isa_board_conf moxa_isa_boards[] = | 100 | static struct moxa_isa_board_conf moxa_isa_boards[] = |
126 | { | 101 | { |
127 | /* {MOXA_BOARD_C218_ISA,8,0xDC000}, */ | 102 | /* {MOXA_BOARD_C218_ISA,8,0xDC000}, */ |
128 | }; | 103 | }; |
129 | 104 | ||
130 | typedef struct _moxa_pci_devinfo { | 105 | static struct moxa_board_conf { |
131 | ushort busNum; | ||
132 | ushort devNum; | ||
133 | struct pci_dev *pdev; | ||
134 | } moxa_pci_devinfo; | ||
135 | |||
136 | typedef struct _moxa_board_conf { | ||
137 | int boardType; | 106 | int boardType; |
138 | int numPorts; | 107 | int numPorts; |
139 | unsigned long baseAddr; | 108 | unsigned long baseAddr; |
140 | int busType; | 109 | int busType; |
141 | moxa_pci_devinfo pciInfo; | ||
142 | } moxa_board_conf; | ||
143 | 110 | ||
144 | static moxa_board_conf moxa_boards[MAX_BOARDS]; | 111 | int loadstat; |
145 | static void __iomem *moxaBaseAddr[MAX_BOARDS]; | 112 | |
146 | static int loadstat[MAX_BOARDS]; | 113 | void __iomem *basemem; |
114 | void __iomem *intNdx; | ||
115 | void __iomem *intPend; | ||
116 | void __iomem *intTable; | ||
117 | } moxa_boards[MAX_BOARDS]; | ||
118 | |||
119 | struct mxser_mstatus { | ||
120 | tcflag_t cflag; | ||
121 | int cts; | ||
122 | int dsr; | ||
123 | int ri; | ||
124 | int dcd; | ||
125 | }; | ||
126 | |||
127 | struct moxaq_str { | ||
128 | int inq; | ||
129 | int outq; | ||
130 | }; | ||
147 | 131 | ||
148 | struct moxa_str { | 132 | struct moxa_port { |
149 | int type; | 133 | int type; |
150 | int port; | 134 | int port; |
151 | int close_delay; | 135 | int close_delay; |
@@ -159,18 +143,18 @@ struct moxa_str { | |||
159 | int cflag; | 143 | int cflag; |
160 | wait_queue_head_t open_wait; | 144 | wait_queue_head_t open_wait; |
161 | wait_queue_head_t close_wait; | 145 | wait_queue_head_t close_wait; |
162 | struct work_struct tqueue; | ||
163 | }; | ||
164 | 146 | ||
165 | struct mxser_mstatus { | 147 | struct timer_list emptyTimer; |
166 | tcflag_t cflag; | ||
167 | int cts; | ||
168 | int dsr; | ||
169 | int ri; | ||
170 | int dcd; | ||
171 | }; | ||
172 | 148 | ||
173 | static struct mxser_mstatus GMStatus[MAX_PORTS]; | 149 | char chkPort; |
150 | char lineCtrl; | ||
151 | void __iomem *tableAddr; | ||
152 | long curBaud; | ||
153 | char DCDState; | ||
154 | char lowChkFlag; | ||
155 | |||
156 | ushort breakCnt; | ||
157 | }; | ||
174 | 158 | ||
175 | /* statusflags */ | 159 | /* statusflags */ |
176 | #define TXSTOPPED 0x1 | 160 | #define TXSTOPPED 0x1 |
@@ -178,25 +162,17 @@ static struct mxser_mstatus GMStatus[MAX_PORTS]; | |||
178 | #define EMPTYWAIT 0x4 | 162 | #define EMPTYWAIT 0x4 |
179 | #define THROTTLE 0x8 | 163 | #define THROTTLE 0x8 |
180 | 164 | ||
181 | /* event */ | ||
182 | #define MOXA_EVENT_HANGUP 1 | ||
183 | |||
184 | #define SERIAL_DO_RESTART | 165 | #define SERIAL_DO_RESTART |
185 | 166 | ||
186 | |||
187 | #define SERIAL_TYPE_NORMAL 1 | ||
188 | |||
189 | #define WAKEUP_CHARS 256 | 167 | #define WAKEUP_CHARS 256 |
190 | 168 | ||
191 | #define PORTNO(x) ((x)->index) | ||
192 | |||
193 | static int verbose = 0; | 169 | static int verbose = 0; |
194 | static int ttymajor = MOXAMAJOR; | 170 | static int ttymajor = MOXAMAJOR; |
195 | /* Variables for insmod */ | 171 | /* Variables for insmod */ |
196 | #ifdef MODULE | 172 | #ifdef MODULE |
197 | static int baseaddr[] = {0, 0, 0, 0}; | 173 | static int baseaddr[4]; |
198 | static int type[] = {0, 0, 0, 0}; | 174 | static int type[4]; |
199 | static int numports[] = {0, 0, 0, 0}; | 175 | static int numports[4]; |
200 | #endif | 176 | #endif |
201 | 177 | ||
202 | MODULE_AUTHOR("William Chen"); | 178 | MODULE_AUTHOR("William Chen"); |
@@ -210,19 +186,9 @@ module_param_array(numports, int, NULL, 0); | |||
210 | module_param(ttymajor, int, 0); | 186 | module_param(ttymajor, int, 0); |
211 | module_param(verbose, bool, 0644); | 187 | module_param(verbose, bool, 0644); |
212 | 188 | ||
213 | static struct tty_driver *moxaDriver; | ||
214 | static struct moxa_str moxaChannels[MAX_PORTS]; | ||
215 | static unsigned char *moxaXmitBuff; | ||
216 | static int moxaTimer_on; | ||
217 | static struct timer_list moxaTimer; | ||
218 | static int moxaEmptyTimer_on[MAX_PORTS]; | ||
219 | static struct timer_list moxaEmptyTimer[MAX_PORTS]; | ||
220 | static struct semaphore moxaBuffSem; | ||
221 | |||
222 | /* | 189 | /* |
223 | * static functions: | 190 | * static functions: |
224 | */ | 191 | */ |
225 | static void do_moxa_softint(struct work_struct *); | ||
226 | static int moxa_open(struct tty_struct *, struct file *); | 192 | static int moxa_open(struct tty_struct *, struct file *); |
227 | static void moxa_close(struct tty_struct *, struct file *); | 193 | static void moxa_close(struct tty_struct *, struct file *); |
228 | static int moxa_write(struct tty_struct *, const unsigned char *, int); | 194 | static int moxa_write(struct tty_struct *, const unsigned char *, int); |
@@ -244,11 +210,11 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file, | |||
244 | static void moxa_poll(unsigned long); | 210 | static void moxa_poll(unsigned long); |
245 | static void set_tty_param(struct tty_struct *); | 211 | static void set_tty_param(struct tty_struct *); |
246 | static int block_till_ready(struct tty_struct *, struct file *, | 212 | static int block_till_ready(struct tty_struct *, struct file *, |
247 | struct moxa_str *); | 213 | struct moxa_port *); |
248 | static void setup_empty_event(struct tty_struct *); | 214 | static void setup_empty_event(struct tty_struct *); |
249 | static void check_xmit_empty(unsigned long); | 215 | static void check_xmit_empty(unsigned long); |
250 | static void shut_down(struct moxa_str *); | 216 | static void shut_down(struct moxa_port *); |
251 | static void receive_data(struct moxa_str *); | 217 | static void receive_data(struct moxa_port *); |
252 | /* | 218 | /* |
253 | * moxa board interface functions: | 219 | * moxa board interface functions: |
254 | */ | 220 | */ |
@@ -278,8 +244,8 @@ static void MoxaPortTxDisable(int); | |||
278 | static void MoxaPortTxEnable(int); | 244 | static void MoxaPortTxEnable(int); |
279 | static int MoxaPortResetBrkCnt(int); | 245 | static int MoxaPortResetBrkCnt(int); |
280 | static void MoxaPortSendBreak(int, int); | 246 | static void MoxaPortSendBreak(int, int); |
281 | static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user *); | 247 | static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *); |
282 | static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); | 248 | static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *); |
283 | static void MoxaSetFifo(int port, int enable); | 249 | static void MoxaSetFifo(int port, int enable); |
284 | 250 | ||
285 | static const struct tty_operations moxa_ops = { | 251 | static const struct tty_operations moxa_ops = { |
@@ -302,12 +268,41 @@ static const struct tty_operations moxa_ops = { | |||
302 | .tiocmset = moxa_tiocmset, | 268 | .tiocmset = moxa_tiocmset, |
303 | }; | 269 | }; |
304 | 270 | ||
271 | static struct tty_driver *moxaDriver; | ||
272 | static struct moxa_port moxa_ports[MAX_PORTS]; | ||
273 | static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); | ||
305 | static DEFINE_SPINLOCK(moxa_lock); | 274 | static DEFINE_SPINLOCK(moxa_lock); |
306 | 275 | ||
307 | #ifdef CONFIG_PCI | 276 | #ifdef CONFIG_PCI |
308 | static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board) | 277 | static int __devinit moxa_pci_probe(struct pci_dev *pdev, |
278 | const struct pci_device_id *ent) | ||
309 | { | 279 | { |
310 | board->baseAddr = pci_resource_start (p, 2); | 280 | struct moxa_board_conf *board; |
281 | unsigned int i; | ||
282 | int board_type = ent->driver_data; | ||
283 | int retval; | ||
284 | |||
285 | retval = pci_enable_device(pdev); | ||
286 | if (retval) | ||
287 | goto err; | ||
288 | |||
289 | for (i = 0; i < MAX_BOARDS; i++) | ||
290 | if (moxa_boards[i].basemem == NULL) | ||
291 | break; | ||
292 | |||
293 | retval = -ENODEV; | ||
294 | if (i >= MAX_BOARDS) { | ||
295 | if (verbose) | ||
296 | printk("More than %d MOXA Intellio family boards " | ||
297 | "found. Board is ignored.\n", MAX_BOARDS); | ||
298 | goto err; | ||
299 | } | ||
300 | |||
301 | board = &moxa_boards[i]; | ||
302 | board->basemem = pci_iomap(pdev, 2, 0x4000); | ||
303 | if (board->basemem == NULL) | ||
304 | goto err; | ||
305 | |||
311 | board->boardType = board_type; | 306 | board->boardType = board_type; |
312 | switch (board_type) { | 307 | switch (board_type) { |
313 | case MOXA_BOARD_C218_ISA: | 308 | case MOXA_BOARD_C218_ISA: |
@@ -323,27 +318,40 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf | |||
323 | break; | 318 | break; |
324 | } | 319 | } |
325 | board->busType = MOXA_BUS_TYPE_PCI; | 320 | board->busType = MOXA_BUS_TYPE_PCI; |
326 | board->pciInfo.busNum = p->bus->number; | 321 | |
327 | board->pciInfo.devNum = p->devfn >> 3; | 322 | pci_set_drvdata(pdev, board); |
328 | board->pciInfo.pdev = p; | ||
329 | /* don't lose the reference in the next pci_get_device iteration */ | ||
330 | pci_dev_get(p); | ||
331 | 323 | ||
332 | return (0); | 324 | return (0); |
325 | err: | ||
326 | return retval; | ||
333 | } | 327 | } |
328 | |||
329 | static void __devexit moxa_pci_remove(struct pci_dev *pdev) | ||
330 | { | ||
331 | struct moxa_board_conf *brd = pci_get_drvdata(pdev); | ||
332 | |||
333 | pci_iounmap(pdev, brd->basemem); | ||
334 | brd->basemem = NULL; | ||
335 | } | ||
336 | |||
337 | static struct pci_driver moxa_pci_driver = { | ||
338 | .name = "moxa", | ||
339 | .id_table = moxa_pcibrds, | ||
340 | .probe = moxa_pci_probe, | ||
341 | .remove = __devexit_p(moxa_pci_remove) | ||
342 | }; | ||
334 | #endif /* CONFIG_PCI */ | 343 | #endif /* CONFIG_PCI */ |
335 | 344 | ||
336 | static int __init moxa_init(void) | 345 | static int __init moxa_init(void) |
337 | { | 346 | { |
338 | int i, numBoards; | 347 | int i, numBoards, retval = 0; |
339 | struct moxa_str *ch; | 348 | struct moxa_port *ch; |
340 | 349 | ||
341 | printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION); | 350 | printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION); |
342 | moxaDriver = alloc_tty_driver(MAX_PORTS + 1); | 351 | moxaDriver = alloc_tty_driver(MAX_PORTS + 1); |
343 | if (!moxaDriver) | 352 | if (!moxaDriver) |
344 | return -ENOMEM; | 353 | return -ENOMEM; |
345 | 354 | ||
346 | init_MUTEX(&moxaBuffSem); | ||
347 | moxaDriver->owner = THIS_MODULE; | 355 | moxaDriver->owner = THIS_MODULE; |
348 | moxaDriver->name = "ttyMX"; | 356 | moxaDriver->name = "ttyMX"; |
349 | moxaDriver->major = ttymajor; | 357 | moxaDriver->major = ttymajor; |
@@ -351,40 +359,25 @@ static int __init moxa_init(void) | |||
351 | moxaDriver->type = TTY_DRIVER_TYPE_SERIAL; | 359 | moxaDriver->type = TTY_DRIVER_TYPE_SERIAL; |
352 | moxaDriver->subtype = SERIAL_TYPE_NORMAL; | 360 | moxaDriver->subtype = SERIAL_TYPE_NORMAL; |
353 | moxaDriver->init_termios = tty_std_termios; | 361 | moxaDriver->init_termios = tty_std_termios; |
354 | moxaDriver->init_termios.c_iflag = 0; | ||
355 | moxaDriver->init_termios.c_oflag = 0; | ||
356 | moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; | 362 | moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; |
357 | moxaDriver->init_termios.c_lflag = 0; | ||
358 | moxaDriver->init_termios.c_ispeed = 9600; | 363 | moxaDriver->init_termios.c_ispeed = 9600; |
359 | moxaDriver->init_termios.c_ospeed = 9600; | 364 | moxaDriver->init_termios.c_ospeed = 9600; |
360 | moxaDriver->flags = TTY_DRIVER_REAL_RAW; | 365 | moxaDriver->flags = TTY_DRIVER_REAL_RAW; |
361 | tty_set_operations(moxaDriver, &moxa_ops); | 366 | tty_set_operations(moxaDriver, &moxa_ops); |
362 | 367 | ||
363 | moxaXmitBuff = NULL; | 368 | for (i = 0, ch = moxa_ports; i < MAX_PORTS; i++, ch++) { |
364 | |||
365 | for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) { | ||
366 | ch->type = PORT_16550A; | 369 | ch->type = PORT_16550A; |
367 | ch->port = i; | 370 | ch->port = i; |
368 | INIT_WORK(&ch->tqueue, do_moxa_softint); | ||
369 | ch->tty = NULL; | ||
370 | ch->close_delay = 5 * HZ / 10; | 371 | ch->close_delay = 5 * HZ / 10; |
371 | ch->closing_wait = 30 * HZ; | 372 | ch->closing_wait = 30 * HZ; |
372 | ch->count = 0; | ||
373 | ch->blocked_open = 0; | ||
374 | ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; | 373 | ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; |
375 | init_waitqueue_head(&ch->open_wait); | 374 | init_waitqueue_head(&ch->open_wait); |
376 | init_waitqueue_head(&ch->close_wait); | 375 | init_waitqueue_head(&ch->close_wait); |
377 | } | ||
378 | 376 | ||
379 | for (i = 0; i < MAX_BOARDS; i++) { | 377 | setup_timer(&ch->emptyTimer, check_xmit_empty, |
380 | moxa_boards[i].boardType = 0; | 378 | (unsigned long)ch); |
381 | moxa_boards[i].numPorts = 0; | ||
382 | moxa_boards[i].baseAddr = 0; | ||
383 | moxa_boards[i].busType = 0; | ||
384 | moxa_boards[i].pciInfo.busNum = 0; | ||
385 | moxa_boards[i].pciInfo.devNum = 0; | ||
386 | } | 379 | } |
387 | MoxaDriverInit(); | 380 | |
388 | printk("Tty devices major number = %d\n", ttymajor); | 381 | printk("Tty devices major number = %d\n", ttymajor); |
389 | 382 | ||
390 | if (tty_register_driver(moxaDriver)) { | 383 | if (tty_register_driver(moxaDriver)) { |
@@ -392,18 +385,8 @@ static int __init moxa_init(void) | |||
392 | put_tty_driver(moxaDriver); | 385 | put_tty_driver(moxaDriver); |
393 | return -1; | 386 | return -1; |
394 | } | 387 | } |
395 | for (i = 0; i < MAX_PORTS; i++) { | ||
396 | init_timer(&moxaEmptyTimer[i]); | ||
397 | moxaEmptyTimer[i].function = check_xmit_empty; | ||
398 | moxaEmptyTimer[i].data = (unsigned long) & moxaChannels[i]; | ||
399 | moxaEmptyTimer_on[i] = 0; | ||
400 | } | ||
401 | 388 | ||
402 | init_timer(&moxaTimer); | 389 | mod_timer(&moxaTimer, jiffies + HZ / 50); |
403 | moxaTimer.function = moxa_poll; | ||
404 | moxaTimer.expires = jiffies + (HZ / 50); | ||
405 | moxaTimer_on = 1; | ||
406 | add_timer(&moxaTimer); | ||
407 | 390 | ||
408 | /* Find the boards defined in source code */ | 391 | /* Find the boards defined in source code */ |
409 | numBoards = 0; | 392 | numBoards = 0; |
@@ -451,35 +434,22 @@ static int __init moxa_init(void) | |||
451 | } | 434 | } |
452 | } | 435 | } |
453 | #endif | 436 | #endif |
454 | /* Find PCI boards here */ | 437 | |
455 | #ifdef CONFIG_PCI | 438 | #ifdef CONFIG_PCI |
456 | { | 439 | retval = pci_register_driver(&moxa_pci_driver); |
457 | struct pci_dev *p = NULL; | 440 | if (retval) { |
458 | int n = ARRAY_SIZE(moxa_pcibrds) - 1; | 441 | printk(KERN_ERR "Can't register moxa pci driver!\n"); |
459 | i = 0; | 442 | if (numBoards) |
460 | while (i < n) { | 443 | retval = 0; |
461 | while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) | ||
462 | { | ||
463 | if (pci_enable_device(p)) | ||
464 | continue; | ||
465 | if (numBoards >= MAX_BOARDS) { | ||
466 | if (verbose) | ||
467 | printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS); | ||
468 | } else { | ||
469 | moxa_get_PCI_conf(p, moxa_pcibrds[i].driver_data, | ||
470 | &moxa_boards[numBoards]); | ||
471 | numBoards++; | ||
472 | } | ||
473 | } | ||
474 | i++; | ||
475 | } | ||
476 | } | 444 | } |
477 | #endif | 445 | #endif |
446 | |||
478 | for (i = 0; i < numBoards; i++) { | 447 | for (i = 0; i < numBoards; i++) { |
479 | moxaBaseAddr[i] = ioremap((unsigned long) moxa_boards[i].baseAddr, 0x4000); | 448 | moxa_boards[i].basemem = ioremap(moxa_boards[i].baseAddr, |
449 | 0x4000); | ||
480 | } | 450 | } |
481 | 451 | ||
482 | return (0); | 452 | return retval; |
483 | } | 453 | } |
484 | 454 | ||
485 | static void __exit moxa_exit(void) | 455 | static void __exit moxa_exit(void) |
@@ -489,23 +459,22 @@ static void __exit moxa_exit(void) | |||
489 | if (verbose) | 459 | if (verbose) |
490 | printk("Unloading module moxa ...\n"); | 460 | printk("Unloading module moxa ...\n"); |
491 | 461 | ||
492 | if (moxaTimer_on) | 462 | del_timer_sync(&moxaTimer); |
493 | del_timer(&moxaTimer); | ||
494 | 463 | ||
495 | for (i = 0; i < MAX_PORTS; i++) | 464 | for (i = 0; i < MAX_PORTS; i++) |
496 | if (moxaEmptyTimer_on[i]) | 465 | del_timer_sync(&moxa_ports[i].emptyTimer); |
497 | del_timer(&moxaEmptyTimer[i]); | ||
498 | 466 | ||
499 | if (tty_unregister_driver(moxaDriver)) | 467 | if (tty_unregister_driver(moxaDriver)) |
500 | printk("Couldn't unregister MOXA Intellio family serial driver\n"); | 468 | printk("Couldn't unregister MOXA Intellio family serial driver\n"); |
501 | put_tty_driver(moxaDriver); | 469 | put_tty_driver(moxaDriver); |
502 | 470 | ||
503 | for (i = 0; i < MAX_BOARDS; i++) { | 471 | #ifdef CONFIG_PCI |
504 | if (moxaBaseAddr[i]) | 472 | pci_unregister_driver(&moxa_pci_driver); |
505 | iounmap(moxaBaseAddr[i]); | 473 | #endif |
506 | if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) | 474 | |
507 | pci_dev_put(moxa_boards[i].pciInfo.pdev); | 475 | for (i = 0; i < MAX_BOARDS; i++) |
508 | } | 476 | if (moxa_boards[i].basemem) |
477 | iounmap(moxa_boards[i].basemem); | ||
509 | 478 | ||
510 | if (verbose) | 479 | if (verbose) |
511 | printk("Done\n"); | 480 | printk("Done\n"); |
@@ -514,28 +483,13 @@ static void __exit moxa_exit(void) | |||
514 | module_init(moxa_init); | 483 | module_init(moxa_init); |
515 | module_exit(moxa_exit); | 484 | module_exit(moxa_exit); |
516 | 485 | ||
517 | static void do_moxa_softint(struct work_struct *work) | ||
518 | { | ||
519 | struct moxa_str *ch = container_of(work, struct moxa_str, tqueue); | ||
520 | struct tty_struct *tty; | ||
521 | |||
522 | if (ch && (tty = ch->tty)) { | ||
523 | if (test_and_clear_bit(MOXA_EVENT_HANGUP, &ch->event)) { | ||
524 | tty_hangup(tty); /* FIXME: module removal race here - AKPM */ | ||
525 | wake_up_interruptible(&ch->open_wait); | ||
526 | ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; | ||
527 | } | ||
528 | } | ||
529 | } | ||
530 | |||
531 | static int moxa_open(struct tty_struct *tty, struct file *filp) | 486 | static int moxa_open(struct tty_struct *tty, struct file *filp) |
532 | { | 487 | { |
533 | struct moxa_str *ch; | 488 | struct moxa_port *ch; |
534 | int port; | 489 | int port; |
535 | int retval; | 490 | int retval; |
536 | unsigned long page; | ||
537 | 491 | ||
538 | port = PORTNO(tty); | 492 | port = tty->index; |
539 | if (port == MAX_PORTS) { | 493 | if (port == MAX_PORTS) { |
540 | return (0); | 494 | return (0); |
541 | } | 495 | } |
@@ -543,23 +497,8 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
543 | tty->driver_data = NULL; | 497 | tty->driver_data = NULL; |
544 | return (-ENODEV); | 498 | return (-ENODEV); |
545 | } | 499 | } |
546 | down(&moxaBuffSem); | ||
547 | if (!moxaXmitBuff) { | ||
548 | page = get_zeroed_page(GFP_KERNEL); | ||
549 | if (!page) { | ||
550 | up(&moxaBuffSem); | ||
551 | return (-ENOMEM); | ||
552 | } | ||
553 | /* This test is guarded by the BuffSem so no longer needed | ||
554 | delete me in 2.5 */ | ||
555 | if (moxaXmitBuff) | ||
556 | free_page(page); | ||
557 | else | ||
558 | moxaXmitBuff = (unsigned char *) page; | ||
559 | } | ||
560 | up(&moxaBuffSem); | ||
561 | 500 | ||
562 | ch = &moxaChannels[port]; | 501 | ch = &moxa_ports[port]; |
563 | ch->count++; | 502 | ch->count++; |
564 | tty->driver_data = ch; | 503 | tty->driver_data = ch; |
565 | ch->tty = tty; | 504 | ch->tty = tty; |
@@ -585,10 +524,10 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
585 | 524 | ||
586 | static void moxa_close(struct tty_struct *tty, struct file *filp) | 525 | static void moxa_close(struct tty_struct *tty, struct file *filp) |
587 | { | 526 | { |
588 | struct moxa_str *ch; | 527 | struct moxa_port *ch; |
589 | int port; | 528 | int port; |
590 | 529 | ||
591 | port = PORTNO(tty); | 530 | port = tty->index; |
592 | if (port == MAX_PORTS) { | 531 | if (port == MAX_PORTS) { |
593 | return; | 532 | return; |
594 | } | 533 | } |
@@ -605,7 +544,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) | |||
605 | if (tty_hung_up_p(filp)) { | 544 | if (tty_hung_up_p(filp)) { |
606 | return; | 545 | return; |
607 | } | 546 | } |
608 | ch = (struct moxa_str *) tty->driver_data; | 547 | ch = (struct moxa_port *) tty->driver_data; |
609 | 548 | ||
610 | if ((tty->count == 1) && (ch->count != 1)) { | 549 | if ((tty->count == 1) && (ch->count != 1)) { |
611 | printk("moxa_close: bad serial port count; tty->count is 1, " | 550 | printk("moxa_close: bad serial port count; tty->count is 1, " |
@@ -626,8 +565,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) | |||
626 | if (ch->asyncflags & ASYNC_INITIALIZED) { | 565 | if (ch->asyncflags & ASYNC_INITIALIZED) { |
627 | setup_empty_event(tty); | 566 | setup_empty_event(tty); |
628 | tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ | 567 | tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ |
629 | moxaEmptyTimer_on[ch->port] = 0; | 568 | del_timer_sync(&moxa_ports[ch->port].emptyTimer); |
630 | del_timer(&moxaEmptyTimer[ch->port]); | ||
631 | } | 569 | } |
632 | shut_down(ch); | 570 | shut_down(ch); |
633 | MoxaPortFlushData(port, 2); | 571 | MoxaPortFlushData(port, 2); |
@@ -652,11 +590,11 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) | |||
652 | static int moxa_write(struct tty_struct *tty, | 590 | static int moxa_write(struct tty_struct *tty, |
653 | const unsigned char *buf, int count) | 591 | const unsigned char *buf, int count) |
654 | { | 592 | { |
655 | struct moxa_str *ch; | 593 | struct moxa_port *ch; |
656 | int len, port; | 594 | int len, port; |
657 | unsigned long flags; | 595 | unsigned long flags; |
658 | 596 | ||
659 | ch = (struct moxa_str *) tty->driver_data; | 597 | ch = (struct moxa_port *) tty->driver_data; |
660 | if (ch == NULL) | 598 | if (ch == NULL) |
661 | return (0); | 599 | return (0); |
662 | port = ch->port; | 600 | port = ch->port; |
@@ -675,11 +613,11 @@ static int moxa_write(struct tty_struct *tty, | |||
675 | 613 | ||
676 | static int moxa_write_room(struct tty_struct *tty) | 614 | static int moxa_write_room(struct tty_struct *tty) |
677 | { | 615 | { |
678 | struct moxa_str *ch; | 616 | struct moxa_port *ch; |
679 | 617 | ||
680 | if (tty->stopped) | 618 | if (tty->stopped) |
681 | return (0); | 619 | return (0); |
682 | ch = (struct moxa_str *) tty->driver_data; | 620 | ch = (struct moxa_port *) tty->driver_data; |
683 | if (ch == NULL) | 621 | if (ch == NULL) |
684 | return (0); | 622 | return (0); |
685 | return (MoxaPortTxFree(ch->port)); | 623 | return (MoxaPortTxFree(ch->port)); |
@@ -687,7 +625,7 @@ static int moxa_write_room(struct tty_struct *tty) | |||
687 | 625 | ||
688 | static void moxa_flush_buffer(struct tty_struct *tty) | 626 | static void moxa_flush_buffer(struct tty_struct *tty) |
689 | { | 627 | { |
690 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 628 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
691 | 629 | ||
692 | if (ch == NULL) | 630 | if (ch == NULL) |
693 | return; | 631 | return; |
@@ -698,7 +636,7 @@ static void moxa_flush_buffer(struct tty_struct *tty) | |||
698 | static int moxa_chars_in_buffer(struct tty_struct *tty) | 636 | static int moxa_chars_in_buffer(struct tty_struct *tty) |
699 | { | 637 | { |
700 | int chars; | 638 | int chars; |
701 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 639 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
702 | 640 | ||
703 | /* | 641 | /* |
704 | * Sigh...I have to check if driver_data is NULL here, because | 642 | * Sigh...I have to check if driver_data is NULL here, because |
@@ -730,17 +668,16 @@ static void moxa_flush_chars(struct tty_struct *tty) | |||
730 | 668 | ||
731 | static void moxa_put_char(struct tty_struct *tty, unsigned char c) | 669 | static void moxa_put_char(struct tty_struct *tty, unsigned char c) |
732 | { | 670 | { |
733 | struct moxa_str *ch; | 671 | struct moxa_port *ch; |
734 | int port; | 672 | int port; |
735 | unsigned long flags; | 673 | unsigned long flags; |
736 | 674 | ||
737 | ch = (struct moxa_str *) tty->driver_data; | 675 | ch = (struct moxa_port *) tty->driver_data; |
738 | if (ch == NULL) | 676 | if (ch == NULL) |
739 | return; | 677 | return; |
740 | port = ch->port; | 678 | port = ch->port; |
741 | spin_lock_irqsave(&moxa_lock, flags); | 679 | spin_lock_irqsave(&moxa_lock, flags); |
742 | moxaXmitBuff[0] = c; | 680 | MoxaPortWriteData(port, &c, 1); |
743 | MoxaPortWriteData(port, moxaXmitBuff, 1); | ||
744 | spin_unlock_irqrestore(&moxa_lock, flags); | 681 | spin_unlock_irqrestore(&moxa_lock, flags); |
745 | /************************************************ | 682 | /************************************************ |
746 | if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) ) | 683 | if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) ) |
@@ -750,11 +687,11 @@ static void moxa_put_char(struct tty_struct *tty, unsigned char c) | |||
750 | 687 | ||
751 | static int moxa_tiocmget(struct tty_struct *tty, struct file *file) | 688 | static int moxa_tiocmget(struct tty_struct *tty, struct file *file) |
752 | { | 689 | { |
753 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 690 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
754 | int port; | 691 | int port; |
755 | int flag = 0, dtr, rts; | 692 | int flag = 0, dtr, rts; |
756 | 693 | ||
757 | port = PORTNO(tty); | 694 | port = tty->index; |
758 | if ((port != MAX_PORTS) && (!ch)) | 695 | if ((port != MAX_PORTS) && (!ch)) |
759 | return (-EINVAL); | 696 | return (-EINVAL); |
760 | 697 | ||
@@ -776,11 +713,11 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file) | |||
776 | static int moxa_tiocmset(struct tty_struct *tty, struct file *file, | 713 | static int moxa_tiocmset(struct tty_struct *tty, struct file *file, |
777 | unsigned int set, unsigned int clear) | 714 | unsigned int set, unsigned int clear) |
778 | { | 715 | { |
779 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 716 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
780 | int port; | 717 | int port; |
781 | int dtr, rts; | 718 | int dtr, rts; |
782 | 719 | ||
783 | port = PORTNO(tty); | 720 | port = tty->index; |
784 | if ((port != MAX_PORTS) && (!ch)) | 721 | if ((port != MAX_PORTS) && (!ch)) |
785 | return (-EINVAL); | 722 | return (-EINVAL); |
786 | 723 | ||
@@ -800,12 +737,12 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file, | |||
800 | static int moxa_ioctl(struct tty_struct *tty, struct file *file, | 737 | static int moxa_ioctl(struct tty_struct *tty, struct file *file, |
801 | unsigned int cmd, unsigned long arg) | 738 | unsigned int cmd, unsigned long arg) |
802 | { | 739 | { |
803 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 740 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
804 | register int port; | 741 | register int port; |
805 | void __user *argp = (void __user *)arg; | 742 | void __user *argp = (void __user *)arg; |
806 | int retval; | 743 | int retval; |
807 | 744 | ||
808 | port = PORTNO(tty); | 745 | port = tty->index; |
809 | if ((port != MAX_PORTS) && (!ch)) | 746 | if ((port != MAX_PORTS) && (!ch)) |
810 | return (-EINVAL); | 747 | return (-EINVAL); |
811 | 748 | ||
@@ -853,14 +790,14 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file, | |||
853 | 790 | ||
854 | static void moxa_throttle(struct tty_struct *tty) | 791 | static void moxa_throttle(struct tty_struct *tty) |
855 | { | 792 | { |
856 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 793 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
857 | 794 | ||
858 | ch->statusflags |= THROTTLE; | 795 | ch->statusflags |= THROTTLE; |
859 | } | 796 | } |
860 | 797 | ||
861 | static void moxa_unthrottle(struct tty_struct *tty) | 798 | static void moxa_unthrottle(struct tty_struct *tty) |
862 | { | 799 | { |
863 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 800 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
864 | 801 | ||
865 | ch->statusflags &= ~THROTTLE; | 802 | ch->statusflags &= ~THROTTLE; |
866 | } | 803 | } |
@@ -868,7 +805,7 @@ static void moxa_unthrottle(struct tty_struct *tty) | |||
868 | static void moxa_set_termios(struct tty_struct *tty, | 805 | static void moxa_set_termios(struct tty_struct *tty, |
869 | struct ktermios *old_termios) | 806 | struct ktermios *old_termios) |
870 | { | 807 | { |
871 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 808 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
872 | 809 | ||
873 | if (ch == NULL) | 810 | if (ch == NULL) |
874 | return; | 811 | return; |
@@ -880,7 +817,7 @@ static void moxa_set_termios(struct tty_struct *tty, | |||
880 | 817 | ||
881 | static void moxa_stop(struct tty_struct *tty) | 818 | static void moxa_stop(struct tty_struct *tty) |
882 | { | 819 | { |
883 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 820 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
884 | 821 | ||
885 | if (ch == NULL) | 822 | if (ch == NULL) |
886 | return; | 823 | return; |
@@ -891,7 +828,7 @@ static void moxa_stop(struct tty_struct *tty) | |||
891 | 828 | ||
892 | static void moxa_start(struct tty_struct *tty) | 829 | static void moxa_start(struct tty_struct *tty) |
893 | { | 830 | { |
894 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 831 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
895 | 832 | ||
896 | if (ch == NULL) | 833 | if (ch == NULL) |
897 | return; | 834 | return; |
@@ -905,7 +842,7 @@ static void moxa_start(struct tty_struct *tty) | |||
905 | 842 | ||
906 | static void moxa_hangup(struct tty_struct *tty) | 843 | static void moxa_hangup(struct tty_struct *tty) |
907 | { | 844 | { |
908 | struct moxa_str *ch = (struct moxa_str *) tty->driver_data; | 845 | struct moxa_port *ch = (struct moxa_port *) tty->driver_data; |
909 | 846 | ||
910 | moxa_flush_buffer(tty); | 847 | moxa_flush_buffer(tty); |
911 | shut_down(ch); | 848 | shut_down(ch); |
@@ -919,24 +856,20 @@ static void moxa_hangup(struct tty_struct *tty) | |||
919 | static void moxa_poll(unsigned long ignored) | 856 | static void moxa_poll(unsigned long ignored) |
920 | { | 857 | { |
921 | register int card; | 858 | register int card; |
922 | struct moxa_str *ch; | 859 | struct moxa_port *ch; |
923 | struct tty_struct *tp; | 860 | struct tty_struct *tp; |
924 | int i, ports; | 861 | int i, ports; |
925 | 862 | ||
926 | moxaTimer_on = 0; | ||
927 | del_timer(&moxaTimer); | 863 | del_timer(&moxaTimer); |
928 | 864 | ||
929 | if (MoxaDriverPoll() < 0) { | 865 | if (MoxaDriverPoll() < 0) { |
930 | moxaTimer.function = moxa_poll; | 866 | mod_timer(&moxaTimer, jiffies + HZ / 50); |
931 | moxaTimer.expires = jiffies + (HZ / 50); | ||
932 | moxaTimer_on = 1; | ||
933 | add_timer(&moxaTimer); | ||
934 | return; | 867 | return; |
935 | } | 868 | } |
936 | for (card = 0; card < MAX_BOARDS; card++) { | 869 | for (card = 0; card < MAX_BOARDS; card++) { |
937 | if ((ports = MoxaPortsOfCard(card)) <= 0) | 870 | if ((ports = MoxaPortsOfCard(card)) <= 0) |
938 | continue; | 871 | continue; |
939 | ch = &moxaChannels[card * MAX_PORTS_PER_BOARD]; | 872 | ch = &moxa_ports[card * MAX_PORTS_PER_BOARD]; |
940 | for (i = 0; i < ports; i++, ch++) { | 873 | for (i = 0; i < ports; i++, ch++) { |
941 | if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) | 874 | if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) |
942 | continue; | 875 | continue; |
@@ -962,18 +895,16 @@ static void moxa_poll(unsigned long ignored) | |||
962 | if (MoxaPortDCDON(ch->port)) | 895 | if (MoxaPortDCDON(ch->port)) |
963 | wake_up_interruptible(&ch->open_wait); | 896 | wake_up_interruptible(&ch->open_wait); |
964 | else { | 897 | else { |
965 | set_bit(MOXA_EVENT_HANGUP, &ch->event); | 898 | tty_hangup(tp); |
966 | schedule_work(&ch->tqueue); | 899 | wake_up_interruptible(&ch->open_wait); |
900 | ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; | ||
967 | } | 901 | } |
968 | } | 902 | } |
969 | } | 903 | } |
970 | } | 904 | } |
971 | } | 905 | } |
972 | 906 | ||
973 | moxaTimer.function = moxa_poll; | 907 | mod_timer(&moxaTimer, jiffies + HZ / 50); |
974 | moxaTimer.expires = jiffies + (HZ / 50); | ||
975 | moxaTimer_on = 1; | ||
976 | add_timer(&moxaTimer); | ||
977 | } | 908 | } |
978 | 909 | ||
979 | /******************************************************************************/ | 910 | /******************************************************************************/ |
@@ -981,10 +912,10 @@ static void moxa_poll(unsigned long ignored) | |||
981 | static void set_tty_param(struct tty_struct *tty) | 912 | static void set_tty_param(struct tty_struct *tty) |
982 | { | 913 | { |
983 | register struct ktermios *ts; | 914 | register struct ktermios *ts; |
984 | struct moxa_str *ch; | 915 | struct moxa_port *ch; |
985 | int rts, cts, txflow, rxflow, xany; | 916 | int rts, cts, txflow, rxflow, xany; |
986 | 917 | ||
987 | ch = (struct moxa_str *) tty->driver_data; | 918 | ch = (struct moxa_port *) tty->driver_data; |
988 | ts = tty->termios; | 919 | ts = tty->termios; |
989 | if (ts->c_cflag & CLOCAL) | 920 | if (ts->c_cflag & CLOCAL) |
990 | ch->asyncflags &= ~ASYNC_CHECK_CD; | 921 | ch->asyncflags &= ~ASYNC_CHECK_CD; |
@@ -1004,7 +935,7 @@ static void set_tty_param(struct tty_struct *tty) | |||
1004 | } | 935 | } |
1005 | 936 | ||
1006 | static int block_till_ready(struct tty_struct *tty, struct file *filp, | 937 | static int block_till_ready(struct tty_struct *tty, struct file *filp, |
1007 | struct moxa_str *ch) | 938 | struct moxa_port *ch) |
1008 | { | 939 | { |
1009 | DECLARE_WAITQUEUE(wait,current); | 940 | DECLARE_WAITQUEUE(wait,current); |
1010 | unsigned long flags; | 941 | unsigned long flags; |
@@ -1095,40 +1026,33 @@ static int block_till_ready(struct tty_struct *tty, struct file *filp, | |||
1095 | 1026 | ||
1096 | static void setup_empty_event(struct tty_struct *tty) | 1027 | static void setup_empty_event(struct tty_struct *tty) |
1097 | { | 1028 | { |
1098 | struct moxa_str *ch = tty->driver_data; | 1029 | struct moxa_port *ch = tty->driver_data; |
1099 | unsigned long flags; | 1030 | unsigned long flags; |
1100 | 1031 | ||
1101 | spin_lock_irqsave(&moxa_lock, flags); | 1032 | spin_lock_irqsave(&moxa_lock, flags); |
1102 | ch->statusflags |= EMPTYWAIT; | 1033 | ch->statusflags |= EMPTYWAIT; |
1103 | moxaEmptyTimer_on[ch->port] = 0; | 1034 | mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ); |
1104 | del_timer(&moxaEmptyTimer[ch->port]); | ||
1105 | moxaEmptyTimer[ch->port].expires = jiffies + HZ; | ||
1106 | moxaEmptyTimer_on[ch->port] = 1; | ||
1107 | add_timer(&moxaEmptyTimer[ch->port]); | ||
1108 | spin_unlock_irqrestore(&moxa_lock, flags); | 1035 | spin_unlock_irqrestore(&moxa_lock, flags); |
1109 | } | 1036 | } |
1110 | 1037 | ||
1111 | static void check_xmit_empty(unsigned long data) | 1038 | static void check_xmit_empty(unsigned long data) |
1112 | { | 1039 | { |
1113 | struct moxa_str *ch; | 1040 | struct moxa_port *ch; |
1114 | 1041 | ||
1115 | ch = (struct moxa_str *) data; | 1042 | ch = (struct moxa_port *) data; |
1116 | moxaEmptyTimer_on[ch->port] = 0; | 1043 | del_timer_sync(&moxa_ports[ch->port].emptyTimer); |
1117 | del_timer(&moxaEmptyTimer[ch->port]); | ||
1118 | if (ch->tty && (ch->statusflags & EMPTYWAIT)) { | 1044 | if (ch->tty && (ch->statusflags & EMPTYWAIT)) { |
1119 | if (MoxaPortTxQueue(ch->port) == 0) { | 1045 | if (MoxaPortTxQueue(ch->port) == 0) { |
1120 | ch->statusflags &= ~EMPTYWAIT; | 1046 | ch->statusflags &= ~EMPTYWAIT; |
1121 | tty_wakeup(ch->tty); | 1047 | tty_wakeup(ch->tty); |
1122 | return; | 1048 | return; |
1123 | } | 1049 | } |
1124 | moxaEmptyTimer[ch->port].expires = jiffies + HZ; | 1050 | mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ); |
1125 | moxaEmptyTimer_on[ch->port] = 1; | ||
1126 | add_timer(&moxaEmptyTimer[ch->port]); | ||
1127 | } else | 1051 | } else |
1128 | ch->statusflags &= ~EMPTYWAIT; | 1052 | ch->statusflags &= ~EMPTYWAIT; |
1129 | } | 1053 | } |
1130 | 1054 | ||
1131 | static void shut_down(struct moxa_str *ch) | 1055 | static void shut_down(struct moxa_port *ch) |
1132 | { | 1056 | { |
1133 | struct tty_struct *tp; | 1057 | struct tty_struct *tp; |
1134 | 1058 | ||
@@ -1148,7 +1072,7 @@ static void shut_down(struct moxa_str *ch) | |||
1148 | ch->asyncflags &= ~ASYNC_INITIALIZED; | 1072 | ch->asyncflags &= ~ASYNC_INITIALIZED; |
1149 | } | 1073 | } |
1150 | 1074 | ||
1151 | static void receive_data(struct moxa_str *ch) | 1075 | static void receive_data(struct moxa_port *ch) |
1152 | { | 1076 | { |
1153 | struct tty_struct *tp; | 1077 | struct tty_struct *tp; |
1154 | struct ktermios *ts; | 1078 | struct ktermios *ts; |
@@ -1465,35 +1389,21 @@ static void receive_data(struct moxa_str *ch) | |||
1465 | /* | 1389 | /* |
1466 | * Query | 1390 | * Query |
1467 | */ | 1391 | */ |
1468 | #define QueryPort MAX_PORTS | ||
1469 | |||
1470 | |||
1471 | 1392 | ||
1472 | struct mon_str { | 1393 | struct mon_str { |
1473 | int tick; | 1394 | int tick; |
1474 | int rxcnt[MAX_PORTS]; | 1395 | int rxcnt[MAX_PORTS]; |
1475 | int txcnt[MAX_PORTS]; | 1396 | int txcnt[MAX_PORTS]; |
1476 | }; | 1397 | }; |
1477 | typedef struct mon_str mon_st; | ||
1478 | 1398 | ||
1479 | #define DCD_changed 0x01 | 1399 | #define DCD_changed 0x01 |
1480 | #define DCD_oldstate 0x80 | 1400 | #define DCD_oldstate 0x80 |
1481 | 1401 | ||
1482 | static unsigned char moxaBuff[10240]; | 1402 | static unsigned char moxaBuff[10240]; |
1483 | static void __iomem *moxaIntNdx[MAX_BOARDS]; | ||
1484 | static void __iomem *moxaIntPend[MAX_BOARDS]; | ||
1485 | static void __iomem *moxaIntTable[MAX_BOARDS]; | ||
1486 | static char moxaChkPort[MAX_PORTS]; | ||
1487 | static char moxaLineCtrl[MAX_PORTS]; | ||
1488 | static void __iomem *moxaTableAddr[MAX_PORTS]; | ||
1489 | static long moxaCurBaud[MAX_PORTS]; | ||
1490 | static char moxaDCDState[MAX_PORTS]; | ||
1491 | static char moxaLowChkFlag[MAX_PORTS]; | ||
1492 | static int moxaLowWaterChk; | 1403 | static int moxaLowWaterChk; |
1493 | static int moxaCard; | 1404 | static int moxaCard; |
1494 | static mon_st moxaLog; | 1405 | static struct mon_str moxaLog; |
1495 | static int moxaFuncTout; | 1406 | static int moxaFuncTout = HZ / 2; |
1496 | static ushort moxaBreakCnt[MAX_PORTS]; | ||
1497 | 1407 | ||
1498 | static void moxadelay(int); | 1408 | static void moxadelay(int); |
1499 | static void moxafunc(void __iomem *, int, ushort); | 1409 | static void moxafunc(void __iomem *, int, ushort); |
@@ -1514,16 +1424,18 @@ static int moxaloadc320(int, void __iomem *, int, int *); | |||
1514 | *****************************************************************************/ | 1424 | *****************************************************************************/ |
1515 | void MoxaDriverInit(void) | 1425 | void MoxaDriverInit(void) |
1516 | { | 1426 | { |
1517 | int i; | 1427 | struct moxa_port *p; |
1428 | unsigned int i; | ||
1518 | 1429 | ||
1519 | moxaFuncTout = HZ / 2; /* 500 mini-seconds */ | 1430 | moxaFuncTout = HZ / 2; /* 500 mini-seconds */ |
1520 | moxaCard = 0; | 1431 | moxaCard = 0; |
1521 | moxaLog.tick = 0; | 1432 | moxaLog.tick = 0; |
1522 | moxaLowWaterChk = 0; | 1433 | moxaLowWaterChk = 0; |
1523 | for (i = 0; i < MAX_PORTS; i++) { | 1434 | for (i = 0; i < MAX_PORTS; i++) { |
1524 | moxaChkPort[i] = 0; | 1435 | p = &moxa_ports[i]; |
1525 | moxaLowChkFlag[i] = 0; | 1436 | p->chkPort = 0; |
1526 | moxaLineCtrl[i] = 0; | 1437 | p->lowChkFlag = 0; |
1438 | p->lineCtrl = 0; | ||
1527 | moxaLog.rxcnt[i] = 0; | 1439 | moxaLog.rxcnt[i] = 0; |
1528 | moxaLog.txcnt[i] = 0; | 1440 | moxaLog.txcnt[i] = 0; |
1529 | } | 1441 | } |
@@ -1545,19 +1457,12 @@ void MoxaDriverInit(void) | |||
1545 | #define MOXA_GET_CUMAJOR (MOXA + 64) | 1457 | #define MOXA_GET_CUMAJOR (MOXA + 64) |
1546 | #define MOXA_GETMSTATUS (MOXA + 65) | 1458 | #define MOXA_GETMSTATUS (MOXA + 65) |
1547 | 1459 | ||
1548 | |||
1549 | struct moxaq_str { | ||
1550 | int inq; | ||
1551 | int outq; | ||
1552 | }; | ||
1553 | |||
1554 | struct dl_str { | 1460 | struct dl_str { |
1555 | char __user *buf; | 1461 | char __user *buf; |
1556 | int len; | 1462 | int len; |
1557 | int cardno; | 1463 | int cardno; |
1558 | }; | 1464 | }; |
1559 | 1465 | ||
1560 | static struct moxaq_str temp_queue[MAX_PORTS]; | ||
1561 | static struct dl_str dltmp; | 1466 | static struct dl_str dltmp; |
1562 | 1467 | ||
1563 | void MoxaPortFlushData(int port, int mode) | 1468 | void MoxaPortFlushData(int port, int mode) |
@@ -1565,10 +1470,10 @@ void MoxaPortFlushData(int port, int mode) | |||
1565 | void __iomem *ofsAddr; | 1470 | void __iomem *ofsAddr; |
1566 | if ((mode < 0) || (mode > 2)) | 1471 | if ((mode < 0) || (mode > 2)) |
1567 | return; | 1472 | return; |
1568 | ofsAddr = moxaTableAddr[port]; | 1473 | ofsAddr = moxa_ports[port].tableAddr; |
1569 | moxafunc(ofsAddr, FC_FlushQueue, mode); | 1474 | moxafunc(ofsAddr, FC_FlushQueue, mode); |
1570 | if (mode != 1) { | 1475 | if (mode != 1) { |
1571 | moxaLowChkFlag[port] = 0; | 1476 | moxa_ports[port].lowChkFlag = 0; |
1572 | low_water_check(ofsAddr); | 1477 | low_water_check(ofsAddr); |
1573 | } | 1478 | } |
1574 | } | 1479 | } |
@@ -1580,7 +1485,7 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) | |||
1580 | int MoxaPortTxQueue(int), MoxaPortRxQueue(int); | 1485 | int MoxaPortTxQueue(int), MoxaPortRxQueue(int); |
1581 | void __user *argp = (void __user *)arg; | 1486 | void __user *argp = (void __user *)arg; |
1582 | 1487 | ||
1583 | if (port == QueryPort) { | 1488 | if (port == MAX_PORTS) { |
1584 | if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_INIT_DRIVER) && | 1489 | if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_INIT_DRIVER) && |
1585 | (cmd != MOXA_LOAD_BIOS) && (cmd != MOXA_FIND_BOARD) && (cmd != MOXA_LOAD_C320B) && | 1490 | (cmd != MOXA_LOAD_BIOS) && (cmd != MOXA_FIND_BOARD) && (cmd != MOXA_LOAD_C320B) && |
1586 | (cmd != MOXA_LOAD_CODE) && (cmd != MOXA_GETDATACOUNT) && | 1491 | (cmd != MOXA_LOAD_CODE) && (cmd != MOXA_GETDATACOUNT) && |
@@ -1590,7 +1495,8 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) | |||
1590 | } | 1495 | } |
1591 | switch (cmd) { | 1496 | switch (cmd) { |
1592 | case MOXA_GET_CONF: | 1497 | case MOXA_GET_CONF: |
1593 | if(copy_to_user(argp, &moxa_boards, MAX_BOARDS * sizeof(moxa_board_conf))) | 1498 | if(copy_to_user(argp, &moxa_boards, MAX_BOARDS * |
1499 | sizeof(struct moxa_board_conf))) | ||
1594 | return -EFAULT; | 1500 | return -EFAULT; |
1595 | return (0); | 1501 | return (0); |
1596 | case MOXA_INIT_DRIVER: | 1502 | case MOXA_INIT_DRIVER: |
@@ -1599,23 +1505,27 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) | |||
1599 | return (0); | 1505 | return (0); |
1600 | case MOXA_GETDATACOUNT: | 1506 | case MOXA_GETDATACOUNT: |
1601 | moxaLog.tick = jiffies; | 1507 | moxaLog.tick = jiffies; |
1602 | if(copy_to_user(argp, &moxaLog, sizeof(mon_st))) | 1508 | if(copy_to_user(argp, &moxaLog, sizeof(struct mon_str))) |
1603 | return -EFAULT; | 1509 | return -EFAULT; |
1604 | return (0); | 1510 | return (0); |
1605 | case MOXA_FLUSH_QUEUE: | 1511 | case MOXA_FLUSH_QUEUE: |
1606 | MoxaPortFlushData(port, arg); | 1512 | MoxaPortFlushData(port, arg); |
1607 | return (0); | 1513 | return (0); |
1608 | case MOXA_GET_IOQUEUE: | 1514 | case MOXA_GET_IOQUEUE: { |
1609 | for (i = 0; i < MAX_PORTS; i++) { | 1515 | struct moxaq_str __user *argm = argp; |
1610 | if (moxaChkPort[i]) { | 1516 | struct moxaq_str tmp; |
1611 | temp_queue[i].inq = MoxaPortRxQueue(i); | 1517 | |
1612 | temp_queue[i].outq = MoxaPortTxQueue(i); | 1518 | for (i = 0; i < MAX_PORTS; i++, argm++) { |
1519 | memset(&tmp, 0, sizeof(tmp)); | ||
1520 | if (moxa_ports[i].chkPort) { | ||
1521 | tmp.inq = MoxaPortRxQueue(i); | ||
1522 | tmp.outq = MoxaPortTxQueue(i); | ||
1613 | } | 1523 | } |
1524 | if (copy_to_user(argm, &tmp, sizeof(tmp))) | ||
1525 | return -EFAULT; | ||
1614 | } | 1526 | } |
1615 | if(copy_to_user(argp, temp_queue, sizeof(struct moxaq_str) * MAX_PORTS)) | ||
1616 | return -EFAULT; | ||
1617 | return (0); | 1527 | return (0); |
1618 | case MOXA_GET_OQUEUE: | 1528 | } case MOXA_GET_OQUEUE: |
1619 | i = MoxaPortTxQueue(port); | 1529 | i = MoxaPortTxQueue(port); |
1620 | return put_user(i, (unsigned long __user *)argp); | 1530 | return put_user(i, (unsigned long __user *)argp); |
1621 | case MOXA_GET_IQUEUE: | 1531 | case MOXA_GET_IQUEUE: |
@@ -1630,33 +1540,36 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) | |||
1630 | if(copy_to_user(argp, &i, sizeof(int))) | 1540 | if(copy_to_user(argp, &i, sizeof(int))) |
1631 | return -EFAULT; | 1541 | return -EFAULT; |
1632 | return 0; | 1542 | return 0; |
1633 | case MOXA_GETMSTATUS: | 1543 | case MOXA_GETMSTATUS: { |
1634 | for (i = 0; i < MAX_PORTS; i++) { | 1544 | struct mxser_mstatus __user *argm = argp; |
1635 | GMStatus[i].ri = 0; | 1545 | struct mxser_mstatus tmp; |
1636 | GMStatus[i].dcd = 0; | 1546 | struct moxa_port *p; |
1637 | GMStatus[i].dsr = 0; | 1547 | |
1638 | GMStatus[i].cts = 0; | 1548 | for (i = 0; i < MAX_PORTS; i++, argm++) { |
1639 | if (!moxaChkPort[i]) { | 1549 | p = &moxa_ports[i]; |
1640 | continue; | 1550 | memset(&tmp, 0, sizeof(tmp)); |
1551 | if (!p->chkPort) { | ||
1552 | goto copy; | ||
1641 | } else { | 1553 | } else { |
1642 | status = MoxaPortLineStatus(moxaChannels[i].port); | 1554 | status = MoxaPortLineStatus(p->port); |
1643 | if (status & 1) | 1555 | if (status & 1) |
1644 | GMStatus[i].cts = 1; | 1556 | tmp.cts = 1; |
1645 | if (status & 2) | 1557 | if (status & 2) |
1646 | GMStatus[i].dsr = 1; | 1558 | tmp.dsr = 1; |
1647 | if (status & 4) | 1559 | if (status & 4) |
1648 | GMStatus[i].dcd = 1; | 1560 | tmp.dcd = 1; |
1649 | } | 1561 | } |
1650 | 1562 | ||
1651 | if (!moxaChannels[i].tty || !moxaChannels[i].tty->termios) | 1563 | if (!p->tty || !p->tty->termios) |
1652 | GMStatus[i].cflag = moxaChannels[i].cflag; | 1564 | tmp.cflag = p->cflag; |
1653 | else | 1565 | else |
1654 | GMStatus[i].cflag = moxaChannels[i].tty->termios->c_cflag; | 1566 | tmp.cflag = p->tty->termios->c_cflag; |
1567 | copy: | ||
1568 | if (copy_to_user(argm, &tmp, sizeof(tmp))) | ||
1569 | return -EFAULT; | ||
1655 | } | 1570 | } |
1656 | if(copy_to_user(argp, GMStatus, sizeof(struct mxser_mstatus) * MAX_PORTS)) | ||
1657 | return -EFAULT; | ||
1658 | return 0; | 1571 | return 0; |
1659 | default: | 1572 | } default: |
1660 | return (-ENOIOCTLCMD); | 1573 | return (-ENOIOCTLCMD); |
1661 | case MOXA_LOAD_BIOS: | 1574 | case MOXA_LOAD_BIOS: |
1662 | case MOXA_FIND_BOARD: | 1575 | case MOXA_FIND_BOARD: |
@@ -1694,6 +1607,7 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) | |||
1694 | 1607 | ||
1695 | int MoxaDriverPoll(void) | 1608 | int MoxaDriverPoll(void) |
1696 | { | 1609 | { |
1610 | struct moxa_board_conf *brd; | ||
1697 | register ushort temp; | 1611 | register ushort temp; |
1698 | register int card; | 1612 | register int card; |
1699 | void __iomem *ofsAddr; | 1613 | void __iomem *ofsAddr; |
@@ -1703,43 +1617,44 @@ int MoxaDriverPoll(void) | |||
1703 | if (moxaCard == 0) | 1617 | if (moxaCard == 0) |
1704 | return (-1); | 1618 | return (-1); |
1705 | for (card = 0; card < MAX_BOARDS; card++) { | 1619 | for (card = 0; card < MAX_BOARDS; card++) { |
1706 | if (loadstat[card] == 0) | 1620 | brd = &moxa_boards[card]; |
1621 | if (brd->loadstat == 0) | ||
1707 | continue; | 1622 | continue; |
1708 | if ((ports = moxa_boards[card].numPorts) == 0) | 1623 | if ((ports = brd->numPorts) == 0) |
1709 | continue; | 1624 | continue; |
1710 | if (readb(moxaIntPend[card]) == 0xff) { | 1625 | if (readb(brd->intPend) == 0xff) { |
1711 | ip = moxaIntTable[card] + readb(moxaIntNdx[card]); | 1626 | ip = brd->intTable + readb(brd->intNdx); |
1712 | p = card * MAX_PORTS_PER_BOARD; | 1627 | p = card * MAX_PORTS_PER_BOARD; |
1713 | ports <<= 1; | 1628 | ports <<= 1; |
1714 | for (port = 0; port < ports; port += 2, p++) { | 1629 | for (port = 0; port < ports; port += 2, p++) { |
1715 | if ((temp = readw(ip + port)) != 0) { | 1630 | if ((temp = readw(ip + port)) != 0) { |
1716 | writew(0, ip + port); | 1631 | writew(0, ip + port); |
1717 | ofsAddr = moxaTableAddr[p]; | 1632 | ofsAddr = moxa_ports[p].tableAddr; |
1718 | if (temp & IntrTx) | 1633 | if (temp & IntrTx) |
1719 | writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat); | 1634 | writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat); |
1720 | if (temp & IntrBreak) { | 1635 | if (temp & IntrBreak) { |
1721 | moxaBreakCnt[p]++; | 1636 | moxa_ports[p].breakCnt++; |
1722 | } | 1637 | } |
1723 | if (temp & IntrLine) { | 1638 | if (temp & IntrLine) { |
1724 | if (readb(ofsAddr + FlagStat) & DCD_state) { | 1639 | if (readb(ofsAddr + FlagStat) & DCD_state) { |
1725 | if ((moxaDCDState[p] & DCD_oldstate) == 0) | 1640 | if ((moxa_ports[p].DCDState & DCD_oldstate) == 0) |
1726 | moxaDCDState[p] = (DCD_oldstate | | 1641 | moxa_ports[p].DCDState = (DCD_oldstate | |
1727 | DCD_changed); | 1642 | DCD_changed); |
1728 | } else { | 1643 | } else { |
1729 | if (moxaDCDState[p] & DCD_oldstate) | 1644 | if (moxa_ports[p].DCDState & DCD_oldstate) |
1730 | moxaDCDState[p] = DCD_changed; | 1645 | moxa_ports[p].DCDState = DCD_changed; |
1731 | } | 1646 | } |
1732 | } | 1647 | } |
1733 | } | 1648 | } |
1734 | } | 1649 | } |
1735 | writeb(0, moxaIntPend[card]); | 1650 | writeb(0, brd->intPend); |
1736 | } | 1651 | } |
1737 | if (moxaLowWaterChk) { | 1652 | if (moxaLowWaterChk) { |
1738 | p = card * MAX_PORTS_PER_BOARD; | 1653 | p = card * MAX_PORTS_PER_BOARD; |
1739 | for (port = 0; port < ports; port++, p++) { | 1654 | for (port = 0; port < ports; port++, p++) { |
1740 | if (moxaLowChkFlag[p]) { | 1655 | if (moxa_ports[p].lowChkFlag) { |
1741 | moxaLowChkFlag[p] = 0; | 1656 | moxa_ports[p].lowChkFlag = 0; |
1742 | ofsAddr = moxaTableAddr[p]; | 1657 | ofsAddr = moxa_ports[p].tableAddr; |
1743 | low_water_check(ofsAddr); | 1658 | low_water_check(ofsAddr); |
1744 | } | 1659 | } |
1745 | } | 1660 | } |
@@ -1767,9 +1682,7 @@ int MoxaPortsOfCard(int cardno) | |||
1767 | * 2. MoxaPortEnable(int port); * | 1682 | * 2. MoxaPortEnable(int port); * |
1768 | * 3. MoxaPortDisable(int port); * | 1683 | * 3. MoxaPortDisable(int port); * |
1769 | * 4. MoxaPortGetMaxBaud(int port); * | 1684 | * 4. MoxaPortGetMaxBaud(int port); * |
1770 | * 5. MoxaPortGetCurBaud(int port); * | ||
1771 | * 6. MoxaPortSetBaud(int port, long baud); * | 1685 | * 6. MoxaPortSetBaud(int port, long baud); * |
1772 | * 7. MoxaPortSetMode(int port, int databit, int stopbit, int parity); * | ||
1773 | * 8. MoxaPortSetTermio(int port, unsigned char *termio); * | 1686 | * 8. MoxaPortSetTermio(int port, unsigned char *termio); * |
1774 | * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); * | 1687 | * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); * |
1775 | * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); * | 1688 | * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); * |
@@ -1780,18 +1693,12 @@ int MoxaPortsOfCard(int cardno) | |||
1780 | * 15. MoxaPortFlushData(int port, int mode); * | 1693 | * 15. MoxaPortFlushData(int port, int mode); * |
1781 | * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); * | 1694 | * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); * |
1782 | * 17. MoxaPortReadData(int port, struct tty_struct *tty); * | 1695 | * 17. MoxaPortReadData(int port, struct tty_struct *tty); * |
1783 | * 18. MoxaPortTxBufSize(int port); * | ||
1784 | * 19. MoxaPortRxBufSize(int port); * | ||
1785 | * 20. MoxaPortTxQueue(int port); * | 1696 | * 20. MoxaPortTxQueue(int port); * |
1786 | * 21. MoxaPortTxFree(int port); * | 1697 | * 21. MoxaPortTxFree(int port); * |
1787 | * 22. MoxaPortRxQueue(int port); * | 1698 | * 22. MoxaPortRxQueue(int port); * |
1788 | * 23. MoxaPortRxFree(int port); * | ||
1789 | * 24. MoxaPortTxDisable(int port); * | 1699 | * 24. MoxaPortTxDisable(int port); * |
1790 | * 25. MoxaPortTxEnable(int port); * | 1700 | * 25. MoxaPortTxEnable(int port); * |
1791 | * 26. MoxaPortGetBrkCnt(int port); * | ||
1792 | * 27. MoxaPortResetBrkCnt(int port); * | 1701 | * 27. MoxaPortResetBrkCnt(int port); * |
1793 | * 28. MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); * | ||
1794 | * 29. MoxaPortIsTxHold(int port); * | ||
1795 | * 30. MoxaPortSendBreak(int port, int ticks); * | 1702 | * 30. MoxaPortSendBreak(int port, int ticks); * |
1796 | *****************************************************************************/ | 1703 | *****************************************************************************/ |
1797 | /* | 1704 | /* |
@@ -1878,15 +1785,6 @@ int MoxaPortsOfCard(int cardno) | |||
1878 | * 38400/57600/115200 bps | 1785 | * 38400/57600/115200 bps |
1879 | * | 1786 | * |
1880 | * | 1787 | * |
1881 | * Function 9: Get the current baud rate of this port. | ||
1882 | * Syntax: | ||
1883 | * long MoxaPortGetCurBaud(int port); | ||
1884 | * int port : port number (0 - 127) | ||
1885 | * | ||
1886 | * return: 0 : this port is invalid | ||
1887 | * 50 - 115200 bps | ||
1888 | * | ||
1889 | * | ||
1890 | * Function 10: Setting baud rate of this port. | 1788 | * Function 10: Setting baud rate of this port. |
1891 | * Syntax: | 1789 | * Syntax: |
1892 | * long MoxaPortSetBaud(int port, long baud); | 1790 | * long MoxaPortSetBaud(int port, long baud); |
@@ -1900,18 +1798,6 @@ int MoxaPortsOfCard(int cardno) | |||
1900 | * baud rate will be the maximun baud rate. | 1798 | * baud rate will be the maximun baud rate. |
1901 | * | 1799 | * |
1902 | * | 1800 | * |
1903 | * Function 11: Setting the data-bits/stop-bits/parity of this port | ||
1904 | * Syntax: | ||
1905 | * int MoxaPortSetMode(int port, int databits, int stopbits, int parity); | ||
1906 | * int port : port number (0 - 127) | ||
1907 | * int databits : data bits (8/7/6/5) | ||
1908 | * int stopbits : stop bits (2/1/0, 0 show 1.5 stop bits) | ||
1909 | int parity : parity (0:None,1:Odd,2:Even,3:Mark,4:Space) | ||
1910 | * | ||
1911 | * return: -1 : invalid parameter | ||
1912 | * 0 : setting O.K. | ||
1913 | * | ||
1914 | * | ||
1915 | * Function 12: Configure the port. | 1801 | * Function 12: Configure the port. |
1916 | * Syntax: | 1802 | * Syntax: |
1917 | * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud); | 1803 | * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud); |
@@ -2016,22 +1902,6 @@ int MoxaPortsOfCard(int cardno) | |||
2016 | * return: 0 - length : real read data length | 1902 | * return: 0 - length : real read data length |
2017 | * | 1903 | * |
2018 | * | 1904 | * |
2019 | * Function 22: Get the Tx buffer size of this port | ||
2020 | * Syntax: | ||
2021 | * int MoxaPortTxBufSize(int port); | ||
2022 | * int port : port number (0 - 127) | ||
2023 | * | ||
2024 | * return: .. : Tx buffer size | ||
2025 | * | ||
2026 | * | ||
2027 | * Function 23: Get the Rx buffer size of this port | ||
2028 | * Syntax: | ||
2029 | * int MoxaPortRxBufSize(int port); | ||
2030 | * int port : port number (0 - 127) | ||
2031 | * | ||
2032 | * return: .. : Rx buffer size | ||
2033 | * | ||
2034 | * | ||
2035 | * Function 24: Get the Tx buffer current queued data bytes | 1905 | * Function 24: Get the Tx buffer current queued data bytes |
2036 | * Syntax: | 1906 | * Syntax: |
2037 | * int MoxaPortTxQueue(int port); | 1907 | * int MoxaPortTxQueue(int port); |
@@ -2056,14 +1926,6 @@ int MoxaPortsOfCard(int cardno) | |||
2056 | * return: .. : Rx buffer current queued data bytes | 1926 | * return: .. : Rx buffer current queued data bytes |
2057 | * | 1927 | * |
2058 | * | 1928 | * |
2059 | * Function 27: Get the Rx buffer current free space | ||
2060 | * Syntax: | ||
2061 | * int MoxaPortRxFree(int port); | ||
2062 | * int port : port number (0 - 127) | ||
2063 | * | ||
2064 | * return: .. : Rx buffer current free space | ||
2065 | * | ||
2066 | * | ||
2067 | * Function 28: Disable port data transmission. | 1929 | * Function 28: Disable port data transmission. |
2068 | * Syntax: | 1930 | * Syntax: |
2069 | * void MoxaPortTxDisable(int port); | 1931 | * void MoxaPortTxDisable(int port); |
@@ -2076,14 +1938,6 @@ int MoxaPortsOfCard(int cardno) | |||
2076 | * int port : port number (0 - 127) | 1938 | * int port : port number (0 - 127) |
2077 | * | 1939 | * |
2078 | * | 1940 | * |
2079 | * Function 30: Get the received BREAK signal count. | ||
2080 | * Syntax: | ||
2081 | * int MoxaPortGetBrkCnt(int port); | ||
2082 | * int port : port number (0 - 127) | ||
2083 | * | ||
2084 | * return: 0 - .. : BREAK signal count | ||
2085 | * | ||
2086 | * | ||
2087 | * Function 31: Get the received BREAK signal count and reset it. | 1941 | * Function 31: Get the received BREAK signal count and reset it. |
2088 | * Syntax: | 1942 | * Syntax: |
2089 | * int MoxaPortResetBrkCnt(int port); | 1943 | * int MoxaPortResetBrkCnt(int port); |
@@ -2092,25 +1946,6 @@ int MoxaPortsOfCard(int cardno) | |||
2092 | * return: 0 - .. : BREAK signal count | 1946 | * return: 0 - .. : BREAK signal count |
2093 | * | 1947 | * |
2094 | * | 1948 | * |
2095 | * Function 32: Set the S/W flow control new XON/XOFF value, default | ||
2096 | * XON is 0x11 & XOFF is 0x13. | ||
2097 | * Syntax: | ||
2098 | * void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); | ||
2099 | * int port : port number (0 - 127) | ||
2100 | * int xonValue : new XON value (0 - 255) | ||
2101 | * int xoffValue : new XOFF value (0 - 255) | ||
2102 | * | ||
2103 | * | ||
2104 | * Function 33: Check this port's transmission is hold by remote site | ||
2105 | * because the flow control. | ||
2106 | * Syntax: | ||
2107 | * int MoxaPortIsTxHold(int port); | ||
2108 | * int port : port number (0 - 127) | ||
2109 | * | ||
2110 | * return: 0 : normal | ||
2111 | * 1 : hold by remote site | ||
2112 | * | ||
2113 | * | ||
2114 | * Function 34: Send out a BREAK signal. | 1949 | * Function 34: Send out a BREAK signal. |
2115 | * Syntax: | 1950 | * Syntax: |
2116 | * void MoxaPortSendBreak(int port, int ms100); | 1951 | * void MoxaPortSendBreak(int port, int ms100); |
@@ -2125,7 +1960,7 @@ int MoxaPortIsValid(int port) | |||
2125 | 1960 | ||
2126 | if (moxaCard == 0) | 1961 | if (moxaCard == 0) |
2127 | return (0); | 1962 | return (0); |
2128 | if (moxaChkPort[port] == 0) | 1963 | if (moxa_ports[port].chkPort == 0) |
2129 | return (0); | 1964 | return (0); |
2130 | return (1); | 1965 | return (1); |
2131 | } | 1966 | } |
@@ -2136,9 +1971,9 @@ void MoxaPortEnable(int port) | |||
2136 | int MoxaPortLineStatus(int); | 1971 | int MoxaPortLineStatus(int); |
2137 | short lowwater = 512; | 1972 | short lowwater = 512; |
2138 | 1973 | ||
2139 | ofsAddr = moxaTableAddr[port]; | 1974 | ofsAddr = moxa_ports[port].tableAddr; |
2140 | writew(lowwater, ofsAddr + Low_water); | 1975 | writew(lowwater, ofsAddr + Low_water); |
2141 | moxaBreakCnt[port] = 0; | 1976 | moxa_ports[port].breakCnt = 0; |
2142 | if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || | 1977 | if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || |
2143 | (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { | 1978 | (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { |
2144 | moxafunc(ofsAddr, FC_SetBreakIrq, 0); | 1979 | moxafunc(ofsAddr, FC_SetBreakIrq, 0); |
@@ -2155,7 +1990,7 @@ void MoxaPortEnable(int port) | |||
2155 | 1990 | ||
2156 | void MoxaPortDisable(int port) | 1991 | void MoxaPortDisable(int port) |
2157 | { | 1992 | { |
2158 | void __iomem *ofsAddr = moxaTableAddr[port]; | 1993 | void __iomem *ofsAddr = moxa_ports[port].tableAddr; |
2159 | 1994 | ||
2160 | moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ | 1995 | moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ |
2161 | moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); | 1996 | moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); |
@@ -2181,7 +2016,7 @@ long MoxaPortSetBaud(int port, long baud) | |||
2181 | 2016 | ||
2182 | if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) | 2017 | if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) |
2183 | return (0); | 2018 | return (0); |
2184 | ofsAddr = moxaTableAddr[port]; | 2019 | ofsAddr = moxa_ports[port].tableAddr; |
2185 | if (baud > max) | 2020 | if (baud > max) |
2186 | baud = max; | 2021 | baud = max; |
2187 | if (max == 38400L) | 2022 | if (max == 38400L) |
@@ -2193,7 +2028,7 @@ long MoxaPortSetBaud(int port, long baud) | |||
2193 | val = clock / baud; | 2028 | val = clock / baud; |
2194 | moxafunc(ofsAddr, FC_SetBaud, val); | 2029 | moxafunc(ofsAddr, FC_SetBaud, val); |
2195 | baud = clock / val; | 2030 | baud = clock / val; |
2196 | moxaCurBaud[port] = baud; | 2031 | moxa_ports[port].curBaud = baud; |
2197 | return (baud); | 2032 | return (baud); |
2198 | } | 2033 | } |
2199 | 2034 | ||
@@ -2203,9 +2038,9 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud) | |||
2203 | tcflag_t cflag; | 2038 | tcflag_t cflag; |
2204 | tcflag_t mode = 0; | 2039 | tcflag_t mode = 0; |
2205 | 2040 | ||
2206 | if (moxaChkPort[port] == 0 || termio == 0) | 2041 | if (moxa_ports[port].chkPort == 0 || termio == 0) |
2207 | return (-1); | 2042 | return (-1); |
2208 | ofsAddr = moxaTableAddr[port]; | 2043 | ofsAddr = moxa_ports[port].tableAddr; |
2209 | cflag = termio->c_cflag; /* termio->c_cflag */ | 2044 | cflag = termio->c_cflag; /* termio->c_cflag */ |
2210 | 2045 | ||
2211 | mode = termio->c_cflag & CSIZE; | 2046 | mode = termio->c_cflag & CSIZE; |
@@ -2259,13 +2094,13 @@ int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState) | |||
2259 | if (!MoxaPortIsValid(port)) | 2094 | if (!MoxaPortIsValid(port)) |
2260 | return (-1); | 2095 | return (-1); |
2261 | if (dtrState) { | 2096 | if (dtrState) { |
2262 | if (moxaLineCtrl[port] & DTR_ON) | 2097 | if (moxa_ports[port].lineCtrl & DTR_ON) |
2263 | *dtrState = 1; | 2098 | *dtrState = 1; |
2264 | else | 2099 | else |
2265 | *dtrState = 0; | 2100 | *dtrState = 0; |
2266 | } | 2101 | } |
2267 | if (rtsState) { | 2102 | if (rtsState) { |
2268 | if (moxaLineCtrl[port] & RTS_ON) | 2103 | if (moxa_ports[port].lineCtrl & RTS_ON) |
2269 | *rtsState = 1; | 2104 | *rtsState = 1; |
2270 | else | 2105 | else |
2271 | *rtsState = 0; | 2106 | *rtsState = 0; |
@@ -2278,13 +2113,13 @@ void MoxaPortLineCtrl(int port, int dtr, int rts) | |||
2278 | void __iomem *ofsAddr; | 2113 | void __iomem *ofsAddr; |
2279 | int mode; | 2114 | int mode; |
2280 | 2115 | ||
2281 | ofsAddr = moxaTableAddr[port]; | 2116 | ofsAddr = moxa_ports[port].tableAddr; |
2282 | mode = 0; | 2117 | mode = 0; |
2283 | if (dtr) | 2118 | if (dtr) |
2284 | mode |= DTR_ON; | 2119 | mode |= DTR_ON; |
2285 | if (rts) | 2120 | if (rts) |
2286 | mode |= RTS_ON; | 2121 | mode |= RTS_ON; |
2287 | moxaLineCtrl[port] = mode; | 2122 | moxa_ports[port].lineCtrl = mode; |
2288 | moxafunc(ofsAddr, FC_LineControl, mode); | 2123 | moxafunc(ofsAddr, FC_LineControl, mode); |
2289 | } | 2124 | } |
2290 | 2125 | ||
@@ -2293,7 +2128,7 @@ void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int tx | |||
2293 | void __iomem *ofsAddr; | 2128 | void __iomem *ofsAddr; |
2294 | int mode; | 2129 | int mode; |
2295 | 2130 | ||
2296 | ofsAddr = moxaTableAddr[port]; | 2131 | ofsAddr = moxa_ports[port].tableAddr; |
2297 | mode = 0; | 2132 | mode = 0; |
2298 | if (rts) | 2133 | if (rts) |
2299 | mode |= RTS_FlowCtl; | 2134 | mode |= RTS_FlowCtl; |
@@ -2313,7 +2148,7 @@ int MoxaPortLineStatus(int port) | |||
2313 | void __iomem *ofsAddr; | 2148 | void __iomem *ofsAddr; |
2314 | int val; | 2149 | int val; |
2315 | 2150 | ||
2316 | ofsAddr = moxaTableAddr[port]; | 2151 | ofsAddr = moxa_ports[port].tableAddr; |
2317 | if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || | 2152 | if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || |
2318 | (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { | 2153 | (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { |
2319 | moxafunc(ofsAddr, FC_LineStatus, 0); | 2154 | moxafunc(ofsAddr, FC_LineStatus, 0); |
@@ -2324,11 +2159,11 @@ int MoxaPortLineStatus(int port) | |||
2324 | val &= 0x0B; | 2159 | val &= 0x0B; |
2325 | if (val & 8) { | 2160 | if (val & 8) { |
2326 | val |= 4; | 2161 | val |= 4; |
2327 | if ((moxaDCDState[port] & DCD_oldstate) == 0) | 2162 | if ((moxa_ports[port].DCDState & DCD_oldstate) == 0) |
2328 | moxaDCDState[port] = (DCD_oldstate | DCD_changed); | 2163 | moxa_ports[port].DCDState = (DCD_oldstate | DCD_changed); |
2329 | } else { | 2164 | } else { |
2330 | if (moxaDCDState[port] & DCD_oldstate) | 2165 | if (moxa_ports[port].DCDState & DCD_oldstate) |
2331 | moxaDCDState[port] = DCD_changed; | 2166 | moxa_ports[port].DCDState = DCD_changed; |
2332 | } | 2167 | } |
2333 | val &= 7; | 2168 | val &= 7; |
2334 | return (val); | 2169 | return (val); |
@@ -2338,10 +2173,10 @@ int MoxaPortDCDChange(int port) | |||
2338 | { | 2173 | { |
2339 | int n; | 2174 | int n; |
2340 | 2175 | ||
2341 | if (moxaChkPort[port] == 0) | 2176 | if (moxa_ports[port].chkPort == 0) |
2342 | return (0); | 2177 | return (0); |
2343 | n = moxaDCDState[port]; | 2178 | n = moxa_ports[port].DCDState; |
2344 | moxaDCDState[port] &= ~DCD_changed; | 2179 | moxa_ports[port].DCDState &= ~DCD_changed; |
2345 | n &= DCD_changed; | 2180 | n &= DCD_changed; |
2346 | return (n); | 2181 | return (n); |
2347 | } | 2182 | } |
@@ -2350,32 +2185,15 @@ int MoxaPortDCDON(int port) | |||
2350 | { | 2185 | { |
2351 | int n; | 2186 | int n; |
2352 | 2187 | ||
2353 | if (moxaChkPort[port] == 0) | 2188 | if (moxa_ports[port].chkPort == 0) |
2354 | return (0); | 2189 | return (0); |
2355 | if (moxaDCDState[port] & DCD_oldstate) | 2190 | if (moxa_ports[port].DCDState & DCD_oldstate) |
2356 | n = 1; | 2191 | n = 1; |
2357 | else | 2192 | else |
2358 | n = 0; | 2193 | n = 0; |
2359 | return (n); | 2194 | return (n); |
2360 | } | 2195 | } |
2361 | 2196 | ||
2362 | |||
2363 | /* | ||
2364 | int MoxaDumpMem(int port, unsigned char * buffer, int len) | ||
2365 | { | ||
2366 | int i; | ||
2367 | unsigned long baseAddr,ofsAddr,ofs; | ||
2368 | |||
2369 | baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; | ||
2370 | ofs = baseAddr + DynPage_addr + pageofs; | ||
2371 | if (len > 0x2000L) | ||
2372 | len = 0x2000L; | ||
2373 | for (i = 0; i < len; i++) | ||
2374 | buffer[i] = readb(ofs+i); | ||
2375 | } | ||
2376 | */ | ||
2377 | |||
2378 | |||
2379 | int MoxaPortWriteData(int port, unsigned char * buffer, int len) | 2197 | int MoxaPortWriteData(int port, unsigned char * buffer, int len) |
2380 | { | 2198 | { |
2381 | int c, total, i; | 2199 | int c, total, i; |
@@ -2385,8 +2203,8 @@ int MoxaPortWriteData(int port, unsigned char * buffer, int len) | |||
2385 | ushort pageno, pageofs, bufhead; | 2203 | ushort pageno, pageofs, bufhead; |
2386 | void __iomem *baseAddr, *ofsAddr, *ofs; | 2204 | void __iomem *baseAddr, *ofsAddr, *ofs; |
2387 | 2205 | ||
2388 | ofsAddr = moxaTableAddr[port]; | 2206 | ofsAddr = moxa_ports[port].tableAddr; |
2389 | baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; | 2207 | baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem; |
2390 | tx_mask = readw(ofsAddr + TX_mask); | 2208 | tx_mask = readw(ofsAddr + TX_mask); |
2391 | spage = readw(ofsAddr + Page_txb); | 2209 | spage = readw(ofsAddr + Page_txb); |
2392 | epage = readw(ofsAddr + EndPage_txb); | 2210 | epage = readw(ofsAddr + EndPage_txb); |
@@ -2448,8 +2266,8 @@ int MoxaPortReadData(int port, struct tty_struct *tty) | |||
2448 | ushort pageno, bufhead; | 2266 | ushort pageno, bufhead; |
2449 | void __iomem *baseAddr, *ofsAddr, *ofs; | 2267 | void __iomem *baseAddr, *ofsAddr, *ofs; |
2450 | 2268 | ||
2451 | ofsAddr = moxaTableAddr[port]; | 2269 | ofsAddr = moxa_ports[port].tableAddr; |
2452 | baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; | 2270 | baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem; |
2453 | head = readw(ofsAddr + RXrptr); | 2271 | head = readw(ofsAddr + RXrptr); |
2454 | tail = readw(ofsAddr + RXwptr); | 2272 | tail = readw(ofsAddr + RXwptr); |
2455 | rx_mask = readw(ofsAddr + RX_mask); | 2273 | rx_mask = readw(ofsAddr + RX_mask); |
@@ -2504,7 +2322,7 @@ int MoxaPortReadData(int port, struct tty_struct *tty) | |||
2504 | } | 2322 | } |
2505 | if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { | 2323 | if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { |
2506 | moxaLowWaterChk = 1; | 2324 | moxaLowWaterChk = 1; |
2507 | moxaLowChkFlag[port] = 1; | 2325 | moxa_ports[port].lowChkFlag = 1; |
2508 | } | 2326 | } |
2509 | return (total); | 2327 | return (total); |
2510 | } | 2328 | } |
@@ -2516,7 +2334,7 @@ int MoxaPortTxQueue(int port) | |||
2516 | ushort rptr, wptr, mask; | 2334 | ushort rptr, wptr, mask; |
2517 | int len; | 2335 | int len; |
2518 | 2336 | ||
2519 | ofsAddr = moxaTableAddr[port]; | 2337 | ofsAddr = moxa_ports[port].tableAddr; |
2520 | rptr = readw(ofsAddr + TXrptr); | 2338 | rptr = readw(ofsAddr + TXrptr); |
2521 | wptr = readw(ofsAddr + TXwptr); | 2339 | wptr = readw(ofsAddr + TXwptr); |
2522 | mask = readw(ofsAddr + TX_mask); | 2340 | mask = readw(ofsAddr + TX_mask); |
@@ -2530,7 +2348,7 @@ int MoxaPortTxFree(int port) | |||
2530 | ushort rptr, wptr, mask; | 2348 | ushort rptr, wptr, mask; |
2531 | int len; | 2349 | int len; |
2532 | 2350 | ||
2533 | ofsAddr = moxaTableAddr[port]; | 2351 | ofsAddr = moxa_ports[port].tableAddr; |
2534 | rptr = readw(ofsAddr + TXrptr); | 2352 | rptr = readw(ofsAddr + TXrptr); |
2535 | wptr = readw(ofsAddr + TXwptr); | 2353 | wptr = readw(ofsAddr + TXwptr); |
2536 | mask = readw(ofsAddr + TX_mask); | 2354 | mask = readw(ofsAddr + TX_mask); |
@@ -2544,7 +2362,7 @@ int MoxaPortRxQueue(int port) | |||
2544 | ushort rptr, wptr, mask; | 2362 | ushort rptr, wptr, mask; |
2545 | int len; | 2363 | int len; |
2546 | 2364 | ||
2547 | ofsAddr = moxaTableAddr[port]; | 2365 | ofsAddr = moxa_ports[port].tableAddr; |
2548 | rptr = readw(ofsAddr + RXrptr); | 2366 | rptr = readw(ofsAddr + RXrptr); |
2549 | wptr = readw(ofsAddr + RXwptr); | 2367 | wptr = readw(ofsAddr + RXwptr); |
2550 | mask = readw(ofsAddr + RX_mask); | 2368 | mask = readw(ofsAddr + RX_mask); |
@@ -2557,7 +2375,7 @@ void MoxaPortTxDisable(int port) | |||
2557 | { | 2375 | { |
2558 | void __iomem *ofsAddr; | 2376 | void __iomem *ofsAddr; |
2559 | 2377 | ||
2560 | ofsAddr = moxaTableAddr[port]; | 2378 | ofsAddr = moxa_ports[port].tableAddr; |
2561 | moxafunc(ofsAddr, FC_SetXoffState, Magic_code); | 2379 | moxafunc(ofsAddr, FC_SetXoffState, Magic_code); |
2562 | } | 2380 | } |
2563 | 2381 | ||
@@ -2565,7 +2383,7 @@ void MoxaPortTxEnable(int port) | |||
2565 | { | 2383 | { |
2566 | void __iomem *ofsAddr; | 2384 | void __iomem *ofsAddr; |
2567 | 2385 | ||
2568 | ofsAddr = moxaTableAddr[port]; | 2386 | ofsAddr = moxa_ports[port].tableAddr; |
2569 | moxafunc(ofsAddr, FC_SetXonState, Magic_code); | 2387 | moxafunc(ofsAddr, FC_SetXonState, Magic_code); |
2570 | } | 2388 | } |
2571 | 2389 | ||
@@ -2573,8 +2391,8 @@ void MoxaPortTxEnable(int port) | |||
2573 | int MoxaPortResetBrkCnt(int port) | 2391 | int MoxaPortResetBrkCnt(int port) |
2574 | { | 2392 | { |
2575 | ushort cnt; | 2393 | ushort cnt; |
2576 | cnt = moxaBreakCnt[port]; | 2394 | cnt = moxa_ports[port].breakCnt; |
2577 | moxaBreakCnt[port] = 0; | 2395 | moxa_ports[port].breakCnt = 0; |
2578 | return (cnt); | 2396 | return (cnt); |
2579 | } | 2397 | } |
2580 | 2398 | ||
@@ -2583,7 +2401,7 @@ void MoxaPortSendBreak(int port, int ms100) | |||
2583 | { | 2401 | { |
2584 | void __iomem *ofsAddr; | 2402 | void __iomem *ofsAddr; |
2585 | 2403 | ||
2586 | ofsAddr = moxaTableAddr[port]; | 2404 | ofsAddr = moxa_ports[port].tableAddr; |
2587 | if (ms100) { | 2405 | if (ms100) { |
2588 | moxafunc(ofsAddr, FC_SendBreak, Magic_code); | 2406 | moxafunc(ofsAddr, FC_SendBreak, Magic_code); |
2589 | moxadelay(ms100 * (HZ / 10)); | 2407 | moxadelay(ms100 * (HZ / 10)); |
@@ -2594,7 +2412,7 @@ void MoxaPortSendBreak(int port, int ms100) | |||
2594 | moxafunc(ofsAddr, FC_StopBreak, Magic_code); | 2412 | moxafunc(ofsAddr, FC_StopBreak, Magic_code); |
2595 | } | 2413 | } |
2596 | 2414 | ||
2597 | static int moxa_get_serial_info(struct moxa_str *info, | 2415 | static int moxa_get_serial_info(struct moxa_port *info, |
2598 | struct serial_struct __user *retinfo) | 2416 | struct serial_struct __user *retinfo) |
2599 | { | 2417 | { |
2600 | struct serial_struct tmp; | 2418 | struct serial_struct tmp; |
@@ -2616,7 +2434,7 @@ static int moxa_get_serial_info(struct moxa_str *info, | |||
2616 | } | 2434 | } |
2617 | 2435 | ||
2618 | 2436 | ||
2619 | static int moxa_set_serial_info(struct moxa_str *info, | 2437 | static int moxa_set_serial_info(struct moxa_port *info, |
2620 | struct serial_struct __user *new_info) | 2438 | struct serial_struct __user *new_info) |
2621 | { | 2439 | { |
2622 | struct serial_struct new_serial; | 2440 | struct serial_struct new_serial; |
@@ -2713,7 +2531,7 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len) | |||
2713 | 2531 | ||
2714 | if(copy_from_user(moxaBuff, tmp, len)) | 2532 | if(copy_from_user(moxaBuff, tmp, len)) |
2715 | return -EFAULT; | 2533 | return -EFAULT; |
2716 | baseAddr = moxaBaseAddr[cardno]; | 2534 | baseAddr = moxa_boards[cardno].basemem; |
2717 | writeb(HW_reset, baseAddr + Control_reg); /* reset */ | 2535 | writeb(HW_reset, baseAddr + Control_reg); /* reset */ |
2718 | moxadelay(1); /* delay 10 ms */ | 2536 | moxadelay(1); /* delay 10 ms */ |
2719 | for (i = 0; i < 4096; i++) | 2537 | for (i = 0; i < 4096; i++) |
@@ -2729,7 +2547,7 @@ static int moxafindcard(int cardno) | |||
2729 | void __iomem *baseAddr; | 2547 | void __iomem *baseAddr; |
2730 | ushort tmp; | 2548 | ushort tmp; |
2731 | 2549 | ||
2732 | baseAddr = moxaBaseAddr[cardno]; | 2550 | baseAddr = moxa_boards[cardno].basemem; |
2733 | switch (moxa_boards[cardno].boardType) { | 2551 | switch (moxa_boards[cardno].boardType) { |
2734 | case MOXA_BOARD_C218_ISA: | 2552 | case MOXA_BOARD_C218_ISA: |
2735 | case MOXA_BOARD_C218_PCI: | 2553 | case MOXA_BOARD_C218_PCI: |
@@ -2762,7 +2580,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len) | |||
2762 | return -EINVAL; | 2580 | return -EINVAL; |
2763 | if(copy_from_user(moxaBuff, tmp, len)) | 2581 | if(copy_from_user(moxaBuff, tmp, len)) |
2764 | return -EFAULT; | 2582 | return -EFAULT; |
2765 | baseAddr = moxaBaseAddr[cardno]; | 2583 | baseAddr = moxa_boards[cardno].basemem; |
2766 | writew(len - 7168 - 2, baseAddr + C320bapi_len); | 2584 | writew(len - 7168 - 2, baseAddr + C320bapi_len); |
2767 | writeb(1, baseAddr + Control_reg); /* Select Page 1 */ | 2585 | writeb(1, baseAddr + Control_reg); /* Select Page 1 */ |
2768 | for (i = 0; i < 7168; i++) | 2586 | for (i = 0; i < 7168; i++) |
@@ -2780,7 +2598,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) | |||
2780 | 2598 | ||
2781 | if(copy_from_user(moxaBuff, tmp, len)) | 2599 | if(copy_from_user(moxaBuff, tmp, len)) |
2782 | return -EFAULT; | 2600 | return -EFAULT; |
2783 | baseAddr = moxaBaseAddr[cardno]; | 2601 | baseAddr = moxa_boards[cardno].basemem; |
2784 | switch (moxa_boards[cardno].boardType) { | 2602 | switch (moxa_boards[cardno].boardType) { |
2785 | case MOXA_BOARD_C218_ISA: | 2603 | case MOXA_BOARD_C218_ISA: |
2786 | case MOXA_BOARD_C218_PCI: | 2604 | case MOXA_BOARD_C218_PCI: |
@@ -2790,11 +2608,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) | |||
2790 | return (retval); | 2608 | return (retval); |
2791 | port = cardno * MAX_PORTS_PER_BOARD; | 2609 | port = cardno * MAX_PORTS_PER_BOARD; |
2792 | for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { | 2610 | for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { |
2793 | moxaChkPort[port] = 1; | 2611 | struct moxa_port *p = &moxa_ports[port]; |
2794 | moxaCurBaud[port] = 9600L; | 2612 | |
2795 | moxaDCDState[port] = 0; | 2613 | p->chkPort = 1; |
2796 | moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; | 2614 | p->curBaud = 9600L; |
2797 | ofsAddr = moxaTableAddr[port]; | 2615 | p->DCDState = 0; |
2616 | p->tableAddr = baseAddr + Extern_table + Extern_size * i; | ||
2617 | ofsAddr = p->tableAddr; | ||
2798 | writew(C218rx_mask, ofsAddr + RX_mask); | 2618 | writew(C218rx_mask, ofsAddr + RX_mask); |
2799 | writew(C218tx_mask, ofsAddr + TX_mask); | 2619 | writew(C218tx_mask, ofsAddr + TX_mask); |
2800 | writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb); | 2620 | writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb); |
@@ -2812,11 +2632,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) | |||
2812 | return (retval); | 2632 | return (retval); |
2813 | port = cardno * MAX_PORTS_PER_BOARD; | 2633 | port = cardno * MAX_PORTS_PER_BOARD; |
2814 | for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { | 2634 | for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { |
2815 | moxaChkPort[port] = 1; | 2635 | struct moxa_port *p = &moxa_ports[port]; |
2816 | moxaCurBaud[port] = 9600L; | 2636 | |
2817 | moxaDCDState[port] = 0; | 2637 | p->chkPort = 1; |
2818 | moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; | 2638 | p->curBaud = 9600L; |
2819 | ofsAddr = moxaTableAddr[port]; | 2639 | p->DCDState = 0; |
2640 | p->tableAddr = baseAddr + Extern_table + Extern_size * i; | ||
2641 | ofsAddr = p->tableAddr; | ||
2820 | if (moxa_boards[cardno].numPorts == 8) { | 2642 | if (moxa_boards[cardno].numPorts == 8) { |
2821 | writew(C320p8rx_mask, ofsAddr + RX_mask); | 2643 | writew(C320p8rx_mask, ofsAddr + RX_mask); |
2822 | writew(C320p8tx_mask, ofsAddr + TX_mask); | 2644 | writew(C320p8tx_mask, ofsAddr + TX_mask); |
@@ -2852,7 +2674,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) | |||
2852 | } | 2674 | } |
2853 | break; | 2675 | break; |
2854 | } | 2676 | } |
2855 | loadstat[cardno] = 1; | 2677 | moxa_boards[cardno].loadstat = 1; |
2856 | return (0); | 2678 | return (0); |
2857 | } | 2679 | } |
2858 | 2680 | ||
@@ -2926,9 +2748,9 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len) | |||
2926 | return (-1); | 2748 | return (-1); |
2927 | } | 2749 | } |
2928 | moxaCard = 1; | 2750 | moxaCard = 1; |
2929 | moxaIntNdx[cardno] = baseAddr + IRQindex; | 2751 | moxa_boards[cardno].intNdx = baseAddr + IRQindex; |
2930 | moxaIntPend[cardno] = baseAddr + IRQpending; | 2752 | moxa_boards[cardno].intPend = baseAddr + IRQpending; |
2931 | moxaIntTable[cardno] = baseAddr + IRQtable; | 2753 | moxa_boards[cardno].intTable = baseAddr + IRQtable; |
2932 | return (0); | 2754 | return (0); |
2933 | } | 2755 | } |
2934 | 2756 | ||
@@ -3021,25 +2843,15 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor | |||
3021 | if (readw(baseAddr + Magic_no) != Magic_code) | 2843 | if (readw(baseAddr + Magic_no) != Magic_code) |
3022 | return (-102); | 2844 | return (-102); |
3023 | moxaCard = 1; | 2845 | moxaCard = 1; |
3024 | moxaIntNdx[cardno] = baseAddr + IRQindex; | 2846 | moxa_boards[cardno].intNdx = baseAddr + IRQindex; |
3025 | moxaIntPend[cardno] = baseAddr + IRQpending; | 2847 | moxa_boards[cardno].intPend = baseAddr + IRQpending; |
3026 | moxaIntTable[cardno] = baseAddr + IRQtable; | 2848 | moxa_boards[cardno].intTable = baseAddr + IRQtable; |
3027 | return (0); | 2849 | return (0); |
3028 | } | 2850 | } |
3029 | 2851 | ||
3030 | #if 0 | ||
3031 | long MoxaPortGetCurBaud(int port) | ||
3032 | { | ||
3033 | |||
3034 | if (moxaChkPort[port] == 0) | ||
3035 | return (0); | ||
3036 | return (moxaCurBaud[port]); | ||
3037 | } | ||
3038 | #endif /* 0 */ | ||
3039 | |||
3040 | static void MoxaSetFifo(int port, int enable) | 2852 | static void MoxaSetFifo(int port, int enable) |
3041 | { | 2853 | { |
3042 | void __iomem *ofsAddr = moxaTableAddr[port]; | 2854 | void __iomem *ofsAddr = moxa_ports[port].tableAddr; |
3043 | 2855 | ||
3044 | if (!enable) { | 2856 | if (!enable) { |
3045 | moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); | 2857 | moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); |
@@ -3049,132 +2861,3 @@ static void MoxaSetFifo(int port, int enable) | |||
3049 | moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16); | 2861 | moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16); |
3050 | } | 2862 | } |
3051 | } | 2863 | } |
3052 | |||
3053 | #if 0 | ||
3054 | int MoxaPortSetMode(int port, int databits, int stopbits, int parity) | ||
3055 | { | ||
3056 | void __iomem *ofsAddr; | ||
3057 | int val; | ||
3058 | |||
3059 | val = 0; | ||
3060 | switch (databits) { | ||
3061 | case 5: | ||
3062 | val |= 0; | ||
3063 | break; | ||
3064 | case 6: | ||
3065 | val |= 1; | ||
3066 | break; | ||
3067 | case 7: | ||
3068 | val |= 2; | ||
3069 | break; | ||
3070 | case 8: | ||
3071 | val |= 3; | ||
3072 | break; | ||
3073 | default: | ||
3074 | return (-1); | ||
3075 | } | ||
3076 | switch (stopbits) { | ||
3077 | case 0: | ||
3078 | val |= 0; | ||
3079 | break; /* stop bits 1.5 */ | ||
3080 | case 1: | ||
3081 | val |= 0; | ||
3082 | break; | ||
3083 | case 2: | ||
3084 | val |= 4; | ||
3085 | break; | ||
3086 | default: | ||
3087 | return (-1); | ||
3088 | } | ||
3089 | switch (parity) { | ||
3090 | case 0: | ||
3091 | val |= 0x00; | ||
3092 | break; /* None */ | ||
3093 | case 1: | ||
3094 | val |= 0x08; | ||
3095 | break; /* Odd */ | ||
3096 | case 2: | ||
3097 | val |= 0x18; | ||
3098 | break; /* Even */ | ||
3099 | case 3: | ||
3100 | val |= 0x28; | ||
3101 | break; /* Mark */ | ||
3102 | case 4: | ||
3103 | val |= 0x38; | ||
3104 | break; /* Space */ | ||
3105 | default: | ||
3106 | return (-1); | ||
3107 | } | ||
3108 | ofsAddr = moxaTableAddr[port]; | ||
3109 | moxafunc(ofsAddr, FC_SetMode, val); | ||
3110 | return (0); | ||
3111 | } | ||
3112 | |||
3113 | int MoxaPortTxBufSize(int port) | ||
3114 | { | ||
3115 | void __iomem *ofsAddr; | ||
3116 | int size; | ||
3117 | |||
3118 | ofsAddr = moxaTableAddr[port]; | ||
3119 | size = readw(ofsAddr + TX_mask); | ||
3120 | return (size); | ||
3121 | } | ||
3122 | |||
3123 | int MoxaPortRxBufSize(int port) | ||
3124 | { | ||
3125 | void __iomem *ofsAddr; | ||
3126 | int size; | ||
3127 | |||
3128 | ofsAddr = moxaTableAddr[port]; | ||
3129 | size = readw(ofsAddr + RX_mask); | ||
3130 | return (size); | ||
3131 | } | ||
3132 | |||
3133 | int MoxaPortRxFree(int port) | ||
3134 | { | ||
3135 | void __iomem *ofsAddr; | ||
3136 | ushort rptr, wptr, mask; | ||
3137 | int len; | ||
3138 | |||
3139 | ofsAddr = moxaTableAddr[port]; | ||
3140 | rptr = readw(ofsAddr + RXrptr); | ||
3141 | wptr = readw(ofsAddr + RXwptr); | ||
3142 | mask = readw(ofsAddr + RX_mask); | ||
3143 | len = mask - ((wptr - rptr) & mask); | ||
3144 | return (len); | ||
3145 | } | ||
3146 | int MoxaPortGetBrkCnt(int port) | ||
3147 | { | ||
3148 | return (moxaBreakCnt[port]); | ||
3149 | } | ||
3150 | |||
3151 | void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue) | ||
3152 | { | ||
3153 | void __iomem *ofsAddr; | ||
3154 | |||
3155 | ofsAddr = moxaTableAddr[port]; | ||
3156 | writew(xonValue, ofsAddr + FuncArg); | ||
3157 | writew(xoffValue, ofsAddr + FuncArg1); | ||
3158 | writew(FC_SetXonXoff, ofsAddr + FuncCode); | ||
3159 | wait_finish(ofsAddr); | ||
3160 | } | ||
3161 | |||
3162 | int MoxaPortIsTxHold(int port) | ||
3163 | { | ||
3164 | void __iomem *ofsAddr; | ||
3165 | int val; | ||
3166 | |||
3167 | ofsAddr = moxaTableAddr[port]; | ||
3168 | if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || | ||
3169 | (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { | ||
3170 | moxafunc(ofsAddr, FC_GetCCSR, 0); | ||
3171 | val = readw(ofsAddr + FuncArg); | ||
3172 | if (val & 0x04) | ||
3173 | return (1); | ||
3174 | } else { | ||
3175 | if (readw(ofsAddr + FlagStat) & Tx_flowOff) | ||
3176 | return (1); | ||
3177 | } | ||
3178 | return (0); | ||
3179 | } | ||
3180 | #endif | ||