Merge tag 'for-linus-4.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / staging / dgnc / dgnc_driver.c
CommitLineData
0b99d589
LL
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
817b7847 9 *
0b99d589 10 * This program is distributed in the hope that it will be useful,
817b7847
LL
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
0b99d589 13 * PURPOSE. See the GNU General Public License for more details.
0b99d589
LL
14 */
15
16
17#include <linux/kernel.h>
0b99d589
LL
18#include <linux/module.h>
19#include <linux/pci.h>
68a5a5f3 20#include <linux/slab.h>
0b99d589 21#include <linux/sched.h>
0b99d589
LL
22#include "dgnc_driver.h"
23#include "dgnc_pci.h"
0b99d589
LL
24#include "dgnc_mgmt.h"
25#include "dgnc_tty.h"
0b99d589
LL
26#include "dgnc_cls.h"
27#include "dgnc_neo.h"
28#include "dgnc_sysfs.h"
29
30MODULE_LICENSE("GPL");
31MODULE_AUTHOR("Digi International, http://www.digi.com");
32MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
33MODULE_SUPPORTED_DEVICE("dgnc");
34
0b99d589
LL
35/**************************************************************************
36 *
37 * protos for this file
38 *
39 */
40static int dgnc_start(void);
03425f55 41static int dgnc_finalize_board_init(struct dgnc_board *brd);
0b99d589
LL
42static void dgnc_init_globals(void);
43static int dgnc_found_board(struct pci_dev *pdev, int id);
03425f55 44static void dgnc_cleanup_board(struct dgnc_board *brd);
0b99d589 45static void dgnc_poll_handler(ulong dummy);
65da04c1
GS
46static int dgnc_init_one(struct pci_dev *pdev,
47 const struct pci_device_id *ent);
03425f55 48static void dgnc_do_remap(struct dgnc_board *brd);
0b99d589 49
0b99d589
LL
50/*
51 * File operations permitted on Control/Management major.
52 */
78adbb28 53static const struct file_operations dgnc_BoardFops = {
0b99d589 54 .owner = THIS_MODULE,
338fd80f 55 .unlocked_ioctl = dgnc_mgmt_ioctl,
0b99d589
LL
56 .open = dgnc_mgmt_open,
57 .release = dgnc_mgmt_close
58};
59
60
61/*
62 * Globals
63 */
64uint dgnc_NumBoards;
03425f55 65struct dgnc_board *dgnc_Board[MAXBOARDS];
0b99d589 66DEFINE_SPINLOCK(dgnc_global_lock);
0b99d589
LL
67uint dgnc_Major;
68int dgnc_poll_tick = 20; /* Poll interval - 20 ms */
69
70/*
71 * Static vars.
72 */
0b99d589
LL
73static struct class *dgnc_class;
74
75/*
76 * Poller stuff
77 */
338fd80f 78static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
65da04c1
GS
79static ulong dgnc_poll_time; /* Time of next poll */
80static uint dgnc_poll_stop; /* Used to tell poller to stop */
0b99d589
LL
81static struct timer_list dgnc_poll_timer;
82
83
60e27886
KA
84static const struct pci_device_id dgnc_pci_tbl[] = {
85 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID), .driver_data = 0},
86 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
87 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_DID), .driver_data = 2},
88 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID), .driver_data = 3},
89 {0,}
0b99d589
LL
90};
91MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
92
93struct board_id {
446393e9 94 unsigned char *name;
0b99d589
LL
95 uint maxports;
96 unsigned int is_pci_express;
97};
98
3f288962 99static struct board_id dgnc_Ids[] = {
0b99d589
LL
100 { PCI_DEVICE_CLASSIC_4_PCI_NAME, 4, 0 },
101 { PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 },
102 { PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 },
103 { PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 },
104 { PCI_DEVICE_NEO_4_PCI_NAME, 4, 0 },
105 { PCI_DEVICE_NEO_8_PCI_NAME, 8, 0 },
106 { PCI_DEVICE_NEO_2DB9_PCI_NAME, 2, 0 },
107 { PCI_DEVICE_NEO_2DB9PRI_PCI_NAME, 2, 0 },
108 { PCI_DEVICE_NEO_2RJ45_PCI_NAME, 2, 0 },
109 { PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME, 2, 0 },
110 { PCI_DEVICE_NEO_1_422_PCI_NAME, 1, 0 },
111 { PCI_DEVICE_NEO_1_422_485_PCI_NAME, 1, 0 },
112 { PCI_DEVICE_NEO_2_422_485_PCI_NAME, 2, 0 },
113 { PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME, 8, 1 },
114 { PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME, 4, 1 },
115 { PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME, 4, 1 },
116 { PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME, 8, 1 },
117 { NULL, 0, 0 }
118};
119
120static struct pci_driver dgnc_driver = {
121 .name = "dgnc",
122 .probe = dgnc_init_one,
123 .id_table = dgnc_pci_tbl,
0b99d589
LL
124};
125
0b99d589
LL
126/************************************************************************
127 *
128 * Driver load/unload functions
129 *
130 ************************************************************************/
131
1e881002
KZ
132/*
133 * dgnc_cleanup_module()
134 *
135 * Module unload. This is where it all ends.
136 */
137static void dgnc_cleanup_module(void)
138{
139 int i;
66663dc1 140 unsigned long flags;
1e881002 141
66663dc1 142 spin_lock_irqsave(&dgnc_poll_lock, flags);
1e881002 143 dgnc_poll_stop = 1;
66663dc1 144 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
1e881002
KZ
145
146 /* Turn off poller right away. */
147 del_timer_sync(&dgnc_poll_timer);
148
149 dgnc_remove_driver_sysfiles(&dgnc_driver);
150
ed7f92da
KZ
151 device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
152 class_destroy(dgnc_class);
153 unregister_chrdev(dgnc_Major, "dgnc");
1e881002
KZ
154
155 for (i = 0; i < dgnc_NumBoards; ++i) {
156 dgnc_remove_ports_sysfiles(dgnc_Board[i]);
157 dgnc_tty_uninit(dgnc_Board[i]);
158 dgnc_cleanup_board(dgnc_Board[i]);
159 }
160
161 dgnc_tty_post_uninit();
162
163 if (dgnc_NumBoards)
164 pci_unregister_driver(&dgnc_driver);
165}
0b99d589
LL
166
167/*
168 * init_module()
169 *
170 * Module load. This is where it all starts.
171 */
1e881002 172static int __init dgnc_init_module(void)
0b99d589
LL
173{
174 int rc = 0;
175
0b99d589
LL
176 /*
177 * Initialize global stuff
178 */
179 rc = dgnc_start();
180
3f288962 181 if (rc < 0)
8f90ef80 182 return rc;
0b99d589
LL
183
184 /*
185 * Find and configure all the cards
186 */
bbecbacb 187 rc = pci_register_driver(&dgnc_driver);
0b99d589
LL
188
189 /*
190 * If something went wrong in the scan, bail out of driver.
191 */
192 if (rc < 0) {
65da04c1 193 /* Only unregister if it was actually registered. */
0b99d589
LL
194 if (dgnc_NumBoards)
195 pci_unregister_driver(&dgnc_driver);
196 else
cf92c9cc 197 pr_warn("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
0b99d589
LL
198
199 dgnc_cleanup_module();
3f288962 200 } else {
0b99d589
LL
201 dgnc_create_driver_sysfiles(&dgnc_driver);
202 }
203
8f90ef80 204 return rc;
0b99d589
LL
205}
206
1e881002
KZ
207module_init(dgnc_init_module);
208module_exit(dgnc_cleanup_module);
0b99d589
LL
209
210/*
211 * Start of driver.
212 */
213static int dgnc_start(void)
214{
215 int rc = 0;
216 unsigned long flags;
d7312aab 217 struct device *dev;
0b99d589 218
92ded48c
KZ
219 /* make sure that the globals are init'd before we do anything else */
220 dgnc_init_globals();
0b99d589 221
92ded48c
KZ
222 /*
223 * Register our base character device into the kernel.
224 * This allows the download daemon to connect to the downld device
225 * before any of the boards are init'ed.
ed7f92da
KZ
226 *
227 * Register management/dpa devices
92ded48c 228 */
ed7f92da 229 rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
5f9dca1e 230 if (rc < 0) {
1f26adc9 231 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
5f9dca1e 232 return rc;
92ded48c 233 }
ed7f92da
KZ
234 dgnc_Major = rc;
235
236 dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
d7312aab
AK
237 if (IS_ERR(dgnc_class)) {
238 rc = PTR_ERR(dgnc_class);
239 pr_err(DRVSTR ": Can't create dgnc_mgmt class (%d)\n", rc);
240 goto failed_class;
241 }
242
243 dev = device_create(dgnc_class, NULL,
244 MKDEV(dgnc_Major, 0),
245 NULL, "dgnc_mgmt");
246 if (IS_ERR(dev)) {
247 rc = PTR_ERR(dev);
248 pr_err(DRVSTR ": Can't create device (%d)\n", rc);
249 goto failed_device;
250 }
0b99d589 251
92ded48c
KZ
252 /*
253 * Init any global tty stuff.
254 */
255 rc = dgnc_tty_preinit();
0b99d589 256
92ded48c 257 if (rc < 0) {
1f26adc9 258 pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
d7312aab 259 goto failed_tty;
92ded48c 260 }
0b99d589 261
92ded48c 262 /* Start the poller */
66663dc1 263 spin_lock_irqsave(&dgnc_poll_lock, flags);
38e0c9d2 264 setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
92ded48c
KZ
265 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
266 dgnc_poll_timer.expires = dgnc_poll_time;
66663dc1 267 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
0b99d589 268
92ded48c
KZ
269 add_timer(&dgnc_poll_timer);
270
d7312aab
AK
271 return 0;
272
273failed_tty:
274 device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
275failed_device:
276 class_destroy(dgnc_class);
277failed_class:
278 unregister_chrdev(dgnc_Major, "dgnc");
8f90ef80 279 return rc;
0b99d589
LL
280}
281
0b99d589
LL
282/* returns count (>= 0), or negative on error */
283static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
817b7847 284{
0b99d589
LL
285 int rc;
286
287 /* wake up and enable device */
288 rc = pci_enable_device(pdev);
289
290 if (rc < 0) {
291 rc = -EIO;
292 } else {
bbecbacb 293 rc = dgnc_found_board(pdev, ent->driver_data);
f1e51745 294 if (rc == 0)
0b99d589 295 dgnc_NumBoards++;
0b99d589
LL
296 }
297 return rc;
298}
299
0b99d589
LL
300/*
301 * dgnc_cleanup_board()
302 *
303 * Free all the memory associated with a board
304 */
03425f55 305static void dgnc_cleanup_board(struct dgnc_board *brd)
0b99d589
LL
306{
307 int i = 0;
308
78adbb28 309 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
eae9842a 310 return;
0b99d589
LL
311
312 switch (brd->device) {
313 case PCI_DEVICE_CLASSIC_4_DID:
314 case PCI_DEVICE_CLASSIC_8_DID:
315 case PCI_DEVICE_CLASSIC_4_422_DID:
316 case PCI_DEVICE_CLASSIC_8_422_DID:
317
318 /* Tell card not to interrupt anymore. */
319 outb(0, brd->iobase + 0x4c);
320 break;
321
322 default:
323 break;
324 }
325
326 if (brd->irq)
327 free_irq(brd->irq, brd);
328
329 tasklet_kill(&brd->helper_tasklet);
330
331 if (brd->re_map_membase) {
332 iounmap(brd->re_map_membase);
333 brd->re_map_membase = NULL;
334 }
335
336 if (brd->msgbuf_head) {
337 unsigned long flags;
338
66663dc1 339 spin_lock_irqsave(&dgnc_global_lock, flags);
0b99d589 340 brd->msgbuf = NULL;
f40e06f0 341 dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
0b99d589
LL
342 kfree(brd->msgbuf_head);
343 brd->msgbuf_head = NULL;
66663dc1 344 spin_unlock_irqrestore(&dgnc_global_lock, flags);
eae9842a 345 }
0b99d589
LL
346
347 /* Free all allocated channels structs */
348 for (i = 0; i < MAXPORTS ; i++) {
349 if (brd->channels[i]) {
36aa10aa
VO
350 kfree(brd->channels[i]->ch_rqueue);
351 kfree(brd->channels[i]->ch_equeue);
352 kfree(brd->channels[i]->ch_wqueue);
0b99d589
LL
353 kfree(brd->channels[i]);
354 brd->channels[i] = NULL;
355 }
356 }
357
36aa10aa 358 kfree(brd->flipbuf);
0b99d589
LL
359
360 dgnc_Board[brd->boardnum] = NULL;
361
eae9842a 362 kfree(brd);
0b99d589
LL
363}
364
365
366/*
367 * dgnc_found_board()
368 *
369 * A board has been found, init it.
370 */
371static int dgnc_found_board(struct pci_dev *pdev, int id)
372{
03425f55 373 struct dgnc_board *brd;
0b99d589
LL
374 unsigned int pci_irq;
375 int i = 0;
376 int rc = 0;
377 unsigned long flags;
378
eae9842a 379 /* get the board structure and prep it */
587abd7b
SL
380 dgnc_Board[dgnc_NumBoards] = kzalloc(sizeof(*brd), GFP_KERNEL);
381 brd = dgnc_Board[dgnc_NumBoards];
382
78adbb28 383 if (!brd)
8f90ef80 384 return -ENOMEM;
0b99d589 385
eae9842a 386 /* make a temporary message buffer for the boot messages */
2e363be0 387 brd->msgbuf_head = kcalloc(8192, sizeof(u8), GFP_KERNEL);
587abd7b
SL
388 brd->msgbuf = brd->msgbuf_head;
389
eae9842a 390 if (!brd->msgbuf) {
0b99d589 391 kfree(brd);
8f90ef80 392 return -ENOMEM;
eae9842a 393 }
817b7847 394
0b99d589
LL
395 /* store the info for the board we've found */
396 brd->magic = DGNC_BOARD_MAGIC;
397 brd->boardnum = dgnc_NumBoards;
398 brd->vendor = dgnc_pci_tbl[id].vendor;
399 brd->device = dgnc_pci_tbl[id].device;
400 brd->pdev = pdev;
401 brd->pci_bus = pdev->bus->number;
402 brd->pci_slot = PCI_SLOT(pdev->devfn);
403 brd->name = dgnc_Ids[id].name;
404 brd->maxports = dgnc_Ids[id].maxports;
405 if (dgnc_Ids[i].is_pci_express)
406 brd->bd_flags |= BD_IS_PCI_EXPRESS;
407 brd->dpastatus = BD_NOFEP;
408 init_waitqueue_head(&brd->state_wait);
409
66663dc1
RD
410 spin_lock_init(&brd->bd_lock);
411 spin_lock_init(&brd->bd_intr_lock);
0b99d589
LL
412
413 brd->state = BOARD_FOUND;
414
3f288962 415 for (i = 0; i < MAXPORTS; i++)
0b99d589 416 brd->channels[i] = NULL;
0b99d589
LL
417
418 /* store which card & revision we have */
419 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
420 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
421 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
422
423 pci_irq = pdev->irq;
424 brd->irq = pci_irq;
425
426
78adbb28 427 switch (brd->device) {
0b99d589
LL
428
429 case PCI_DEVICE_CLASSIC_4_DID:
430 case PCI_DEVICE_CLASSIC_8_DID:
431 case PCI_DEVICE_CLASSIC_4_422_DID:
432 case PCI_DEVICE_CLASSIC_8_422_DID:
433
434 brd->dpatype = T_CLASSIC | T_PCIBUS;
435
0b99d589
LL
436 /*
437 * For PCI ClassicBoards
438 * PCI Local Address (i.e. "resource" number) space
eae9842a
LL
439 * 0 PLX Memory Mapped Config
440 * 1 PLX I/O Mapped Config
441 * 2 I/O Mapped UARTs and Status
442 * 3 Memory Mapped VPD
443 * 4 Memory Mapped UARTs and Status
0b99d589
LL
444 */
445
446
447 /* get the PCI Base Address Registers */
448 brd->membase = pci_resource_start(pdev, 4);
449
450 if (!brd->membase) {
1f26adc9
RD
451 dev_err(&brd->pdev->dev,
452 "Card has no PCI IO resources, failing.\n");
0b99d589
LL
453 return -ENODEV;
454 }
455
456 brd->membase_end = pci_resource_end(pdev, 4);
457
458 if (brd->membase & 1)
459 brd->membase &= ~3;
460 else
461 brd->membase &= ~15;
462
eae9842a 463 brd->iobase = pci_resource_start(pdev, 1);
0b99d589 464 brd->iobase_end = pci_resource_end(pdev, 1);
eae9842a 465 brd->iobase = ((unsigned int) (brd->iobase)) & 0xFFFE;
0b99d589
LL
466
467 /* Assign the board_ops struct */
468 brd->bd_ops = &dgnc_cls_ops;
469
470 brd->bd_uart_offset = 0x8;
471 brd->bd_dividend = 921600;
472
473 dgnc_do_remap(brd);
474
475 /* Get and store the board VPD, if it exists */
476 brd->bd_ops->vpd(brd);
477
478 /*
479 * Enable Local Interrupt 1 (0x1),
480 * Local Interrupt 1 Polarity Active high (0x2),
481 * Enable PCI interrupt (0x40)
482 */
483 outb(0x43, brd->iobase + 0x4c);
484
485 break;
486
487
488 case PCI_DEVICE_NEO_4_DID:
489 case PCI_DEVICE_NEO_8_DID:
490 case PCI_DEVICE_NEO_2DB9_DID:
491 case PCI_DEVICE_NEO_2DB9PRI_DID:
492 case PCI_DEVICE_NEO_2RJ45_DID:
493 case PCI_DEVICE_NEO_2RJ45PRI_DID:
494 case PCI_DEVICE_NEO_1_422_DID:
495 case PCI_DEVICE_NEO_1_422_485_DID:
496 case PCI_DEVICE_NEO_2_422_485_DID:
497 case PCI_DEVICE_NEO_EXPRESS_8_DID:
498 case PCI_DEVICE_NEO_EXPRESS_4_DID:
499 case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
500 case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
501
502 /*
503 * This chip is set up 100% when we get to it.
817b7847 504 * No need to enable global interrupts or anything.
0b99d589
LL
505 */
506 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
507 brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
508 else
509 brd->dpatype = T_NEO | T_PCIBUS;
510
0b99d589
LL
511 /* get the PCI Base Address Registers */
512 brd->membase = pci_resource_start(pdev, 0);
513 brd->membase_end = pci_resource_end(pdev, 0);
514
515 if (brd->membase & 1)
516 brd->membase &= ~3;
517 else
518 brd->membase &= ~15;
519
520 /* Assign the board_ops struct */
521 brd->bd_ops = &dgnc_neo_ops;
522
523 brd->bd_uart_offset = 0x200;
524 brd->bd_dividend = 921600;
525
526 dgnc_do_remap(brd);
527
528 if (brd->re_map_membase) {
529
65da04c1 530 /* Read and store the dvid after remapping */
0b99d589
LL
531 brd->dvid = readb(brd->re_map_membase + 0x8D);
532
533 /* Get and store the board VPD, if it exists */
534 brd->bd_ops->vpd(brd);
535 }
536 break;
537
538 default:
1f26adc9
RD
539 dev_err(&brd->pdev->dev,
540 "Didn't find any compatible Neo/Classic PCI boards.\n");
8f90ef80 541 return -ENXIO;
0b99d589
LL
542
543 }
544
545 /*
546 * Do tty device initialization.
547 */
548
549 rc = dgnc_tty_register(brd);
550 if (rc < 0) {
1f26adc9 551 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
0b99d589
LL
552 goto failed;
553 }
554
555 rc = dgnc_finalize_board_init(brd);
556 if (rc < 0) {
1f26adc9 557 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
0b99d589
LL
558 goto failed;
559 }
560
561 rc = dgnc_tty_init(brd);
562 if (rc < 0) {
1f26adc9 563 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
0b99d589
LL
564 goto failed;
565 }
566
567 brd->state = BOARD_READY;
568 brd->dpastatus = BD_RUNNING;
569
570 dgnc_create_ports_sysfiles(brd);
571
572 /* init our poll helper tasklet */
371ec403
VH
573 tasklet_init(&brd->helper_tasklet,
574 brd->bd_ops->tasklet,
575 (unsigned long) brd);
0b99d589 576
66663dc1 577 spin_lock_irqsave(&dgnc_global_lock, flags);
0b99d589 578 brd->msgbuf = NULL;
f40e06f0 579 dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
0b99d589
LL
580 kfree(brd->msgbuf_head);
581 brd->msgbuf_head = NULL;
66663dc1 582 spin_unlock_irqrestore(&dgnc_global_lock, flags);
0b99d589
LL
583
584 /*
585 * allocate flip buffer for board.
586 *
587 * Okay to malloc with GFP_KERNEL, we are not at interrupt
588 * context, and there are no locks held.
589 */
52f9d668 590 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
0b99d589 591
0b99d589
LL
592 wake_up_interruptible(&brd->state_wait);
593
8f90ef80 594 return 0;
0b99d589
LL
595
596failed:
f6a14cf0
QL
597 dgnc_tty_uninit(brd);
598 brd->state = BOARD_FAILED;
599 brd->dpastatus = BD_NOFEP;
0b99d589 600
8f90ef80 601 return -ENXIO;
0b99d589
LL
602
603}
604
605
07467e50
VH
606static int dgnc_finalize_board_init(struct dgnc_board *brd)
607{
0b99d589
LL
608 int rc = 0;
609
0b99d589 610 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
8f90ef80 611 return -ENODEV;
0b99d589 612
0b99d589 613 if (brd->irq) {
2b46be68
AS
614 rc = request_irq(brd->irq, brd->bd_ops->intr,
615 IRQF_SHARED, "DGNC", brd);
0b99d589
LL
616
617 if (rc) {
2b46be68
AS
618 dev_err(&brd->pdev->dev,
619 "Failed to hook IRQ %d\n", brd->irq);
0b99d589
LL
620 brd->state = BOARD_FAILED;
621 brd->dpastatus = BD_NOFEP;
622 rc = -ENODEV;
0b99d589
LL
623 }
624 }
8f90ef80 625 return rc;
0b99d589
LL
626}
627
628/*
629 * Remap PCI memory.
630 */
03425f55 631static void dgnc_do_remap(struct dgnc_board *brd)
0b99d589
LL
632{
633
634 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
635 return;
636
637 brd->re_map_membase = ioremap(brd->membase, 0x1000);
0b99d589
LL
638}
639
640
641/*****************************************************************************
642*
643* Function:
817b7847 644*
0b99d589
LL
645* dgnc_poll_handler
646*
647* Author:
648*
649* Scott H Kilau
817b7847 650*
0b99d589
LL
651* Parameters:
652*
817b7847 653* dummy -- ignored
0b99d589
LL
654*
655* Return Values:
656*
657* none
658*
817b7847
LL
659* Description:
660*
0b99d589
LL
661* As each timer expires, it determines (a) whether the "transmit"
662* waiter needs to be woken up, and (b) whether the poller needs to
663* be rescheduled.
664*
665******************************************************************************/
666
667static void dgnc_poll_handler(ulong dummy)
668{
03425f55 669 struct dgnc_board *brd;
66663dc1 670 unsigned long flags;
0b99d589
LL
671 int i;
672 unsigned long new_time;
673
0b99d589
LL
674 /* Go thru each board, kicking off a tasklet for each if needed */
675 for (i = 0; i < dgnc_NumBoards; i++) {
676 brd = dgnc_Board[i];
677
66663dc1 678 spin_lock_irqsave(&brd->bd_lock, flags);
0b99d589 679
65da04c1 680 /* If board is in a failed state don't schedule a tasklet */
0b99d589 681 if (brd->state == BOARD_FAILED) {
66663dc1 682 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
683 continue;
684 }
685
686 /* Schedule a poll helper task */
687 tasklet_schedule(&brd->helper_tasklet);
688
66663dc1 689 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
690 }
691
0b99d589
LL
692 /*
693 * Schedule ourself back at the nominal wakeup interval.
694 */
66663dc1 695 spin_lock_irqsave(&dgnc_poll_lock, flags);
0b99d589
LL
696 dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
697
698 new_time = dgnc_poll_time - jiffies;
699
3f288962 700 if ((ulong) new_time >= 2 * dgnc_poll_tick)
65da04c1 701 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
0b99d589 702
38e0c9d2 703 setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
0b99d589 704 dgnc_poll_timer.expires = dgnc_poll_time;
66663dc1 705 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
0b99d589
LL
706
707 if (!dgnc_poll_stop)
708 add_timer(&dgnc_poll_timer);
709}
710
711/*
712 * dgnc_init_globals()
713 *
714 * This is where we initialize the globals from the static insmod
715 * configuration variables. These are declared near the head of
716 * this file.
717 */
718static void dgnc_init_globals(void)
719{
720 int i = 0;
721
92ded48c 722 dgnc_NumBoards = 0;
0b99d589 723
3f288962 724 for (i = 0; i < MAXBOARDS; i++)
0b99d589 725 dgnc_Board[i] = NULL;
0b99d589
LL
726
727 init_timer(&dgnc_poll_timer);
728}
729