2 /* nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
4 * Written by: Ulf Jakobsson,
8 * Maintained by: Paul Hardwick, p.hardwick@option.com
10 * Source has been ported from an implementation made by Filip Aben, f.aben@option.com
12 * --------------------------------------------------------------------------
14 Copyright (c) 2005 Option Wireless Sweden AB
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 * --------------------------------------------------------------------------
36 * See CHANGELOG in this package
41 * See TODO file in this package
46 #include <linux/version.h>
48 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
50 #elif LINUX_VERSION_CODE > KERNEL_VERSION(2,4,0)
54 #include <linux/module.h>
55 #include <linux/init.h>
56 #include <linux/pci.h>
57 #include <linux/ioport.h>
58 #include <linux/tty.h>
59 #include <linux/tty_driver.h>
60 #include <linux/tty_flip.h>
61 #include <linux/serial.h>
62 #include <linux/interrupt.h>
63 #include <linux/kmod.h>
64 #include <linux/proc_fs.h>
65 #include <asm/uaccess.h>
68 #define VERSION_STRING DRIVER_DESC " (build date: " __DATE__ " " __TIME__ ")"
72 #include <linux/kfifo.h>
75 #include <linux/workqueue.h>
78 #include <linux/tqueue.h>
87 typedef void irqreturn_t
;
92 #error "This driver needs PCI support to be available"
95 /* Macros definitions */
97 /* Enable this to have a lot of debug printouts */
98 //#define NOZOMI_DEBUG
100 /* Default debug printout level */
101 #define NOZOMI_DEBUG_LEVEL 0xff
103 #define P_BUF_SIZE 128
104 #define NFO( _err_flag_, args...) \
106 char t_m_p_[P_BUF_SIZE]; \
107 snprintf(t_m_p_, sizeof(t_m_p_), ##args); \
108 printk( _err_flag_ "[%d] %s(): %s\n", __LINE__, __FUNCTION__, t_m_p_); \
111 #define INFO(args...) NFO(KERN_INFO, ##args)
112 #define ERR(args...) NFO( KERN_ERR, ##args)
114 #define D1(args...) D_(0x01, ##args)
115 #define D2(args...) D_(0x02, ##args)
116 #define D3(args...) D_(0x04, ##args)
117 #define D4(args...) D_(0x08, ##args)
118 #define D5(args...) D_(0x10, ##args)
119 #define D6(args...) D_(0x20, ##args)
120 #define D7(args...) D_(0x40, ##args)
121 #define D8(args...) D_(0x80, ##args)
125 #define D_(lvl, args...) D(lvl, ##args)
126 /* Do we need this settable at runtime? */
127 static int nzdebug
= NOZOMI_DEBUG_LEVEL
;
129 #define D(lvl, args...) do{if(lvl & nzdebug) NFO(KERN_ALERT, ##args );}while(0)
130 #define D_(lvl, args...) D(lvl, ##args)
132 /* These printouts are always printed */
135 static const int nzdebug
= 0;
136 #define D_(lvl, args...)
139 /* TODO: rewrite to optimize macros... */
140 #define SET_FCR(value__) \
142 writew((value__), (u32) (dc->REG_FCR )); \
145 #define SET_IER(value__, mask__) \
147 dc->ier_last_written = (dc->ier_last_written & ~mask__) | (value__ & mask__ );\
148 writew( dc->ier_last_written, (u32)(dc->REG_IER));\
151 #define GET_IER(read_val__) \
153 (read_val__) = readw((u32) (dc->REG_IER));\
156 #define GET_IIR(read_val__) \
158 (read_val__) = readw((u32) (dc->REG_IIR));\
161 #define GET_MEM(value__, addr__, length__) \
163 read_mem32( (u32*) (value__), (u32) (addr__), (length__));\
166 #define GET_MEM_BUF(value__, addr__, length__) \
168 read_mem32_buf( (u32*) (value__), (u32) (addr__), (length__));\
171 #define SET_MEM(addr__, value__, length__) \
173 write_mem32( (addr__), (u32*) (value__), (length__));\
176 #define SET_MEM_BUF(addr__, value__, length__) \
178 write_mem32_buf( (addr__), (u32*) (value__), (length__));\
182 #define TMP_BUF_MAX 256
184 #define DUMP(buf__,len__) \
186 char tbuf[TMP_BUF_MAX]={0};\
188 snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s",buf__);\
189 if(tbuf[len__-2] == '\r') {\
190 tbuf[len__-2] = 'r';\
192 D1( "SENDING: '%s' (%d+n)", tbuf, len__);\
194 D1( "SENDING: '%s' (%d)", tbuf, len__);\
198 #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
202 #define NOZOMI_NAME "nozomi"
203 #define NOZOMI_NAME_TTY "nozomi_tty"
204 #define DRIVER_DESC "Nozomi driver"
206 #define NTTY_TTY_MAJOR 242
207 #define NTTY_TTY_MINORS MAX_PORT
208 #define NTTY_FIFO_BUFFER_SIZE 8192
210 /* Must be power of 2 */
211 #define FIFO_BUFFER_SIZE_UL 8192
213 /* Size of tmp send buffer to card */
214 #define SEND_BUF_MAX 1024
215 #define RECEIVE_BUF_MAX 4
217 /* Our fake UART values */
220 #define MCR_LOOP 0x04
226 /* Define all types of vendors and devices to support */
227 #define VENDOR1 0x1931 /* Vendor Option */
228 #define DEVICE1 0x000c /* HSDPA card */
230 #define R_IIR 0x0000 /* Interrupt Identity Register */
231 #define R_FCR 0x0000 /* Flow Control Register */
232 #define R_IER 0x0004 /* Interrupt Enable Register */
234 #define CONFIG_MAGIC 0xEFEFFEFE
235 #define TOGGLE_VALID 0x0000
237 /* Definition of interrupt tokens */
238 #define MDM_DL1 0x0001
239 #define MDM_UL1 0x0002
240 #define MDM_DL2 0x0004
241 #define MDM_UL2 0x0008
242 #define DIAG_DL1 0x0010
243 #define DIAG_DL2 0x0020
244 #define DIAG_UL 0x0040
245 #define APP1_DL 0x0080
246 #define APP1_UL 0x0100
247 #define APP2_DL 0x0200
248 #define APP2_UL 0x0400
249 #define CTRL_DL 0x0800
250 #define CTRL_UL 0x1000
253 #define MDM_DL (MDM_DL1 | MDM_DL2)
254 #define MDM_UL (MDM_UL1 | MDM_UL2)
255 #define DIAG_DL (DIAG_DL1 | DIAG_DL2)
257 /* modem signal definition */
258 #define CTRL_DSR 0x0001
259 #define CTRL_DCD 0x0002
260 #define CTRL_RI 0x0004
261 #define CTRL_CTS 0x0008
263 #define CTRL_DTR 0x0001
264 #define CTRL_RTS 0x0002
267 #define NOZOMI_MAX_PORTS 5
269 /* Type definitions */
271 /* There are two types of nozomi cards, one with 2048 memory and with 8192 memory */
273 F32_2
= 2048, /* Has 512 bytes downlink and uplink * 2 -> 2048 */
274 F32_8
= 8192, /* Has 3072 bytes downlink and 1024 bytes uplink * 2 -> 8192 */
277 /* Two different toggle channels exist */
283 /* Port definition for the card regarding flow control */
293 /* Ports that the nozomi has */
307 unsigned enabled
: 5; /* Toggle fields are valid if enabled is 0, else A-channels
308 must always be used. */
309 unsigned diag_dl
: 1;
312 } __attribute__ ((packed
)) toggles_t
;
314 /* Configuration table to read at startup of card */
315 /* Is for now only needed during initialization phase */
318 u16 product_information
;
323 u16 dl_mdm_len1
; /* If this is 64, it can hold 60 bytes + 4 that is length field */
327 u16 dl_mdm_len2
; /* If this is 64, it can hold 60 bytes + 4 that is length field */
341 } __attribute__((packed
)) config_table_t
;
343 /* This stores all control downlink flags */
346 unsigned reserved
: 4;
351 } __attribute__ ((packed
)) ctrl_dl_t
;
353 /* This stores all control uplink flags */
356 unsigned reserved
: 6;
359 } __attribute__ ((packed
)) ctrl_ul_t
;
364 /* This represents the toggle information */
368 unsigned diag_dl
: 1;
369 unsigned enabled
: 5; /* Toggle fields are valid if enabled is 0, else A-channels
370 must always be used. */
371 } __attribute__ ((packed
)) toggles_t
;
373 /* Configuration table to read at startup of card */
377 u16 product_information
;
381 u16 dl_mdm_len1
; /* If this is 64, it can hold 60 bytes + 4 that is length field */
396 } __attribute__((packed
)) config_table_t
;
398 /* This stores all control downlink flags */
404 unsigned reserverd
: 4;
406 } __attribute__ ((packed
)) ctrl_dl_t
;
408 /* This stores all control uplink flags */
412 unsigned reserved
: 6;
414 } __attribute__ ((packed
)) ctrl_ul_t
;
417 /* This holds all information that is needed regarding a port */
419 u8 update_flow_control
;
422 struct kfifo
*fifo_ul
;
431 struct tty_struct
*tty
;
433 struct semaphore tty_sem
;
434 wait_queue_head_t tty_wait
;
435 struct async_icount tty_icount
;
437 u32 rx_data
, tx_data
;
442 /* Private data one for each card in the system */
447 /* Register addresses */
452 volatile u16 ier_last_written
;
453 card_type_t card_type
;
454 config_table_t config_table
; /* Configuration table */
455 struct pci_dev
*pdev
;
457 // Add by Jared 05-29-2006. Because we need to know which port we would wakeup in task queue.
460 struct work_struct nozomi_wq
;
461 #elif defined KERNEL_2_4
462 struct tq_struct tqueue
; /* task queue for line discipline waking up */
465 port_t port
[NOZOMI_MAX_PORTS
];
467 struct tty_driver tty_driver
;
470 struct tty_struct
*tty_table
[NTTY_TTY_MINORS
];
471 struct tq_struct tty_flip_queue
;
475 struct workqueue_struct
*tty_flip_wq
;
476 struct work_struct tty_flip_wq_struct
;
479 struct termios
*tty_termios
[NTTY_TTY_MINORS
];
480 struct termios
*tty_termios_locked
[NTTY_TTY_MINORS
];
481 spinlock_t spin_mutex
;
484 struct proc_dir_entry
*proc_entry
;
488 /* This is a data packet that is read or written to/from card */
490 u32 size
; /* size is the length of the data buffer */
492 } __attribute__ ((packed
)) buf_t
;
494 /* Function declarations */
495 static int ntty_tty_init(dc_t
*dc
);
497 static void tty_flip_queue_function(void *tmp_dc
);
499 /* Global variables */
500 static struct pci_device_id nozomi_pci_tbl
[] __devinitdata
= {
501 {VENDOR1
, DEVICE1
, 0, 0, 0, 0, 0},
505 /* Used to store interrupt variables */
507 volatile u16 read_iir
; /* Holds current interrupt tokens */
510 MODULE_DEVICE_TABLE(pci
, nozomi_pci_tbl
);
512 /* Representing the pci device of interest */
513 static int cards_found
;
515 struct pci_dev
*my_pdev
= NULL
;
520 static inline dc_t
* get_dc_by_pdev(struct pci_dev
* pdev
) {
524 static inline dc_t
* get_dc_by_index(s32 index
) {
528 static inline s32
get_index(struct tty_struct
*tty
) {
532 return MINOR(tty
->device
) - tty
->driver
.minor_start
;
536 static inline port_t
* get_port_by_tty(struct tty_struct
*tty
) {
537 return &my_dev
->port
[ get_index(tty
) ];
540 static inline dc_t
* get_dc_by_tty(struct tty_struct
*tty
) {
547 /* -Rewrite cleaner */
548 static void read_mem32(u32
*buf
, u32 mem_addr_start
, u32 size_bytes
) {
550 u32
* ptr
= (u32
*) mem_addr_start
;
554 if (size_bytes
== 2) {
556 *buf16
= readw( (u32
)ptr
);
560 while (i
< size_bytes
) {
561 if ( size_bytes
- i
== 2) {
562 /* Handle 2 bytes in the end */
564 *(buf16
) = readw( (u32
)ptr
);
568 *(buf
) = readl( (u32
)ptr
);
576 /* - Rewrite cleaner */
577 /* - merge with read_mem32() */
578 static void read_mem32_buf(u32
*buf
, u32 mem_addr_start
, u32 size_bytes
) {
581 u32
* ptr
= (u32
*) mem_addr_start
;
585 if (size_bytes
== 2) {
587 *buf16
= __le16_to_cpu( readw( (u32
)ptr
));
591 while (i
< size_bytes
) {
592 if ( size_bytes
- i
== 2) {
593 /* Handle 2 bytes in the end */
595 *(buf16
) = __le16_to_cpu( readw( (u32
)ptr
));
599 *(buf
) = __le32_to_cpu( readl( (u32
)ptr
));
605 read_mem32(buf
, mem_addr_start
, size_bytes
);
611 /* -Rewrite cleaner */
612 static u32
write_mem32(u32 mem_addr_start
, u32
*buf
, u32 size_bytes
) {
614 u32
* ptr
= (u32
*) mem_addr_start
;
618 if (size_bytes
== 2) {
620 writew( (u16
)*buf16
, (u32
)ptr
);
624 while (i
< size_bytes
) {
625 if ( size_bytes
- i
== 2) {
628 writew( (u16
)*buf16
, (u32
)ptr
);
632 writel( (u32
)*buf
, (u32
)ptr
);
641 /* - Merge with write_mem32() */
642 static u32
write_mem32_buf(u32 mem_addr_start
, u32
*buf
, u32 size_bytes
) {
645 u32
* ptr
= (u32
*) mem_addr_start
;
649 if (size_bytes
== 2) {
651 writew( __le16_to_cpu(*buf16
), (u32
)ptr
);
655 while (i
< size_bytes
) {
656 if ( size_bytes
- i
== 2) {
659 writew( __le16_to_cpu(*buf16
), (u32
)ptr
);
663 writel( __cpu_to_le32( *buf
), (u32
)ptr
);
670 return write_mem32(mem_addr_start
, buf
, size_bytes
);
674 /* Setup pointers to different channels and also setup buffer sizes. */
675 static void setup_memory(dc_t
*dc
) {
677 u32 offset
= dc
->base_addr
+ dc
->config_table
.dl_start
;
678 /* The length reported is including the length field of 4 bytes, hence subtract with 4. */
681 /* Modem port dl configuration */
682 dc
->port
[PORT_MDM
].dl_addr
[CH_A
] = offset
;
683 dc
->port
[PORT_MDM
].dl_addr
[CH_B
] = (offset
+= dc
->config_table
.dl_mdm_len1
);
684 dc
->port
[PORT_MDM
].dl_size
[CH_A
] = dc
->config_table
.dl_mdm_len1
- buff_offset
;
685 dc
->port
[PORT_MDM
].dl_size
[CH_B
] = dc
->config_table
.dl_mdm_len2
- buff_offset
;
687 /* Diag port dl configuration */
688 dc
->port
[PORT_DIAG
].dl_addr
[CH_A
] = (offset
+= dc
->config_table
.dl_mdm_len2
);
689 dc
->port
[PORT_DIAG
].dl_size
[CH_A
] = dc
->config_table
.dl_diag_len1
- buff_offset
;
690 dc
->port
[PORT_DIAG
].dl_addr
[CH_B
] = (offset
+= dc
->config_table
.dl_diag_len1
);
691 dc
->port
[PORT_DIAG
].dl_size
[CH_B
] = dc
->config_table
.dl_diag_len2
- buff_offset
;
693 /* App1 port dl configuration */
694 dc
->port
[PORT_APP1
].dl_addr
[CH_A
] = (offset
+= dc
->config_table
.dl_diag_len2
);
695 dc
->port
[PORT_APP1
].dl_size
[CH_A
] = dc
->config_table
.dl_app1_len
- buff_offset
;
697 /* App2 port dl configuration */
698 dc
->port
[PORT_APP2
].dl_addr
[CH_A
] = (offset
+= dc
->config_table
.dl_app1_len
);
699 dc
->port
[PORT_APP2
].dl_size
[CH_A
] = dc
->config_table
.dl_app2_len
- buff_offset
;
701 /* Ctrl dl configuration */
702 dc
->port
[PORT_CTRL
].dl_addr
[CH_A
] = (offset
+= dc
->config_table
.dl_app2_len
);
703 dc
->port
[PORT_CTRL
].dl_size
[CH_A
] = dc
->config_table
.dl_ctrl_len
- buff_offset
;
706 /* Modem Port ul configuration */
707 dc
->port
[PORT_MDM
].ul_addr
[CH_A
] = (offset
= dc
->base_addr
+ dc
->config_table
.ul_start
);
708 dc
->port
[PORT_MDM
].ul_size
[CH_A
] = dc
->config_table
.ul_mdm_len1
- buff_offset
;
709 dc
->port
[PORT_MDM
].ul_addr
[CH_B
] = (offset
+= dc
->config_table
.ul_mdm_len1
);
710 dc
->port
[PORT_MDM
].ul_size
[CH_B
] = dc
->config_table
.ul_mdm_len2
- buff_offset
;
712 /* Diag port ul configuration */
713 dc
->port
[PORT_DIAG
].ul_addr
[CH_A
] = (offset
+= dc
->config_table
.ul_mdm_len2
);
714 dc
->port
[PORT_DIAG
].ul_size
[CH_A
] = dc
->config_table
.ul_diag_len
- buff_offset
;
716 /* App1 port ul configuration */
717 dc
->port
[PORT_APP1
].ul_addr
[CH_A
] = (offset
+= dc
->config_table
.ul_diag_len
);
718 dc
->port
[PORT_APP1
].ul_size
[CH_A
] = dc
->config_table
.ul_app1_len
- buff_offset
;
720 /* App2 port ul configuration */
721 dc
->port
[PORT_APP2
].ul_addr
[CH_A
] = (offset
+= dc
->config_table
.ul_app1_len
);
722 dc
->port
[PORT_APP2
].ul_size
[CH_A
] = dc
->config_table
.ul_app2_len
- buff_offset
;
724 /* Ctrl ul configuration */
725 dc
->port
[PORT_CTRL
].ul_addr
[CH_A
] = (offset
+= dc
->config_table
.ul_app2_len
);
726 dc
->port
[PORT_CTRL
].ul_size
[CH_A
] = dc
->config_table
.ul_ctrl_len
- buff_offset
;
727 offset
= dc
->config_table
.ul_start
;
730 /* Dump config table under initalization phase */
732 static void dump_table(dc_t
*dc
) {
733 D3("signature: 0x%08X", dc
->config_table
.signature
);
734 D3("version: 0x%04X", dc
->config_table
.version
);
735 D3("product_information: 0x%04X", dc
->config_table
.product_information
);
736 D3("toggle enabled: %d", dc
->config_table
.toggle
.enabled
);
737 D3("toggle up_mdm: %d", dc
->config_table
.toggle
.mdm_ul
);
738 D3("toggle dl_mdm: %d", dc
->config_table
.toggle
.mdm_dl
);
739 D3("toggle dl_dbg: %d", dc
->config_table
.toggle
.diag_dl
);
741 D3("dl_start: 0x%04X", dc
->config_table
.dl_start
);
742 D3("dl_mdm_len0: 0x%04X, %d", dc
->config_table
.dl_mdm_len1
, dc
->config_table
.dl_mdm_len1
);
743 D3("dl_mdm_len1: 0x%04X, %d", dc
->config_table
.dl_mdm_len2
, dc
->config_table
.dl_mdm_len2
);
744 D3("dl_diag_len0: 0x%04X, %d", dc
->config_table
.dl_diag_len1
, dc
->config_table
.dl_diag_len1
);
745 D3("dl_diag_len1: 0x%04X, %d", dc
->config_table
.dl_diag_len2
, dc
->config_table
.dl_diag_len2
);
746 D3("dl_app1_len: 0x%04X, %d", dc
->config_table
.dl_app1_len
, dc
->config_table
.dl_app1_len
);
747 D3("dl_app2_len: 0x%04X, %d", dc
->config_table
.dl_app2_len
, dc
->config_table
.dl_app2_len
);
748 D3("dl_ctrl_len: 0x%04X, %d", dc
->config_table
.dl_ctrl_len
, dc
->config_table
.dl_ctrl_len
);
749 D3("ul_start: 0x%04X, %d", dc
->config_table
.ul_start
, dc
->config_table
.ul_start
);
750 D3("ul_mdm_len[0]: 0x%04X, %d", dc
->config_table
.ul_mdm_len1
, dc
->config_table
.ul_mdm_len1
);
751 D3("ul_mdm_len[1]: 0x%04X, %d", dc
->config_table
.ul_mdm_len2
, dc
->config_table
.ul_mdm_len2
);
752 D3("ul_diag_len: 0x%04X, %d", dc
->config_table
.ul_diag_len
, dc
->config_table
.ul_diag_len
);
753 D3("ul_app1_len: 0x%04X, %d", dc
->config_table
.ul_app1_len
, dc
->config_table
.ul_app1_len
);
754 D3("ul_app2_len: 0x%04X, %d", dc
->config_table
.ul_app2_len
, dc
->config_table
.ul_app2_len
);
755 D3("ul_ctrl_len: 0x%04X, %d", dc
->config_table
.ul_ctrl_len
, dc
->config_table
.ul_ctrl_len
);
759 /* Read configuration table from card under intalization phase */
760 /* Returns 1 if ok, else 0 */
761 static int nozomi_read_config_table(dc_t
*dc
) {
763 GET_MEM( &dc
->config_table
, dc
->base_addr
+ 0, sizeof(config_table_t
));
765 /* D1( "0x%08X == 0x%08X ", dc->config_table.signature, CONFIG_MAGIC); */
767 if( dc
->config_table
.signature
!= CONFIG_MAGIC
) {
768 ERR("ConfigTable Bad! 0x%08X != 0x%08X", dc
->config_table
.signature
, CONFIG_MAGIC
);
772 if( (dc
->config_table
.version
== 0) || (dc
->config_table
.toggle
.enabled
== TOGGLE_VALID
) ) {
774 D1( "Second phase, configuring card");
778 dc
->port
[PORT_MDM
].toggle_ul
= dc
->config_table
.toggle
.mdm_ul
;
779 dc
->port
[PORT_MDM
].toggle_dl
= dc
->config_table
.toggle
.mdm_dl
;
780 dc
->port
[PORT_DIAG
].toggle_dl
= dc
->config_table
.toggle
.diag_dl
;
781 D1( "toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
782 dc
->port
[PORT_MDM
].toggle_ul
,
783 dc
->port
[PORT_MDM
].toggle_dl
,
784 dc
->port
[PORT_DIAG
].toggle_dl
);
789 for (i
=PORT_MDM
; i
< MAX_PORT
;i
++) {
790 dc
->port
[i
].fifo_ul
= kfifo_alloc( FIFO_BUFFER_SIZE_UL
, GFP_ATOMIC
, NULL
);
791 memset( &dc
->port
[i
].ctrl_dl
, 0, sizeof (ctrl_dl_t
));
792 memset( &dc
->port
[i
].ctrl_ul
, 0, sizeof (ctrl_ul_t
));
795 /* Enable control channel */
796 SET_IER( CTRL_DL
, CTRL_DL
);
798 INFO("Initialization OK!");
802 if( (dc
->config_table
.version
> 0) && (dc
->config_table
.toggle
.enabled
!= TOGGLE_VALID
) ) {
804 D1( "First phase: pushing upload buffers, clearing download");
806 INFO("Version of card: %d", dc
->config_table
.version
);
808 /* Here we should disable all I/O over F32. */
811 /* We should send ALL channel pair tokens back along with reset token */
813 /* push upload modem buffers */
814 SET_MEM( dc
->port
[PORT_MDM
].ul_addr
[CH_A
], &offset
, 4);
815 SET_MEM( dc
->port
[PORT_MDM
].ul_addr
[CH_B
], &offset
, 4);
817 SET_FCR( MDM_UL
| DIAG_DL
| MDM_DL
);
819 D1( "First phase done");
825 /* Enable uplink interrupts */
826 static void enable_transmit_ul( port_type_t port
, dc_t
*dc
) {
829 case PORT_MDM
: SET_IER( MDM_UL
, MDM_UL
); break;
830 case PORT_DIAG
: SET_IER( DIAG_UL
, DIAG_UL
); break;
831 case PORT_APP1
: SET_IER( APP1_UL
, APP1_UL
); break;
832 case PORT_APP2
: SET_IER( APP2_UL
, APP2_UL
); break;
833 case PORT_CTRL
: SET_IER( CTRL_UL
, CTRL_UL
); break;
835 ERR("Called with wrong port?");
840 /* Disable uplink interrupts */
841 static void disable_transmit_ul( port_type_t port
, dc_t
*dc
) {
844 case PORT_MDM
: SET_IER( 0 ,MDM_UL
); break;
845 case PORT_DIAG
: SET_IER( 0, DIAG_UL
); break;
846 case PORT_APP1
: SET_IER( 0, APP1_UL
); break;
847 case PORT_APP2
: SET_IER( 0, APP2_UL
); break;
848 case PORT_CTRL
: SET_IER( 0, CTRL_UL
); break;
850 ERR("Called with wrong port?");
855 /* Enable downlink interrupts */
856 static void enable_transmit_dl( port_type_t port
, dc_t
*dc
) {
857 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
860 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
863 case PORT_MDM
: SET_IER( MDM_DL
, MDM_DL
); break;
864 case PORT_DIAG
: SET_IER( DIAG_DL
, DIAG_DL
); break;
865 case PORT_APP1
: SET_IER( APP1_DL
, APP1_DL
); break;
866 case PORT_APP2
: SET_IER( APP2_DL
, APP2_DL
); break;
867 case PORT_CTRL
: SET_IER( CTRL_DL
, CTRL_DL
); break;
870 ERR("Called with wrong port?");
873 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
874 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
878 /* Disable downlink interrupts */
879 static void disable_transmit_dl( port_type_t port
, dc_t
*dc
) {
882 case PORT_MDM
: SET_IER( 0 ,MDM_DL
); break;
883 case PORT_DIAG
: SET_IER( 0, DIAG_DL
); break;
884 case PORT_APP1
: SET_IER( 0, APP1_DL
); break;
885 case PORT_APP2
: SET_IER( 0, APP2_DL
); break;
886 case PORT_CTRL
: SET_IER( 0, CTRL_DL
); break;
888 ERR("Called with wrong port?");
893 static void nozomi_softint(void *private)
896 port_t
*port
= &dc
->port
[dc
->index
];
897 struct tty_struct
*tty
= port
->tty
;
900 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) && tty
->ldisc
.write_wakeup
) {
901 tty
->ldisc
.write_wakeup(tty
);
903 wake_up_interruptible(&tty
->write_wait
);
907 /* Return 1 - send buffer to card and ack. */
908 /* Return 0 - don't ack, don't send buffer to card. */
909 int send_data( port_type_t index
, dc_t
*dc
) {
911 port_t
*port
= &dc
->port
[index
];
912 u8 toggle
= port
->toggle_ul
;
913 u32 addr
= port
->ul_addr
[toggle
];
914 u32 ul_size
= port
->ul_size
[toggle
];
915 //struct tty_struct *tty = port->tty;
917 if (index
>= NTTY_TTY_MINORS
) {
918 ERR("Called with wrong index?");
922 /* Get data from tty and place in buf for now */
923 size
= __kfifo_get( port
->fifo_ul
, dc
->send_buf
, ul_size
< SEND_BUF_MAX
? ul_size
: SEND_BUF_MAX
);
926 D4("No more data to send, disable link:");
930 port
->tx_data
+= size
;
932 /* DUMP(buf, size); */
934 /* Write length + data */
935 SET_MEM( addr
, &size
, 4 );
936 SET_MEM_BUF( addr
+ 4, dc
->send_buf
, size
);
937 #if 0 // Mask by Jared 05-29-2006. Should not wakeup line displine in interrupt.
939 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) && tty
->ldisc
.write_wakeup
) {
940 tty
->ldisc
.write_wakeup(tty
);
942 wake_up_interruptible(&tty
->write_wait
);
945 // Modify by Jared 05-29-2006. Wake up the line displine in the task queue.
948 schedule_work(&dc
->nozomi_wq
);
950 queue_task(&dc
->tqueue
, &tq_immediate
);
951 mark_bh(IMMEDIATE_BH
);
957 /* If all data has been read, return 1, else 0 */
958 static int receive_data( port_type_t index
, dc_t
* dc
) {
959 u8 buf
[RECEIVE_BUF_MAX
] = {0};
962 port_t
*port
= &dc
->port
[index
];
963 u8 toggle
= port
->toggle_dl
;
964 u32 addr
= port
->dl_addr
[toggle
];
965 struct tty_struct
*tty
= port
->tty
;
969 D1("tty not open for port: %d?", index
);
973 if (test_bit(TTY_DONT_FLIP
, &tty
->flags
)) {
974 D6("TTY_DONT_FLIP set!! %d", index
);
975 /* Here we disable interrupt for that port and schedule */
976 /* task. Task wakes up a little bit later and enables interrupt.. */
977 port
->tty_dont_flip
= 1;
978 disable_transmit_dl(index
, dc
);
980 schedule_task(&dc
->tty_flip_queue
);
983 if (!queue_work(dc
->tty_flip_wq
, &dc
->tty_flip_wq_struct
)) {
984 ERR("Call to queue_work() failed.");
990 GET_MEM( &size
, addr
, 4 );
991 /* D1( "%d bytes port: %d", size, index); */
993 if ( test_bit( TTY_THROTTLED
, & tty
->flags
) ) {
994 D1("No room in tty, don't read data, don't ack interrupt, disable interrupt");
996 /* disable interrupt in downlink... */
997 disable_transmit_dl(index
, dc
);
1007 GET_MEM_BUF(buf
, addr
+ offset
, 4);
1010 while (i
< 4 && size
> 0) {
1011 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
1012 tty_flip_buffer_push(tty
);
1014 tty_insert_flip_char(tty
, buf
[i
], TTY_NORMAL
);
1023 tty_flip_buffer_push(tty
);
1028 /* Debug for interrupts */
1030 static char* interrupt2str( u16 interrupt
) {
1031 static char buf
[TMP_BUF_MAX
];
1034 interrupt
& MDM_DL1
? p
+= snprintf(p
, TMP_BUF_MAX
, "MDM_DL1 "):0;
1035 interrupt
& MDM_DL2
? p
+= snprintf(p
, TMP_BUF_MAX
, "MDM_DL2 "):0;
1037 interrupt
& MDM_UL1
? p
+= snprintf(p
, TMP_BUF_MAX
, "MDM_UL1 "):0;
1038 interrupt
& MDM_UL2
? p
+= snprintf(p
, TMP_BUF_MAX
, "MDM_UL2 "):0;
1040 interrupt
& DIAG_DL1
? p
+= snprintf(p
, TMP_BUF_MAX
, "DIAG_DL1 "):0;
1041 interrupt
& DIAG_DL2
? p
+= snprintf(p
, TMP_BUF_MAX
, "DIAG_DL2 "):0;
1043 interrupt
& DIAG_UL
? p
+= snprintf(p
, TMP_BUF_MAX
, "DIAG_UL "):0;
1045 interrupt
& APP1_DL
? p
+= snprintf(p
, TMP_BUF_MAX
, "APP1_DL "):0;
1046 interrupt
& APP2_DL
? p
+= snprintf(p
, TMP_BUF_MAX
, "APP2_DL "):0;
1048 interrupt
& APP1_UL
? p
+= snprintf(p
, TMP_BUF_MAX
, "APP1_UL "):0;
1049 interrupt
& APP2_UL
? p
+= snprintf(p
, TMP_BUF_MAX
, "APP2_UL "):0;
1051 interrupt
& CTRL_DL
? p
+= snprintf(p
, TMP_BUF_MAX
, "CTRL_DL "):0;
1052 interrupt
& CTRL_UL
? p
+= snprintf(p
, TMP_BUF_MAX
, "CTRL_UL "):0;
1054 interrupt
& RESET
? p
+= snprintf(p
, TMP_BUF_MAX
, "RESET "):0;
1060 /* Receive flow control */
1061 /* Return 1 - If ok, else 0 */
1062 static int receive_flow_control( dc_t
*dc
, irq_t
*m
) {
1063 port_type_t port
= PORT_MDM
;
1068 GET_MEM( &ctrl_dl
, dc
->port
[PORT_CTRL
].dl_addr
[CH_A
], 2);
1070 switch( ctrl_dl
.port
) {
1072 D1( "The Base Band sends this value as a response to a request for IMSI detach sent"
1073 " over the control channel uplink (see section 7.6.1).");
1075 case CTRL_MDM
: port
= PORT_MDM
; enable_ier
= MDM_DL
; break;
1076 case CTRL_DIAG
: port
= PORT_DIAG
; enable_ier
= DIAG_DL
; break;
1077 case CTRL_APP1
: port
= PORT_APP1
; enable_ier
= APP1_DL
; break;
1078 case CTRL_APP2
: port
= PORT_APP2
; enable_ier
= APP2_DL
; break;
1080 ERR("ERROR: flow control received for non-existing port");
1084 D1( "0x%04X->0x%04X", *((u16
*) &dc
->port
[port
].ctrl_dl
), *((u16
*)&ctrl_dl
));
1086 old_ctrl
= dc
->port
[port
].ctrl_dl
;
1087 dc
->port
[port
].ctrl_dl
= ctrl_dl
;
1089 if ( old_ctrl
.CTS
== 1 && ctrl_dl
.CTS
== 0 ) {
1090 D1( "Disable interrupt (0x%04X) on port: %d", enable_ier
, port
);
1091 disable_transmit_ul(port
, dc
);
1093 } else if ( old_ctrl
.CTS
== 0 && ctrl_dl
.CTS
== 1 ) {
1095 if ( __kfifo_len(dc
->port
[port
].fifo_ul
) ) {
1096 D1( "Enable interrupt (0x%04X) on port: %d", enable_ier
, port
);
1097 D1( "Data in buffer [%d], enable transmit! ", __kfifo_len(dc
->port
[port
].fifo_ul
) );
1098 enable_transmit_ul( port
, dc
);
1100 D1( "No data in buffer...");
1104 if(*(u16
*)&old_ctrl
== *(u16
*)&ctrl_dl
)
1106 D1( " No change in mctrl");
1109 /* Update statistics */
1110 if(old_ctrl
.CTS
!= ctrl_dl
.CTS
) {
1111 dc
->port
[port
].tty_icount
.cts
++;
1113 if(old_ctrl
.DSR
!= ctrl_dl
.DSR
) {
1114 dc
->port
[port
].tty_icount
.dsr
++;
1116 if(old_ctrl
.RI
!= ctrl_dl
.RI
) {
1117 dc
->port
[port
].tty_icount
.rng
++;
1119 if(old_ctrl
.DCD
!= ctrl_dl
.DCD
) {
1120 dc
->port
[port
].tty_icount
.dcd
++;
1122 D1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
1124 dc
->port
[port
].tty_icount
.dcd
, dc
->port
[port
].tty_icount
.cts
,
1125 dc
->port
[port
].tty_icount
.rng
, dc
->port
[port
].tty_icount
.dsr
);
1131 /* - return ctrl_port_t */
1132 static u8
port2ctrl(port_type_t port
) {
1143 ERR("ERROR: send flow control received for non-existing port");
1149 /* Send flow control, can only update one channel at a time */
1150 /* Return 0 - If we have updated all flow control */
1151 /* Return 1 - If we need to update more flow control, ack current enable more */
1152 static int send_flow_control( dc_t
*dc
) {
1153 u32 i
, more_flow_control_to_be_updated
= 0;
1156 for( i
=PORT_MDM
; i
<MAX_PORT
; i
++ ) {
1157 if( dc
->port
[i
].update_flow_control
) {
1158 if ( more_flow_control_to_be_updated
) {
1159 /* We have more flow control to be updated */
1162 dc
->port
[i
].ctrl_ul
.port
= port2ctrl(i
);
1163 ctrl
= (u16
*) &dc
->port
[i
].ctrl_ul
;
1164 /* D1( "sending flow control 0x%04X for port %d, %d", (u16) *ctrl, i, dc->port[i].ctrl_ul.port ); */
1165 SET_MEM( dc
->port
[PORT_CTRL
].ul_addr
[0], (u32
*) ctrl
, 2 );
1166 dc
->port
[i
].update_flow_control
= 0;
1167 more_flow_control_to_be_updated
= 1;
1173 /* Handle donlink data, ports that are handled are modem and diagnostics */
1175 /* Return 0 - toggle fields are out of sync */
1176 static int handle_data_dl(dc_t
*dc
, irq_t
*m
, port_type_t port
, u8
*toggle
, u16 mask1
, u16 mask2
) {
1178 if ( *toggle
== 0 && m
->read_iir
& mask1
) {
1179 if (receive_data( port
, dc
)) {
1181 *toggle
= !(*toggle
);
1184 if ( m
->read_iir
& mask2
) {
1185 if (receive_data( port
, dc
)) {
1187 *toggle
= !(*toggle
);
1190 } else if ( *toggle
== 1 && m
->read_iir
& mask2
) {
1191 if (receive_data( port
, dc
)) {
1193 *toggle
= !(*toggle
);
1196 if ( m
->read_iir
& mask1
) {
1197 if (receive_data( port
, dc
)) {
1199 *toggle
= !(*toggle
);
1203 ERR("port out of sync!, toggle:%d", *toggle
);
1209 /* Handle uplink data, this is currently for the modem port */
1211 /* Return 0 - toggle field are out of sync */
1212 static int handle_data_ul(dc_t
*dc
, irq_t
*m
, port_type_t port
) {
1214 u8
*toggle
= &(dc
->port
[port
].toggle_ul
);
1216 if ( *toggle
==0 && m
->read_iir
& MDM_UL1
) {
1217 SET_IER( 0, MDM_UL
);
1218 if (send_data(port
, dc
)) {
1220 SET_IER( MDM_UL
, MDM_UL
);
1224 if ( m
->read_iir
& MDM_UL2
) {
1225 SET_IER( 0, MDM_UL
);
1226 if (send_data(port
, dc
)) {
1228 SET_IER( MDM_UL
, MDM_UL
);
1233 } else if ( *toggle
==1 && m
->read_iir
& MDM_UL2
) {
1234 SET_IER( 0, MDM_UL
);
1235 if (send_data(port
, dc
)) {
1237 SET_IER( MDM_UL
, MDM_UL
);
1241 if ( m
->read_iir
& MDM_UL1
) {
1242 SET_IER( 0, MDM_UL
);
1243 if (send_data(port
, dc
)) {
1245 SET_IER( MDM_UL
, MDM_UL
);
1250 SET_FCR( m
->read_iir
& MDM_UL
);
1251 ERR("port out of sync!");
1257 static irqreturn_t
interrupt_handler(int irq
, void *dev_id
, struct pt_regs
*regs
) {
1261 if (my_dev
&& my_dev
->pdev
!= dev_id
) {
1265 if ( !(dc
= get_dc_by_pdev(dev_id
)) ) {
1266 ERR("Could not find device context from pci_dev: %d", (u32
) dev_id
);
1270 #if 1 // add by Victor Yu. 05-24-2006
1271 spin_lock(&dc
->spin_mutex
);
1273 GET_IIR( m
->read_iir
);
1275 /* Just handle interrupt enabled in IER (by masking with dc->ier_last_written) */
1276 m
->read_iir
&= dc
->ier_last_written
;
1278 if (m
->read_iir
== 0) {
1279 #if 1 // add by Victor Yu. 05-24-2006
1280 spin_unlock(&dc
->spin_mutex
);
1285 #if 0 // mask by Victor Yu. 05-24-2006
1290 spin_lock(&dc
->spin_mutex
);
1293 D4( "%s irq:0x%04X, prev:0x%04X", interrupt2str(m
->read_iir
), m
->read_iir
, dc
->ier_last_written
);
1295 if ( m
->read_iir
& RESET
) {
1296 if( !nozomi_read_config_table(dc
) ) {
1297 SET_IER( 0, 0xFFFF);
1298 ERR("ERR: Could not read status from card, we should disable interface");
1302 goto exit_handler
; /* No more useful info if this was the reset interrupt. */
1304 if ( m
->read_iir
& CTRL_UL
) {
1306 SET_IER( 0, CTRL_UL
);
1307 if ( send_flow_control(dc
) ) {
1309 SET_IER( CTRL_UL
, CTRL_UL
);
1312 if ( m
->read_iir
& CTRL_DL
) {
1313 receive_flow_control(dc
, m
);
1316 if ( m
->read_iir
& MDM_DL
) {
1317 if ( !(handle_data_dl(dc
, m
, PORT_MDM
, &(dc
->port
[PORT_MDM
].toggle_dl
), MDM_DL1
, MDM_DL2
)) ) {
1318 ERR("MDM_DL out of sync!");
1322 if ( m
->read_iir
& MDM_UL
) {
1323 if ( !handle_data_ul(dc
, m
, PORT_MDM
) ) {
1324 ERR("MDM_UL out of sync!");
1328 if ( m
->read_iir
& DIAG_DL
) {
1329 if ( !(handle_data_dl(dc
, m
, PORT_DIAG
, &(dc
->port
[PORT_DIAG
].toggle_dl
), DIAG_DL1
, DIAG_DL2
)) ) {
1330 ERR("DIAG_DL out of sync!");
1334 if ( m
->read_iir
& DIAG_UL
) {
1335 SET_IER( 0, DIAG_UL
);
1336 if( send_data( PORT_DIAG
, dc
) ) {
1338 SET_IER( DIAG_UL
, DIAG_UL
);
1341 if ( m
->read_iir
& APP1_DL
) {
1342 if (receive_data( PORT_APP1
, dc
) ) {
1346 if ( m
->read_iir
& APP1_UL
) {
1347 SET_IER( 0, APP1_UL
);
1348 if(send_data( PORT_APP1
, dc
)) {
1350 SET_IER( APP1_UL
, APP1_UL
);
1353 if ( m
->read_iir
& APP2_DL
) {
1354 if (receive_data( PORT_APP2
, dc
)) {
1358 if ( m
->read_iir
& APP2_UL
) {
1359 SET_IER( 0, APP2_UL
);
1360 if(send_data( PORT_APP2
, dc
)) {
1362 SET_IER( APP2_UL
, APP2_UL
);
1367 spin_unlock(&dc
->spin_mutex
);
1371 /* Request a shared IRQ from system */
1372 static int nozomi_setup_interrupt(struct pci_dev
*pdev
) {
1376 if ( (rval
= request_irq( pdev
->irq
, &interrupt_handler
, SA_SHIRQ
, NOZOMI_NAME
, pdev
)) ) {
1377 ERR("Cannot open because IRQ %d is already in use.", pdev
->irq
);
1384 static void nozomi_get_card_type(dc_t
*dc
) {
1387 size
+= pci_resource_len(dc
->pdev
, i
);
1390 /* Assume card type F32_8 if no match */
1391 dc
->card_type
= size
== 2048 ? F32_2
: F32_8
;
1393 INFO("Card type is: %d", dc
->card_type
);
1396 void nozomi_setup_private_data(dc_t
*dc
) {
1397 u32 offset
= dc
->base_addr
+ dc
->card_type
/2;
1400 dc
->REG_FCR
= offset
+ R_FCR
;
1401 dc
->REG_IIR
= offset
+ R_IIR
;
1402 dc
->REG_IER
= offset
+ R_IER
;
1403 dc
->ier_last_written
= 0;
1406 dc
->port
[PORT_MDM
].token_dl
= MDM_DL
;
1407 dc
->port
[PORT_DIAG
].token_dl
= DIAG_DL
;
1408 dc
->port
[PORT_APP1
].token_dl
= APP1_DL
;
1409 dc
->port
[PORT_APP2
].token_dl
= APP2_DL
;
1411 for(i
=PORT_MDM
;i
<MAX_PORT
;i
++) {
1412 dc
->port
[i
].rx_data
= dc
->port
[i
].tx_data
= 0;
1413 dc
->port
[i
].tty_dont_flip
= 0;
1418 static void tty_flip_queue_function(void *tmp_dc
) {
1419 dc_t
*dc
= (dc_t
*) tmp_dc
;
1422 /* Enable interrupt for that port */
1423 for(i
=0;i
<MAX_PORT
;i
++) {
1424 if (dc
->port
[i
].tty_dont_flip
) {
1425 D6("Enable for port: %d", i
);
1426 dc
->port
[i
].tty_dont_flip
= 0;
1427 enable_transmit_dl(dc
->port
[i
].tty_index
, dc
);
1432 static int read_proc_card_type(char *buf
, char **start
, off_t offset
, int len
) {
1433 dc_t
*dc
= get_dc_by_index(0);
1436 len
+= sprintf(buf
+len
,"%d\n", dc
->card_type
);
1440 static int read_proc_open_ttys(char *buf
, char **start
, off_t offset
, int len
) {
1441 dc_t
*dc
= get_dc_by_index(0);
1444 len
+= sprintf(buf
+len
,"%d\n", dc
->open_ttys
);
1448 static int read_proc_version(char *buf
, char **start
, off_t offset
, int len
) {
1451 len
+= sprintf(buf
+len
, "%s\n", VERSION_STRING
);
1455 static int read_proc_rtx(char *buf
, char **start
, off_t offset
, int len
) {
1456 dc_t
*dc
= get_dc_by_index(0);
1462 for(i
=PORT_MDM
;i
<MAX_PORT
;i
++) {
1463 len
+= sprintf(buf
+len
,"noz%d rx: %d, tx: %d\n", i
, dc
->port
[i
].rx_data
, dc
->port
[i
].tx_data
);
1468 static void make_proc_dirs(void) {
1469 dc_t
*dc
= get_dc_by_index(0);
1471 dc
->proc_entry
= proc_mkdir("nozomi", &proc_root
);
1473 /* Register the read_proc */
1474 if ( !create_proc_info_entry("card_type",0,dc
->proc_entry
,read_proc_card_type
) ) {
1475 ERR("ERROR: failed to register read_procmem");
1477 if ( !create_proc_info_entry("open_ttys",0,dc
->proc_entry
,read_proc_open_ttys
) ) {
1478 ERR("ERROR: failed to register read_procmem");
1480 if ( !create_proc_info_entry("rtx",0,dc
->proc_entry
,read_proc_rtx
) ) {
1481 ERR("ERROR: failed to register read_procmem");
1483 if ( !create_proc_info_entry("version",0,dc
->proc_entry
,read_proc_version
) ) {
1484 ERR("ERROR: failed to register read_procmem");
1488 static void remove_proc_dirs(void) {
1489 dc_t
*dc
= get_dc_by_index(0);
1491 remove_proc_entry("card_type", dc
->proc_entry
);
1492 remove_proc_entry("open_ttys", dc
->proc_entry
);
1493 remove_proc_entry("rtx", dc
->proc_entry
);
1494 remove_proc_entry("version", dc
->proc_entry
);
1495 remove_proc_entry("nozomi", &proc_root
);
1498 /* Allocate memory for one device */
1499 #if 0 // Mask by Jared 05-24-2006
1500 static int __devinit
nozomi_card_init(struct pci_dev
*pdev
, const struct pci_device_id
*ent
) {
1502 static int nozomi_card_init(struct pci_dev
*pdev
, const struct pci_device_id
*ent
) {
1508 INFO("Init, cards_found: %d", cards_found
);
1510 if (!(my_dev
= kmalloc(sizeof(dc_t
), GFP_KERNEL
))) {
1511 D1( "Could not allocate memory");
1515 memset(my_dev
, 0, sizeof( dc_t
));
1517 if (cards_found
> 1) {
1518 ERR("This driver only supports 1 device");
1522 my_dev
->pdev
= pdev
;
1525 /* Find out what card type it is */
1526 nozomi_get_card_type(dc
);
1528 if (pci_enable_device(dc
->pdev
)) {
1529 ERR("Not possible to enable PCI Device");
1533 if ( (dc
->base_addr
= pci_resource_start(dc
->pdev
, 0)) == 0x0000) {
1534 ERR("No I/O-Address for card detected");
1536 goto err_disable_device
;
1539 if (!(dc
->base_addr
= (u32
) ioremap(dc
->base_addr
, dc
->card_type
))) {
1540 ERR("No I/O-Address for card detected");
1542 goto err_disable_device
;
1547 // Add by Jared 05-29-2006. Wake up the line displine in the task queue.
1549 INIT_WORK(&dc
->nozomi_wq
, nozomi_softint
, my_dev
);
1551 dc
->tqueue
.routine
= nozomi_softint
;
1552 dc
->tqueue
.data
= my_dev
;
1555 nozomi_setup_private_data(dc
);
1557 if (pci_request_regions(dc
->pdev
, NOZOMI_NAME
)) {
1558 ERR("I/O address 0x%04x already in use",
1559 (int) /* nozomi_private.io_addr */ 0);
1561 goto err_disable_regions
;
1564 if ( !(dc
->send_buf
= kmalloc(SEND_BUF_MAX
, GFP_KERNEL
))) {
1565 ERR("Could not allocate send buffer?");
1566 goto err_disable_regions
;
1569 /* Disable all interrupts */
1570 SET_IER( 0 , 0xFFFF );
1572 /* Setup interrupt handler */
1573 if (nozomi_setup_interrupt(dc
->pdev
)) {
1575 goto err_disable_regions
;
1578 D1( "base_addr: 0x%08X", dc
->base_addr
);
1581 dc
->tty_flip_queue
.list
.next
= NULL
;
1582 dc
->tty_flip_queue
.list
.prev
= NULL
;
1583 dc
->tty_flip_queue
.sync
= 0;
1584 dc
->tty_flip_queue
.data
= dc
;
1585 dc
->tty_flip_queue
.routine
= tty_flip_queue_function
;
1588 if ( !(dc
->tty_flip_wq
= create_singlethread_workqueue(NOZOMI_NAME
)) ) {
1589 ERR("Could not create workqueue?");
1590 BUG_ON(!dc
->tty_flip_wq
);
1593 INIT_WORK( &dc
->tty_flip_wq_struct
, tty_flip_queue_function
, (void*) dc
);
1596 spin_lock_init(&dc
->spin_mutex
);
1602 /* Enable RESET interrupt. */
1603 SET_IER( RESET
, 0xFFFF );
1607 err_disable_regions
:
1608 pci_release_regions(pdev
);
1609 iounmap((void *)dc
->base_addr
);
1613 pci_disable_device(pdev
);
1620 static void tty_do_close(dc_t
*dc
, port_t
*port
) {
1623 down(&port
->tty_sem
);
1625 if ( !port
->tty_open_count
) {
1630 port
->tty_open_count
--;
1635 if ( port
->tty_open_count
== 0) {
1636 D1("close: %d", port
->token_dl
);
1638 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1639 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1640 SET_IER( 0, port
->token_dl
);
1641 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1643 SET_IER( 0, port
->token_dl
);
1652 static void __exit
tty_exit(void) {
1654 static void tty_exit(void) {
1662 for (i
= 0; i
< NTTY_TTY_MINORS
; ++i
)
1663 tty_unregister_device(&dc
->tty_driver
, i
);
1666 tty_unregister_driver(&dc
->tty_driver
);
1668 for (i
= 0; i
< NTTY_TTY_MINORS
; i
++) {
1669 while (dc
->port
[i
].tty_open_count
) {
1670 tty_do_close(dc
, &dc
->port
[i
]);
1673 dc
->port
[i
].tty
= NULL
;
1677 /* Deallocate memory for one device */
1678 #if 0 // Mask by Jared 05-24-2006
1679 static void __devexit
nozomi_card_exit(struct pci_dev
*pdev
) {
1681 static void nozomi_card_exit(struct pci_dev
*pdev
) {
1685 dc_t
*dc
= get_dc_by_pdev(pdev
);
1688 /* Disable all interrupts */
1689 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1690 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1691 SET_IER( 0, 0xFFFF);
1692 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1694 SET_IER( 0, 0xFFFF);
1696 /* Send 0x0001, command card to resend the reset token. */
1697 /* This is to get the reset when the module is reloaded. */
1698 ctrl
.port
= 0x00; ctrl
.reserved
= 0; ctrl
.RTS
=0; ctrl
.DTR
=1;
1699 D1( "sending flow control 0x%04X", * ((u16
*) &ctrl
) );
1701 /* Setup dc->reg addresses to we can use defines here */
1702 nozomi_setup_private_data(dc
);
1703 SET_MEM( dc
->port
[PORT_CTRL
].ul_addr
[0], (u32
*) &ctrl
, 2 );
1704 SET_FCR( CTRL_UL
); /* push the token to the card. */
1706 D1( "pci_release_regions");
1707 pci_release_regions(pdev
);
1710 iounmap((void *)dc
->base_addr
);
1712 D1( "pci_disable_device");
1713 pci_disable_device(pdev
);
1715 free_irq( pdev
->irq
, pdev
);
1717 for (i
=PORT_MDM
; i
< MAX_PORT
;i
++) {
1718 kfree ( dc
->port
[i
].fifo_ul
);
1721 kfree( dc
->send_buf
);
1728 destroy_workqueue(dc
->tty_flip_wq
);
1738 static void set_rts(int index
, int rts
) {
1739 dc_t
*dc
= get_dc_by_index(index
);
1740 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1743 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1745 dc
->port
[index
].ctrl_ul
.RTS
= rts
;
1746 dc
->port
[index
].update_flow_control
= 1;
1747 enable_transmit_ul(PORT_CTRL
, dc
);
1748 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1749 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1753 static void set_dtr(int index
, int dtr
) {
1754 dc_t
*dc
= get_dc_by_index(index
);
1756 D1("SETTING DTR index: %d, dtr: %d", index
, dtr
);
1758 dc
->port
[index
].ctrl_ul
.DTR
= dtr
;
1759 dc
->port
[index
].update_flow_control
= 1;
1760 enable_transmit_ul(PORT_CTRL
, dc
);
1764 /* ---------------------------------------------------------------------------------------------------
1766 ---------------------------------------------------------------------------------------------------*/
1769 /* Called when the userspace process opens the tty, /dev/noz*. */
1770 static int ntty_open(struct tty_struct
*tty
, struct file
*file
) {
1772 s32 index
= get_index(tty
);
1773 port_t
*port
= get_port_by_tty(tty
);
1774 dc_t
*dc
= get_dc_by_tty(tty
);
1777 down(&port
->tty_sem
);
1779 tty
->low_latency
= 1;
1780 tty
->driver_data
= port
;
1782 port
->tty_index
= index
;
1784 port
->tty_open_count
++;
1791 /* Enable interrupt downlink for channel */
1792 if ( port
->tty_open_count
== 1) {
1793 port
->rx_data
= port
->tx_data
= 0;
1794 D1("open: %d", port
->token_dl
);
1795 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1796 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1797 SET_IER( port
->token_dl
, port
->token_dl
);
1798 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1800 SET_IER( port
->token_dl
, port
->token_dl
);
1810 /* Called when the userspace process close the tty, /dev/noz*. */
1811 static void ntty_close(struct tty_struct
*tty
, struct file
*file
) {
1812 dc_t
*dc
= get_dc_by_tty(tty
);
1813 tty_do_close(dc
, (port_t
*) tty
->driver_data
);
1816 /* called when the userspace process writes to the tty (/dev/noz*). */
1817 /* Data is inserted into a fifo, which is then read and transfered to the modem. */
1819 static int ntty_write(struct tty_struct
*tty
, const unsigned char *buffer
, int count
) {
1821 static s32
ntty_write(struct tty_struct
*tty
, s32 from_user
, const u8
*buffer
, s32 count
) {
1824 dc_t
*dc
= get_dc_by_tty(tty
);
1825 port_t
*port
= (port_t
*) tty
->driver_data
;
1828 /* D1( "WRITEx: %d, index = %d", count, index); */
1834 down(&port
->tty_sem
);
1836 if (! port
->tty_open_count
) {
1840 #if 0 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1841 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1846 rval
= __kfifo_put_user(port
->fifo_ul
, (unsigned char *) buffer
, count
);
1848 rval
= __kfifo_put(port
->fifo_ul
, (unsigned char *) buffer
, count
);
1851 rval
= __kfifo_put(port
->fifo_ul
, (unsigned char *) buffer
, count
);
1854 #if 0 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1855 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1860 D1( "No device context?");
1864 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1865 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
1867 // CTS is only valid on the modem channel
1868 if ( port
== &(dc
->port
[PORT_MDM
]) ) {
1869 if ( port
->ctrl_dl
.CTS
) {
1870 D4( "Enable interrupt");
1871 enable_transmit_ul(port
->tty_index
, dc
);
1873 ERR("CTS not active on modem port?");
1876 enable_transmit_ul(port
->tty_index
, dc
);
1878 #if 1 // Written by Jared. 05-24-2006. For portect the global variable ier_last_written
1879 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
1886 /* Calculate how much is left in device */
1887 /* This method is called by the upper tty layer. */
1888 /* #according to sources N_TTY.c it expects a value >= 0 and does not check for negative values. */
1889 static int ntty_write_room(struct tty_struct
*tty
) {
1890 port_t
*port
= (port_t
*) tty
->driver_data
;
1893 // dc_t *dc = get_dc_by_tty(tty);
1899 down(&port
->tty_sem
);
1901 if (! port
->tty_open_count
) {
1905 room
= port
->fifo_ul
->size
- __kfifo_len(port
->fifo_ul
);
1912 /* Sets termios flags, called by the tty layer. */
1913 static void ntty_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
) {
1916 cflag
= tty
->termios
->c_cflag
;
1919 if ((cflag
== old_termios
->c_cflag
) &&
1920 (RELEVANT_IFLAG(tty
->termios
->c_iflag
) == RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1921 D1( " - nothing to change...");
1926 /* get the byte size */
1927 switch (cflag
& CSIZE
) {
1929 D1( " - data bits = 5");
1932 D1( " - data bits = 6");
1935 D1( " - data bits = 7");
1939 D1( " - data bits = 8");
1943 /* determine the parity */
1944 if (cflag
& PARENB
) {
1945 if (cflag
& PARODD
) {
1946 D1( " - parity = odd");
1948 D1( " - parity = even");
1951 D1( " - parity = none");
1954 /* figure out the stop bits requested */
1955 if (cflag
& CSTOPB
) {
1956 D1( " - stop bits = 2");
1958 D1( " - stop bits = 1");
1961 /* figure out the hardware flow control settings */
1962 if (cflag
& CRTSCTS
) {
1963 D1( " - RTS/CTS is enabled");
1965 D1( " - RTS/CTS is disabled");
1968 /* determine software flow control */
1969 /* if we are implementing XON/XOFF, set the start and
1970 * stop character in the device */
1971 if (I_IXOFF(tty
) || I_IXON(tty
)) {
1973 unsigned char stop_char
= STOP_CHAR(tty
);
1974 unsigned char start_char
= START_CHAR(tty
);
1976 /* if we are implementing INBOUND XON/XOFF */
1978 D1( " - INBOUND XON/XOFF is enabled, "
1979 "XON = %2x, XOFF = %2x", start_char
, stop_char
);
1981 D1( " - INBOUND XON/XOFF is disabled");
1984 /* if we are implementing OUTBOUND XON/XOFF */
1986 D1( " - OUTBOUND XON/XOFF is enabled, "
1987 "XON = %2x, XOFF = %2x", start_char
, stop_char
);
1989 D1( " - OUTBOUND XON/XOFF is disabled");
1997 /* Gets io control parameters */
1998 static int ntty_tiocmget(struct tty_struct
*tty
, struct file
*file
) {
1999 port_t
*port
= (port_t
*) tty
->driver_data
;
2000 ctrl_dl_t
*ctrl_dl
= &port
->ctrl_dl
;
2001 ctrl_ul_t
*ctrl_ul
= &port
->ctrl_ul
;
2004 | (ctrl_ul
->RTS
? TIOCM_RTS
: 0)
2005 | (ctrl_ul
->DTR
? TIOCM_DTR
: 0)
2006 | (ctrl_dl
->DCD
? TIOCM_CAR
: 0)
2007 | (ctrl_dl
->RI
? TIOCM_RNG
: 0)
2008 | (ctrl_dl
->DSR
? TIOCM_DSR
: 0)
2009 | (ctrl_dl
->CTS
? TIOCM_CTS
: 0);
2012 /* Sets io controls parameters */
2013 static int ntty_tiocmset(struct tty_struct
*tty
, struct file
*file
, u32 arg
) {
2014 port_t
*port
= (port_t
*) tty
->driver_data
;
2016 set_rts(port
->tty_index
, (arg
& TIOCM_RTS
) ? 1 : 0);
2017 set_dtr(port
->tty_index
, (arg
& TIOCM_DTR
) ? 1 : 0);
2022 static int ntty_ioctl_tiocmiwait(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
) {
2023 port_t
*port
= (port_t
*) tty
->driver_data
;
2025 if (cmd
== TIOCMIWAIT
) {
2026 DECLARE_WAITQUEUE(wait
, current
);
2027 struct async_icount cnow
;
2028 struct async_icount cprev
;
2030 cprev
= port
->tty_icount
;
2032 add_wait_queue(&port
->tty_wait
, &wait
);
2033 set_current_state(TASK_INTERRUPTIBLE
);
2035 remove_wait_queue(&port
->tty_wait
, &wait
);
2037 /* see if a signal woke us up */
2038 if (signal_pending(current
))
2039 return -ERESTARTSYS
;
2041 cnow
= port
->tty_icount
;
2042 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2043 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2044 return -EIO
; /* no change => error */
2045 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2046 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2047 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2048 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2055 return -ENOIOCTLCMD
;
2058 static int ntty_ioctl_tiocgicount(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
) {
2059 port_t
*port
= (port_t
*) tty
->driver_data
;
2061 if (cmd
== TIOCGICOUNT
) {
2062 struct async_icount cnow
= port
->tty_icount
;
2063 struct serial_icounter_struct icount
;
2065 icount
.cts
= cnow
.cts
;
2066 icount
.dsr
= cnow
.dsr
;
2067 icount
.rng
= cnow
.rng
;
2068 icount
.dcd
= cnow
.dcd
;
2069 icount
.rx
= cnow
.rx
;
2070 icount
.tx
= cnow
.tx
;
2071 icount
.frame
= cnow
.frame
;
2072 icount
.overrun
= cnow
.overrun
;
2073 icount
.parity
= cnow
.parity
;
2074 icount
.brk
= cnow
.brk
;
2075 icount
.buf_overrun
= cnow
.buf_overrun
;
2077 if (copy_to_user((void *)arg
, &icount
, sizeof(icount
)))
2081 return -ENOIOCTLCMD
;
2084 static int ntty_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
) {
2085 port_t
*port
= (port_t
*) tty
->driver_data
;
2087 int rval
= -ENOIOCTLCMD
;
2089 D1("******** IOCTL, cmd: %d", cmd
);
2094 D1( "IOCTL TCGETS ...");
2095 rval
= -ENOIOCTLCMD
;
2098 D1( "IOCTL TCSETS ...");
2099 rval
= -ENOIOCTLCMD
;
2102 rval
= ntty_ioctl_tiocmiwait(tty
, file
, cmd
, arg
);
2105 rval
= ntty_ioctl_tiocgicount(tty
, file
, cmd
, arg
);
2108 rval
= ntty_tiocmget(tty
, file
);
2111 rval
= ntty_tiocmset(tty
, file
, arg
);
2114 if (get_user(mask
, (unsigned long *) arg
))
2117 if (mask
& TIOCM_RTS
)
2118 set_rts(port
->tty_index
, 0);
2119 if (mask
& TIOCM_DTR
)
2120 set_dtr(port
->tty_index
, 0);
2124 if (get_user(mask
, (unsigned long *) arg
))
2127 if (mask
& TIOCM_RTS
)
2128 set_rts(port
->tty_index
, 1);
2129 if (mask
& TIOCM_DTR
)
2130 set_dtr(port
->tty_index
, 1);
2134 D1( "IOCTL TCFLSH ...");
2135 rval
= -ENOIOCTLCMD
;
2139 D1( "ERR: 0x%08X, %d", cmd
, cmd
);
2146 /* Called by the upper tty layer when tty buffers are ready */
2147 /* to receive data again after a call to throttle. */
2148 static void ntty_unthrottle(struct tty_struct
*tty
) {
2149 port_t
*port
= (port_t
*) tty
->driver_data
;
2150 dc_t
*dc
= get_dc_by_tty(tty
);
2152 #if 0 // Masked by Jared. 05-24-2006. Move into set_rts(), enable_transmit_dl().
2155 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
2159 enable_transmit_dl(port
->tty_index
, dc
);
2160 set_rts(port
->tty_index
, 1);
2161 #if 0 // Masked by Jared. 05-24-2006. Move into set_rts(), enable_transmit_dl().
2162 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
2167 /* Called by the upper tty layer when the tty buffers are almost full. */
2168 /* The driver should stop send more data. */
2169 static void ntty_throttle(struct tty_struct
*tty
) {
2170 port_t
*port
= (port_t
*) tty
->driver_data
;
2171 #if 0 // Masked by Jared. 05-24-2006. Move into set_rts(), enable_transmit_dl().
2172 dc_t
*dc
= get_dc_by_tty(tty
);
2174 spin_lock_irqsave(&dc
->spin_mutex
, flags
);
2177 set_rts(port
->tty_index
, 0);
2178 #if 0 // Masked by Jared. 05-24-2006. Move into set_rts(), enable_transmit_dl().
2179 spin_unlock_irqrestore(&dc
->spin_mutex
, flags
);
2184 static void ntty_put_char(struct tty_struct
*tty
, unsigned char c
) {
2185 D2("PUT CHAR Function: %c", c
);
2188 /* Returns number of chars in buffer, called by tty layer */
2189 static s32
ntty_chars_in_buffer(struct tty_struct
*tty
) {
2190 port_t
*port
= (port_t
*) tty
->driver_data
;
2195 goto exit_in_buffer
;
2198 if (! port
->tty_open_count
) {
2199 ERR("No tty open?");
2201 goto exit_in_buffer
;
2204 rval
= __kfifo_len(port
->fifo_ul
);
2210 /* Initializes the tty */
2211 static int ntty_tty_init(dc_t
*dc
) {
2212 struct tty_driver
*td
= &dc
->tty_driver
;
2216 memset(td
, 0, sizeof(struct tty_driver
));
2218 td
->magic
= TTY_DRIVER_MAGIC
;
2219 td
->driver_name
= NOZOMI_NAME_TTY
;
2221 td
->major
= NTTY_TTY_MAJOR
,
2222 td
->type
= TTY_DRIVER_TYPE_SERIAL
,
2223 td
->subtype
= SERIAL_TYPE_NORMAL
,
2224 td
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
,
2225 td
->init_termios
= tty_std_termios
;
2226 td
->init_termios
.c_cflag
= B115200
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2230 td
->minor_start
= 0;
2233 td
->table
= dc
->tty_table
;
2234 td
->refcount
= &dc
->tty_refcount
;
2237 td
->termios
= dc
->tty_termios
;
2238 td
->termios_locked
= dc
->tty_termios_locked
;
2240 td
->ioctl
= ntty_ioctl
;
2241 td
->open
= ntty_open
;
2242 td
->close
= ntty_close
;
2243 td
->write
= ntty_write
;
2244 td
->write_room
= ntty_write_room
;
2245 td
->unthrottle
= ntty_unthrottle
;
2246 td
->throttle
= ntty_throttle
;
2247 td
->set_termios
= ntty_set_termios
;
2248 td
->chars_in_buffer
= ntty_chars_in_buffer
;
2249 td
->put_char
= ntty_put_char
;
2251 rval
= tty_register_driver(td
);
2254 printk(KERN_ERR
"failed to register ntty tty driver");
2255 D1( "failed to register ntty tty driver");
2259 for (i
= 0; i
< NTTY_TTY_MINORS
; i
++) {
2260 init_MUTEX(&dc
->port
[i
].tty_sem
);
2261 dc
->port
[i
].tty_open_count
= 0;
2262 dc
->port
[i
].tty
= NULL
;
2265 tty_register_device(td
, i
, NULL
);
2269 printk(KERN_INFO DRIVER_DESC
" " NOZOMI_NAME_TTY
);
2274 /* Module initialization */
2275 static struct pci_driver nozomi_driver
= {
2276 .name
= NOZOMI_NAME
,
2277 .id_table
= nozomi_pci_tbl
,
2278 .probe
= nozomi_card_init
,
2279 #if 0 // Mask by Jared 05-24-2006
2280 .remove
= __devexit_p(nozomi_card_exit
),
2282 .remove
= (nozomi_card_exit
),
2286 static int __init
nozomi_init(void) {
2288 #if 0 // Mask by Jared 05-24-2006
2289 rval
= pci_module_init(&nozomi_driver
);
2291 rval
= pci_register_driver(&nozomi_driver
);
2293 printk(KERN_INFO
"Initializing %s\n", VERSION_STRING
);
2297 static void __exit
nozomi_exit(void) {
2298 printk(KERN_INFO
"Unloading %s", DRIVER_DESC
);
2300 pci_unregister_driver(&nozomi_driver
);
2303 module_init(nozomi_init
);
2304 module_exit(nozomi_exit
);
2307 MODULE_PARM(nzdebug
, "i");
2310 MODULE_LICENSE("Dual BSD/GPL");
2311 MODULE_DESCRIPTION( DRIVER_DESC
);