Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * IPWireless 3G PCMCIA Network Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Original code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *   by Stephen Blackheath <stephen@blacksapphire.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *      Ben Martel <benm@symmetric.co.nz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyrighted as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Various driver changes and rewrites, port to new kernels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   Copyright (C) 2006-2007 Jiri Kosina
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Misc code cleanups and updates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   Copyright (C) 2007 David Sterba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/ppp_defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/ppp-ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "tty.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "network.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "hardware.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define IPWIRELESS_PCMCIA_START 	(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define IPWIRELESS_PCMCIA_MINORS	(24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define IPWIRELESS_PCMCIA_MINOR_RANGE	(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define TTYTYPE_MODEM    (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define TTYTYPE_MONITOR  (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TTYTYPE_RAS_RAW  (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct ipw_tty {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct tty_port port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct ipw_hardware *hardware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unsigned int channel_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned int secondary_channel_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int tty_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct ipw_network *network;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned int control_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct mutex ipw_tty_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int tx_bytes_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int closing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static struct tty_driver *ipw_tty_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static char *tty_type_name(int tty_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	static char *channel_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		"modem",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		"monitor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		"RAS-raw"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return channel_names[tty_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static struct ipw_tty *get_tty(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * The 'ras_raw' channel is only available when 'loopback' mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * Number of minor starts with 16 (_RANGE * _RAS_RAW).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (!ipwireless_loopback && index >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			 IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return ttys[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct ipw_tty *tty = get_tty(linux_tty->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mutex_lock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (tty->port.count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		tty->tx_bytes_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	tty->port.count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	tty->port.tty = linux_tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	linux_tty->driver_data = tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	tty->port.low_latency = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (tty->tty_type == TTYTYPE_MODEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		ipwireless_ppp_open(tty->network);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void do_ipw_close(struct ipw_tty *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	tty->port.count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (tty->port.count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		struct tty_struct *linux_tty = tty->port.tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (linux_tty != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			tty->port.tty = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			linux_tty->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			if (tty->tty_type == TTYTYPE_MODEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				ipwireless_ppp_close(tty->network);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void ipw_hangup(struct tty_struct *linux_tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	mutex_lock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (tty->port.count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	do_ipw_close(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	ipw_hangup(linux_tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Take data received from hardware, and send it out the tty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int work = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	mutex_lock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!tty->port.count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	work = tty_insert_flip_string(&tty->port, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (work != length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				": %d chars not inserted to flip buffer!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				length - work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		tty_flip_buffer_push(&tty->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void ipw_write_packet_sent_callback(void *callback_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					   unsigned int packet_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct ipw_tty *tty = callback_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * Packet has been sent, so we subtract the number of bytes from our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * tally of outstanding TX bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	tty->tx_bytes_queued -= packet_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int ipw_write(struct tty_struct *linux_tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		     const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int room, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	mutex_lock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (!tty->port.count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (room < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		room = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* Don't allow caller to write any more than we have room for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (count > room)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		count = room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			       buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			       ipw_write_packet_sent_callback, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	tty->tx_bytes_queued += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	mutex_unlock(&tty->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int ipw_write_room(struct tty_struct *linux_tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	int room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* FIXME: Exactly how is the tty object locked here .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (room < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		room = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int ipwireless_get_serial_info(struct tty_struct *linux_tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				      struct serial_struct *ss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	ss->type = PORT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ss->line = tty->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	ss->baud_base = 115200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int ipwireless_set_serial_info(struct tty_struct *linux_tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				      struct serial_struct *ss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;	/* Keeps the PCMCIA scripts happy. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return tty->tx_bytes_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int get_control_lines(struct ipw_tty *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	unsigned int my = tty->control_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	unsigned int out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (my & IPW_CONTROL_LINE_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		out |= TIOCM_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (my & IPW_CONTROL_LINE_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		out |= TIOCM_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (my & IPW_CONTROL_LINE_CTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		out |= TIOCM_CTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (my & IPW_CONTROL_LINE_DSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		out |= TIOCM_DSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (my & IPW_CONTROL_LINE_DCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		out |= TIOCM_CD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int set_control_lines(struct ipw_tty *tty, unsigned int set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			     unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (set & TIOCM_RTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		if (tty->secondary_channel_idx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			ret = ipwireless_set_RTS(tty->hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 					  tty->secondary_channel_idx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (set & TIOCM_DTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		if (tty->secondary_channel_idx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			ret = ipwireless_set_DTR(tty->hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					  tty->secondary_channel_idx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (clear & TIOCM_RTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (tty->secondary_channel_idx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			ret = ipwireless_set_RTS(tty->hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 					  tty->secondary_channel_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (clear & TIOCM_DTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		if (tty->secondary_channel_idx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			ret = ipwireless_set_DTR(tty->hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					  tty->secondary_channel_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int ipw_tiocmget(struct tty_struct *linux_tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/* FIXME: Exactly how is the tty object locked here .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return get_control_lines(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ipw_tiocmset(struct tty_struct *linux_tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	     unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* FIXME: Exactly how is the tty object locked here .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return set_control_lines(tty, set, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int ipw_ioctl(struct tty_struct *linux_tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		     unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct ipw_tty *tty = linux_tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (!tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (!tty->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* FIXME: Exactly how is the tty object locked here .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (tty->tty_type == TTYTYPE_MODEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		case PPPIOCGCHAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 				int chan = ipwireless_ppp_channel_index(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 							tty->network);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 				if (chan < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 					return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				if (put_user(chan, (int __user *) arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		case PPPIOCGUNIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 				int unit = ipwireless_ppp_unit_number(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 						tty->network);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				if (unit < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				if (put_user(unit, (int __user *) arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		case FIONREAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				if (put_user(val, (int __user *) arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		case TCFLSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			return tty_perform_flush(linux_tty, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int add_tty(int j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		    struct ipw_hardware *hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		    struct ipw_network *network, int channel_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		    int secondary_channel_idx, int tty_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (!ttys[j])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	ttys[j]->index = j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	ttys[j]->hardware = hardware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	ttys[j]->channel_idx = channel_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	ttys[j]->secondary_channel_idx = secondary_channel_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ttys[j]->network = network;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	ttys[j]->tty_type = tty_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	mutex_init(&ttys[j]->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	tty_port_init(&ttys[j]->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	tty_port_register_device(&ttys[j]->port, ipw_tty_driver, j, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (secondary_channel_idx != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		ipwireless_associate_network_tty(network,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 						 secondary_channel_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 						 ttys[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	/* check if we provide raw device (if loopback is enabled) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (get_tty(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		printk(KERN_INFO IPWIRELESS_PCCARD_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		       ": registering %s device ttyIPWp%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		       tty_type_name(tty_type), j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 				      struct ipw_network *network)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		int allfree = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 				j += IPWIRELESS_PCMCIA_MINOR_RANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			if (ttys[j] != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 				allfree = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (allfree) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			j = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			if (add_tty(j, hardware, network,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 					IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 					TTYTYPE_MODEM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			j += IPWIRELESS_PCMCIA_MINOR_RANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			if (add_tty(j, hardware, network,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 					IPW_CHANNEL_DIALLER, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 					TTYTYPE_MONITOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			j += IPWIRELESS_PCMCIA_MINOR_RANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			if (add_tty(j, hardware, network,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 					IPW_CHANNEL_RAS, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 					TTYTYPE_RAS_RAW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			return ttys[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  * Must be called before ipwireless_network_free().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) void ipwireless_tty_free(struct ipw_tty *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	struct ipw_network *network = ttys[tty->index]->network;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		struct ipw_tty *ttyj = ttys[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		if (ttyj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			mutex_lock(&ttyj->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			if (get_tty(j))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				printk(KERN_INFO IPWIRELESS_PCCARD_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 				       ": deregistering %s device ttyIPWp%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 				       tty_type_name(ttyj->tty_type), j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			ttyj->closing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 			if (ttyj->port.tty != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 				mutex_unlock(&ttyj->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				tty_vhangup(ttyj->port.tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 				/* FIXME: Exactly how is the tty object locked here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 				   against a parallel ioctl etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 				/* FIXME2: hangup does not mean all processes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 				 * are gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 				mutex_lock(&ttyj->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			while (ttyj->port.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 				do_ipw_close(ttyj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			ipwireless_disassociate_network_ttys(network,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 							     ttyj->channel_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			tty_unregister_device(ipw_tty_driver, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			tty_port_destroy(&ttyj->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			ttys[j] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			mutex_unlock(&ttyj->ipw_tty_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			kfree(ttyj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static const struct tty_operations tty_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	.open = ipw_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.close = ipw_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.hangup = ipw_hangup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.write = ipw_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.write_room = ipw_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.ioctl = ipw_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	.chars_in_buffer = ipw_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.tiocmget = ipw_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.tiocmset = ipw_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	.set_serial = ipwireless_set_serial_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.get_serial = ipwireless_get_serial_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) int ipwireless_tty_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	if (!ipw_tty_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	ipw_tty_driver->name = "ttyIPWp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	ipw_tty_driver->major = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	ipw_tty_driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	ipw_tty_driver->init_termios.c_cflag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	    B9600 | CS8 | CREAD | HUPCL | CLOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	ipw_tty_driver->init_termios.c_ispeed = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	ipw_tty_driver->init_termios.c_ospeed = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	tty_set_operations(ipw_tty_driver, &tty_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	result = tty_register_driver(ipw_tty_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		printk(KERN_ERR IPWIRELESS_PCCARD_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		       ": failed to register tty driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		put_tty_driver(ipw_tty_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) void ipwireless_tty_release(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	ret = tty_unregister_driver(ipw_tty_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	put_tty_driver(ipw_tty_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		printk(KERN_ERR IPWIRELESS_PCCARD_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 			": tty_unregister_driver failed with code %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int ipwireless_tty_is_modem(struct ipw_tty *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	return tty->tty_type == TTYTYPE_MODEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 					  unsigned int channel_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 					  unsigned int control_lines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 					  unsigned int changed_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	unsigned int old_control_lines = tty->control_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	tty->control_lines = (tty->control_lines & ~changed_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		| (control_lines & changed_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	 * If DCD is de-asserted, we close the tty so pppd can tell that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	 * have gone offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	if ((old_control_lines & IPW_CONTROL_LINE_DCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			&& !(tty->control_lines & IPW_CONTROL_LINE_DCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 			&& tty->port.tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		tty_hangup(tty->port.tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)