#define DEBUG
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/sched.h>
#include <linux/serial.h>
#include <linux/interrupt.h>
#include <linux/kmod.h>
#include <linux/init.h>
#include <linux/kfifo.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <asm/byteorder.h>
#include <linux/delay.h>
#define NOZOMI_DEBUG_LEVEL …
static int debug = …;
module_param(debug, int, S_IRUGO | S_IWUSR);
#define DBG_(lvl, fmt, args...) …
#define DBG1(args...) …
#define DBG2(args...) …
#define DBG3(args...) …
#define DBG4(args...) …
#define TMP_BUF_MAX …
#define NOZOMI_NAME …
#define NOZOMI_NAME_TTY …
#define NTTY_TTY_MAXMINORS …
#define NTTY_FIFO_BUFFER_SIZE …
#define FIFO_BUFFER_SIZE_UL …
#define SEND_BUF_MAX …
#define RECEIVE_BUF_MAX …
#define R_IIR …
#define R_FCR …
#define R_IER …
#define NOZOMI_CONFIG_MAGIC …
#define TOGGLE_VALID …
#define MDM_DL1 …
#define MDM_UL1 …
#define MDM_DL2 …
#define MDM_UL2 …
#define DIAG_DL1 …
#define DIAG_DL2 …
#define DIAG_UL …
#define APP1_DL …
#define APP1_UL …
#define APP2_DL …
#define APP2_UL …
#define CTRL_DL …
#define CTRL_UL …
#define RESET …
#define MDM_DL …
#define MDM_UL …
#define DIAG_DL …
#define CTRL_DSR …
#define CTRL_DCD …
#define CTRL_RI …
#define CTRL_CTS …
#define CTRL_DTR …
#define CTRL_RTS …
#define MAX_PORT …
#define NOZOMI_MAX_PORTS …
#define NOZOMI_MAX_CARDS …
enum card_type { … };
enum card_state { … };
enum channel_type { … };
enum ctrl_port_type { … };
enum port_type { … };
#ifdef __BIG_ENDIAN
struct toggles {
unsigned int enabled:5;
unsigned int diag_dl:1;
unsigned int mdm_dl:1;
unsigned int mdm_ul:1;
} __attribute__ ((packed));
struct config_table {
u32 signature;
u16 product_information;
u16 version;
u8 pad3[3];
struct toggles toggle;
u8 pad1[4];
u16 dl_mdm_len1;
u16 dl_start;
u16 dl_diag_len1;
u16 dl_mdm_len2;
u16 dl_app1_len;
u16 dl_diag_len2;
u16 dl_ctrl_len;
u16 dl_app2_len;
u8 pad2[16];
u16 ul_mdm_len1;
u16 ul_start;
u16 ul_diag_len;
u16 ul_mdm_len2;
u16 ul_app1_len;
u16 ul_app2_len;
u16 ul_ctrl_len;
} __attribute__ ((packed));
struct ctrl_dl {
u8 port;
unsigned int reserved:4;
unsigned int CTS:1;
unsigned int RI:1;
unsigned int DCD:1;
unsigned int DSR:1;
} __attribute__ ((packed));
struct ctrl_ul {
u8 port;
unsigned int reserved:6;
unsigned int RTS:1;
unsigned int DTR:1;
} __attribute__ ((packed));
#else
struct toggles { … } __attribute__ ((packed));
struct config_table { … } __attribute__ ((packed));
struct ctrl_dl { … } __attribute__ ((packed));
struct ctrl_ul { … } __attribute__ ((packed));
#endif
struct port { … };
struct nozomi { … };
static const struct pci_device_id nozomi_pci_tbl[] = …;
MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
static struct tty_driver *ntty_driver;
static const struct tty_port_operations noz_tty_port_ops;
static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
{ … }
static inline struct port *get_port_by_tty(const struct tty_struct *tty)
{ … }
static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
u32 size_bytes)
{ … }
static u32 write_mem32(void __iomem *mem_addr_start, const u32 *buf,
u32 size_bytes)
{ … }
static void nozomi_setup_memory(struct nozomi *dc)
{ … }
#ifdef DEBUG
static void dump_table(const struct nozomi *dc)
{ … }
#else
static inline void dump_table(const struct nozomi *dc) { }
#endif
static int nozomi_read_config_table(struct nozomi *dc)
{ … }
static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
{ … }
static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
{ … }
static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
{ … }
static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
{ … }
static int send_data(enum port_type index, struct nozomi *dc)
{ … }
static int receive_data(enum port_type index, struct nozomi *dc)
{ … }
#ifdef DEBUG
static char *interrupt2str(u16 interrupt)
{ … }
#endif
static int receive_flow_control(struct nozomi *dc)
{ … }
static enum ctrl_port_type port2ctrl(enum port_type port,
const struct nozomi *dc)
{ … }
static int send_flow_control(struct nozomi *dc)
{ … }
static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
u16 read_iir, u16 mask1, u16 mask2)
{ … }
static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
{ … }
static irqreturn_t interrupt_handler(int irq, void *dev_id)
{ … }
static void nozomi_get_card_type(struct nozomi *dc)
{ … }
static void nozomi_setup_private_data(struct nozomi *dc)
{ … }
static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RO(card_type);
static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RO(open_ttys);
static void make_sysfs_files(struct nozomi *dc)
{ … }
static void remove_sysfs_files(struct nozomi *dc)
{ … }
static int nozomi_card_init(struct pci_dev *pdev,
const struct pci_device_id *ent)
{ … }
static void tty_exit(struct nozomi *dc)
{ … }
static void nozomi_card_exit(struct pci_dev *pdev)
{ … }
static void set_rts(const struct tty_struct *tty, int rts)
{ … }
static void set_dtr(const struct tty_struct *tty, int dtr)
{ … }
static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
{ … }
static void ntty_cleanup(struct tty_struct *tty)
{ … }
static int ntty_activate(struct tty_port *tport, struct tty_struct *tty)
{ … }
static int ntty_open(struct tty_struct *tty, struct file *filp)
{ … }
static void ntty_shutdown(struct tty_port *tport)
{ … }
static void ntty_close(struct tty_struct *tty, struct file *filp)
{ … }
static void ntty_hangup(struct tty_struct *tty)
{ … }
static ssize_t ntty_write(struct tty_struct *tty, const u8 *buffer,
size_t count)
{ … }
static unsigned int ntty_write_room(struct tty_struct *tty)
{ … }
static int ntty_tiocmget(struct tty_struct *tty)
{ … }
static int ntty_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear)
{ … }
static int ntty_cflags_changed(struct port *port, unsigned long flags,
struct async_icount *cprev)
{ … }
static int ntty_tiocgicount(struct tty_struct *tty,
struct serial_icounter_struct *icount)
{ … }
static int ntty_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg)
{ … }
static void ntty_unthrottle(struct tty_struct *tty)
{ … }
static void ntty_throttle(struct tty_struct *tty)
{ … }
static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
{ … }
static const struct tty_port_operations noz_tty_port_ops = …;
static const struct tty_operations tty_ops = …;
static struct pci_driver nozomi_driver = …;
static __init int nozomi_init(void)
{ … }
static __exit void nozomi_exit(void)
{ … }
module_init(…) …;
module_exit(nozomi_exit);
MODULE_LICENSE(…) …;
MODULE_DESCRIPTION(…) …;