1 /************************************************************************
2 * Copyright 2003 Digi International (www.digi.com)
4 * Copyright (C) 2004 IBM Corporation. All rights reserved.
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)
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.
16 * Contact Information:
17 * Scott H Kilau <Scott_Kilau@digi.com>
18 * Wendy Xiong <wendyx@us.ibm.com>
21 ***********************************************************************/
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
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_LICENSE("GPL");
31 MODULE_SUPPORTED_DEVICE("jsm");
33 #define JSM_DRIVER_NAME "jsm"
35 #define JSM_MINOR_START 0
37 struct uart_driver jsm_uart_driver
= {
39 .driver_name
= JSM_DRIVER_NAME
,
42 .minor
= JSM_MINOR_START
,
46 static pci_ers_result_t
jsm_io_error_detected(struct pci_dev
*pdev
,
47 pci_channel_state_t state
);
48 static pci_ers_result_t
jsm_io_slot_reset(struct pci_dev
*pdev
);
49 static void jsm_io_resume(struct pci_dev
*pdev
);
51 static const struct pci_error_handlers jsm_err_handler
= {
52 .error_detected
= jsm_io_error_detected
,
53 .slot_reset
= jsm_io_slot_reset
,
54 .resume
= jsm_io_resume
,
58 module_param(jsm_debug
, int, 0);
59 MODULE_PARM_DESC(jsm_debug
, "Driver debugging level");
61 static int jsm_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
64 struct jsm_board
*brd
;
65 static int adapter_count
;
67 rc
= pci_enable_device(pdev
);
69 dev_err(&pdev
->dev
, "Device enable FAILED\n");
73 rc
= pci_request_regions(pdev
, JSM_DRIVER_NAME
);
75 dev_err(&pdev
->dev
, "pci_request_region FAILED\n");
76 goto out_disable_device
;
79 brd
= kzalloc(sizeof(*brd
), GFP_KERNEL
);
82 goto out_release_regions
;
85 /* store the info for the board we've found */
86 brd
->boardnum
= adapter_count
++;
89 switch (pdev
->device
) {
90 case PCI_DEVICE_ID_NEO_2DB9
:
91 case PCI_DEVICE_ID_NEO_2DB9PRI
:
92 case PCI_DEVICE_ID_NEO_2RJ45
:
93 case PCI_DEVICE_ID_NEO_2RJ45PRI
:
94 case PCI_DEVICE_ID_NEO_2_422_485
:
98 case PCI_DEVICE_ID_CLASSIC_4
:
99 case PCI_DEVICE_ID_CLASSIC_4_422
:
100 case PCI_DEVICE_ID_NEO_4
:
101 case PCIE_DEVICE_ID_NEO_4
:
102 case PCIE_DEVICE_ID_NEO_4RJ45
:
103 case PCIE_DEVICE_ID_NEO_4_IBM
:
107 case PCI_DEVICE_ID_CLASSIC_8
:
108 case PCI_DEVICE_ID_CLASSIC_8_422
:
109 case PCI_DEVICE_ID_DIGI_NEO_8
:
110 case PCIE_DEVICE_ID_NEO_8
:
111 case PCIE_DEVICE_ID_NEO_8RJ45
:
120 spin_lock_init(&brd
->bd_intr_lock
);
122 /* store which revision we have */
123 brd
->rev
= pdev
->revision
;
125 brd
->irq
= pdev
->irq
;
127 switch (pdev
->device
) {
128 case PCI_DEVICE_ID_CLASSIC_4
:
129 case PCI_DEVICE_ID_CLASSIC_4_422
:
130 case PCI_DEVICE_ID_CLASSIC_8
:
131 case PCI_DEVICE_ID_CLASSIC_8_422
:
133 jsm_dbg(INIT
, &brd
->pci_dev
,
134 "jsm_found_board - Classic adapter\n");
137 * For PCI ClassicBoards
138 * PCI Local Address (.i.e. "resource" number) space
139 * 0 PLX Memory Mapped Config
140 * 1 PLX I/O Mapped Config
141 * 2 I/O Mapped UARTs and Status
142 * 3 Memory Mapped VPD
143 * 4 Memory Mapped UARTs and Status
146 /* Get the PCI Base Address Registers */
147 brd
->membase
= pci_resource_start(pdev
, 4);
148 brd
->membase_end
= pci_resource_end(pdev
, 4);
150 if (brd
->membase
& 0x1)
151 brd
->membase
&= ~0x3;
153 brd
->membase
&= ~0xF;
155 brd
->iobase
= pci_resource_start(pdev
, 1);
156 brd
->iobase_end
= pci_resource_end(pdev
, 1);
157 brd
->iobase
= ((unsigned int)(brd
->iobase
)) & 0xFFFE;
159 /* Assign the board_ops struct */
160 brd
->bd_ops
= &jsm_cls_ops
;
162 brd
->bd_uart_offset
= 0x8;
163 brd
->bd_dividend
= 921600;
165 brd
->re_map_membase
= ioremap(brd
->membase
,
166 pci_resource_len(pdev
, 4));
167 if (!brd
->re_map_membase
) {
169 "Card has no PCI Memory resources, failing board.\n");
175 * Enable Local Interrupt 1 (0x1),
176 * Local Interrupt 1 Polarity Active high (0x2),
177 * Enable PCI interrupt (0x43)
179 outb(0x43, brd
->iobase
+ 0x4c);
183 case PCI_DEVICE_ID_NEO_2DB9
:
184 case PCI_DEVICE_ID_NEO_2DB9PRI
:
185 case PCI_DEVICE_ID_NEO_2RJ45
:
186 case PCI_DEVICE_ID_NEO_2RJ45PRI
:
187 case PCI_DEVICE_ID_NEO_2_422_485
:
188 case PCI_DEVICE_ID_NEO_4
:
189 case PCIE_DEVICE_ID_NEO_4
:
190 case PCIE_DEVICE_ID_NEO_4RJ45
:
191 case PCIE_DEVICE_ID_NEO_4_IBM
:
192 case PCI_DEVICE_ID_DIGI_NEO_8
:
193 case PCIE_DEVICE_ID_NEO_8
:
194 case PCIE_DEVICE_ID_NEO_8RJ45
:
196 jsm_dbg(INIT
, &brd
->pci_dev
, "jsm_found_board - NEO adapter\n");
198 /* get the PCI Base Address Registers */
199 brd
->membase
= pci_resource_start(pdev
, 0);
200 brd
->membase_end
= pci_resource_end(pdev
, 0);
202 if (brd
->membase
& 1)
203 brd
->membase
&= ~0x3;
205 brd
->membase
&= ~0xF;
207 /* Assign the board_ops struct */
208 brd
->bd_ops
= &jsm_neo_ops
;
210 brd
->bd_uart_offset
= 0x200;
211 brd
->bd_dividend
= 921600;
213 brd
->re_map_membase
= ioremap(brd
->membase
,
214 pci_resource_len(pdev
, 0));
215 if (!brd
->re_map_membase
) {
217 "Card has no PCI Memory resources, failing board.\n");
227 rc
= request_irq(brd
->irq
, brd
->bd_ops
->intr
, IRQF_SHARED
, "JSM", brd
);
229 dev_warn(&pdev
->dev
, "Failed to hook IRQ %d\n", brd
->irq
);
233 rc
= jsm_tty_init(brd
);
235 dev_err(&pdev
->dev
, "Can't init tty devices (%d)\n", rc
);
240 rc
= jsm_uart_port_init(brd
);
242 /* XXX: leaking all resources from jsm_tty_init here! */
243 dev_err(&pdev
->dev
, "Can't init uart port (%d)\n", rc
);
248 /* Log the information about the board */
249 dev_info(&pdev
->dev
, "board %d: Digi Classic/Neo (rev %d), irq %d\n",
250 adapter_count
, brd
->rev
, brd
->irq
);
252 pci_set_drvdata(pdev
, brd
);
253 pci_save_state(pdev
);
257 jsm_remove_uart_port(brd
);
258 free_irq(brd
->irq
, brd
);
260 iounmap(brd
->re_map_membase
);
264 pci_release_regions(pdev
);
266 pci_disable_device(pdev
);
271 static void jsm_remove_one(struct pci_dev
*pdev
)
273 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
276 switch (pdev
->device
) {
277 case PCI_DEVICE_ID_CLASSIC_4
:
278 case PCI_DEVICE_ID_CLASSIC_4_422
:
279 case PCI_DEVICE_ID_CLASSIC_8
:
280 case PCI_DEVICE_ID_CLASSIC_8_422
:
281 /* Tell card not to interrupt anymore. */
282 outb(0x0, brd
->iobase
+ 0x4c);
288 jsm_remove_uart_port(brd
);
290 free_irq(brd
->irq
, brd
);
291 iounmap(brd
->re_map_membase
);
293 /* Free all allocated channels structs */
294 for (i
= 0; i
< brd
->maxports
; i
++) {
295 if (brd
->channels
[i
]) {
296 kfree(brd
->channels
[i
]->ch_rqueue
);
297 kfree(brd
->channels
[i
]->ch_equeue
);
298 kfree(brd
->channels
[i
]);
302 pci_release_regions(pdev
);
303 pci_disable_device(pdev
);
307 static struct pci_device_id jsm_pci_tbl
[] = {
308 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2DB9
), 0, 0, 0 },
309 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2DB9PRI
), 0, 0, 1 },
310 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2RJ45
), 0, 0, 2 },
311 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2RJ45PRI
), 0, 0, 3 },
312 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_4_IBM
), 0, 0, 4 },
313 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_NEO_8
), 0, 0, 5 },
314 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_4
), 0, 0, 6 },
315 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_1_422
), 0, 0, 7 },
316 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_1_422_485
), 0, 0, 8 },
317 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2_422_485
), 0, 0, 9 },
318 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_8
), 0, 0, 10 },
319 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_4
), 0, 0, 11 },
320 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_4RJ45
), 0, 0, 12 },
321 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_8RJ45
), 0, 0, 13 },
322 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_CLASSIC_4
), 0, 0, 14 },
323 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_CLASSIC_4_422
), 0, 0, 15 },
324 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_CLASSIC_8
), 0, 0, 16 },
325 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_CLASSIC_8_422
), 0, 0, 17 },
328 MODULE_DEVICE_TABLE(pci
, jsm_pci_tbl
);
330 static struct pci_driver jsm_driver
= {
331 .name
= JSM_DRIVER_NAME
,
332 .id_table
= jsm_pci_tbl
,
333 .probe
= jsm_probe_one
,
334 .remove
= jsm_remove_one
,
335 .err_handler
= &jsm_err_handler
,
338 static pci_ers_result_t
jsm_io_error_detected(struct pci_dev
*pdev
,
339 pci_channel_state_t state
)
341 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
343 jsm_remove_uart_port(brd
);
345 return PCI_ERS_RESULT_NEED_RESET
;
348 static pci_ers_result_t
jsm_io_slot_reset(struct pci_dev
*pdev
)
352 rc
= pci_enable_device(pdev
);
355 return PCI_ERS_RESULT_DISCONNECT
;
357 pci_set_master(pdev
);
359 return PCI_ERS_RESULT_RECOVERED
;
362 static void jsm_io_resume(struct pci_dev
*pdev
)
364 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
366 pci_restore_state(pdev
);
367 pci_save_state(pdev
);
369 jsm_uart_port_init(brd
);
372 static int __init
jsm_init_module(void)
376 rc
= uart_register_driver(&jsm_uart_driver
);
378 rc
= pci_register_driver(&jsm_driver
);
380 uart_unregister_driver(&jsm_uart_driver
);
385 static void __exit
jsm_exit_module(void)
387 pci_unregister_driver(&jsm_driver
);
388 uart_unregister_driver(&jsm_uart_driver
);
391 module_init(jsm_init_module
);
392 module_exit(jsm_exit_module
);