Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
0002 /*
0003  * nozomi.c  -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
0004  *
0005  * Written by: Ulf Jakobsson,
0006  *             Jan Ã…kerfeldt,
0007  *             Stefan Thomasson,
0008  *
0009  * Maintained by: Paul Hardwick (p.hardwick@option.com)
0010  *
0011  * Patches:
0012  *          Locking code changes for Vodafone by Sphere Systems Ltd,
0013  *                              Andrew Bird (ajb@spheresystems.co.uk )
0014  *                              & Phil Sanderson
0015  *
0016  * Source has been ported from an implementation made by Filip Aben @ Option
0017  *
0018  * --------------------------------------------------------------------------
0019  *
0020  * Copyright (c) 2005,2006 Option Wireless Sweden AB
0021  * Copyright (c) 2006 Sphere Systems Ltd
0022  * Copyright (c) 2006 Option Wireless n/v
0023  * All rights Reserved.
0024  *
0025  * --------------------------------------------------------------------------
0026  */
0027 
0028 /* Enable this to have a lot of debug printouts */
0029 #define DEBUG
0030 
0031 #include <linux/kernel.h>
0032 #include <linux/module.h>
0033 #include <linux/pci.h>
0034 #include <linux/ioport.h>
0035 #include <linux/tty.h>
0036 #include <linux/tty_driver.h>
0037 #include <linux/tty_flip.h>
0038 #include <linux/sched.h>
0039 #include <linux/serial.h>
0040 #include <linux/interrupt.h>
0041 #include <linux/kmod.h>
0042 #include <linux/init.h>
0043 #include <linux/kfifo.h>
0044 #include <linux/uaccess.h>
0045 #include <linux/slab.h>
0046 #include <asm/byteorder.h>
0047 
0048 #include <linux/delay.h>
0049 
0050 /* Default debug printout level */
0051 #define NOZOMI_DEBUG_LEVEL 0x00
0052 static int debug = NOZOMI_DEBUG_LEVEL;
0053 module_param(debug, int, S_IRUGO | S_IWUSR);
0054 
0055 /*    Macros definitions */
0056 #define DBG_(lvl, fmt, args...)             \
0057 do {                            \
0058     if (lvl & debug)                \
0059         pr_debug("[%d] %s(): " fmt "\n",    \
0060              __LINE__, __func__,  ##args);  \
0061 } while (0)
0062 
0063 #define DBG1(args...) DBG_(0x01, ##args)
0064 #define DBG2(args...) DBG_(0x02, ##args)
0065 #define DBG3(args...) DBG_(0x04, ##args)
0066 #define DBG4(args...) DBG_(0x08, ##args)
0067 
0068 /* TODO: rewrite to optimize macros... */
0069 
0070 #define TMP_BUF_MAX 256
0071 
0072 #define DUMP(buf__, len__)                      \
0073     do {                                \
0074         char tbuf[TMP_BUF_MAX] = {0};               \
0075         if (len__ > 1) {                    \
0076             u32 data_len = min_t(u32, len__, TMP_BUF_MAX);  \
0077             strscpy(tbuf, buf__, data_len);         \
0078             if (tbuf[data_len - 2] == '\r')         \
0079                 tbuf[data_len - 2] = 'r';       \
0080             DBG1("SENDING: '%s' (%d+n)", tbuf, len__);  \
0081         } else {                        \
0082             DBG1("SENDING: '%s' (%d)", tbuf, len__);    \
0083         }                           \
0084     } while (0)
0085 
0086 /*    Defines */
0087 #define NOZOMI_NAME     "nozomi"
0088 #define NOZOMI_NAME_TTY     "nozomi_tty"
0089 
0090 #define NTTY_TTY_MAXMINORS  256
0091 #define NTTY_FIFO_BUFFER_SIZE   8192
0092 
0093 /* Must be power of 2 */
0094 #define FIFO_BUFFER_SIZE_UL 8192
0095 
0096 /* Size of tmp send buffer to card */
0097 #define SEND_BUF_MAX        1024
0098 #define RECEIVE_BUF_MAX     4
0099 
0100 
0101 #define R_IIR           0x0000  /* Interrupt Identity Register */
0102 #define R_FCR           0x0000  /* Flow Control Register */
0103 #define R_IER           0x0004  /* Interrupt Enable Register */
0104 
0105 #define NOZOMI_CONFIG_MAGIC 0xEFEFFEFE
0106 #define TOGGLE_VALID        0x0000
0107 
0108 /* Definition of interrupt tokens */
0109 #define MDM_DL1         0x0001
0110 #define MDM_UL1         0x0002
0111 #define MDM_DL2         0x0004
0112 #define MDM_UL2         0x0008
0113 #define DIAG_DL1        0x0010
0114 #define DIAG_DL2        0x0020
0115 #define DIAG_UL         0x0040
0116 #define APP1_DL         0x0080
0117 #define APP1_UL         0x0100
0118 #define APP2_DL         0x0200
0119 #define APP2_UL         0x0400
0120 #define CTRL_DL         0x0800
0121 #define CTRL_UL         0x1000
0122 #define RESET           0x8000
0123 
0124 #define MDM_DL          (MDM_DL1  | MDM_DL2)
0125 #define MDM_UL          (MDM_UL1  | MDM_UL2)
0126 #define DIAG_DL         (DIAG_DL1 | DIAG_DL2)
0127 
0128 /* modem signal definition */
0129 #define CTRL_DSR        0x0001
0130 #define CTRL_DCD        0x0002
0131 #define CTRL_RI         0x0004
0132 #define CTRL_CTS        0x0008
0133 
0134 #define CTRL_DTR        0x0001
0135 #define CTRL_RTS        0x0002
0136 
0137 #define MAX_PORT        4
0138 #define NOZOMI_MAX_PORTS    5
0139 #define NOZOMI_MAX_CARDS    (NTTY_TTY_MAXMINORS / MAX_PORT)
0140 
0141 /*    Type definitions */
0142 
0143 /*
0144  * There are two types of nozomi cards,
0145  * one with 2048 memory and with 8192 memory
0146  */
0147 enum card_type {
0148     F32_2 = 2048,   /* 512 bytes downlink + uplink * 2 -> 2048 */
0149     F32_8 = 8192,   /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
0150 };
0151 
0152 /* Initialization states a card can be in */
0153 enum card_state {
0154     NOZOMI_STATE_UNKNOWN    = 0,
0155     NOZOMI_STATE_ENABLED    = 1,    /* pci device enabled */
0156     NOZOMI_STATE_ALLOCATED  = 2,    /* config setup done */
0157     NOZOMI_STATE_READY  = 3,    /* flowcontrols received */
0158 };
0159 
0160 /* Two different toggle channels exist */
0161 enum channel_type {
0162     CH_A = 0,
0163     CH_B = 1,
0164 };
0165 
0166 /* Port definition for the card regarding flow control */
0167 enum ctrl_port_type {
0168     CTRL_CMD    = 0,
0169     CTRL_MDM    = 1,
0170     CTRL_DIAG   = 2,
0171     CTRL_APP1   = 3,
0172     CTRL_APP2   = 4,
0173     CTRL_ERROR  = -1,
0174 };
0175 
0176 /* Ports that the nozomi has */
0177 enum port_type {
0178     PORT_MDM    = 0,
0179     PORT_DIAG   = 1,
0180     PORT_APP1   = 2,
0181     PORT_APP2   = 3,
0182     PORT_CTRL   = 4,
0183     PORT_ERROR  = -1,
0184 };
0185 
0186 #ifdef __BIG_ENDIAN
0187 /* Big endian */
0188 
0189 struct toggles {
0190     unsigned int enabled:5; /*
0191                  * Toggle fields are valid if enabled is 0,
0192                  * else A-channels must always be used.
0193                  */
0194     unsigned int diag_dl:1;
0195     unsigned int mdm_dl:1;
0196     unsigned int mdm_ul:1;
0197 } __attribute__ ((packed));
0198 
0199 /* Configuration table to read at startup of card */
0200 /* Is for now only needed during initialization phase */
0201 struct config_table {
0202     u32 signature;
0203     u16 product_information;
0204     u16 version;
0205     u8 pad3[3];
0206     struct toggles toggle;
0207     u8 pad1[4];
0208     u16 dl_mdm_len1;    /*
0209                  * If this is 64, it can hold
0210                  * 60 bytes + 4 that is length field
0211                  */
0212     u16 dl_start;
0213 
0214     u16 dl_diag_len1;
0215     u16 dl_mdm_len2;    /*
0216                  * If this is 64, it can hold
0217                  * 60 bytes + 4 that is length field
0218                  */
0219     u16 dl_app1_len;
0220 
0221     u16 dl_diag_len2;
0222     u16 dl_ctrl_len;
0223     u16 dl_app2_len;
0224     u8 pad2[16];
0225     u16 ul_mdm_len1;
0226     u16 ul_start;
0227     u16 ul_diag_len;
0228     u16 ul_mdm_len2;
0229     u16 ul_app1_len;
0230     u16 ul_app2_len;
0231     u16 ul_ctrl_len;
0232 } __attribute__ ((packed));
0233 
0234 /* This stores all control downlink flags */
0235 struct ctrl_dl {
0236     u8 port;
0237     unsigned int reserved:4;
0238     unsigned int CTS:1;
0239     unsigned int RI:1;
0240     unsigned int DCD:1;
0241     unsigned int DSR:1;
0242 } __attribute__ ((packed));
0243 
0244 /* This stores all control uplink flags */
0245 struct ctrl_ul {
0246     u8 port;
0247     unsigned int reserved:6;
0248     unsigned int RTS:1;
0249     unsigned int DTR:1;
0250 } __attribute__ ((packed));
0251 
0252 #else
0253 /* Little endian */
0254 
0255 /* This represents the toggle information */
0256 struct toggles {
0257     unsigned int mdm_ul:1;
0258     unsigned int mdm_dl:1;
0259     unsigned int diag_dl:1;
0260     unsigned int enabled:5; /*
0261                  * Toggle fields are valid if enabled is 0,
0262                  * else A-channels must always be used.
0263                  */
0264 } __attribute__ ((packed));
0265 
0266 /* Configuration table to read at startup of card */
0267 struct config_table {
0268     u32 signature;
0269     u16 version;
0270     u16 product_information;
0271     struct toggles toggle;
0272     u8 pad1[7];
0273     u16 dl_start;
0274     u16 dl_mdm_len1;    /*
0275                  * If this is 64, it can hold
0276                  * 60 bytes + 4 that is length field
0277                  */
0278     u16 dl_mdm_len2;
0279     u16 dl_diag_len1;
0280     u16 dl_diag_len2;
0281     u16 dl_app1_len;
0282     u16 dl_app2_len;
0283     u16 dl_ctrl_len;
0284     u8 pad2[16];
0285     u16 ul_start;
0286     u16 ul_mdm_len2;
0287     u16 ul_mdm_len1;
0288     u16 ul_diag_len;
0289     u16 ul_app1_len;
0290     u16 ul_app2_len;
0291     u16 ul_ctrl_len;
0292 } __attribute__ ((packed));
0293 
0294 /* This stores all control downlink flags */
0295 struct ctrl_dl {
0296     unsigned int DSR:1;
0297     unsigned int DCD:1;
0298     unsigned int RI:1;
0299     unsigned int CTS:1;
0300     unsigned int reserved:4;
0301     u8 port;
0302 } __attribute__ ((packed));
0303 
0304 /* This stores all control uplink flags */
0305 struct ctrl_ul {
0306     unsigned int DTR:1;
0307     unsigned int RTS:1;
0308     unsigned int reserved:6;
0309     u8 port;
0310 } __attribute__ ((packed));
0311 #endif
0312 
0313 /* This holds all information that is needed regarding a port */
0314 struct port {
0315     struct tty_port port;
0316     u8 update_flow_control;
0317     struct ctrl_ul ctrl_ul;
0318     struct ctrl_dl ctrl_dl;
0319     struct kfifo fifo_ul;
0320     void __iomem *dl_addr[2];
0321     u32 dl_size[2];
0322     u8 toggle_dl;
0323     void __iomem *ul_addr[2];
0324     u32 ul_size[2];
0325     u8 toggle_ul;
0326     u16 token_dl;
0327 
0328     wait_queue_head_t tty_wait;
0329     struct async_icount tty_icount;
0330 
0331     struct nozomi *dc;
0332 };
0333 
0334 /* Private data one for each card in the system */
0335 struct nozomi {
0336     void __iomem *base_addr;
0337     unsigned long flip;
0338 
0339     /* Pointers to registers */
0340     void __iomem *reg_iir;
0341     void __iomem *reg_fcr;
0342     void __iomem *reg_ier;
0343 
0344     u16 last_ier;
0345     enum card_type card_type;
0346     struct config_table config_table;   /* Configuration table */
0347     struct pci_dev *pdev;
0348     struct port port[NOZOMI_MAX_PORTS];
0349     u8 *send_buf;
0350 
0351     spinlock_t spin_mutex;  /* secures access to registers and tty */
0352 
0353     unsigned int index_start;
0354     enum card_state state;
0355     u32 open_ttys;
0356 };
0357 
0358 /* Global variables */
0359 static const struct pci_device_id nozomi_pci_tbl[] = {
0360     {PCI_DEVICE(0x1931, 0x000c)},   /* Nozomi HSDPA */
0361     {},
0362 };
0363 
0364 MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
0365 
0366 static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
0367 static struct tty_driver *ntty_driver;
0368 
0369 static const struct tty_port_operations noz_tty_port_ops;
0370 
0371 /*
0372  * find card by tty_index
0373  */
0374 static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
0375 {
0376     return tty ? ndevs[tty->index / MAX_PORT] : NULL;
0377 }
0378 
0379 static inline struct port *get_port_by_tty(const struct tty_struct *tty)
0380 {
0381     struct nozomi *ndev = get_dc_by_tty(tty);
0382     return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL;
0383 }
0384 
0385 /*
0386  * TODO:
0387  * -Optimize
0388  * -Rewrite cleaner
0389  */
0390 
0391 static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
0392             u32 size_bytes)
0393 {
0394     u32 i = 0;
0395     const u32 __iomem *ptr = mem_addr_start;
0396     u16 *buf16;
0397 
0398     if (unlikely(!ptr || !buf))
0399         goto out;
0400 
0401     /* shortcut for extremely often used cases */
0402     switch (size_bytes) {
0403     case 2: /* 2 bytes */
0404         buf16 = (u16 *) buf;
0405         *buf16 = __le16_to_cpu(readw(ptr));
0406         goto out;
0407     case 4: /* 4 bytes */
0408         *(buf) = __le32_to_cpu(readl(ptr));
0409         goto out;
0410     }
0411 
0412     while (i < size_bytes) {
0413         if (size_bytes - i == 2) {
0414             /* Handle 2 bytes in the end */
0415             buf16 = (u16 *) buf;
0416             *(buf16) = __le16_to_cpu(readw(ptr));
0417             i += 2;
0418         } else {
0419             /* Read 4 bytes */
0420             *(buf) = __le32_to_cpu(readl(ptr));
0421             i += 4;
0422         }
0423         buf++;
0424         ptr++;
0425     }
0426 out:
0427     return;
0428 }
0429 
0430 /*
0431  * TODO:
0432  * -Optimize
0433  * -Rewrite cleaner
0434  */
0435 static u32 write_mem32(void __iomem *mem_addr_start, const u32 *buf,
0436             u32 size_bytes)
0437 {
0438     u32 i = 0;
0439     u32 __iomem *ptr = mem_addr_start;
0440     const u16 *buf16;
0441 
0442     if (unlikely(!ptr || !buf))
0443         return 0;
0444 
0445     /* shortcut for extremely often used cases */
0446     switch (size_bytes) {
0447     case 2: /* 2 bytes */
0448         buf16 = (const u16 *)buf;
0449         writew(__cpu_to_le16(*buf16), ptr);
0450         return 2;
0451     case 1: /*
0452          * also needs to write 4 bytes in this case
0453          * so falling through..
0454          */
0455         fallthrough;
0456     case 4: /* 4 bytes */
0457         writel(__cpu_to_le32(*buf), ptr);
0458         return 4;
0459     }
0460 
0461     while (i < size_bytes) {
0462         if (size_bytes - i == 2) {
0463             /* 2 bytes */
0464             buf16 = (const u16 *)buf;
0465             writew(__cpu_to_le16(*buf16), ptr);
0466             i += 2;
0467         } else {
0468             /* 4 bytes */
0469             writel(__cpu_to_le32(*buf), ptr);
0470             i += 4;
0471         }
0472         buf++;
0473         ptr++;
0474     }
0475     return i;
0476 }
0477 
0478 /* Setup pointers to different channels and also setup buffer sizes. */
0479 static void nozomi_setup_memory(struct nozomi *dc)
0480 {
0481     void __iomem *offset = dc->base_addr + dc->config_table.dl_start;
0482     /* The length reported is including the length field of 4 bytes,
0483      * hence subtract with 4.
0484      */
0485     const u16 buff_offset = 4;
0486 
0487     /* Modem port dl configuration */
0488     dc->port[PORT_MDM].dl_addr[CH_A] = offset;
0489     dc->port[PORT_MDM].dl_addr[CH_B] =
0490                 (offset += dc->config_table.dl_mdm_len1);
0491     dc->port[PORT_MDM].dl_size[CH_A] =
0492                 dc->config_table.dl_mdm_len1 - buff_offset;
0493     dc->port[PORT_MDM].dl_size[CH_B] =
0494                 dc->config_table.dl_mdm_len2 - buff_offset;
0495 
0496     /* Diag port dl configuration */
0497     dc->port[PORT_DIAG].dl_addr[CH_A] =
0498                 (offset += dc->config_table.dl_mdm_len2);
0499     dc->port[PORT_DIAG].dl_size[CH_A] =
0500                 dc->config_table.dl_diag_len1 - buff_offset;
0501     dc->port[PORT_DIAG].dl_addr[CH_B] =
0502                 (offset += dc->config_table.dl_diag_len1);
0503     dc->port[PORT_DIAG].dl_size[CH_B] =
0504                 dc->config_table.dl_diag_len2 - buff_offset;
0505 
0506     /* App1 port dl configuration */
0507     dc->port[PORT_APP1].dl_addr[CH_A] =
0508                 (offset += dc->config_table.dl_diag_len2);
0509     dc->port[PORT_APP1].dl_size[CH_A] =
0510                 dc->config_table.dl_app1_len - buff_offset;
0511 
0512     /* App2 port dl configuration */
0513     dc->port[PORT_APP2].dl_addr[CH_A] =
0514                 (offset += dc->config_table.dl_app1_len);
0515     dc->port[PORT_APP2].dl_size[CH_A] =
0516                 dc->config_table.dl_app2_len - buff_offset;
0517 
0518     /* Ctrl dl configuration */
0519     dc->port[PORT_CTRL].dl_addr[CH_A] =
0520                 (offset += dc->config_table.dl_app2_len);
0521     dc->port[PORT_CTRL].dl_size[CH_A] =
0522                 dc->config_table.dl_ctrl_len - buff_offset;
0523 
0524     offset = dc->base_addr + dc->config_table.ul_start;
0525 
0526     /* Modem Port ul configuration */
0527     dc->port[PORT_MDM].ul_addr[CH_A] = offset;
0528     dc->port[PORT_MDM].ul_size[CH_A] =
0529                 dc->config_table.ul_mdm_len1 - buff_offset;
0530     dc->port[PORT_MDM].ul_addr[CH_B] =
0531                 (offset += dc->config_table.ul_mdm_len1);
0532     dc->port[PORT_MDM].ul_size[CH_B] =
0533                 dc->config_table.ul_mdm_len2 - buff_offset;
0534 
0535     /* Diag port ul configuration */
0536     dc->port[PORT_DIAG].ul_addr[CH_A] =
0537                 (offset += dc->config_table.ul_mdm_len2);
0538     dc->port[PORT_DIAG].ul_size[CH_A] =
0539                 dc->config_table.ul_diag_len - buff_offset;
0540 
0541     /* App1 port ul configuration */
0542     dc->port[PORT_APP1].ul_addr[CH_A] =
0543                 (offset += dc->config_table.ul_diag_len);
0544     dc->port[PORT_APP1].ul_size[CH_A] =
0545                 dc->config_table.ul_app1_len - buff_offset;
0546 
0547     /* App2 port ul configuration */
0548     dc->port[PORT_APP2].ul_addr[CH_A] =
0549                 (offset += dc->config_table.ul_app1_len);
0550     dc->port[PORT_APP2].ul_size[CH_A] =
0551                 dc->config_table.ul_app2_len - buff_offset;
0552 
0553     /* Ctrl ul configuration */
0554     dc->port[PORT_CTRL].ul_addr[CH_A] =
0555                 (offset += dc->config_table.ul_app2_len);
0556     dc->port[PORT_CTRL].ul_size[CH_A] =
0557                 dc->config_table.ul_ctrl_len - buff_offset;
0558 }
0559 
0560 /* Dump config table under initalization phase */
0561 #ifdef DEBUG
0562 static void dump_table(const struct nozomi *dc)
0563 {
0564     DBG3("signature: 0x%08X", dc->config_table.signature);
0565     DBG3("version: 0x%04X", dc->config_table.version);
0566     DBG3("product_information: 0x%04X", \
0567                 dc->config_table.product_information);
0568     DBG3("toggle enabled: %d", dc->config_table.toggle.enabled);
0569     DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul);
0570     DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl);
0571     DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl);
0572 
0573     DBG3("dl_start: 0x%04X", dc->config_table.dl_start);
0574     DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1,
0575        dc->config_table.dl_mdm_len1);
0576     DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2,
0577        dc->config_table.dl_mdm_len2);
0578     DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1,
0579        dc->config_table.dl_diag_len1);
0580     DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2,
0581        dc->config_table.dl_diag_len2);
0582     DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len,
0583        dc->config_table.dl_app1_len);
0584     DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len,
0585        dc->config_table.dl_app2_len);
0586     DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len,
0587        dc->config_table.dl_ctrl_len);
0588     DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start,
0589        dc->config_table.ul_start);
0590     DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1,
0591        dc->config_table.ul_mdm_len1);
0592     DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2,
0593        dc->config_table.ul_mdm_len2);
0594     DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len,
0595        dc->config_table.ul_diag_len);
0596     DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len,
0597        dc->config_table.ul_app1_len);
0598     DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len,
0599        dc->config_table.ul_app2_len);
0600     DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len,
0601        dc->config_table.ul_ctrl_len);
0602 }
0603 #else
0604 static inline void dump_table(const struct nozomi *dc) { }
0605 #endif
0606 
0607 /*
0608  * Read configuration table from card under intalization phase
0609  * Returns 1 if ok, else 0
0610  */
0611 static int nozomi_read_config_table(struct nozomi *dc)
0612 {
0613     read_mem32((u32 *) &dc->config_table, dc->base_addr + 0,
0614                         sizeof(struct config_table));
0615 
0616     if (dc->config_table.signature != NOZOMI_CONFIG_MAGIC) {
0617         dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n",
0618             dc->config_table.signature, NOZOMI_CONFIG_MAGIC);
0619         return 0;
0620     }
0621 
0622     if ((dc->config_table.version == 0)
0623         || (dc->config_table.toggle.enabled == TOGGLE_VALID)) {
0624         int i;
0625         DBG1("Second phase, configuring card");
0626 
0627         nozomi_setup_memory(dc);
0628 
0629         dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul;
0630         dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl;
0631         dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl;
0632         DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
0633            dc->port[PORT_MDM].toggle_ul,
0634            dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl);
0635 
0636         dump_table(dc);
0637 
0638         for (i = PORT_MDM; i < MAX_PORT; i++) {
0639             memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
0640             memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
0641         }
0642 
0643         /* Enable control channel */
0644         dc->last_ier = dc->last_ier | CTRL_DL;
0645         writew(dc->last_ier, dc->reg_ier);
0646 
0647         dc->state = NOZOMI_STATE_ALLOCATED;
0648         dev_info(&dc->pdev->dev, "Initialization OK!\n");
0649         return 1;
0650     }
0651 
0652     if ((dc->config_table.version > 0)
0653         && (dc->config_table.toggle.enabled != TOGGLE_VALID)) {
0654         u32 offset = 0;
0655         DBG1("First phase: pushing upload buffers, clearing download");
0656 
0657         dev_info(&dc->pdev->dev, "Version of card: %d\n",
0658              dc->config_table.version);
0659 
0660         /* Here we should disable all I/O over F32. */
0661         nozomi_setup_memory(dc);
0662 
0663         /*
0664          * We should send ALL channel pair tokens back along
0665          * with reset token
0666          */
0667 
0668         /* push upload modem buffers */
0669         write_mem32(dc->port[PORT_MDM].ul_addr[CH_A],
0670             (u32 *) &offset, 4);
0671         write_mem32(dc->port[PORT_MDM].ul_addr[CH_B],
0672             (u32 *) &offset, 4);
0673 
0674         writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr);
0675 
0676         DBG1("First phase done");
0677     }
0678 
0679     return 1;
0680 }
0681 
0682 /* Enable uplink interrupts  */
0683 static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
0684 {
0685     static const u16 mask[] = {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
0686 
0687     if (port < NOZOMI_MAX_PORTS) {
0688         dc->last_ier |= mask[port];
0689         writew(dc->last_ier, dc->reg_ier);
0690     } else {
0691         dev_err(&dc->pdev->dev, "Called with wrong port?\n");
0692     }
0693 }
0694 
0695 /* Disable uplink interrupts  */
0696 static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
0697 {
0698     static const u16 mask[] =
0699         {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
0700 
0701     if (port < NOZOMI_MAX_PORTS) {
0702         dc->last_ier &= mask[port];
0703         writew(dc->last_ier, dc->reg_ier);
0704     } else {
0705         dev_err(&dc->pdev->dev, "Called with wrong port?\n");
0706     }
0707 }
0708 
0709 /* Enable downlink interrupts */
0710 static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
0711 {
0712     static const u16 mask[] = {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
0713 
0714     if (port < NOZOMI_MAX_PORTS) {
0715         dc->last_ier |= mask[port];
0716         writew(dc->last_ier, dc->reg_ier);
0717     } else {
0718         dev_err(&dc->pdev->dev, "Called with wrong port?\n");
0719     }
0720 }
0721 
0722 /* Disable downlink interrupts */
0723 static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
0724 {
0725     static const u16 mask[] =
0726         {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
0727 
0728     if (port < NOZOMI_MAX_PORTS) {
0729         dc->last_ier &= mask[port];
0730         writew(dc->last_ier, dc->reg_ier);
0731     } else {
0732         dev_err(&dc->pdev->dev, "Called with wrong port?\n");
0733     }
0734 }
0735 
0736 /*
0737  * Return 1 - send buffer to card and ack.
0738  * Return 0 - don't ack, don't send buffer to card.
0739  */
0740 static int send_data(enum port_type index, struct nozomi *dc)
0741 {
0742     u32 size = 0;
0743     struct port *port = &dc->port[index];
0744     const u8 toggle = port->toggle_ul;
0745     void __iomem *addr = port->ul_addr[toggle];
0746     const u32 ul_size = port->ul_size[toggle];
0747 
0748     /* Get data from tty and place in buf for now */
0749     size = kfifo_out(&port->fifo_ul, dc->send_buf,
0750                ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
0751 
0752     if (size == 0) {
0753         DBG4("No more data to send, disable link:");
0754         return 0;
0755     }
0756 
0757     /* DUMP(buf, size); */
0758 
0759     /* Write length + data */
0760     write_mem32(addr, (u32 *) &size, 4);
0761     write_mem32(addr + 4, (u32 *) dc->send_buf, size);
0762 
0763     tty_port_tty_wakeup(&port->port);
0764 
0765     return 1;
0766 }
0767 
0768 /* If all data has been read, return 1, else 0 */
0769 static int receive_data(enum port_type index, struct nozomi *dc)
0770 {
0771     u8 buf[RECEIVE_BUF_MAX] = { 0 };
0772     int size;
0773     u32 offset = 4;
0774     struct port *port = &dc->port[index];
0775     void __iomem *addr = port->dl_addr[port->toggle_dl];
0776     struct tty_struct *tty = tty_port_tty_get(&port->port);
0777     int i, ret;
0778 
0779     size = __le32_to_cpu(readl(addr));
0780 
0781     if (tty && tty_throttled(tty)) {
0782         DBG1("No room in tty, don't read data, don't ack interrupt, "
0783             "disable interrupt");
0784 
0785         /* disable interrupt in downlink... */
0786         disable_transmit_dl(index, dc);
0787         ret = 0;
0788         goto put;
0789     }
0790 
0791     if (unlikely(size == 0)) {
0792         dev_err(&dc->pdev->dev, "size == 0?\n");
0793         ret = 1;
0794         goto put;
0795     }
0796 
0797     while (size > 0) {
0798         read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
0799 
0800         if (size == 1) {
0801             tty_insert_flip_char(&port->port, buf[0], TTY_NORMAL);
0802             size = 0;
0803         } else if (size < RECEIVE_BUF_MAX) {
0804             size -= tty_insert_flip_string(&port->port,
0805                     (char *)buf, size);
0806         } else {
0807             i = tty_insert_flip_string(&port->port,
0808                     (char *)buf, RECEIVE_BUF_MAX);
0809             size -= i;
0810             offset += i;
0811         }
0812     }
0813 
0814     set_bit(index, &dc->flip);
0815     ret = 1;
0816 put:
0817     tty_kref_put(tty);
0818     return ret;
0819 }
0820 
0821 /* Debug for interrupts */
0822 #ifdef DEBUG
0823 static char *interrupt2str(u16 interrupt)
0824 {
0825     static char buf[TMP_BUF_MAX];
0826     char *p = buf;
0827 
0828     if (interrupt & MDM_DL1)
0829         p += scnprintf(p, TMP_BUF_MAX, "MDM_DL1 ");
0830     if (interrupt & MDM_DL2)
0831         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_DL2 ");
0832     if (interrupt & MDM_UL1)
0833         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL1 ");
0834     if (interrupt & MDM_UL2)
0835         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL2 ");
0836     if (interrupt & DIAG_DL1)
0837         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL1 ");
0838     if (interrupt & DIAG_DL2)
0839         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL2 ");
0840 
0841     if (interrupt & DIAG_UL)
0842         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_UL ");
0843 
0844     if (interrupt & APP1_DL)
0845         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_DL ");
0846     if (interrupt & APP2_DL)
0847         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_DL ");
0848 
0849     if (interrupt & APP1_UL)
0850         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_UL ");
0851     if (interrupt & APP2_UL)
0852         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_UL ");
0853 
0854     if (interrupt & CTRL_DL)
0855         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_DL ");
0856     if (interrupt & CTRL_UL)
0857         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_UL ");
0858 
0859     if (interrupt & RESET)
0860         p += scnprintf(p, TMP_BUF_MAX - (p - buf), "RESET ");
0861 
0862     return buf;
0863 }
0864 #endif
0865 
0866 /*
0867  * Receive flow control
0868  * Return 1 - If ok, else 0
0869  */
0870 static int receive_flow_control(struct nozomi *dc)
0871 {
0872     enum port_type port = PORT_MDM;
0873     struct ctrl_dl ctrl_dl;
0874     struct ctrl_dl old_ctrl;
0875     u16 enable_ier = 0;
0876 
0877     read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2);
0878 
0879     switch (ctrl_dl.port) {
0880     case CTRL_CMD:
0881         DBG1("The Base Band sends this value as a response to a "
0882             "request for IMSI detach sent over the control "
0883             "channel uplink (see section 7.6.1).");
0884         break;
0885     case CTRL_MDM:
0886         port = PORT_MDM;
0887         enable_ier = MDM_DL;
0888         break;
0889     case CTRL_DIAG:
0890         port = PORT_DIAG;
0891         enable_ier = DIAG_DL;
0892         break;
0893     case CTRL_APP1:
0894         port = PORT_APP1;
0895         enable_ier = APP1_DL;
0896         break;
0897     case CTRL_APP2:
0898         port = PORT_APP2;
0899         enable_ier = APP2_DL;
0900         if (dc->state == NOZOMI_STATE_ALLOCATED) {
0901             /*
0902              * After card initialization the flow control
0903              * received for APP2 is always the last
0904              */
0905             dc->state = NOZOMI_STATE_READY;
0906             dev_info(&dc->pdev->dev, "Device READY!\n");
0907         }
0908         break;
0909     default:
0910         dev_err(&dc->pdev->dev,
0911             "ERROR: flow control received for non-existing port\n");
0912         return 0;
0913     }
0914 
0915     DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl),
0916        *((u16 *)&ctrl_dl));
0917 
0918     old_ctrl = dc->port[port].ctrl_dl;
0919     dc->port[port].ctrl_dl = ctrl_dl;
0920 
0921     if (old_ctrl.CTS == 1 && ctrl_dl.CTS == 0) {
0922         DBG1("Disable interrupt (0x%04X) on port: %d",
0923             enable_ier, port);
0924         disable_transmit_ul(port, dc);
0925 
0926     } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
0927 
0928         if (kfifo_len(&dc->port[port].fifo_ul)) {
0929             DBG1("Enable interrupt (0x%04X) on port: %d",
0930                 enable_ier, port);
0931             DBG1("Data in buffer [%d], enable transmit! ",
0932                 kfifo_len(&dc->port[port].fifo_ul));
0933             enable_transmit_ul(port, dc);
0934         } else {
0935             DBG1("No data in buffer...");
0936         }
0937     }
0938 
0939     if (*(u16 *)&old_ctrl == *(u16 *)&ctrl_dl) {
0940         DBG1(" No change in mctrl");
0941         return 1;
0942     }
0943     /* Update statistics */
0944     if (old_ctrl.CTS != ctrl_dl.CTS)
0945         dc->port[port].tty_icount.cts++;
0946     if (old_ctrl.DSR != ctrl_dl.DSR)
0947         dc->port[port].tty_icount.dsr++;
0948     if (old_ctrl.RI != ctrl_dl.RI)
0949         dc->port[port].tty_icount.rng++;
0950     if (old_ctrl.DCD != ctrl_dl.DCD)
0951         dc->port[port].tty_icount.dcd++;
0952 
0953     wake_up_interruptible(&dc->port[port].tty_wait);
0954 
0955     DBG1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
0956        port,
0957        dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts,
0958        dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr);
0959 
0960     return 1;
0961 }
0962 
0963 static enum ctrl_port_type port2ctrl(enum port_type port,
0964                     const struct nozomi *dc)
0965 {
0966     switch (port) {
0967     case PORT_MDM:
0968         return CTRL_MDM;
0969     case PORT_DIAG:
0970         return CTRL_DIAG;
0971     case PORT_APP1:
0972         return CTRL_APP1;
0973     case PORT_APP2:
0974         return CTRL_APP2;
0975     default:
0976         dev_err(&dc->pdev->dev,
0977             "ERROR: send flow control " \
0978             "received for non-existing port\n");
0979     }
0980     return CTRL_ERROR;
0981 }
0982 
0983 /*
0984  * Send flow control, can only update one channel at a time
0985  * Return 0 - If we have updated all flow control
0986  * Return 1 - If we need to update more flow control, ack current enable more
0987  */
0988 static int send_flow_control(struct nozomi *dc)
0989 {
0990     u32 i, more_flow_control_to_be_updated = 0;
0991     u16 *ctrl;
0992 
0993     for (i = PORT_MDM; i < MAX_PORT; i++) {
0994         if (dc->port[i].update_flow_control) {
0995             if (more_flow_control_to_be_updated) {
0996                 /* We have more flow control to be updated */
0997                 return 1;
0998             }
0999             dc->port[i].ctrl_ul.port = port2ctrl(i, dc);
1000             ctrl = (u16 *)&dc->port[i].ctrl_ul;
1001             write_mem32(dc->port[PORT_CTRL].ul_addr[0], \
1002                 (u32 *) ctrl, 2);
1003             dc->port[i].update_flow_control = 0;
1004             more_flow_control_to_be_updated = 1;
1005         }
1006     }
1007     return 0;
1008 }
1009 
1010 /*
1011  * Handle downlink data, ports that are handled are modem and diagnostics
1012  * Return 1 - ok
1013  * Return 0 - toggle fields are out of sync
1014  */
1015 static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
1016             u16 read_iir, u16 mask1, u16 mask2)
1017 {
1018     if (*toggle == 0 && read_iir & mask1) {
1019         if (receive_data(port, dc)) {
1020             writew(mask1, dc->reg_fcr);
1021             *toggle = !(*toggle);
1022         }
1023 
1024         if (read_iir & mask2) {
1025             if (receive_data(port, dc)) {
1026                 writew(mask2, dc->reg_fcr);
1027                 *toggle = !(*toggle);
1028             }
1029         }
1030     } else if (*toggle == 1 && read_iir & mask2) {
1031         if (receive_data(port, dc)) {
1032             writew(mask2, dc->reg_fcr);
1033             *toggle = !(*toggle);
1034         }
1035 
1036         if (read_iir & mask1) {
1037             if (receive_data(port, dc)) {
1038                 writew(mask1, dc->reg_fcr);
1039                 *toggle = !(*toggle);
1040             }
1041         }
1042     } else {
1043         dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n",
1044             *toggle);
1045         return 0;
1046     }
1047     return 1;
1048 }
1049 
1050 /*
1051  * Handle uplink data, this is currently for the modem port
1052  * Return 1 - ok
1053  * Return 0 - toggle field are out of sync
1054  */
1055 static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
1056 {
1057     u8 *toggle = &(dc->port[port].toggle_ul);
1058 
1059     if (*toggle == 0 && read_iir & MDM_UL1) {
1060         dc->last_ier &= ~MDM_UL;
1061         writew(dc->last_ier, dc->reg_ier);
1062         if (send_data(port, dc)) {
1063             writew(MDM_UL1, dc->reg_fcr);
1064             dc->last_ier = dc->last_ier | MDM_UL;
1065             writew(dc->last_ier, dc->reg_ier);
1066             *toggle = !*toggle;
1067         }
1068 
1069         if (read_iir & MDM_UL2) {
1070             dc->last_ier &= ~MDM_UL;
1071             writew(dc->last_ier, dc->reg_ier);
1072             if (send_data(port, dc)) {
1073                 writew(MDM_UL2, dc->reg_fcr);
1074                 dc->last_ier = dc->last_ier | MDM_UL;
1075                 writew(dc->last_ier, dc->reg_ier);
1076                 *toggle = !*toggle;
1077             }
1078         }
1079 
1080     } else if (*toggle == 1 && read_iir & MDM_UL2) {
1081         dc->last_ier &= ~MDM_UL;
1082         writew(dc->last_ier, dc->reg_ier);
1083         if (send_data(port, dc)) {
1084             writew(MDM_UL2, dc->reg_fcr);
1085             dc->last_ier = dc->last_ier | MDM_UL;
1086             writew(dc->last_ier, dc->reg_ier);
1087             *toggle = !*toggle;
1088         }
1089 
1090         if (read_iir & MDM_UL1) {
1091             dc->last_ier &= ~MDM_UL;
1092             writew(dc->last_ier, dc->reg_ier);
1093             if (send_data(port, dc)) {
1094                 writew(MDM_UL1, dc->reg_fcr);
1095                 dc->last_ier = dc->last_ier | MDM_UL;
1096                 writew(dc->last_ier, dc->reg_ier);
1097                 *toggle = !*toggle;
1098             }
1099         }
1100     } else {
1101         writew(read_iir & MDM_UL, dc->reg_fcr);
1102         dev_err(&dc->pdev->dev, "port out of sync!\n");
1103         return 0;
1104     }
1105     return 1;
1106 }
1107 
1108 static irqreturn_t interrupt_handler(int irq, void *dev_id)
1109 {
1110     struct nozomi *dc = dev_id;
1111     unsigned int a;
1112     u16 read_iir;
1113 
1114     if (!dc)
1115         return IRQ_NONE;
1116 
1117     spin_lock(&dc->spin_mutex);
1118     read_iir = readw(dc->reg_iir);
1119 
1120     /* Card removed */
1121     if (read_iir == (u16)-1)
1122         goto none;
1123     /*
1124      * Just handle interrupt enabled in IER
1125      * (by masking with dc->last_ier)
1126      */
1127     read_iir &= dc->last_ier;
1128 
1129     if (read_iir == 0)
1130         goto none;
1131 
1132 
1133     DBG4("%s irq:0x%04X, prev:0x%04X", interrupt2str(read_iir), read_iir,
1134         dc->last_ier);
1135 
1136     if (read_iir & RESET) {
1137         if (unlikely(!nozomi_read_config_table(dc))) {
1138             dc->last_ier = 0x0;
1139             writew(dc->last_ier, dc->reg_ier);
1140             dev_err(&dc->pdev->dev, "Could not read status from "
1141                 "card, we should disable interface\n");
1142         } else {
1143             writew(RESET, dc->reg_fcr);
1144         }
1145         /* No more useful info if this was the reset interrupt. */
1146         goto exit_handler;
1147     }
1148     if (read_iir & CTRL_UL) {
1149         DBG1("CTRL_UL");
1150         dc->last_ier &= ~CTRL_UL;
1151         writew(dc->last_ier, dc->reg_ier);
1152         if (send_flow_control(dc)) {
1153             writew(CTRL_UL, dc->reg_fcr);
1154             dc->last_ier = dc->last_ier | CTRL_UL;
1155             writew(dc->last_ier, dc->reg_ier);
1156         }
1157     }
1158     if (read_iir & CTRL_DL) {
1159         receive_flow_control(dc);
1160         writew(CTRL_DL, dc->reg_fcr);
1161     }
1162     if (read_iir & MDM_DL) {
1163         if (!handle_data_dl(dc, PORT_MDM,
1164                 &(dc->port[PORT_MDM].toggle_dl), read_iir,
1165                 MDM_DL1, MDM_DL2)) {
1166             dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n");
1167             goto exit_handler;
1168         }
1169     }
1170     if (read_iir & MDM_UL) {
1171         if (!handle_data_ul(dc, PORT_MDM, read_iir)) {
1172             dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n");
1173             goto exit_handler;
1174         }
1175     }
1176     if (read_iir & DIAG_DL) {
1177         if (!handle_data_dl(dc, PORT_DIAG,
1178                 &(dc->port[PORT_DIAG].toggle_dl), read_iir,
1179                 DIAG_DL1, DIAG_DL2)) {
1180             dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n");
1181             goto exit_handler;
1182         }
1183     }
1184     if (read_iir & DIAG_UL) {
1185         dc->last_ier &= ~DIAG_UL;
1186         writew(dc->last_ier, dc->reg_ier);
1187         if (send_data(PORT_DIAG, dc)) {
1188             writew(DIAG_UL, dc->reg_fcr);
1189             dc->last_ier = dc->last_ier | DIAG_UL;
1190             writew(dc->last_ier, dc->reg_ier);
1191         }
1192     }
1193     if (read_iir & APP1_DL) {
1194         if (receive_data(PORT_APP1, dc))
1195             writew(APP1_DL, dc->reg_fcr);
1196     }
1197     if (read_iir & APP1_UL) {
1198         dc->last_ier &= ~APP1_UL;
1199         writew(dc->last_ier, dc->reg_ier);
1200         if (send_data(PORT_APP1, dc)) {
1201             writew(APP1_UL, dc->reg_fcr);
1202             dc->last_ier = dc->last_ier | APP1_UL;
1203             writew(dc->last_ier, dc->reg_ier);
1204         }
1205     }
1206     if (read_iir & APP2_DL) {
1207         if (receive_data(PORT_APP2, dc))
1208             writew(APP2_DL, dc->reg_fcr);
1209     }
1210     if (read_iir & APP2_UL) {
1211         dc->last_ier &= ~APP2_UL;
1212         writew(dc->last_ier, dc->reg_ier);
1213         if (send_data(PORT_APP2, dc)) {
1214             writew(APP2_UL, dc->reg_fcr);
1215             dc->last_ier = dc->last_ier | APP2_UL;
1216             writew(dc->last_ier, dc->reg_ier);
1217         }
1218     }
1219 
1220 exit_handler:
1221     spin_unlock(&dc->spin_mutex);
1222 
1223     for (a = 0; a < NOZOMI_MAX_PORTS; a++)
1224         if (test_and_clear_bit(a, &dc->flip))
1225             tty_flip_buffer_push(&dc->port[a].port);
1226 
1227     return IRQ_HANDLED;
1228 none:
1229     spin_unlock(&dc->spin_mutex);
1230     return IRQ_NONE;
1231 }
1232 
1233 static void nozomi_get_card_type(struct nozomi *dc)
1234 {
1235     int i;
1236     u32 size = 0;
1237 
1238     for (i = 0; i < 6; i++)
1239         size += pci_resource_len(dc->pdev, i);
1240 
1241     /* Assume card type F32_8 if no match */
1242     dc->card_type = size == 2048 ? F32_2 : F32_8;
1243 
1244     dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type);
1245 }
1246 
1247 static void nozomi_setup_private_data(struct nozomi *dc)
1248 {
1249     void __iomem *offset = dc->base_addr + dc->card_type / 2;
1250     unsigned int i;
1251 
1252     dc->reg_fcr = (void __iomem *)(offset + R_FCR);
1253     dc->reg_iir = (void __iomem *)(offset + R_IIR);
1254     dc->reg_ier = (void __iomem *)(offset + R_IER);
1255     dc->last_ier = 0;
1256     dc->flip = 0;
1257 
1258     dc->port[PORT_MDM].token_dl = MDM_DL;
1259     dc->port[PORT_DIAG].token_dl = DIAG_DL;
1260     dc->port[PORT_APP1].token_dl = APP1_DL;
1261     dc->port[PORT_APP2].token_dl = APP2_DL;
1262 
1263     for (i = 0; i < MAX_PORT; i++)
1264         init_waitqueue_head(&dc->port[i].tty_wait);
1265 }
1266 
1267 static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
1268               char *buf)
1269 {
1270     const struct nozomi *dc = dev_get_drvdata(dev);
1271 
1272     return sprintf(buf, "%d\n", dc->card_type);
1273 }
1274 static DEVICE_ATTR_RO(card_type);
1275 
1276 static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
1277               char *buf)
1278 {
1279     const struct nozomi *dc = dev_get_drvdata(dev);
1280 
1281     return sprintf(buf, "%u\n", dc->open_ttys);
1282 }
1283 static DEVICE_ATTR_RO(open_ttys);
1284 
1285 static void make_sysfs_files(struct nozomi *dc)
1286 {
1287     if (device_create_file(&dc->pdev->dev, &dev_attr_card_type))
1288         dev_err(&dc->pdev->dev,
1289             "Could not create sysfs file for card_type\n");
1290     if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys))
1291         dev_err(&dc->pdev->dev,
1292             "Could not create sysfs file for open_ttys\n");
1293 }
1294 
1295 static void remove_sysfs_files(struct nozomi *dc)
1296 {
1297     device_remove_file(&dc->pdev->dev, &dev_attr_card_type);
1298     device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys);
1299 }
1300 
1301 /* Allocate memory for one device */
1302 static int nozomi_card_init(struct pci_dev *pdev,
1303                       const struct pci_device_id *ent)
1304 {
1305     int ret;
1306     struct nozomi *dc = NULL;
1307     int ndev_idx;
1308     int i;
1309 
1310     for (ndev_idx = 0; ndev_idx < ARRAY_SIZE(ndevs); ndev_idx++)
1311         if (!ndevs[ndev_idx])
1312             break;
1313 
1314     if (ndev_idx >= ARRAY_SIZE(ndevs)) {
1315         dev_err(&pdev->dev, "no free tty range for this card left\n");
1316         ret = -EIO;
1317         goto err;
1318     }
1319 
1320     dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL);
1321     if (unlikely(!dc)) {
1322         dev_err(&pdev->dev, "Could not allocate memory\n");
1323         ret = -ENOMEM;
1324         goto err_free;
1325     }
1326 
1327     dc->pdev = pdev;
1328 
1329     ret = pci_enable_device(dc->pdev);
1330     if (ret) {
1331         dev_err(&pdev->dev, "Failed to enable PCI Device\n");
1332         goto err_free;
1333     }
1334 
1335     ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
1336     if (ret) {
1337         dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
1338             (int) /* nozomi_private.io_addr */ 0);
1339         goto err_disable_device;
1340     }
1341 
1342     /* Find out what card type it is */
1343     nozomi_get_card_type(dc);
1344 
1345     dc->base_addr = pci_iomap(dc->pdev, 0, dc->card_type);
1346     if (!dc->base_addr) {
1347         dev_err(&pdev->dev, "Unable to map card MMIO\n");
1348         ret = -ENODEV;
1349         goto err_rel_regs;
1350     }
1351 
1352     dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
1353     if (!dc->send_buf) {
1354         dev_err(&pdev->dev, "Could not allocate send buffer?\n");
1355         ret = -ENOMEM;
1356         goto err_free_sbuf;
1357     }
1358 
1359     for (i = PORT_MDM; i < MAX_PORT; i++) {
1360         if (kfifo_alloc(&dc->port[i].fifo_ul, FIFO_BUFFER_SIZE_UL,
1361                     GFP_KERNEL)) {
1362             dev_err(&pdev->dev,
1363                     "Could not allocate kfifo buffer\n");
1364             ret = -ENOMEM;
1365             goto err_free_kfifo;
1366         }
1367     }
1368 
1369     spin_lock_init(&dc->spin_mutex);
1370 
1371     nozomi_setup_private_data(dc);
1372 
1373     /* Disable all interrupts */
1374     dc->last_ier = 0;
1375     writew(dc->last_ier, dc->reg_ier);
1376 
1377     ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED,
1378             NOZOMI_NAME, dc);
1379     if (unlikely(ret)) {
1380         dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
1381         goto err_free_all_kfifo;
1382     }
1383 
1384     DBG1("base_addr: %p", dc->base_addr);
1385 
1386     make_sysfs_files(dc);
1387 
1388     dc->index_start = ndev_idx * MAX_PORT;
1389     ndevs[ndev_idx] = dc;
1390 
1391     pci_set_drvdata(pdev, dc);
1392 
1393     /* Enable RESET interrupt */
1394     dc->last_ier = RESET;
1395     iowrite16(dc->last_ier, dc->reg_ier);
1396 
1397     dc->state = NOZOMI_STATE_ENABLED;
1398 
1399     for (i = 0; i < MAX_PORT; i++) {
1400         struct device *tty_dev;
1401         struct port *port = &dc->port[i];
1402         port->dc = dc;
1403         tty_port_init(&port->port);
1404         port->port.ops = &noz_tty_port_ops;
1405         tty_dev = tty_port_register_device(&port->port, ntty_driver,
1406                 dc->index_start + i, &pdev->dev);
1407 
1408         if (IS_ERR(tty_dev)) {
1409             ret = PTR_ERR(tty_dev);
1410             dev_err(&pdev->dev, "Could not allocate tty?\n");
1411             tty_port_destroy(&port->port);
1412             goto err_free_tty;
1413         }
1414     }
1415 
1416     return 0;
1417 
1418 err_free_tty:
1419     for (i--; i >= 0; i--) {
1420         tty_unregister_device(ntty_driver, dc->index_start + i);
1421         tty_port_destroy(&dc->port[i].port);
1422     }
1423     free_irq(pdev->irq, dc);
1424 err_free_all_kfifo:
1425     i = MAX_PORT;
1426 err_free_kfifo:
1427     for (i--; i >= PORT_MDM; i--)
1428         kfifo_free(&dc->port[i].fifo_ul);
1429 err_free_sbuf:
1430     kfree(dc->send_buf);
1431     iounmap(dc->base_addr);
1432 err_rel_regs:
1433     pci_release_regions(pdev);
1434 err_disable_device:
1435     pci_disable_device(pdev);
1436 err_free:
1437     kfree(dc);
1438 err:
1439     return ret;
1440 }
1441 
1442 static void tty_exit(struct nozomi *dc)
1443 {
1444     unsigned int i;
1445 
1446     for (i = 0; i < MAX_PORT; ++i)
1447         tty_port_tty_hangup(&dc->port[i].port, false);
1448 
1449     /* Racy below - surely should wait for scheduled work to be done or
1450        complete off a hangup method ? */
1451     while (dc->open_ttys)
1452         msleep(1);
1453     for (i = 0; i < MAX_PORT; ++i) {
1454         tty_unregister_device(ntty_driver, dc->index_start + i);
1455         tty_port_destroy(&dc->port[i].port);
1456     }
1457 }
1458 
1459 /* Deallocate memory for one device */
1460 static void nozomi_card_exit(struct pci_dev *pdev)
1461 {
1462     int i;
1463     struct ctrl_ul ctrl;
1464     struct nozomi *dc = pci_get_drvdata(pdev);
1465 
1466     /* Disable all interrupts */
1467     dc->last_ier = 0;
1468     writew(dc->last_ier, dc->reg_ier);
1469 
1470     tty_exit(dc);
1471 
1472     /* Send 0x0001, command card to resend the reset token.  */
1473     /* This is to get the reset when the module is reloaded. */
1474     ctrl.port = 0x00;
1475     ctrl.reserved = 0;
1476     ctrl.RTS = 0;
1477     ctrl.DTR = 1;
1478     DBG1("sending flow control 0x%04X", *((u16 *)&ctrl));
1479 
1480     /* Setup dc->reg addresses to we can use defines here */
1481     write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2);
1482     writew(CTRL_UL, dc->reg_fcr);   /* push the token to the card. */
1483 
1484     remove_sysfs_files(dc);
1485 
1486     free_irq(pdev->irq, dc);
1487 
1488     for (i = 0; i < MAX_PORT; i++)
1489         kfifo_free(&dc->port[i].fifo_ul);
1490 
1491     kfree(dc->send_buf);
1492 
1493     iounmap(dc->base_addr);
1494 
1495     pci_release_regions(pdev);
1496 
1497     pci_disable_device(pdev);
1498 
1499     ndevs[dc->index_start / MAX_PORT] = NULL;
1500 
1501     kfree(dc);
1502 }
1503 
1504 static void set_rts(const struct tty_struct *tty, int rts)
1505 {
1506     struct port *port = get_port_by_tty(tty);
1507 
1508     port->ctrl_ul.RTS = rts;
1509     port->update_flow_control = 1;
1510     enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
1511 }
1512 
1513 static void set_dtr(const struct tty_struct *tty, int dtr)
1514 {
1515     struct port *port = get_port_by_tty(tty);
1516 
1517     DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr);
1518 
1519     port->ctrl_ul.DTR = dtr;
1520     port->update_flow_control = 1;
1521     enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
1522 }
1523 
1524 /*
1525  * ----------------------------------------------------------------------------
1526  * TTY code
1527  * ----------------------------------------------------------------------------
1528  */
1529 
1530 static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
1531 {
1532     struct port *port = get_port_by_tty(tty);
1533     struct nozomi *dc = get_dc_by_tty(tty);
1534     int ret;
1535     if (!port || !dc || dc->state != NOZOMI_STATE_READY)
1536         return -ENODEV;
1537     ret = tty_standard_install(driver, tty);
1538     if (ret == 0)
1539         tty->driver_data = port;
1540     return ret;
1541 }
1542 
1543 static void ntty_cleanup(struct tty_struct *tty)
1544 {
1545     tty->driver_data = NULL;
1546 }
1547 
1548 static int ntty_activate(struct tty_port *tport, struct tty_struct *tty)
1549 {
1550     struct port *port = container_of(tport, struct port, port);
1551     struct nozomi *dc = port->dc;
1552     unsigned long flags;
1553 
1554     DBG1("open: %d", port->token_dl);
1555     spin_lock_irqsave(&dc->spin_mutex, flags);
1556     dc->last_ier = dc->last_ier | port->token_dl;
1557     writew(dc->last_ier, dc->reg_ier);
1558     dc->open_ttys++;
1559     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1560     printk("noz: activated %d: %p\n", tty->index, tport);
1561     return 0;
1562 }
1563 
1564 static int ntty_open(struct tty_struct *tty, struct file *filp)
1565 {
1566     struct port *port = tty->driver_data;
1567     return tty_port_open(&port->port, tty, filp);
1568 }
1569 
1570 static void ntty_shutdown(struct tty_port *tport)
1571 {
1572     struct port *port = container_of(tport, struct port, port);
1573     struct nozomi *dc = port->dc;
1574     unsigned long flags;
1575 
1576     DBG1("close: %d", port->token_dl);
1577     spin_lock_irqsave(&dc->spin_mutex, flags);
1578     dc->last_ier &= ~(port->token_dl);
1579     writew(dc->last_ier, dc->reg_ier);
1580     dc->open_ttys--;
1581     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1582     printk("noz: shutdown %p\n", tport);
1583 }
1584 
1585 static void ntty_close(struct tty_struct *tty, struct file *filp)
1586 {
1587     struct port *port = tty->driver_data;
1588     if (port)
1589         tty_port_close(&port->port, tty, filp);
1590 }
1591 
1592 static void ntty_hangup(struct tty_struct *tty)
1593 {
1594     struct port *port = tty->driver_data;
1595     tty_port_hangup(&port->port);
1596 }
1597 
1598 /*
1599  * called when the userspace process writes to the tty (/dev/noz*).
1600  * Data is inserted into a fifo, which is then read and transferred to the modem.
1601  */
1602 static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
1603               int count)
1604 {
1605     int rval = -EINVAL;
1606     struct nozomi *dc = get_dc_by_tty(tty);
1607     struct port *port = tty->driver_data;
1608     unsigned long flags;
1609 
1610     if (!dc || !port)
1611         return -ENODEV;
1612 
1613     rval = kfifo_in(&port->fifo_ul, (unsigned char *)buffer, count);
1614 
1615     spin_lock_irqsave(&dc->spin_mutex, flags);
1616     /* CTS is only valid on the modem channel */
1617     if (port == &(dc->port[PORT_MDM])) {
1618         if (port->ctrl_dl.CTS) {
1619             DBG4("Enable interrupt");
1620             enable_transmit_ul(tty->index % MAX_PORT, dc);
1621         } else {
1622             dev_err(&dc->pdev->dev,
1623                 "CTS not active on modem port?\n");
1624         }
1625     } else {
1626         enable_transmit_ul(tty->index % MAX_PORT, dc);
1627     }
1628     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1629 
1630     return rval;
1631 }
1632 
1633 /*
1634  * Calculate how much is left in device
1635  * This method is called by the upper tty layer.
1636  *   #according to sources N_TTY.c it expects a value >= 0 and
1637  *    does not check for negative values.
1638  *
1639  * If the port is unplugged report lots of room and let the bits
1640  * dribble away so we don't block anything.
1641  */
1642 static unsigned int ntty_write_room(struct tty_struct *tty)
1643 {
1644     struct port *port = tty->driver_data;
1645     unsigned int room = 4096;
1646     const struct nozomi *dc = get_dc_by_tty(tty);
1647 
1648     if (dc)
1649         room = kfifo_avail(&port->fifo_ul);
1650 
1651     return room;
1652 }
1653 
1654 /* Gets io control parameters */
1655 static int ntty_tiocmget(struct tty_struct *tty)
1656 {
1657     const struct port *port = tty->driver_data;
1658     const struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
1659     const struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
1660 
1661     /* Note: these could change under us but it is not clear this
1662        matters if so */
1663     return (ctrl_ul->RTS ? TIOCM_RTS : 0)
1664         | (ctrl_ul->DTR ? TIOCM_DTR : 0)
1665         | (ctrl_dl->DCD ? TIOCM_CAR : 0)
1666         | (ctrl_dl->RI  ? TIOCM_RNG : 0)
1667         | (ctrl_dl->DSR ? TIOCM_DSR : 0)
1668         | (ctrl_dl->CTS ? TIOCM_CTS : 0);
1669 }
1670 
1671 /* Sets io controls parameters */
1672 static int ntty_tiocmset(struct tty_struct *tty,
1673                     unsigned int set, unsigned int clear)
1674 {
1675     struct nozomi *dc = get_dc_by_tty(tty);
1676     unsigned long flags;
1677 
1678     spin_lock_irqsave(&dc->spin_mutex, flags);
1679     if (set & TIOCM_RTS)
1680         set_rts(tty, 1);
1681     else if (clear & TIOCM_RTS)
1682         set_rts(tty, 0);
1683 
1684     if (set & TIOCM_DTR)
1685         set_dtr(tty, 1);
1686     else if (clear & TIOCM_DTR)
1687         set_dtr(tty, 0);
1688     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1689 
1690     return 0;
1691 }
1692 
1693 static int ntty_cflags_changed(struct port *port, unsigned long flags,
1694         struct async_icount *cprev)
1695 {
1696     const struct async_icount cnow = port->tty_icount;
1697     int ret;
1698 
1699     ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng))
1700         || ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr))
1701         || ((flags & TIOCM_CD)  && (cnow.dcd != cprev->dcd))
1702         || ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
1703 
1704     *cprev = cnow;
1705 
1706     return ret;
1707 }
1708 
1709 static int ntty_tiocgicount(struct tty_struct *tty,
1710                 struct serial_icounter_struct *icount)
1711 {
1712     struct port *port = tty->driver_data;
1713     const struct async_icount cnow = port->tty_icount;
1714 
1715     icount->cts = cnow.cts;
1716     icount->dsr = cnow.dsr;
1717     icount->rng = cnow.rng;
1718     icount->dcd = cnow.dcd;
1719     icount->rx = cnow.rx;
1720     icount->tx = cnow.tx;
1721     icount->frame = cnow.frame;
1722     icount->overrun = cnow.overrun;
1723     icount->parity = cnow.parity;
1724     icount->brk = cnow.brk;
1725     icount->buf_overrun = cnow.buf_overrun;
1726     return 0;
1727 }
1728 
1729 static int ntty_ioctl(struct tty_struct *tty,
1730               unsigned int cmd, unsigned long arg)
1731 {
1732     struct port *port = tty->driver_data;
1733     int rval = -ENOIOCTLCMD;
1734 
1735     switch (cmd) {
1736     case TIOCMIWAIT: {
1737         struct async_icount cprev = port->tty_icount;
1738 
1739         rval = wait_event_interruptible(port->tty_wait,
1740                 ntty_cflags_changed(port, arg, &cprev));
1741         break;
1742     }
1743     default:
1744         DBG1("ERR: 0x%08X, %d", cmd, cmd);
1745         break;
1746     }
1747 
1748     return rval;
1749 }
1750 
1751 /*
1752  * Called by the upper tty layer when tty buffers are ready
1753  * to receive data again after a call to throttle.
1754  */
1755 static void ntty_unthrottle(struct tty_struct *tty)
1756 {
1757     struct nozomi *dc = get_dc_by_tty(tty);
1758     unsigned long flags;
1759 
1760     spin_lock_irqsave(&dc->spin_mutex, flags);
1761     enable_transmit_dl(tty->index % MAX_PORT, dc);
1762     set_rts(tty, 1);
1763 
1764     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1765 }
1766 
1767 /*
1768  * Called by the upper tty layer when the tty buffers are almost full.
1769  * The driver should stop send more data.
1770  */
1771 static void ntty_throttle(struct tty_struct *tty)
1772 {
1773     struct nozomi *dc = get_dc_by_tty(tty);
1774     unsigned long flags;
1775 
1776     spin_lock_irqsave(&dc->spin_mutex, flags);
1777     set_rts(tty, 0);
1778     spin_unlock_irqrestore(&dc->spin_mutex, flags);
1779 }
1780 
1781 /* Returns number of chars in buffer, called by tty layer */
1782 static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
1783 {
1784     struct port *port = tty->driver_data;
1785     struct nozomi *dc = get_dc_by_tty(tty);
1786 
1787     if (unlikely(!dc || !port))
1788         return 0;
1789 
1790     return kfifo_len(&port->fifo_ul);
1791 }
1792 
1793 static const struct tty_port_operations noz_tty_port_ops = {
1794     .activate = ntty_activate,
1795     .shutdown = ntty_shutdown,
1796 };
1797 
1798 static const struct tty_operations tty_ops = {
1799     .ioctl = ntty_ioctl,
1800     .open = ntty_open,
1801     .close = ntty_close,
1802     .hangup = ntty_hangup,
1803     .write = ntty_write,
1804     .write_room = ntty_write_room,
1805     .unthrottle = ntty_unthrottle,
1806     .throttle = ntty_throttle,
1807     .chars_in_buffer = ntty_chars_in_buffer,
1808     .tiocmget = ntty_tiocmget,
1809     .tiocmset = ntty_tiocmset,
1810     .get_icount = ntty_tiocgicount,
1811     .install = ntty_install,
1812     .cleanup = ntty_cleanup,
1813 };
1814 
1815 /* Module initialization */
1816 static struct pci_driver nozomi_driver = {
1817     .name = NOZOMI_NAME,
1818     .id_table = nozomi_pci_tbl,
1819     .probe = nozomi_card_init,
1820     .remove = nozomi_card_exit,
1821 };
1822 
1823 static __init int nozomi_init(void)
1824 {
1825     int ret;
1826 
1827     ntty_driver = tty_alloc_driver(NTTY_TTY_MAXMINORS, TTY_DRIVER_REAL_RAW |
1828             TTY_DRIVER_DYNAMIC_DEV);
1829     if (IS_ERR(ntty_driver))
1830         return PTR_ERR(ntty_driver);
1831 
1832     ntty_driver->driver_name = NOZOMI_NAME_TTY;
1833     ntty_driver->name = "noz";
1834     ntty_driver->major = 0;
1835     ntty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1836     ntty_driver->subtype = SERIAL_TYPE_NORMAL;
1837     ntty_driver->init_termios = tty_std_termios;
1838     ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \
1839                         HUPCL | CLOCAL;
1840     ntty_driver->init_termios.c_ispeed = 115200;
1841     ntty_driver->init_termios.c_ospeed = 115200;
1842     tty_set_operations(ntty_driver, &tty_ops);
1843 
1844     ret = tty_register_driver(ntty_driver);
1845     if (ret) {
1846         printk(KERN_ERR "Nozomi: failed to register ntty driver\n");
1847         goto free_tty;
1848     }
1849 
1850     ret = pci_register_driver(&nozomi_driver);
1851     if (ret) {
1852         printk(KERN_ERR "Nozomi: can't register pci driver\n");
1853         goto unr_tty;
1854     }
1855 
1856     return 0;
1857 unr_tty:
1858     tty_unregister_driver(ntty_driver);
1859 free_tty:
1860     tty_driver_kref_put(ntty_driver);
1861     return ret;
1862 }
1863 
1864 static __exit void nozomi_exit(void)
1865 {
1866     pci_unregister_driver(&nozomi_driver);
1867     tty_unregister_driver(ntty_driver);
1868     tty_driver_kref_put(ntty_driver);
1869 }
1870 
1871 module_init(nozomi_init);
1872 module_exit(nozomi_exit);
1873 
1874 MODULE_LICENSE("Dual BSD/GPL");
1875 MODULE_DESCRIPTION("Nozomi driver");