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 * 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,
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ibm.com>
26 ***********************************************************************/
27 #include <linux/moduleparam.h>
28 #include <linux/pci.h>
29 #include <linux/slab.h>
33 MODULE_AUTHOR("Digi International, http://www.digi.com");
34 MODULE_DESCRIPTION("Driver for the Digi International "
35 "Neo PCI based product line");
36 MODULE_LICENSE("GPL");
37 MODULE_SUPPORTED_DEVICE("jsm");
39 #define JSM_DRIVER_NAME "jsm"
41 #define JSM_MINOR_START 0
43 struct uart_driver jsm_uart_driver
= {
45 .driver_name
= JSM_DRIVER_NAME
,
48 .minor
= JSM_MINOR_START
,
52 static pci_ers_result_t
jsm_io_error_detected(struct pci_dev
*pdev
,
53 pci_channel_state_t state
);
54 static pci_ers_result_t
jsm_io_slot_reset(struct pci_dev
*pdev
);
55 static void jsm_io_resume(struct pci_dev
*pdev
);
57 static struct pci_error_handlers jsm_err_handler
= {
58 .error_detected
= jsm_io_error_detected
,
59 .slot_reset
= jsm_io_slot_reset
,
60 .resume
= jsm_io_resume
,
64 module_param(jsm_debug
, int, 0);
65 MODULE_PARM_DESC(jsm_debug
, "Driver debugging level");
67 static int __devinit
jsm_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
70 struct jsm_board
*brd
;
71 static int adapter_count
= 0;
73 rc
= pci_enable_device(pdev
);
75 dev_err(&pdev
->dev
, "Device enable FAILED\n");
79 rc
= pci_request_regions(pdev
, "jsm");
81 dev_err(&pdev
->dev
, "pci_request_region FAILED\n");
82 goto out_disable_device
;
85 brd
= kzalloc(sizeof(struct jsm_board
), GFP_KERNEL
);
88 "memory allocation for board structure failed\n");
90 goto out_release_regions
;
93 /* store the info for the board we've found */
94 brd
->boardnum
= adapter_count
++;
96 if (pdev
->device
== PCIE_DEVICE_ID_NEO_4_IBM
)
98 else if (pdev
->device
== PCI_DEVICE_ID_DIGI_NEO_8
)
103 spin_lock_init(&brd
->bd_intr_lock
);
105 /* store which revision we have */
106 brd
->rev
= pdev
->revision
;
108 brd
->irq
= pdev
->irq
;
110 jsm_printk(INIT
, INFO
, &brd
->pci_dev
,
111 "jsm_found_board - NEO adapter\n");
113 /* get the PCI Base Address Registers */
114 brd
->membase
= pci_resource_start(pdev
, 0);
115 brd
->membase_end
= pci_resource_end(pdev
, 0);
117 if (brd
->membase
& 1)
122 /* Assign the board_ops struct */
123 brd
->bd_ops
= &jsm_neo_ops
;
125 brd
->bd_uart_offset
= 0x200;
126 brd
->bd_dividend
= 921600;
128 brd
->re_map_membase
= ioremap(brd
->membase
, 0x1000);
129 if (!brd
->re_map_membase
) {
131 "card has no PCI Memory resources, "
137 rc
= request_irq(brd
->irq
, brd
->bd_ops
->intr
,
138 IRQF_SHARED
, "JSM", brd
);
140 printk(KERN_WARNING
"Failed to hook IRQ %d\n",brd
->irq
);
144 rc
= jsm_tty_init(brd
);
146 dev_err(&pdev
->dev
, "Can't init tty devices (%d)\n", rc
);
151 rc
= jsm_uart_port_init(brd
);
153 /* XXX: leaking all resources from jsm_tty_init here! */
154 dev_err(&pdev
->dev
, "Can't init uart port (%d)\n", rc
);
159 /* Log the information about the board */
160 dev_info(&pdev
->dev
, "board %d: Digi Neo (rev %d), irq %d\n",
161 adapter_count
, brd
->rev
, brd
->irq
);
164 * allocate flip buffer for board.
166 * Okay to malloc with GFP_KERNEL, we are not at interrupt
167 * context, and there are no locks held.
169 brd
->flipbuf
= kzalloc(MYFLIPLEN
, GFP_KERNEL
);
171 /* XXX: leaking all resources from jsm_tty_init and
172 jsm_uart_port_init here! */
173 dev_err(&pdev
->dev
, "memory allocation for flipbuf failed\n");
178 pci_set_drvdata(pdev
, brd
);
179 pci_save_state(pdev
);
183 jsm_remove_uart_port(brd
);
185 jsm_remove_uart_port(brd
);
186 free_irq(brd
->irq
, brd
);
188 iounmap(brd
->re_map_membase
);
192 pci_release_regions(pdev
);
194 pci_disable_device(pdev
);
199 static void __devexit
jsm_remove_one(struct pci_dev
*pdev
)
201 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
204 jsm_remove_uart_port(brd
);
206 free_irq(brd
->irq
, brd
);
207 iounmap(brd
->re_map_membase
);
209 /* Free all allocated channels structs */
210 for (i
= 0; i
< brd
->maxports
; i
++) {
211 if (brd
->channels
[i
]) {
212 kfree(brd
->channels
[i
]->ch_rqueue
);
213 kfree(brd
->channels
[i
]->ch_equeue
);
214 kfree(brd
->channels
[i
]->ch_wqueue
);
215 kfree(brd
->channels
[i
]);
219 pci_release_regions(pdev
);
220 pci_disable_device(pdev
);
225 static struct pci_device_id jsm_pci_tbl
[] = {
226 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2DB9
), 0, 0, 0 },
227 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2DB9PRI
), 0, 0, 1 },
228 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2RJ45
), 0, 0, 2 },
229 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_NEO_2RJ45PRI
), 0, 0, 3 },
230 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCIE_DEVICE_ID_NEO_4_IBM
), 0, 0, 4 },
231 { PCI_DEVICE(PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_NEO_8
), 0, 0, 5 },
234 MODULE_DEVICE_TABLE(pci
, jsm_pci_tbl
);
236 static struct pci_driver jsm_driver
= {
238 .id_table
= jsm_pci_tbl
,
239 .probe
= jsm_probe_one
,
240 .remove
= __devexit_p(jsm_remove_one
),
241 .err_handler
= &jsm_err_handler
,
244 static pci_ers_result_t
jsm_io_error_detected(struct pci_dev
*pdev
,
245 pci_channel_state_t state
)
247 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
249 jsm_remove_uart_port(brd
);
251 return PCI_ERS_RESULT_NEED_RESET
;
254 static pci_ers_result_t
jsm_io_slot_reset(struct pci_dev
*pdev
)
258 rc
= pci_enable_device(pdev
);
261 return PCI_ERS_RESULT_DISCONNECT
;
263 pci_set_master(pdev
);
265 return PCI_ERS_RESULT_RECOVERED
;
268 static void jsm_io_resume(struct pci_dev
*pdev
)
270 struct jsm_board
*brd
= pci_get_drvdata(pdev
);
272 pci_restore_state(pdev
);
274 jsm_uart_port_init(brd
);
277 static int __init
jsm_init_module(void)
281 rc
= uart_register_driver(&jsm_uart_driver
);
283 rc
= pci_register_driver(&jsm_driver
);
285 uart_unregister_driver(&jsm_uart_driver
);
290 static void __exit
jsm_exit_module(void)
292 pci_unregister_driver(&jsm_driver
);
293 uart_unregister_driver(&jsm_uart_driver
);
296 module_init(jsm_init_module
);
297 module_exit(jsm_exit_module
);