blob: 16bdf23ee02b1234b95805354a0cde070546e24d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Peter Tiedemann293d9842008-02-08 00:03:49 +01002/*
Peter Tiedemann293d9842008-02-08 00:03:49 +01003 * Copyright IBM Corp. 2001, 2007
4 * Authors: Fritz Elfert (felfert@millenux.com)
5 * Peter Tiedemann (ptiedem@de.ibm.com)
6 */
7
8#ifndef _CTCM_MAIN_H_
9#define _CTCM_MAIN_H_
10
11#include <asm/ccwdev.h>
12#include <asm/ccwgroup.h>
13
14#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16
17#include "fsm.h"
Peter Tiedemann293d9842008-02-08 00:03:49 +010018#include "ctcm_dbug.h"
19#include "ctcm_mpc.h"
20
21#define CTC_DRIVER_NAME "ctcm"
22#define CTC_DEVICE_NAME "ctc"
Peter Tiedemann293d9842008-02-08 00:03:49 +010023#define MPC_DEVICE_NAME "mpc"
Peter Tiedemannaa3f2cb62008-07-18 15:24:57 +020024#define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
25#define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
Peter Tiedemann293d9842008-02-08 00:03:49 +010026
27#define CHANNEL_FLAGS_READ 0
28#define CHANNEL_FLAGS_WRITE 1
29#define CHANNEL_FLAGS_INUSE 2
30#define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
31#define CHANNEL_FLAGS_FAILED 8
32#define CHANNEL_FLAGS_WAITIRQ 16
33#define CHANNEL_FLAGS_RWMASK 1
34#define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
35
36#define LOG_FLAG_ILLEGALPKT 1
37#define LOG_FLAG_ILLEGALSIZE 2
38#define LOG_FLAG_OVERRUN 4
39#define LOG_FLAG_NOMEM 8
40
41#define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
Peter Tiedemann293d9842008-02-08 00:03:49 +010042
Peter Tiedemannaa3f2cb62008-07-18 15:24:57 +020043#define CTCM_PR_DEBUG(fmt, arg...) \
44 do { \
45 if (do_debug) \
46 printk(KERN_DEBUG fmt, ##arg); \
47 } while (0)
48
49#define CTCM_PR_DBGDATA(fmt, arg...) \
50 do { \
51 if (do_debug_data) \
52 printk(KERN_DEBUG fmt, ##arg); \
53 } while (0)
54
55#define CTCM_D3_DUMP(buf, len) \
56 do { \
57 if (do_debug_data) \
58 ctcmpc_dumpit(buf, len); \
59 } while (0)
60
61#define CTCM_CCW_DUMP(buf, len) \
62 do { \
63 if (do_debug_ccw) \
64 ctcmpc_dumpit(buf, len); \
65 } while (0)
66
Ursula Braun0ca8cc62009-11-12 21:46:29 +000067/**
68 * Enum for classifying detected devices
69 */
70enum ctcm_channel_types {
71 /* Device is not a channel */
72 ctcm_channel_type_none,
73
74 /* Device is a CTC/A */
75 ctcm_channel_type_parallel,
76
77 /* Device is a FICON channel */
78 ctcm_channel_type_ficon,
79
80 /* Device is a ESCON channel */
81 ctcm_channel_type_escon
82};
83
Peter Tiedemann293d9842008-02-08 00:03:49 +010084/*
85 * CCW commands, used in this driver.
86 */
87#define CCW_CMD_WRITE 0x01
88#define CCW_CMD_READ 0x02
89#define CCW_CMD_NOOP 0x03
90#define CCW_CMD_TIC 0x08
91#define CCW_CMD_SENSE_CMD 0x14
92#define CCW_CMD_WRITE_CTL 0x17
93#define CCW_CMD_SET_EXTENDED 0xc3
94#define CCW_CMD_PREPARE 0xe3
95
96#define CTCM_PROTO_S390 0
97#define CTCM_PROTO_LINUX 1
98#define CTCM_PROTO_LINUX_TTY 2
99#define CTCM_PROTO_OS390 3
100#define CTCM_PROTO_MPC 4
101#define CTCM_PROTO_MAX 4
102
103#define CTCM_BUFSIZE_LIMIT 65535
104#define CTCM_BUFSIZE_DEFAULT 32768
105#define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
106
107#define CTCM_TIME_1_SEC 1000
108#define CTCM_TIME_5_SEC 5000
109#define CTCM_TIME_10_SEC 10000
110
111#define CTCM_INITIAL_BLOCKLEN 2
112
Ursula Braun3c09e262010-08-12 01:58:28 +0000113#define CTCM_READ 0
114#define CTCM_WRITE 1
Peter Tiedemann293d9842008-02-08 00:03:49 +0100115
Kay Sievers2a0217d2008-10-10 21:33:09 +0200116#define CTCM_ID_SIZE 20+3
Peter Tiedemann293d9842008-02-08 00:03:49 +0100117
118struct ctcm_profile {
119 unsigned long maxmulti;
120 unsigned long maxcqueue;
121 unsigned long doios_single;
122 unsigned long doios_multi;
123 unsigned long txlen;
124 unsigned long tx_time;
Aya Mahfouzee6edb92015-01-16 14:05:45 +0100125 unsigned long send_stamp;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100126};
127
128/*
129 * Definition of one channel
130 */
131struct channel {
132 struct channel *next;
133 char id[CTCM_ID_SIZE];
134 struct ccw_device *cdev;
135 /*
136 * Type of this channel.
137 * CTC/A or Escon for valid channels.
138 */
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000139 enum ctcm_channel_types type;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100140 /*
141 * Misc. flags. See CHANNEL_FLAGS_... below
142 */
143 __u32 flags;
144 __u16 protocol; /* protocol of this channel (4 = MPC) */
145 /*
146 * I/O and irq related stuff
147 */
148 struct ccw1 *ccw;
149 struct irb *irb;
150 /*
151 * RX/TX buffer size
152 */
153 int max_bufsize;
154 struct sk_buff *trans_skb; /* transmit/receive buffer */
155 struct sk_buff_head io_queue; /* universal I/O queue */
156 struct tasklet_struct ch_tasklet; /* MPC ONLY */
157 /*
158 * TX queue for collecting skb's during busy.
159 */
160 struct sk_buff_head collect_queue;
161 /*
162 * Amount of data in collect_queue.
163 */
164 int collect_len;
165 /*
166 * spinlock for collect_queue and collect_len
167 */
168 spinlock_t collect_lock;
169 /*
170 * Timer for detecting unresposive
171 * I/O operations.
172 */
173 fsm_timer timer;
174 /* MPC ONLY section begin */
175 __u32 th_seq_num; /* SNA TH seq number */
176 __u8 th_seg;
177 __u32 pdu_seq;
178 struct sk_buff *xid_skb;
179 char *xid_skb_data;
180 struct th_header *xid_th;
181 struct xid2 *xid;
182 char *xid_id;
183 struct th_header *rcvd_xid_th;
184 struct xid2 *rcvd_xid;
185 char *rcvd_xid_id;
186 __u8 in_mpcgroup;
187 fsm_timer sweep_timer;
188 struct sk_buff_head sweep_queue;
189 struct th_header *discontact_th;
190 struct tasklet_struct ch_disc_tasklet;
191 /* MPC ONLY section end */
192
193 int retry; /* retry counter for misc. operations */
194 fsm_instance *fsm; /* finite state machine of this channel */
195 struct net_device *netdev; /* corresponding net_device */
196 struct ctcm_profile prof;
Peter Tiedemannaa3f2cb62008-07-18 15:24:57 +0200197 __u8 *trans_skb_data;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100198 __u16 logflags;
Peter Tiedemannaa3f2cb62008-07-18 15:24:57 +0200199 __u8 sense_rc; /* last unit check sense code report control */
Peter Tiedemann293d9842008-02-08 00:03:49 +0100200};
201
202struct ctcm_priv {
203 struct net_device_stats stats;
204 unsigned long tbusy;
205
206 /* The MPC group struct of this interface */
207 struct mpc_group *mpcg; /* MPC only */
208 struct xid2 *xid; /* MPC only */
209
210 /* The finite state machine of this interface */
211 fsm_instance *fsm;
212
213 /* The protocol of this device */
214 __u16 protocol;
215
216 /* Timer for restarting after I/O Errors */
217 fsm_timer restart_timer;
218
219 int buffer_size; /* ctc only */
220
221 struct channel *channel[2];
222};
223
224int ctcm_open(struct net_device *dev);
225int ctcm_close(struct net_device *dev);
226
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200227extern const struct attribute_group *ctcm_attr_groups[];
Peter Tiedemann293d9842008-02-08 00:03:49 +0100228
229/*
230 * Compatibility macros for busy handling
231 * of network devices.
232 */
233static inline void ctcm_clear_busy_do(struct net_device *dev)
234{
Peter Tiedemann261893d2008-08-21 17:10:24 +0200235 clear_bit(0, &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100236 netif_wake_queue(dev);
237}
238
239static inline void ctcm_clear_busy(struct net_device *dev)
240{
241 struct mpc_group *grp;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200242 grp = ((struct ctcm_priv *)dev->ml_priv)->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100243
244 if (!(grp && grp->in_sweep))
245 ctcm_clear_busy_do(dev);
246}
247
248
249static inline int ctcm_test_and_set_busy(struct net_device *dev)
250{
251 netif_stop_queue(dev);
Peter Tiedemann261893d2008-08-21 17:10:24 +0200252 return test_and_set_bit(0,
253 &(((struct ctcm_priv *)dev->ml_priv)->tbusy));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100254}
255
256extern int loglevel;
257extern struct channel *channels;
258
259void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
260
261/*
262 * Functions related to setup and device detection.
263 */
264
265static inline int ctcm_less_than(char *id1, char *id2)
266{
267 unsigned long dev1, dev2;
268
269 id1 = id1 + 5;
270 id2 = id2 + 5;
271
272 dev1 = simple_strtoul(id1, &id1, 16);
273 dev2 = simple_strtoul(id2, &id2, 16);
274
275 return (dev1 < dev2);
276}
277
278int ctcm_ch_alloc_buffer(struct channel *ch);
279
280static inline int ctcm_checkalloc_buffer(struct channel *ch)
281{
282 if (ch->trans_skb == NULL)
283 return ctcm_ch_alloc_buffer(ch);
284 if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
285 dev_kfree_skb(ch->trans_skb);
286 return ctcm_ch_alloc_buffer(ch);
287 }
288 return 0;
289}
290
291struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
292
293/* test if protocol attribute (of struct ctcm_priv or struct channel)
294 * has MPC protocol setting. Type is not checked
295 */
296#define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
297
298/* test if struct ctcm_priv of struct net_device has MPC protocol setting */
Peter Tiedemann261893d2008-08-21 17:10:24 +0200299#define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100300
301static inline gfp_t gfp_type(void)
302{
303 return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
304}
305
306/*
307 * Definition of our link level header.
308 */
309struct ll_header {
310 __u16 length;
311 __u16 type;
312 __u16 unused;
313};
314#define LL_HEADER_LENGTH (sizeof(struct ll_header))
315
316#endif