blob: d2d32a19862961a06e6ecd0738d5e3877ade07a0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/************************************************************************
2 * Copyright 2003 Digi International (www.digi.com)
3 *
4 * Copyright (C) 2004 IBM Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 *
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
Adrian Bunk2a08b4e2006-04-01 01:04:20 +020023 * Wendy Xiong <wendyx@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
V. ANANDA KRISHNANc2236952005-07-27 11:43:49 -070025 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 ***********************************************************************/
27#include <linux/moduleparam.h>
28#include <linux/pci.h>
29
30#include "jsm.h"
31
32MODULE_AUTHOR("Digi International, http://www.digi.com");
Christoph Hellwig614a7d62005-04-16 15:25:44 -070033MODULE_DESCRIPTION("Driver for the Digi International "
34 "Neo PCI based product line");
35MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -070036MODULE_SUPPORTED_DEVICE("jsm");
37
38#define JSM_DRIVER_NAME "jsm"
39#define NR_PORTS 32
40#define JSM_MINOR_START 0
41
42struct uart_driver jsm_uart_driver = {
43 .owner = THIS_MODULE,
44 .driver_name = JSM_DRIVER_NAME,
45 .dev_name = "ttyn",
V. ANANDA KRISHNAN9539c1d2005-07-27 11:43:48 -070046 .major = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .minor = JSM_MINOR_START,
48 .nr = NR_PORTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
51int jsm_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052module_param(jsm_debug, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Breno Leitaoaacf17a2009-04-06 17:34:17 +010055static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 struct jsm_board *brd;
Christoph Hellwig614a7d62005-04-16 15:25:44 -070059 static int adapter_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Christoph Hellwig614a7d62005-04-16 15:25:44 -070061 rc = pci_enable_device(pdev);
62 if (rc) {
63 dev_err(&pdev->dev, "Device enable FAILED\n");
64 goto out;
65 }
66
67 rc = pci_request_regions(pdev, "jsm");
68 if (rc) {
69 dev_err(&pdev->dev, "pci_request_region FAILED\n");
70 goto out_disable_device;
71 }
72
Burman Yan8f31bb32007-02-14 00:33:07 -080073 brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if (!brd) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -070075 dev_err(&pdev->dev,
76 "memory allocation for board structure failed\n");
77 rc = -ENOMEM;
78 goto out_release_regions;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* store the info for the board we've found */
Christoph Hellwig614a7d62005-04-16 15:25:44 -070082 brd->boardnum = adapter_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 brd->pci_dev = pdev;
Scott Kilau99da9042008-05-01 04:35:00 -070084 if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
85 brd->maxports = 4;
Adam Lackorzynskiffa75252009-02-18 14:48:34 -080086 else if (pdev->device == PCI_DEVICE_ID_DIGI_NEO_8)
87 brd->maxports = 8;
Scott Kilau99da9042008-05-01 04:35:00 -070088 else
89 brd->maxports = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 spin_lock_init(&brd->bd_lock);
92 spin_lock_init(&brd->bd_intr_lock);
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 /* store which revision we have */
Auke Kok44c10132007-06-08 15:46:36 -070095 brd->rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 brd->irq = pdev->irq;
98
Christoph Hellwig614a7d62005-04-16 15:25:44 -070099 jsm_printk(INIT, INFO, &brd->pci_dev,
100 "jsm_found_board - NEO adapter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700102 /* get the PCI Base Address Registers */
103 brd->membase = pci_resource_start(pdev, 0);
104 brd->membase_end = pci_resource_end(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700106 if (brd->membase & 1)
107 brd->membase &= ~3;
108 else
109 brd->membase &= ~15;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700111 /* Assign the board_ops struct */
112 brd->bd_ops = &jsm_neo_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700114 brd->bd_uart_offset = 0x200;
115 brd->bd_dividend = 921600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700117 brd->re_map_membase = ioremap(brd->membase, 0x1000);
118 if (!brd->re_map_membase) {
119 dev_err(&pdev->dev,
120 "card has no PCI Memory resources, "
121 "failing board.\n");
122 rc = -ENOMEM;
123 goto out_kfree_brd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700126 rc = request_irq(brd->irq, brd->bd_ops->intr,
Thomas Gleixner40663cc2006-07-01 19:29:43 -0700127 IRQF_DISABLED|IRQF_SHARED, "JSM", brd);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700128 if (rc) {
129 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
130 goto out_iounmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
133 rc = jsm_tty_init(brd);
134 if (rc < 0) {
135 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
Breno Leitaoe713abe2009-04-06 17:34:27 +0100136 rc = -ENXIO;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700137 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
140 rc = jsm_uart_port_init(brd);
141 if (rc < 0) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700142 /* XXX: leaking all resources from jsm_tty_init here! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
Breno Leitaoe713abe2009-04-06 17:34:27 +0100144 rc = -ENXIO;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700145 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* Log the information about the board */
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700149 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
150 adapter_count, brd->rev, brd->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /*
153 * allocate flip buffer for board.
154 *
155 * Okay to malloc with GFP_KERNEL, we are not at interrupt
156 * context, and there are no locks held.
157 */
Burman Yan8f31bb32007-02-14 00:33:07 -0800158 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (!brd->flipbuf) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700160 /* XXX: leaking all resources from jsm_tty_init and
161 jsm_uart_port_init here! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
Breno Leitaoe713abe2009-04-06 17:34:27 +0100163 rc = -ENOMEM;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700164 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700167 pci_set_drvdata(pdev, brd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return 0;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700170 out_free_irq:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 free_irq(brd->irq, brd);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700172 out_iounmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 iounmap(brd->re_map_membase);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700174 out_kfree_brd:
175 kfree(brd);
176 out_release_regions:
177 pci_release_regions(pdev);
178 out_disable_device:
179 pci_disable_device(pdev);
180 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return rc;
182}
183
Uwe Kleine-Könige9fed562009-01-27 11:51:06 +0000184static void __devexit jsm_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700186 struct jsm_board *brd = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 int i = 0;
188
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700189 jsm_remove_uart_port(brd);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 free_irq(brd->irq, brd);
192 iounmap(brd->re_map_membase);
193
194 /* Free all allocated channels structs */
195 for (i = 0; i < brd->maxports; i++) {
196 if (brd->channels[i]) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700197 kfree(brd->channels[i]->ch_rqueue);
198 kfree(brd->channels[i]->ch_equeue);
199 kfree(brd->channels[i]->ch_wqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 kfree(brd->channels[i]);
201 }
202 }
203
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700204 pci_release_regions(pdev);
205 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 kfree(brd->flipbuf);
207 kfree(brd);
208}
209
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700210static struct pci_device_id jsm_pci_tbl[] = {
211 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
212 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
213 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
214 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
Scott Kilau99da9042008-05-01 04:35:00 -0700215 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
Adam Lackorzynskiffa75252009-02-18 14:48:34 -0800216 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_NEO_8), 0, 0, 5 },
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700217 { 0, }
218};
219MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700221static struct pci_driver jsm_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .name = "jsm",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .id_table = jsm_pci_tbl,
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700224 .probe = jsm_probe_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .remove = __devexit_p(jsm_remove_one),
226};
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static int __init jsm_init_module(void)
229{
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700230 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 rc = uart_register_driver(&jsm_uart_driver);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700233 if (!rc) {
234 rc = pci_register_driver(&jsm_driver);
235 if (rc)
236 uart_unregister_driver(&jsm_uart_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return rc;
239}
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static void __exit jsm_exit_module(void)
242{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 pci_unregister_driver(&jsm_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 uart_unregister_driver(&jsm_uart_driver);
245}
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700246
247module_init(jsm_init_module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248module_exit(jsm_exit_module);