cregit-Linux how code gets into the kernel

Release 4.18 drivers/staging/dgnc/dgnc_driver.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2003 Digi International (www.digi.com)
 *      Scott H Kilau <Scott_Kilau at digi dot com>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include "dgnc_driver.h"
#include "dgnc_tty.h"
#include "dgnc_cls.h"

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Digi International, http://www.digi.com");
MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
MODULE_SUPPORTED_DEVICE("dgnc");


static unsigned int dgnc_num_boards;

struct dgnc_board		*dgnc_board[MAXBOARDS];
static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */


static int		dgnc_poll_tick = 20;	
/* Poll interval - 20 ms */

static ulong		dgnc_poll_time; 
/* Time of next poll */

static uint		dgnc_poll_stop; 
/* Used to tell poller to stop */

static struct timer_list dgnc_poll_timer;


#define DIGI_VID				0x114F

#define PCI_DEVICE_CLASSIC_4_DID		0x0028

#define PCI_DEVICE_CLASSIC_8_DID		0x0029

#define PCI_DEVICE_CLASSIC_4_422_DID		0x00D0

#define PCI_DEVICE_CLASSIC_8_422_DID		0x00D1


#define PCI_DEVICE_CLASSIC_4_PCI_NAME		"ClassicBoard 4 PCI"

#define PCI_DEVICE_CLASSIC_8_PCI_NAME		"ClassicBoard 8 PCI"

#define PCI_DEVICE_CLASSIC_4_422_PCI_NAME	"ClassicBoard 4 422 PCI"

#define PCI_DEVICE_CLASSIC_8_422_PCI_NAME	"ClassicBoard 8 422 PCI"


static const struct pci_device_id dgnc_pci_tbl[] = {
	{PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID),     .driver_data = 0},
	{PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
	{PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_DID),     .driver_data = 2},
	{PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID), .driver_data = 3},
	{0,}
};
MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);


struct board_id {
	
unsigned char *name;
	
uint maxports;
	
unsigned int is_pci_express;
};


static const struct board_id dgnc_ids[] = {
	{	PCI_DEVICE_CLASSIC_4_PCI_NAME,		4,	0	},
	{	PCI_DEVICE_CLASSIC_4_422_PCI_NAME,	4,	0	},
	{	PCI_DEVICE_CLASSIC_8_PCI_NAME,		8,	0	},
	{	PCI_DEVICE_CLASSIC_8_422_PCI_NAME,	8,	0	},
	{	NULL,					0,	0	}
};

/* Remap PCI memory. */

static int dgnc_do_remap(struct dgnc_board *brd) { brd->re_map_membase = ioremap(brd->membase, 0x1000); if (!brd->re_map_membase) return -ENOMEM; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn3181.58%133.33%
Lidza Louina410.53%133.33%
Tobin C Harding37.89%133.33%
Total38100.00%3100.00%

/* A board has been found, initialize it. */
static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id) { struct dgnc_board *brd; unsigned int pci_irq; int rc = 0; brd = kzalloc(sizeof(*brd), GFP_KERNEL); if (!brd) return ERR_PTR(-ENOMEM); /* store the info for the board we've found */ brd->boardnum = dgnc_num_boards; brd->device = dgnc_pci_tbl[id].device; brd->pdev = pdev; brd->name = dgnc_ids[id].name; brd->maxports = dgnc_ids[id].maxports; init_waitqueue_head(&brd->state_wait); spin_lock_init(&brd->bd_lock); spin_lock_init(&brd->bd_intr_lock); brd->state = BOARD_FOUND; pci_irq = pdev->irq; brd->irq = pci_irq; switch (brd->device) { case PCI_DEVICE_CLASSIC_4_DID: case PCI_DEVICE_CLASSIC_8_DID: case PCI_DEVICE_CLASSIC_4_422_DID: case PCI_DEVICE_CLASSIC_8_422_DID: /* * For PCI ClassicBoards * PCI Local Address (i.e. "resource" number) space * 0 PLX Memory Mapped Config * 1 PLX I/O Mapped Config * 2 I/O Mapped UARTs and Status * 3 Memory Mapped VPD * 4 Memory Mapped UARTs and Status */ brd->membase = pci_resource_start(pdev, 4); if (!brd->membase) { dev_err(&brd->pdev->dev, "Card has no PCI IO resources, failing.\n"); rc = -ENODEV; goto failed; } brd->membase_end = pci_resource_end(pdev, 4); if (brd->membase & 1) brd->membase &= ~3; else brd->membase &= ~15; brd->iobase = pci_resource_start(pdev, 1); brd->iobase_end = pci_resource_end(pdev, 1); brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE; brd->bd_ops = &dgnc_cls_ops; brd->bd_uart_offset = 0x8; brd->bd_dividend = 921600; rc = dgnc_do_remap(brd); if (rc < 0) goto failed; /* * Enable Local Interrupt 1 (0x1), * Local Interrupt 1 Polarity Active high (0x2), * Enable PCI interrupt (0x40) */ outb(0x43, brd->iobase + 0x4c); break; default: dev_err(&brd->pdev->dev, "Didn't find any compatible Neo/Classic PCI boards.\n"); rc = -ENXIO; goto failed; } tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long)brd); wake_up_interruptible(&brd->state_wait); return brd; failed: kfree(brd); return ERR_PTR(rc); }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn32282.35%450.00%
Lidza Louina379.46%112.50%
Konrad Zapalowicz174.35%112.50%
Alexey Khoroshilov123.07%112.50%
Sudip Mukherjee30.77%112.50%
Total391100.00%8100.00%


static int dgnc_request_irq(struct dgnc_board *brd) { if (brd->irq) { int rc = request_irq(brd->irq, brd->bd_ops->intr, IRQF_SHARED, "DGNC", brd); if (rc) { dev_err(&brd->pdev->dev, "Failed to hook IRQ %d\n", brd->irq); brd->state = BOARD_FAILED; return -ENODEV; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn3951.32%125.00%
Lidza Louina3140.79%250.00%
Tobin C Harding67.89%125.00%
Total76100.00%4100.00%


static void dgnc_free_irq(struct dgnc_board *brd) { if (brd->irq) free_irq(brd->irq, brd); }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn1557.69%150.00%
Lidza Louina1142.31%150.00%
Total26100.00%2100.00%

/* * As each timer expires, it determines (a) whether the "transmit" * waiter needs to be woken up, and (b) whether the poller needs to * be rescheduled. */
static void dgnc_poll_handler(struct timer_list *unused) { struct dgnc_board *brd; unsigned long flags; int i; unsigned long new_time; for (i = 0; i < dgnc_num_boards; i++) { brd = dgnc_board[i]; spin_lock_irqsave(&brd->bd_lock, flags); if (brd->state == BOARD_FAILED) { spin_unlock_irqrestore(&brd->bd_lock, flags); continue; } tasklet_schedule(&brd->helper_tasklet); spin_unlock_irqrestore(&brd->bd_lock, flags); } /* Schedule ourself back at the nominal wakeup interval. */ spin_lock_irqsave(&dgnc_poll_lock, flags); dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick); new_time = dgnc_poll_time - jiffies; if ((ulong)new_time >= 2 * dgnc_poll_tick) dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick); timer_setup(&dgnc_poll_timer, dgnc_poll_handler, 0); dgnc_poll_timer.expires = dgnc_poll_time; spin_unlock_irqrestore(&dgnc_poll_lock, flags); if (!dgnc_poll_stop) add_timer(&dgnc_poll_timer); }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn12470.86%125.00%
Lidza Louina4525.71%125.00%
Kees Cook52.86%125.00%
Walt Feasel10.57%125.00%
Total175100.00%4100.00%

/* returns count (>= 0), or negative on error */
static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { int rc; struct dgnc_board *brd; rc = pci_enable_device(pdev); if (rc) return -EIO; brd = dgnc_found_board(pdev, ent->driver_data); if (IS_ERR(brd)) return PTR_ERR(brd); rc = dgnc_tty_register(brd); if (rc < 0) { pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc); goto failed; } rc = dgnc_request_irq(brd); if (rc < 0) { pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc); goto unregister_tty; } rc = dgnc_tty_init(brd); if (rc < 0) { pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc); goto free_irq; } brd->state = BOARD_READY; dgnc_board[dgnc_num_boards++] = brd; return 0; free_irq: dgnc_free_irq(brd); unregister_tty: dgnc_tty_unregister(brd); failed: kfree(brd); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn13473.22%350.00%
Lidza Louina4926.78%350.00%
Total183100.00%6100.00%

static struct pci_driver dgnc_driver = { .name = "dgnc", .probe = dgnc_init_one, .id_table = dgnc_pci_tbl, };
static int dgnc_start(void) { unsigned long flags; /* Start the poller */ spin_lock_irqsave(&dgnc_poll_lock, flags); timer_setup(&dgnc_poll_timer, dgnc_poll_handler, 0); dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick); dgnc_poll_timer.expires = dgnc_poll_time; spin_unlock_irqrestore(&dgnc_poll_lock, flags); add_timer(&dgnc_poll_timer); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn4673.02%133.33%
Lidza Louina1625.40%133.33%
Kees Cook11.59%133.33%
Total63100.00%3100.00%

/* Free all the memory associated with a board */
static void dgnc_cleanup_board(struct dgnc_board *brd) { int i = 0; if (!brd) return; switch (brd->device) { case PCI_DEVICE_CLASSIC_4_DID: case PCI_DEVICE_CLASSIC_8_DID: case PCI_DEVICE_CLASSIC_4_422_DID: case PCI_DEVICE_CLASSIC_8_422_DID: /* Tell card not to interrupt anymore. */ outb(0, brd->iobase + 0x4c); break; default: break; } if (brd->irq) free_irq(brd->irq, brd); tasklet_kill(&brd->helper_tasklet); if (brd->re_map_membase) { iounmap(brd->re_map_membase); brd->re_map_membase = NULL; } for (i = 0; i < MAXPORTS ; i++) { if (brd->channels[i]) { kfree(brd->channels[i]->ch_rqueue); kfree(brd->channels[i]->ch_equeue); kfree(brd->channels[i]->ch_wqueue); kfree(brd->channels[i]); brd->channels[i] = NULL; } } dgnc_board[brd->boardnum] = NULL; kfree(brd); }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn12865.31%457.14%
Lidza Louina6332.14%114.29%
Roberta Dobrescu31.53%114.29%
Quentin Lambert21.02%114.29%
Total196100.00%7100.00%

/* Driver load/unload functions */
static void cleanup(void) { int i; unsigned long flags; spin_lock_irqsave(&dgnc_poll_lock, flags); dgnc_poll_stop = 1; spin_unlock_irqrestore(&dgnc_poll_lock, flags); /* Turn off poller right away. */ del_timer_sync(&dgnc_poll_timer); for (i = 0; i < dgnc_num_boards; ++i) { dgnc_cleanup_tty(dgnc_board[i]); dgnc_cleanup_board(dgnc_board[i]); } }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn6082.19%250.00%
Lidza Louina1216.44%125.00%
Greg Kroah-Hartman11.37%125.00%
Total73100.00%4100.00%


static void __exit dgnc_cleanup_module(void) { cleanup(); pci_unregister_driver(&dgnc_driver); }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn1161.11%250.00%
Lidza Louina633.33%125.00%
Greg Kroah-Hartman15.56%125.00%
Total18100.00%4100.00%


static int __init dgnc_init_module(void) { int rc; /* Initialize global stuff */ rc = dgnc_start(); if (rc < 0) return rc; /* Find and configure all the cards */ rc = pci_register_driver(&dgnc_driver); if (rc) { pr_warn("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n"); cleanup(); return rc; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn3053.57%120.00%
Lidza Louina2239.29%120.00%
Walt Feasel23.57%120.00%
Greg Kroah-Hartman11.79%120.00%
Roberta Dobrescu11.79%120.00%
Total56100.00%5100.00%

module_init(dgnc_init_module); module_exit(dgnc_cleanup_module);

Overall Contributors

PersonTokensPropCommitsCommitProp
DaeSeok Youn96960.60%721.88%
Lidza Louina48230.14%39.38%
Greg Kroah-Hartman462.88%721.88%
Krzysztof Adamski291.81%13.12%
Konrad Zapalowicz171.06%13.12%
Tobin C Harding120.75%26.25%
Alexey Khoroshilov120.75%13.12%
Salah Triki60.38%13.12%
Kees Cook60.38%13.12%
Walt Feasel50.31%13.12%
Roberta Dobrescu40.25%26.25%
Sudip Mukherjee30.19%13.12%
Tushar Behera30.19%13.12%
Quentin Lambert20.13%13.12%
Ebru Akagunduz20.13%13.12%
Elise Lennion10.06%13.12%
Total1599100.00%32100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.