1/*
2 * CTC / ESCON network driver
3 *
4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
6	      Peter Tiedemann (ptiedem@de.ibm.com)
7 *
8 *
9 * Documentation used:
10 *  - Principles of Operation (IBM doc#: SA22-7201-06)
11 *  - Common IO/-Device Commands and Self Description (IBM doc#: SA22-7204-02)
12 *  - Common IO/-Device Commands and Self Description (IBM doc#: SN22-5535)
13 *  - ESCON Channel-to-Channel Adapter (IBM doc#: SA22-7203-00)
14 *  - ESCON I/O Interface (IBM doc#: SA22-7202-029
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31
32#ifndef _CTCMAIN_H_
33#define _CTCMAIN_H_
34
35#include <asm/ccwdev.h>
36#include <asm/ccwgroup.h>
37
38#include <linux/skbuff.h>
39#include <linux/netdevice.h>
40
41#include "fsm.h"
42#include "cu3088.h"
43
44
45/**
46 * CCW commands, used in this driver.
47 */
48#define CCW_CMD_WRITE		0x01
49#define CCW_CMD_READ		0x02
50#define CCW_CMD_SET_EXTENDED	0xc3
51#define CCW_CMD_PREPARE		0xe3
52
53#define CTC_PROTO_S390          0
54#define CTC_PROTO_LINUX         1
55#define CTC_PROTO_OS390         3
56
57#define CTC_BUFSIZE_LIMIT       65535
58#define CTC_BUFSIZE_DEFAULT     32768
59
60#define CTC_TIMEOUT_5SEC        5000
61
62#define CTC_INITIAL_BLOCKLEN    2
63
64#define READ			0
65#define WRITE			1
66
67#define CTC_ID_SIZE             BUS_ID_SIZE+3
68
69
70struct ctc_profile {
71	unsigned long maxmulti;
72	unsigned long maxcqueue;
73	unsigned long doios_single;
74	unsigned long doios_multi;
75	unsigned long txlen;
76	unsigned long tx_time;
77	struct timespec send_stamp;
78};
79
80/**
81 * Definition of one channel
82 */
83struct channel {
84
85	/**
86	 * Pointer to next channel in list.
87	 */
88	struct channel *next;
89	char id[CTC_ID_SIZE];
90	struct ccw_device *cdev;
91
92	/**
93	 * Type of this channel.
94	 * CTC/A or Escon for valid channels.
95	 */
96	enum channel_types type;
97
98	/**
99	 * Misc. flags. See CHANNEL_FLAGS_... below
100	 */
101	__u32 flags;
102
103	/**
104	 * The protocol of this channel
105	 */
106	__u16 protocol;
107
108	/**
109	 * I/O and irq related stuff
110	 */
111	struct ccw1 *ccw;
112	struct irb *irb;
113
114	/**
115	 * RX/TX buffer size
116	 */
117	int max_bufsize;
118
119	/**
120	 * Transmit/Receive buffer.
121	 */
122	struct sk_buff *trans_skb;
123
124	/**
125	 * Universal I/O queue.
126	 */
127	struct sk_buff_head io_queue;
128
129	/**
130	 * TX queue for collecting skb's during busy.
131	 */
132	struct sk_buff_head collect_queue;
133
134	/**
135	 * Amount of data in collect_queue.
136	 */
137	int collect_len;
138
139	/**
140	 * spinlock for collect_queue and collect_len
141	 */
142	spinlock_t collect_lock;
143
144	/**
145	 * Timer for detecting unresposive
146	 * I/O operations.
147	 */
148	fsm_timer timer;
149
150	/**
151	 * Retry counter for misc. operations.
152	 */
153	int retry;
154
155	/**
156	 * The finite state machine of this channel
157	 */
158	fsm_instance *fsm;
159
160	/**
161	 * The corresponding net_device this channel
162	 * belongs to.
163	 */
164	struct net_device *netdev;
165
166	struct ctc_profile prof;
167
168	unsigned char *trans_skb_data;
169
170	__u16 logflags;
171};
172
173#define CHANNEL_FLAGS_READ            0
174#define CHANNEL_FLAGS_WRITE           1
175#define CHANNEL_FLAGS_INUSE           2
176#define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
177#define CHANNEL_FLAGS_FAILED          8
178#define CHANNEL_FLAGS_WAITIRQ        16
179#define CHANNEL_FLAGS_RWMASK 1
180#define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
181
182#define LOG_FLAG_ILLEGALPKT  1
183#define LOG_FLAG_ILLEGALSIZE 2
184#define LOG_FLAG_OVERRUN     4
185#define LOG_FLAG_NOMEM       8
186
187#define CTC_LOGLEVEL_INFO     1
188#define CTC_LOGLEVEL_NOTICE   2
189#define CTC_LOGLEVEL_WARN     4
190#define CTC_LOGLEVEL_EMERG    8
191#define CTC_LOGLEVEL_ERR     16
192#define CTC_LOGLEVEL_DEBUG   32
193#define CTC_LOGLEVEL_CRIT    64
194
195#define CTC_LOGLEVEL_DEFAULT \
196(CTC_LOGLEVEL_INFO | CTC_LOGLEVEL_NOTICE | CTC_LOGLEVEL_WARN | CTC_LOGLEVEL_CRIT)
197
198#define CTC_LOGLEVEL_MAX     ((CTC_LOGLEVEL_CRIT<<1)-1)
199
200#define ctc_pr_debug(fmt, arg...) \
201do { if (loglevel & CTC_LOGLEVEL_DEBUG) printk(KERN_DEBUG fmt,##arg); } while (0)
202
203#define ctc_pr_info(fmt, arg...) \
204do { if (loglevel & CTC_LOGLEVEL_INFO) printk(KERN_INFO fmt,##arg); } while (0)
205
206#define ctc_pr_notice(fmt, arg...) \
207do { if (loglevel & CTC_LOGLEVEL_NOTICE) printk(KERN_NOTICE fmt,##arg); } while (0)
208
209#define ctc_pr_warn(fmt, arg...) \
210do { if (loglevel & CTC_LOGLEVEL_WARN) printk(KERN_WARNING fmt,##arg); } while (0)
211
212#define ctc_pr_emerg(fmt, arg...) \
213do { if (loglevel & CTC_LOGLEVEL_EMERG) printk(KERN_EMERG fmt,##arg); } while (0)
214
215#define ctc_pr_err(fmt, arg...) \
216do { if (loglevel & CTC_LOGLEVEL_ERR) printk(KERN_ERR fmt,##arg); } while (0)
217
218#define ctc_pr_crit(fmt, arg...) \
219do { if (loglevel & CTC_LOGLEVEL_CRIT) printk(KERN_CRIT fmt,##arg); } while (0)
220
221struct ctc_priv {
222	struct net_device_stats stats;
223	unsigned long tbusy;
224	/**
225	 * The finite state machine of this interface.
226	 */
227	fsm_instance *fsm;
228	/**
229	 * The protocol of this device
230	 */
231	__u16 protocol;
232 	/**
233 	 * Timer for restarting after I/O Errors
234 	 */
235 	fsm_timer               restart_timer;
236
237	int buffer_size;
238
239	struct channel *channel[2];
240};
241
242/**
243 * Definition of our link level header.
244 */
245struct ll_header {
246	__u16 length;
247	__u16 type;
248	__u16 unused;
249};
250#define LL_HEADER_LENGTH (sizeof(struct ll_header))
251
252/**
253 * Compatibility macros for busy handling
254 * of network devices.
255 */
256static __inline__ void
257ctc_clear_busy(struct net_device * dev)
258{
259	clear_bit(0, &(((struct ctc_priv *) dev->priv)->tbusy));
260	netif_wake_queue(dev);
261}
262
263static __inline__ int
264ctc_test_and_set_busy(struct net_device * dev)
265{
266	netif_stop_queue(dev);
267	return test_and_set_bit(0, &((struct ctc_priv *) dev->priv)->tbusy);
268}
269
270#endif
271