dgnc_driver.c 16 KB

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