Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Mar 24-27, 2025, special US time zones
Register
Loading...
v3.1
  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/moduleparam.h>
 28#include <linux/pci.h>
 29#include <linux/slab.h>
 30
 31#include "jsm.h"
 32
 33MODULE_AUTHOR("Digi International, http://www.digi.com");
 34MODULE_DESCRIPTION("Driver for the Digi International "
 35		   "Neo PCI based product line");
 36MODULE_LICENSE("GPL");
 37MODULE_SUPPORTED_DEVICE("jsm");
 38
 39#define JSM_DRIVER_NAME "jsm"
 40#define NR_PORTS	32
 41#define JSM_MINOR_START	0
 42
 43struct 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
 52static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
 53                                       pci_channel_state_t state);
 54static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
 55static void jsm_io_resume(struct pci_dev *pdev);
 56
 57static 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
 63int jsm_debug;
 64module_param(jsm_debug, int, 0);
 65MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
 66
 67static int __devinit 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	if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
 97		brd->maxports = 4;
 98	else if (pdev->device == PCI_DEVICE_ID_DIGI_NEO_8)
 99		brd->maxports = 8;
100	else
101		brd->maxports = 2;
102
103	spin_lock_init(&brd->bd_intr_lock);
104
105	/* store which revision we have */
106	brd->rev = pdev->revision;
107
108	brd->irq = pdev->irq;
109
110	jsm_printk(INIT, INFO, &brd->pci_dev,
111		"jsm_found_board - NEO adapter\n");
112
113	/* get the PCI Base Address Registers */
114	brd->membase	= pci_resource_start(pdev, 0);
115	brd->membase_end = pci_resource_end(pdev, 0);
116
117	if (brd->membase & 1)
118		brd->membase &= ~3;
119	else
120		brd->membase &= ~15;
121
122	/* Assign the board_ops struct */
123	brd->bd_ops = &jsm_neo_ops;
124
125	brd->bd_uart_offset = 0x200;
126	brd->bd_dividend = 921600;
127
128	brd->re_map_membase = ioremap(brd->membase, pci_resource_len(pdev, 0));
129	if (!brd->re_map_membase) {
130		dev_err(&pdev->dev,
131			"card has no PCI Memory resources, "
132			"failing board.\n");
133		rc = -ENOMEM;
134		goto out_kfree_brd;
135	}
136
137	rc = request_irq(brd->irq, brd->bd_ops->intr,
138			IRQF_SHARED, "JSM", brd);
139	if (rc) {
140		printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
141		goto out_iounmap;
142	}
143
144	rc = jsm_tty_init(brd);
145	if (rc < 0) {
146		dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
147		rc = -ENXIO;
148		goto out_free_irq;
149	}
150
151	rc = jsm_uart_port_init(brd);
152	if (rc < 0) {
153		/* XXX: leaking all resources from jsm_tty_init here! */
154		dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
155		rc = -ENXIO;
156		goto out_free_irq;
157	}
158
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);
162
163	/*
164	 * allocate flip buffer for board.
165	 *
166	 * Okay to malloc with GFP_KERNEL, we are not at interrupt
167	 * context, and there are no locks held.
168	 */
169	brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
170	if (!brd->flipbuf) {
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");
174		rc = -ENOMEM;
175		goto out_free_uart;
176	}
177
178	pci_set_drvdata(pdev, brd);
179	pci_save_state(pdev);
180
181	return 0;
182 out_free_uart:
183	jsm_remove_uart_port(brd);
184 out_free_irq:
185	jsm_remove_uart_port(brd);
186	free_irq(brd->irq, brd);
187 out_iounmap:
188	iounmap(brd->re_map_membase);
189 out_kfree_brd:
190	kfree(brd);
191 out_release_regions:
192	pci_release_regions(pdev);
193 out_disable_device:
194	pci_disable_device(pdev);
195 out:
196	return rc;
197}
198
199static void __devexit jsm_remove_one(struct pci_dev *pdev)
200{
201	struct jsm_board *brd = pci_get_drvdata(pdev);
202	int i = 0;
203
204	jsm_remove_uart_port(brd);
205
206	free_irq(brd->irq, brd);
207	iounmap(brd->re_map_membase);
208
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]);
216		}
217	}
218
219	pci_release_regions(pdev);
220	pci_disable_device(pdev);
221	kfree(brd->flipbuf);
222	kfree(brd);
223}
224
225static 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 },
232	{ 0, }
233};
234MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
235
236static struct pci_driver jsm_driver = {
237	.name		= "jsm",
238	.id_table	= jsm_pci_tbl,
239	.probe		= jsm_probe_one,
240	.remove		= __devexit_p(jsm_remove_one),
241	.err_handler    = &jsm_err_handler,
242};
243
244static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
245					pci_channel_state_t state)
246{
247	struct jsm_board *brd = pci_get_drvdata(pdev);
248
249	jsm_remove_uart_port(brd);
250
251	return PCI_ERS_RESULT_NEED_RESET;
252}
253
254static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev)
255{
256	int rc;
257
258	rc = pci_enable_device(pdev);
259
260	if (rc)
261		return PCI_ERS_RESULT_DISCONNECT;
262
263	pci_set_master(pdev);
264
265	return PCI_ERS_RESULT_RECOVERED;
266}
267
268static void jsm_io_resume(struct pci_dev *pdev)
269{
270	struct jsm_board *brd = pci_get_drvdata(pdev);
271
272	pci_restore_state(pdev);
 
273
274	jsm_uart_port_init(brd);
275}
276
277static int __init jsm_init_module(void)
278{
279	int rc;
280
281	rc = uart_register_driver(&jsm_uart_driver);
282	if (!rc) {
283		rc = pci_register_driver(&jsm_driver);
284		if (rc)
285			uart_unregister_driver(&jsm_uart_driver);
286	}
287	return rc;
288}
289
290static void __exit jsm_exit_module(void)
291{
292	pci_unregister_driver(&jsm_driver);
293	uart_unregister_driver(&jsm_uart_driver);
294}
295
296module_init(jsm_init_module);
297module_exit(jsm_exit_module);
v3.5.6
  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
 33MODULE_AUTHOR("Digi International, http://www.digi.com");
 34MODULE_DESCRIPTION("Driver for the Digi International "
 35		   "Neo PCI based product line");
 36MODULE_LICENSE("GPL");
 37MODULE_SUPPORTED_DEVICE("jsm");
 38
 39#define JSM_DRIVER_NAME "jsm"
 40#define NR_PORTS	32
 41#define JSM_MINOR_START	0
 42
 43struct 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
 52static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
 53                                       pci_channel_state_t state);
 54static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
 55static void jsm_io_resume(struct pci_dev *pdev);
 56
 57static 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
 63int jsm_debug;
 64module_param(jsm_debug, int, 0);
 65MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
 66
 67static int __devinit 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	if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
 97		brd->maxports = 4;
 98	else if (pdev->device == PCI_DEVICE_ID_DIGI_NEO_8)
 99		brd->maxports = 8;
100	else
101		brd->maxports = 2;
102
103	spin_lock_init(&brd->bd_intr_lock);
104
105	/* store which revision we have */
106	brd->rev = pdev->revision;
107
108	brd->irq = pdev->irq;
109
110	jsm_printk(INIT, INFO, &brd->pci_dev,
111		"jsm_found_board - NEO adapter\n");
112
113	/* get the PCI Base Address Registers */
114	brd->membase	= pci_resource_start(pdev, 0);
115	brd->membase_end = pci_resource_end(pdev, 0);
116
117	if (brd->membase & 1)
118		brd->membase &= ~3;
119	else
120		brd->membase &= ~15;
121
122	/* Assign the board_ops struct */
123	brd->bd_ops = &jsm_neo_ops;
124
125	brd->bd_uart_offset = 0x200;
126	brd->bd_dividend = 921600;
127
128	brd->re_map_membase = ioremap(brd->membase, pci_resource_len(pdev, 0));
129	if (!brd->re_map_membase) {
130		dev_err(&pdev->dev,
131			"card has no PCI Memory resources, "
132			"failing board.\n");
133		rc = -ENOMEM;
134		goto out_kfree_brd;
135	}
136
137	rc = request_irq(brd->irq, brd->bd_ops->intr,
138			IRQF_SHARED, "JSM", brd);
139	if (rc) {
140		printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
141		goto out_iounmap;
142	}
143
144	rc = jsm_tty_init(brd);
145	if (rc < 0) {
146		dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
147		rc = -ENXIO;
148		goto out_free_irq;
149	}
150
151	rc = jsm_uart_port_init(brd);
152	if (rc < 0) {
153		/* XXX: leaking all resources from jsm_tty_init here! */
154		dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
155		rc = -ENXIO;
156		goto out_free_irq;
157	}
158
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);
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163	pci_set_drvdata(pdev, brd);
164	pci_save_state(pdev);
165
166	return 0;
 
 
167 out_free_irq:
168	jsm_remove_uart_port(brd);
169	free_irq(brd->irq, brd);
170 out_iounmap:
171	iounmap(brd->re_map_membase);
172 out_kfree_brd:
173	kfree(brd);
174 out_release_regions:
175	pci_release_regions(pdev);
176 out_disable_device:
177	pci_disable_device(pdev);
178 out:
179	return rc;
180}
181
182static void __devexit jsm_remove_one(struct pci_dev *pdev)
183{
184	struct jsm_board *brd = pci_get_drvdata(pdev);
185	int i = 0;
186
187	jsm_remove_uart_port(brd);
188
189	free_irq(brd->irq, brd);
190	iounmap(brd->re_map_membase);
191
192	/* Free all allocated channels structs */
193	for (i = 0; i < brd->maxports; i++) {
194		if (brd->channels[i]) {
195			kfree(brd->channels[i]->ch_rqueue);
196			kfree(brd->channels[i]->ch_equeue);
 
197			kfree(brd->channels[i]);
198		}
199	}
200
201	pci_release_regions(pdev);
202	pci_disable_device(pdev);
 
203	kfree(brd);
204}
205
206static struct pci_device_id jsm_pci_tbl[] = {
207	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
208	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
209	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
210	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
211	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
212	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_NEO_8), 0, 0, 5 },
213	{ 0, }
214};
215MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
216
217static struct pci_driver jsm_driver = {
218	.name		= "jsm",
219	.id_table	= jsm_pci_tbl,
220	.probe		= jsm_probe_one,
221	.remove		= __devexit_p(jsm_remove_one),
222	.err_handler    = &jsm_err_handler,
223};
224
225static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
226					pci_channel_state_t state)
227{
228	struct jsm_board *brd = pci_get_drvdata(pdev);
229
230	jsm_remove_uart_port(brd);
231
232	return PCI_ERS_RESULT_NEED_RESET;
233}
234
235static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev)
236{
237	int rc;
238
239	rc = pci_enable_device(pdev);
240
241	if (rc)
242		return PCI_ERS_RESULT_DISCONNECT;
243
244	pci_set_master(pdev);
245
246	return PCI_ERS_RESULT_RECOVERED;
247}
248
249static void jsm_io_resume(struct pci_dev *pdev)
250{
251	struct jsm_board *brd = pci_get_drvdata(pdev);
252
253	pci_restore_state(pdev);
254	pci_save_state(pdev);
255
256	jsm_uart_port_init(brd);
257}
258
259static int __init jsm_init_module(void)
260{
261	int rc;
262
263	rc = uart_register_driver(&jsm_uart_driver);
264	if (!rc) {
265		rc = pci_register_driver(&jsm_driver);
266		if (rc)
267			uart_unregister_driver(&jsm_uart_driver);
268	}
269	return rc;
270}
271
272static void __exit jsm_exit_module(void)
273{
274	pci_unregister_driver(&jsm_driver);
275	uart_unregister_driver(&jsm_uart_driver);
276}
277
278module_init(jsm_init_module);
279module_exit(jsm_exit_module);