Merge remote-tracking branch 'staging/staging-next'
[deliverable/linux.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 */
80e3e241 51static const struct file_operations dgnc_board_fops = {
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 */
80e3e241
DY
61uint dgnc_num_boards;
62struct dgnc_board *dgnc_board[MAXBOARDS];
0b99d589 63DEFINE_SPINLOCK(dgnc_global_lock);
51abf45c 64DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
80e3e241 65uint dgnc_major;
0b99d589
LL
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
80e3e241 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
18f038e6 128static void cleanup(bool sysfiles)
1e881002
KZ
129{
130 int i;
66663dc1 131 unsigned long flags;
1e881002 132
66663dc1 133 spin_lock_irqsave(&dgnc_poll_lock, flags);
1e881002 134 dgnc_poll_stop = 1;
66663dc1 135 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
1e881002
KZ
136
137 /* Turn off poller right away. */
138 del_timer_sync(&dgnc_poll_timer);
139
18f038e6
SM
140 if (sysfiles)
141 dgnc_remove_driver_sysfiles(&dgnc_driver);
1e881002 142
80e3e241 143 device_destroy(dgnc_class, MKDEV(dgnc_major, 0));
ed7f92da 144 class_destroy(dgnc_class);
80e3e241 145 unregister_chrdev(dgnc_major, "dgnc");
1e881002 146
80e3e241
DY
147 for (i = 0; i < dgnc_num_boards; ++i) {
148 dgnc_remove_ports_sysfiles(dgnc_board[i]);
149 dgnc_tty_uninit(dgnc_board[i]);
150 dgnc_cleanup_board(dgnc_board[i]);
1e881002
KZ
151 }
152
153 dgnc_tty_post_uninit();
18f038e6 154}
1e881002 155
18f038e6
SM
156/*
157 * dgnc_cleanup_module()
158 *
159 * Module unload. This is where it all ends.
160 */
598b1529 161static void __exit dgnc_cleanup_module(void)
18f038e6
SM
162{
163 cleanup(true);
b3ca2e08 164 pci_unregister_driver(&dgnc_driver);
1e881002 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 173{
f4edff52 174 int rc;
0b99d589 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);
e9961fc1
SM
188 if (rc) {
189 pr_warn("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
18f038e6 190 cleanup(false);
e9961fc1 191 return rc;
0b99d589 192 }
e9961fc1 193 dgnc_create_driver_sysfiles(&dgnc_driver);
0b99d589 194
e9961fc1 195 return 0;
0b99d589
LL
196}
197
1e881002
KZ
198module_init(dgnc_init_module);
199module_exit(dgnc_cleanup_module);
0b99d589
LL
200
201/*
202 * Start of driver.
203 */
204static int dgnc_start(void)
205{
206 int rc = 0;
207 unsigned long flags;
d7312aab 208 struct device *dev;
0b99d589 209
6d99d6a3
SM
210 /* make sure timer is initialized before we do anything else */
211 init_timer(&dgnc_poll_timer);
0b99d589 212
92ded48c
KZ
213 /*
214 * Register our base character device into the kernel.
215 * This allows the download daemon to connect to the downld device
216 * before any of the boards are init'ed.
ed7f92da
KZ
217 *
218 * Register management/dpa devices
92ded48c 219 */
80e3e241 220 rc = register_chrdev(0, "dgnc", &dgnc_board_fops);
5f9dca1e 221 if (rc < 0) {
1f26adc9 222 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
5f9dca1e 223 return rc;
92ded48c 224 }
80e3e241 225 dgnc_major = rc;
ed7f92da
KZ
226
227 dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
d7312aab
AK
228 if (IS_ERR(dgnc_class)) {
229 rc = PTR_ERR(dgnc_class);
230 pr_err(DRVSTR ": Can't create dgnc_mgmt class (%d)\n", rc);
231 goto failed_class;
232 }
233
234 dev = device_create(dgnc_class, NULL,
80e3e241 235 MKDEV(dgnc_major, 0),
d7312aab
AK
236 NULL, "dgnc_mgmt");
237 if (IS_ERR(dev)) {
238 rc = PTR_ERR(dev);
239 pr_err(DRVSTR ": Can't create device (%d)\n", rc);
240 goto failed_device;
241 }
0b99d589 242
92ded48c
KZ
243 /*
244 * Init any global tty stuff.
245 */
246 rc = dgnc_tty_preinit();
0b99d589 247
92ded48c 248 if (rc < 0) {
1f26adc9 249 pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
d7312aab 250 goto failed_tty;
92ded48c 251 }
0b99d589 252
92ded48c 253 /* Start the poller */
66663dc1 254 spin_lock_irqsave(&dgnc_poll_lock, flags);
38e0c9d2 255 setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
92ded48c
KZ
256 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
257 dgnc_poll_timer.expires = dgnc_poll_time;
66663dc1 258 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
0b99d589 259
92ded48c
KZ
260 add_timer(&dgnc_poll_timer);
261
d7312aab
AK
262 return 0;
263
264failed_tty:
80e3e241 265 device_destroy(dgnc_class, MKDEV(dgnc_major, 0));
d7312aab
AK
266failed_device:
267 class_destroy(dgnc_class);
268failed_class:
80e3e241 269 unregister_chrdev(dgnc_major, "dgnc");
8f90ef80 270 return rc;
0b99d589
LL
271}
272
0b99d589
LL
273/* returns count (>= 0), or negative on error */
274static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
817b7847 275{
0b99d589
LL
276 int rc;
277
278 /* wake up and enable device */
279 rc = pci_enable_device(pdev);
280
757b816e
SM
281 if (rc)
282 return -EIO;
283
284 rc = dgnc_found_board(pdev, ent->driver_data);
285 if (rc == 0)
80e3e241 286 dgnc_num_boards++;
757b816e 287
0b99d589
LL
288 return rc;
289}
290
0b99d589
LL
291/*
292 * dgnc_cleanup_board()
293 *
294 * Free all the memory associated with a board
295 */
03425f55 296static void dgnc_cleanup_board(struct dgnc_board *brd)
0b99d589
LL
297{
298 int i = 0;
299
78adbb28 300 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
eae9842a 301 return;
0b99d589
LL
302
303 switch (brd->device) {
304 case PCI_DEVICE_CLASSIC_4_DID:
305 case PCI_DEVICE_CLASSIC_8_DID:
306 case PCI_DEVICE_CLASSIC_4_422_DID:
307 case PCI_DEVICE_CLASSIC_8_422_DID:
308
309 /* Tell card not to interrupt anymore. */
310 outb(0, brd->iobase + 0x4c);
311 break;
312
313 default:
314 break;
315 }
316
317 if (brd->irq)
318 free_irq(brd->irq, brd);
319
320 tasklet_kill(&brd->helper_tasklet);
321
322 if (brd->re_map_membase) {
323 iounmap(brd->re_map_membase);
324 brd->re_map_membase = NULL;
325 }
326
327 if (brd->msgbuf_head) {
328 unsigned long flags;
329
66663dc1 330 spin_lock_irqsave(&dgnc_global_lock, flags);
0b99d589 331 brd->msgbuf = NULL;
f40e06f0 332 dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
0b99d589
LL
333 kfree(brd->msgbuf_head);
334 brd->msgbuf_head = NULL;
66663dc1 335 spin_unlock_irqrestore(&dgnc_global_lock, flags);
eae9842a 336 }
0b99d589
LL
337
338 /* Free all allocated channels structs */
339 for (i = 0; i < MAXPORTS ; i++) {
340 if (brd->channels[i]) {
36aa10aa
VO
341 kfree(brd->channels[i]->ch_rqueue);
342 kfree(brd->channels[i]->ch_equeue);
343 kfree(brd->channels[i]->ch_wqueue);
0b99d589
LL
344 kfree(brd->channels[i]);
345 brd->channels[i] = NULL;
346 }
347 }
348
80e3e241 349 dgnc_board[brd->boardnum] = NULL;
0b99d589 350
eae9842a 351 kfree(brd);
0b99d589
LL
352}
353
0b99d589
LL
354/*
355 * dgnc_found_board()
356 *
357 * A board has been found, init it.
358 */
359static int dgnc_found_board(struct pci_dev *pdev, int id)
360{
03425f55 361 struct dgnc_board *brd;
0b99d589
LL
362 unsigned int pci_irq;
363 int i = 0;
364 int rc = 0;
365 unsigned long flags;
366
eae9842a 367 /* get the board structure and prep it */
80e3e241
DY
368 dgnc_board[dgnc_num_boards] = kzalloc(sizeof(*brd), GFP_KERNEL);
369 brd = dgnc_board[dgnc_num_boards];
587abd7b 370
78adbb28 371 if (!brd)
8f90ef80 372 return -ENOMEM;
0b99d589 373
eae9842a 374 /* make a temporary message buffer for the boot messages */
2e363be0 375 brd->msgbuf_head = kcalloc(8192, sizeof(u8), GFP_KERNEL);
587abd7b
SL
376 brd->msgbuf = brd->msgbuf_head;
377
eae9842a 378 if (!brd->msgbuf) {
0b99d589 379 kfree(brd);
8f90ef80 380 return -ENOMEM;
eae9842a 381 }
817b7847 382
0b99d589
LL
383 /* store the info for the board we've found */
384 brd->magic = DGNC_BOARD_MAGIC;
80e3e241 385 brd->boardnum = dgnc_num_boards;
0b99d589
LL
386 brd->vendor = dgnc_pci_tbl[id].vendor;
387 brd->device = dgnc_pci_tbl[id].device;
388 brd->pdev = pdev;
389 brd->pci_bus = pdev->bus->number;
390 brd->pci_slot = PCI_SLOT(pdev->devfn);
80e3e241
DY
391 brd->name = dgnc_ids[id].name;
392 brd->maxports = dgnc_ids[id].maxports;
393 if (dgnc_ids[i].is_pci_express)
0b99d589
LL
394 brd->bd_flags |= BD_IS_PCI_EXPRESS;
395 brd->dpastatus = BD_NOFEP;
396 init_waitqueue_head(&brd->state_wait);
397
66663dc1
RD
398 spin_lock_init(&brd->bd_lock);
399 spin_lock_init(&brd->bd_intr_lock);
0b99d589
LL
400
401 brd->state = BOARD_FOUND;
402
3f288962 403 for (i = 0; i < MAXPORTS; i++)
0b99d589 404 brd->channels[i] = NULL;
0b99d589
LL
405
406 /* store which card & revision we have */
407 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
408 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
409 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
410
411 pci_irq = pdev->irq;
412 brd->irq = pci_irq;
413
78adbb28 414 switch (brd->device) {
0b99d589
LL
415 case PCI_DEVICE_CLASSIC_4_DID:
416 case PCI_DEVICE_CLASSIC_8_DID:
417 case PCI_DEVICE_CLASSIC_4_422_DID:
418 case PCI_DEVICE_CLASSIC_8_422_DID:
419
420 brd->dpatype = T_CLASSIC | T_PCIBUS;
421
0b99d589
LL
422 /*
423 * For PCI ClassicBoards
424 * PCI Local Address (i.e. "resource" number) space
eae9842a
LL
425 * 0 PLX Memory Mapped Config
426 * 1 PLX I/O Mapped Config
427 * 2 I/O Mapped UARTs and Status
428 * 3 Memory Mapped VPD
429 * 4 Memory Mapped UARTs and Status
0b99d589
LL
430 */
431
0b99d589
LL
432 /* get the PCI Base Address Registers */
433 brd->membase = pci_resource_start(pdev, 4);
434
435 if (!brd->membase) {
1f26adc9
RD
436 dev_err(&brd->pdev->dev,
437 "Card has no PCI IO resources, failing.\n");
0b99d589
LL
438 return -ENODEV;
439 }
440
441 brd->membase_end = pci_resource_end(pdev, 4);
442
443 if (brd->membase & 1)
444 brd->membase &= ~3;
445 else
446 brd->membase &= ~15;
447
eae9842a 448 brd->iobase = pci_resource_start(pdev, 1);
0b99d589 449 brd->iobase_end = pci_resource_end(pdev, 1);
6f418259 450 brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE;
0b99d589
LL
451
452 /* Assign the board_ops struct */
453 brd->bd_ops = &dgnc_cls_ops;
454
455 brd->bd_uart_offset = 0x8;
456 brd->bd_dividend = 921600;
457
458 dgnc_do_remap(brd);
459
460 /* Get and store the board VPD, if it exists */
461 brd->bd_ops->vpd(brd);
462
463 /*
464 * Enable Local Interrupt 1 (0x1),
465 * Local Interrupt 1 Polarity Active high (0x2),
466 * Enable PCI interrupt (0x40)
467 */
468 outb(0x43, brd->iobase + 0x4c);
469
470 break;
471
0b99d589
LL
472 case PCI_DEVICE_NEO_4_DID:
473 case PCI_DEVICE_NEO_8_DID:
474 case PCI_DEVICE_NEO_2DB9_DID:
475 case PCI_DEVICE_NEO_2DB9PRI_DID:
476 case PCI_DEVICE_NEO_2RJ45_DID:
477 case PCI_DEVICE_NEO_2RJ45PRI_DID:
478 case PCI_DEVICE_NEO_1_422_DID:
479 case PCI_DEVICE_NEO_1_422_485_DID:
480 case PCI_DEVICE_NEO_2_422_485_DID:
481 case PCI_DEVICE_NEO_EXPRESS_8_DID:
482 case PCI_DEVICE_NEO_EXPRESS_4_DID:
483 case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
484 case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
485
486 /*
487 * This chip is set up 100% when we get to it.
817b7847 488 * No need to enable global interrupts or anything.
0b99d589
LL
489 */
490 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
491 brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
492 else
493 brd->dpatype = T_NEO | T_PCIBUS;
494
0b99d589
LL
495 /* get the PCI Base Address Registers */
496 brd->membase = pci_resource_start(pdev, 0);
497 brd->membase_end = pci_resource_end(pdev, 0);
498
499 if (brd->membase & 1)
500 brd->membase &= ~3;
501 else
502 brd->membase &= ~15;
503
504 /* Assign the board_ops struct */
505 brd->bd_ops = &dgnc_neo_ops;
506
507 brd->bd_uart_offset = 0x200;
508 brd->bd_dividend = 921600;
509
510 dgnc_do_remap(brd);
511
512 if (brd->re_map_membase) {
65da04c1 513 /* Read and store the dvid after remapping */
0b99d589
LL
514 brd->dvid = readb(brd->re_map_membase + 0x8D);
515
516 /* Get and store the board VPD, if it exists */
517 brd->bd_ops->vpd(brd);
518 }
519 break;
520
521 default:
1f26adc9
RD
522 dev_err(&brd->pdev->dev,
523 "Didn't find any compatible Neo/Classic PCI boards.\n");
8f90ef80 524 return -ENXIO;
0b99d589
LL
525 }
526
527 /*
528 * Do tty device initialization.
529 */
530
531 rc = dgnc_tty_register(brd);
532 if (rc < 0) {
1f26adc9 533 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
0b99d589
LL
534 goto failed;
535 }
536
537 rc = dgnc_finalize_board_init(brd);
538 if (rc < 0) {
1f26adc9 539 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
0b99d589
LL
540 goto failed;
541 }
542
543 rc = dgnc_tty_init(brd);
544 if (rc < 0) {
1f26adc9 545 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
0b99d589
LL
546 goto failed;
547 }
548
549 brd->state = BOARD_READY;
550 brd->dpastatus = BD_RUNNING;
551
552 dgnc_create_ports_sysfiles(brd);
553
554 /* init our poll helper tasklet */
371ec403
VH
555 tasklet_init(&brd->helper_tasklet,
556 brd->bd_ops->tasklet,
6f418259 557 (unsigned long)brd);
0b99d589 558
66663dc1 559 spin_lock_irqsave(&dgnc_global_lock, flags);
0b99d589 560 brd->msgbuf = NULL;
f40e06f0 561 dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
0b99d589
LL
562 kfree(brd->msgbuf_head);
563 brd->msgbuf_head = NULL;
66663dc1 564 spin_unlock_irqrestore(&dgnc_global_lock, flags);
0b99d589 565
0b99d589
LL
566 wake_up_interruptible(&brd->state_wait);
567
8f90ef80 568 return 0;
0b99d589
LL
569
570failed:
f6a14cf0
QL
571 dgnc_tty_uninit(brd);
572 brd->state = BOARD_FAILED;
573 brd->dpastatus = BD_NOFEP;
0b99d589 574
8f90ef80 575 return -ENXIO;
0b99d589
LL
576}
577
07467e50
VH
578static int dgnc_finalize_board_init(struct dgnc_board *brd)
579{
0b99d589
LL
580 int rc = 0;
581
0b99d589 582 if (brd->irq) {
2b46be68
AS
583 rc = request_irq(brd->irq, brd->bd_ops->intr,
584 IRQF_SHARED, "DGNC", brd);
0b99d589
LL
585
586 if (rc) {
2b46be68
AS
587 dev_err(&brd->pdev->dev,
588 "Failed to hook IRQ %d\n", brd->irq);
0b99d589
LL
589 brd->state = BOARD_FAILED;
590 brd->dpastatus = BD_NOFEP;
591 rc = -ENODEV;
0b99d589
LL
592 }
593 }
8f90ef80 594 return rc;
0b99d589
LL
595}
596
597/*
598 * Remap PCI memory.
599 */
03425f55 600static void dgnc_do_remap(struct dgnc_board *brd)
0b99d589 601{
0b99d589 602 brd->re_map_membase = ioremap(brd->membase, 0x1000);
0b99d589
LL
603}
604
970e82df
FA
605/*
606 *
607 * Function:
608 *
609 * dgnc_poll_handler
610 *
611 * Author:
612 *
613 * Scott H Kilau
614 *
615 * Parameters:
616 *
617 * dummy -- ignored
618 *
619 * Return Values:
620 *
621 * none
622 *
623 * Description:
624 *
625 * As each timer expires, it determines (a) whether the "transmit"
626 * waiter needs to be woken up, and (b) whether the poller needs to
627 * be rescheduled.
628 *
629 */
0b99d589
LL
630
631static void dgnc_poll_handler(ulong dummy)
632{
03425f55 633 struct dgnc_board *brd;
66663dc1 634 unsigned long flags;
0b99d589
LL
635 int i;
636 unsigned long new_time;
637
0b99d589 638 /* Go thru each board, kicking off a tasklet for each if needed */
80e3e241
DY
639 for (i = 0; i < dgnc_num_boards; i++) {
640 brd = dgnc_board[i];
0b99d589 641
66663dc1 642 spin_lock_irqsave(&brd->bd_lock, flags);
0b99d589 643
65da04c1 644 /* If board is in a failed state don't schedule a tasklet */
0b99d589 645 if (brd->state == BOARD_FAILED) {
66663dc1 646 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
647 continue;
648 }
649
650 /* Schedule a poll helper task */
651 tasklet_schedule(&brd->helper_tasklet);
652
66663dc1 653 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
654 }
655
0b99d589
LL
656 /*
657 * Schedule ourself back at the nominal wakeup interval.
658 */
66663dc1 659 spin_lock_irqsave(&dgnc_poll_lock, flags);
0b99d589
LL
660 dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
661
662 new_time = dgnc_poll_time - jiffies;
663
6f418259 664 if ((ulong)new_time >= 2 * dgnc_poll_tick)
65da04c1 665 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
0b99d589 666
38e0c9d2 667 setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
0b99d589 668 dgnc_poll_timer.expires = dgnc_poll_time;
66663dc1 669 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
0b99d589
LL
670
671 if (!dgnc_poll_stop)
672 add_timer(&dgnc_poll_timer);
673}
This page took 0.523843 seconds and 5 git commands to generate.