2 * drivers/s390/net/ctcm_main.h
4 * Copyright IBM Corp. 2001, 2007
5 * Authors: Fritz Elfert (felfert@millenux.com)
6 * Peter Tiedemann (ptiedem@de.ibm.com)
12 #include <asm/ccwdev.h>
13 #include <asm/ccwgroup.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
19 #include "ctcm_dbug.h"
22 #define CTC_DRIVER_NAME "ctcm"
23 #define CTC_DEVICE_NAME "ctc"
24 #define MPC_DEVICE_NAME "mpc"
25 #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
26 #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
28 #define CHANNEL_FLAGS_READ 0
29 #define CHANNEL_FLAGS_WRITE 1
30 #define CHANNEL_FLAGS_INUSE 2
31 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
32 #define CHANNEL_FLAGS_FAILED 8
33 #define CHANNEL_FLAGS_WAITIRQ 16
34 #define CHANNEL_FLAGS_RWMASK 1
35 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
37 #define LOG_FLAG_ILLEGALPKT 1
38 #define LOG_FLAG_ILLEGALSIZE 2
39 #define LOG_FLAG_OVERRUN 4
40 #define LOG_FLAG_NOMEM 8
42 #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
44 #define CTCM_PR_DEBUG(fmt, arg...) \
47 printk(KERN_DEBUG fmt, ##arg); \
50 #define CTCM_PR_DBGDATA(fmt, arg...) \
53 printk(KERN_DEBUG fmt, ##arg); \
56 #define CTCM_D3_DUMP(buf, len) \
59 ctcmpc_dumpit(buf, len); \
62 #define CTCM_CCW_DUMP(buf, len) \
65 ctcmpc_dumpit(buf, len); \
69 * Enum for classifying detected devices
71 enum ctcm_channel_types
{
72 /* Device is not a channel */
73 ctcm_channel_type_none
,
75 /* Device is a CTC/A */
76 ctcm_channel_type_parallel
,
78 /* Device is a FICON channel */
79 ctcm_channel_type_ficon
,
81 /* Device is a ESCON channel */
82 ctcm_channel_type_escon
86 * CCW commands, used in this driver.
88 #define CCW_CMD_WRITE 0x01
89 #define CCW_CMD_READ 0x02
90 #define CCW_CMD_NOOP 0x03
91 #define CCW_CMD_TIC 0x08
92 #define CCW_CMD_SENSE_CMD 0x14
93 #define CCW_CMD_WRITE_CTL 0x17
94 #define CCW_CMD_SET_EXTENDED 0xc3
95 #define CCW_CMD_PREPARE 0xe3
97 #define CTCM_PROTO_S390 0
98 #define CTCM_PROTO_LINUX 1
99 #define CTCM_PROTO_LINUX_TTY 2
100 #define CTCM_PROTO_OS390 3
101 #define CTCM_PROTO_MPC 4
102 #define CTCM_PROTO_MAX 4
104 #define CTCM_BUFSIZE_LIMIT 65535
105 #define CTCM_BUFSIZE_DEFAULT 32768
106 #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
108 #define CTCM_TIME_1_SEC 1000
109 #define CTCM_TIME_5_SEC 5000
110 #define CTCM_TIME_10_SEC 10000
112 #define CTCM_INITIAL_BLOCKLEN 2
117 #define CTCM_ID_SIZE 20+3
119 struct ctcm_profile
{
120 unsigned long maxmulti
;
121 unsigned long maxcqueue
;
122 unsigned long doios_single
;
123 unsigned long doios_multi
;
125 unsigned long tx_time
;
126 struct timespec send_stamp
;
130 * Definition of one channel
133 struct channel
*next
;
134 char id
[CTCM_ID_SIZE
];
135 struct ccw_device
*cdev
;
137 * Type of this channel.
138 * CTC/A or Escon for valid channels.
140 enum ctcm_channel_types type
;
142 * Misc. flags. See CHANNEL_FLAGS_... below
145 __u16 protocol
; /* protocol of this channel (4 = MPC) */
147 * I/O and irq related stuff
155 struct sk_buff
*trans_skb
; /* transmit/receive buffer */
156 struct sk_buff_head io_queue
; /* universal I/O queue */
157 struct tasklet_struct ch_tasklet
; /* MPC ONLY */
159 * TX queue for collecting skb's during busy.
161 struct sk_buff_head collect_queue
;
163 * Amount of data in collect_queue.
167 * spinlock for collect_queue and collect_len
169 spinlock_t collect_lock
;
171 * Timer for detecting unresposive
175 /* MPC ONLY section begin */
176 __u32 th_seq_num
; /* SNA TH seq number */
179 struct sk_buff
*xid_skb
;
181 struct th_header
*xid_th
;
184 struct th_header
*rcvd_xid_th
;
185 struct xid2
*rcvd_xid
;
188 fsm_timer sweep_timer
;
189 struct sk_buff_head sweep_queue
;
190 struct th_header
*discontact_th
;
191 struct tasklet_struct ch_disc_tasklet
;
192 /* MPC ONLY section end */
194 int retry
; /* retry counter for misc. operations */
195 fsm_instance
*fsm
; /* finite state machine of this channel */
196 struct net_device
*netdev
; /* corresponding net_device */
197 struct ctcm_profile prof
;
198 __u8
*trans_skb_data
;
200 __u8 sense_rc
; /* last unit check sense code report control */
204 struct net_device_stats stats
;
207 /* The MPC group struct of this interface */
208 struct mpc_group
*mpcg
; /* MPC only */
209 struct xid2
*xid
; /* MPC only */
211 /* The finite state machine of this interface */
214 /* The protocol of this device */
217 /* Timer for restarting after I/O Errors */
218 fsm_timer restart_timer
;
220 int buffer_size
; /* ctc only */
222 struct channel
*channel
[2];
225 int ctcm_open(struct net_device
*dev
);
226 int ctcm_close(struct net_device
*dev
);
229 * prototypes for non-static sysfs functions
231 int ctcm_add_attributes(struct device
*dev
);
232 void ctcm_remove_attributes(struct device
*dev
);
233 int ctcm_add_files(struct device
*dev
);
234 void ctcm_remove_files(struct device
*dev
);
237 * Compatibility macros for busy handling
238 * of network devices.
240 static inline void ctcm_clear_busy_do(struct net_device
*dev
)
242 clear_bit(0, &(((struct ctcm_priv
*)dev
->ml_priv
)->tbusy
));
243 netif_wake_queue(dev
);
246 static inline void ctcm_clear_busy(struct net_device
*dev
)
248 struct mpc_group
*grp
;
249 grp
= ((struct ctcm_priv
*)dev
->ml_priv
)->mpcg
;
251 if (!(grp
&& grp
->in_sweep
))
252 ctcm_clear_busy_do(dev
);
256 static inline int ctcm_test_and_set_busy(struct net_device
*dev
)
258 netif_stop_queue(dev
);
259 return test_and_set_bit(0,
260 &(((struct ctcm_priv
*)dev
->ml_priv
)->tbusy
));
264 extern struct channel
*channels
;
266 void ctcm_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
);
269 * Functions related to setup and device detection.
272 static inline int ctcm_less_than(char *id1
, char *id2
)
274 unsigned long dev1
, dev2
;
279 dev1
= simple_strtoul(id1
, &id1
, 16);
280 dev2
= simple_strtoul(id2
, &id2
, 16);
282 return (dev1
< dev2
);
285 int ctcm_ch_alloc_buffer(struct channel
*ch
);
287 static inline int ctcm_checkalloc_buffer(struct channel
*ch
)
289 if (ch
->trans_skb
== NULL
)
290 return ctcm_ch_alloc_buffer(ch
);
291 if (ch
->flags
& CHANNEL_FLAGS_BUFSIZE_CHANGED
) {
292 dev_kfree_skb(ch
->trans_skb
);
293 return ctcm_ch_alloc_buffer(ch
);
298 struct mpc_group
*ctcmpc_init_mpc_group(struct ctcm_priv
*priv
);
300 /* test if protocol attribute (of struct ctcm_priv or struct channel)
301 * has MPC protocol setting. Type is not checked
303 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
305 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
306 #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
308 static inline gfp_t
gfp_type(void)
310 return in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
;
314 * Definition of our link level header.
321 #define LL_HEADER_LENGTH (sizeof(struct ll_header))