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