2 * Copyright IBM Corp. 2001, 2007
3 * Authors: Fritz Elfert (felfert@millenux.com)
4 * Peter Tiedemann (ptiedem@de.ibm.com)
10 #include <asm/ccwdev.h>
11 #include <asm/ccwgroup.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
17 #include "ctcm_dbug.h"
20 #define CTC_DRIVER_NAME "ctcm"
21 #define CTC_DEVICE_NAME "ctc"
22 #define MPC_DEVICE_NAME "mpc"
23 #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
24 #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
26 #define CHANNEL_FLAGS_READ 0
27 #define CHANNEL_FLAGS_WRITE 1
28 #define CHANNEL_FLAGS_INUSE 2
29 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
30 #define CHANNEL_FLAGS_FAILED 8
31 #define CHANNEL_FLAGS_WAITIRQ 16
32 #define CHANNEL_FLAGS_RWMASK 1
33 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
35 #define LOG_FLAG_ILLEGALPKT 1
36 #define LOG_FLAG_ILLEGALSIZE 2
37 #define LOG_FLAG_OVERRUN 4
38 #define LOG_FLAG_NOMEM 8
40 #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
42 #define CTCM_PR_DEBUG(fmt, arg...) \
45 printk(KERN_DEBUG fmt, ##arg); \
48 #define CTCM_PR_DBGDATA(fmt, arg...) \
51 printk(KERN_DEBUG fmt, ##arg); \
54 #define CTCM_D3_DUMP(buf, len) \
57 ctcmpc_dumpit(buf, len); \
60 #define CTCM_CCW_DUMP(buf, len) \
63 ctcmpc_dumpit(buf, len); \
67 * Enum for classifying detected devices
69 enum ctcm_channel_types
{
70 /* Device is not a channel */
71 ctcm_channel_type_none
,
73 /* Device is a CTC/A */
74 ctcm_channel_type_parallel
,
76 /* Device is a FICON channel */
77 ctcm_channel_type_ficon
,
79 /* Device is a ESCON channel */
80 ctcm_channel_type_escon
84 * CCW commands, used in this driver.
86 #define CCW_CMD_WRITE 0x01
87 #define CCW_CMD_READ 0x02
88 #define CCW_CMD_NOOP 0x03
89 #define CCW_CMD_TIC 0x08
90 #define CCW_CMD_SENSE_CMD 0x14
91 #define CCW_CMD_WRITE_CTL 0x17
92 #define CCW_CMD_SET_EXTENDED 0xc3
93 #define CCW_CMD_PREPARE 0xe3
95 #define CTCM_PROTO_S390 0
96 #define CTCM_PROTO_LINUX 1
97 #define CTCM_PROTO_LINUX_TTY 2
98 #define CTCM_PROTO_OS390 3
99 #define CTCM_PROTO_MPC 4
100 #define CTCM_PROTO_MAX 4
102 #define CTCM_BUFSIZE_LIMIT 65535
103 #define CTCM_BUFSIZE_DEFAULT 32768
104 #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
106 #define CTCM_TIME_1_SEC 1000
107 #define CTCM_TIME_5_SEC 5000
108 #define CTCM_TIME_10_SEC 10000
110 #define CTCM_INITIAL_BLOCKLEN 2
115 #define CTCM_ID_SIZE 20+3
117 struct ctcm_profile
{
118 unsigned long maxmulti
;
119 unsigned long maxcqueue
;
120 unsigned long doios_single
;
121 unsigned long doios_multi
;
123 unsigned long tx_time
;
124 struct timespec send_stamp
;
128 * Definition of one channel
131 struct channel
*next
;
132 char id
[CTCM_ID_SIZE
];
133 struct ccw_device
*cdev
;
135 * Type of this channel.
136 * CTC/A or Escon for valid channels.
138 enum ctcm_channel_types type
;
140 * Misc. flags. See CHANNEL_FLAGS_... below
143 __u16 protocol
; /* protocol of this channel (4 = MPC) */
145 * I/O and irq related stuff
153 struct sk_buff
*trans_skb
; /* transmit/receive buffer */
154 struct sk_buff_head io_queue
; /* universal I/O queue */
155 struct tasklet_struct ch_tasklet
; /* MPC ONLY */
157 * TX queue for collecting skb's during busy.
159 struct sk_buff_head collect_queue
;
161 * Amount of data in collect_queue.
165 * spinlock for collect_queue and collect_len
167 spinlock_t collect_lock
;
169 * Timer for detecting unresposive
173 /* MPC ONLY section begin */
174 __u32 th_seq_num
; /* SNA TH seq number */
177 struct sk_buff
*xid_skb
;
179 struct th_header
*xid_th
;
182 struct th_header
*rcvd_xid_th
;
183 struct xid2
*rcvd_xid
;
186 fsm_timer sweep_timer
;
187 struct sk_buff_head sweep_queue
;
188 struct th_header
*discontact_th
;
189 struct tasklet_struct ch_disc_tasklet
;
190 /* MPC ONLY section end */
192 int retry
; /* retry counter for misc. operations */
193 fsm_instance
*fsm
; /* finite state machine of this channel */
194 struct net_device
*netdev
; /* corresponding net_device */
195 struct ctcm_profile prof
;
196 __u8
*trans_skb_data
;
198 __u8 sense_rc
; /* last unit check sense code report control */
202 struct net_device_stats stats
;
205 /* The MPC group struct of this interface */
206 struct mpc_group
*mpcg
; /* MPC only */
207 struct xid2
*xid
; /* MPC only */
209 /* The finite state machine of this interface */
212 /* The protocol of this device */
215 /* Timer for restarting after I/O Errors */
216 fsm_timer restart_timer
;
218 int buffer_size
; /* ctc only */
220 struct channel
*channel
[2];
223 int ctcm_open(struct net_device
*dev
);
224 int ctcm_close(struct net_device
*dev
);
226 extern const struct attribute_group
*ctcm_attr_groups
[];
229 * Compatibility macros for busy handling
230 * of network devices.
232 static inline void ctcm_clear_busy_do(struct net_device
*dev
)
234 clear_bit(0, &(((struct ctcm_priv
*)dev
->ml_priv
)->tbusy
));
235 netif_wake_queue(dev
);
238 static inline void ctcm_clear_busy(struct net_device
*dev
)
240 struct mpc_group
*grp
;
241 grp
= ((struct ctcm_priv
*)dev
->ml_priv
)->mpcg
;
243 if (!(grp
&& grp
->in_sweep
))
244 ctcm_clear_busy_do(dev
);
248 static inline int ctcm_test_and_set_busy(struct net_device
*dev
)
250 netif_stop_queue(dev
);
251 return test_and_set_bit(0,
252 &(((struct ctcm_priv
*)dev
->ml_priv
)->tbusy
));
256 extern struct channel
*channels
;
258 void ctcm_unpack_skb(struct channel
*ch
, struct sk_buff
*pskb
);
261 * Functions related to setup and device detection.
264 static inline int ctcm_less_than(char *id1
, char *id2
)
266 unsigned long dev1
, dev2
;
271 dev1
= simple_strtoul(id1
, &id1
, 16);
272 dev2
= simple_strtoul(id2
, &id2
, 16);
274 return (dev1
< dev2
);
277 int ctcm_ch_alloc_buffer(struct channel
*ch
);
279 static inline int ctcm_checkalloc_buffer(struct channel
*ch
)
281 if (ch
->trans_skb
== NULL
)
282 return ctcm_ch_alloc_buffer(ch
);
283 if (ch
->flags
& CHANNEL_FLAGS_BUFSIZE_CHANGED
) {
284 dev_kfree_skb(ch
->trans_skb
);
285 return ctcm_ch_alloc_buffer(ch
);
290 struct mpc_group
*ctcmpc_init_mpc_group(struct ctcm_priv
*priv
);
292 /* test if protocol attribute (of struct ctcm_priv or struct channel)
293 * has MPC protocol setting. Type is not checked
295 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
297 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
298 #define IS_MPCDEV(dev) IS_MPC((struct ctcm_priv *)dev->ml_priv)
300 static inline gfp_t
gfp_type(void)
302 return in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
;
306 * Definition of our link level header.
313 #define LL_HEADER_LENGTH (sizeof(struct ll_header))