Version:  2.0.40 2.2.26 2.4.37 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18

Linux/drivers/tty/serial/jsm/jsm_driver.c

  1 /************************************************************************
  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>
 23  * Wendy Xiong   <wendyx@us.ibm.com>
 24  *
 25  *
 26  ***********************************************************************/
 27 #include <linux/module.h>
 28 #include <linux/pci.h>
 29 #include <linux/slab.h>
 30 
 31 #include "jsm.h"
 32 
 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");
 38 
 39 #define JSM_DRIVER_NAME "jsm"
 40 #define NR_PORTS        32
 41 #define JSM_MINOR_START 0
 42 
 43 struct uart_driver jsm_uart_driver = {
 44         .owner          = THIS_MODULE,
 45         .driver_name    = JSM_DRIVER_NAME,
 46         .dev_name       = "ttyn",
 47         .major          = 0,
 48         .minor          = JSM_MINOR_START,
 49         .nr             = NR_PORTS,
 50 };
 51 
 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);
 56 
 57 static const 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,
 61 };
 62 
 63 int jsm_debug;
 64 module_param(jsm_debug, int, 0);
 65 MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
 66 
 67 static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 68 {
 69         int rc = 0;
 70         struct jsm_board *brd;
 71         static int adapter_count = 0;
 72 
 73         rc = pci_enable_device(pdev);
 74         if (rc) {
 75                 dev_err(&pdev->dev, "Device enable FAILED\n");
 76                 goto out;
 77         }
 78 
 79         rc = pci_request_regions(pdev, "jsm");
 80         if (rc) {
 81                 dev_err(&pdev->dev, "pci_request_region FAILED\n");
 82                 goto out_disable_device;
 83         }
 84 
 85         brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
 86         if (!brd) {
 87                 dev_err(&pdev->dev,
 88                         "memory allocation for board structure failed\n");
 89                 rc = -ENOMEM;
 90                 goto out_release_regions;
 91         }
 92 
 93         /* store the info for the board we've found */
 94         brd->boardnum = adapter_count++;
 95         brd->pci_dev = pdev;
 96 
 97         switch (pdev->device) {
 98 
 99         case PCI_DEVICE_ID_NEO_2DB9:
100         case PCI_DEVICE_ID_NEO_2DB9PRI:
101         case PCI_DEVICE_ID_NEO_2RJ45:
102         case PCI_DEVICE_ID_NEO_2RJ45PRI:
103         case PCI_DEVICE_ID_NEO_2_422_485:
104                 brd->maxports = 2;
105                 break;
106 
107         case PCI_DEVICE_ID_NEO_4:
108         case PCIE_DEVICE_ID_NEO_4:
109         case PCIE_DEVICE_ID_NEO_4RJ45:
110         case PCIE_DEVICE_ID_NEO_4_IBM:
111                 brd->maxports = 4;
112                 break;
113 
114         case PCI_DEVICE_ID_DIGI_NEO_8:
115         case PCIE_DEVICE_ID_NEO_8:
116         case PCIE_DEVICE_ID_NEO_8RJ45:
117                 brd->maxports = 8;
118                 break;
119 
120         default:
121                 brd->maxports = 1;
122                 break;
123         }
124 
125         spin_lock_init(&brd->bd_intr_lock);
126 
127         /* store which revision we have */
128         brd->rev = pdev->revision;
129 
130         brd->irq = pdev->irq;
131 
132         jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n");
133 
134         /* get the PCI Base Address Registers */
135         brd->membase    = pci_resource_start(pdev, 0);
136         brd->membase_end = pci_resource_end(pdev, 0);
137 
138         if (brd->membase & 1)
139                 brd->membase &= ~3;
140         else
141                 brd->membase &= ~15;
142 
143         /* Assign the board_ops struct */
144         brd->bd_ops = &jsm_neo_ops;
145 
146         brd->bd_uart_offset = 0x200;
147         brd->bd_dividend = 921600;
148 
149         brd->re_map_membase = ioremap(brd->membase, pci_resource_len(pdev, 0));
150         if (!brd->re_map_membase) {
151                 dev_err(&pdev->dev,
152                         "card has no PCI Memory resources, "
153                         "failing board.\n");
154                 rc = -ENOMEM;
155                 goto out_kfree_brd;
156         }
157 
158         rc = request_irq(brd->irq, brd->bd_ops->intr,
159                         IRQF_SHARED, "JSM", brd);
160         if (rc) {
161                 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
162                 goto out_iounmap;
163         }
164 
165         rc = jsm_tty_init(brd);
166         if (rc < 0) {
167                 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
168                 rc = -ENXIO;
169                 goto out_free_irq;
170         }
171 
172         rc = jsm_uart_port_init(brd);
173         if (rc < 0) {
174                 /* XXX: leaking all resources from jsm_tty_init here! */
175                 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
176                 rc = -ENXIO;
177                 goto out_free_irq;
178         }
179 
180         /* Log the information about the board */
181         dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
182                         adapter_count, brd->rev, brd->irq);
183 
184         pci_set_drvdata(pdev, brd);
185         pci_save_state(pdev);
186 
187         return 0;
188  out_free_irq:
189         jsm_remove_uart_port(brd);
190         free_irq(brd->irq, brd);
191  out_iounmap:
192         iounmap(brd->re_map_membase);
193  out_kfree_brd:
194         kfree(brd);
195  out_release_regions:
196         pci_release_regions(pdev);
197  out_disable_device:
198         pci_disable_device(pdev);
199  out:
200         return rc;
201 }
202 
203 static void jsm_remove_one(struct pci_dev *pdev)
204 {
205         struct jsm_board *brd = pci_get_drvdata(pdev);
206         int i = 0;
207 
208         jsm_remove_uart_port(brd);
209 
210         free_irq(brd->irq, brd);
211         iounmap(brd->re_map_membase);
212 
213         /* Free all allocated channels structs */
214         for (i = 0; i < brd->maxports; i++) {
215                 if (brd->channels[i]) {
216                         kfree(brd->channels[i]->ch_rqueue);
217                         kfree(brd->channels[i]->ch_equeue);
218                         kfree(brd->channels[i]);
219                 }
220         }
221 
222         pci_release_regions(pdev);
223         pci_disable_device(pdev);
224         kfree(brd);
225 }
226 
227 static struct pci_device_id jsm_pci_tbl[] = {
228         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
229         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
230         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
231         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
232         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
233         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_NEO_8), 0, 0, 5 },
234         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_4), 0, 0, 6 },
235         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_1_422), 0, 0, 7 },
236         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_1_422_485), 0, 0, 8 },
237         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2_422_485), 0, 0, 9 },
238         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_8), 0, 0, 10 },
239         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4), 0, 0, 11 },
240         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4RJ45), 0, 0, 12 },
241         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_8RJ45), 0, 0, 13 },
242         { 0, }
243 };
244 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
245 
246 static struct pci_driver jsm_driver = {
247         .name           = "jsm",
248         .id_table       = jsm_pci_tbl,
249         .probe          = jsm_probe_one,
250         .remove         = jsm_remove_one,
251         .err_handler    = &jsm_err_handler,
252 };
253 
254 static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
255                                         pci_channel_state_t state)
256 {
257         struct jsm_board *brd = pci_get_drvdata(pdev);
258 
259         jsm_remove_uart_port(brd);
260 
261         return PCI_ERS_RESULT_NEED_RESET;
262 }
263 
264 static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev)
265 {
266         int rc;
267 
268         rc = pci_enable_device(pdev);
269 
270         if (rc)
271                 return PCI_ERS_RESULT_DISCONNECT;
272 
273         pci_set_master(pdev);
274 
275         return PCI_ERS_RESULT_RECOVERED;
276 }
277 
278 static void jsm_io_resume(struct pci_dev *pdev)
279 {
280         struct jsm_board *brd = pci_get_drvdata(pdev);
281 
282         pci_restore_state(pdev);
283         pci_save_state(pdev);
284 
285         jsm_uart_port_init(brd);
286 }
287 
288 static int __init jsm_init_module(void)
289 {
290         int rc;
291 
292         rc = uart_register_driver(&jsm_uart_driver);
293         if (!rc) {
294                 rc = pci_register_driver(&jsm_driver);
295                 if (rc)
296                         uart_unregister_driver(&jsm_uart_driver);
297         }
298         return rc;
299 }
300 
301 static void __exit jsm_exit_module(void)
302 {
303         pci_unregister_driver(&jsm_driver);
304         uart_unregister_driver(&jsm_uart_driver);
305 }
306 
307 module_init(jsm_init_module);
308 module_exit(jsm_exit_module);
309 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us