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>
20 #include "ctcm_dbug.h"
23 #define CTC_DRIVER_NAME "ctcm"
24 #define CTC_DEVICE_NAME "ctc"
25 #define MPC_DEVICE_NAME "mpc"
26 #define CTC_DEVICE_GENE CTC_DEVICE_NAME "%d"
27 #define MPC_DEVICE_GENE MPC_DEVICE_NAME "%d"
29 #define CHANNEL_FLAGS_READ 0
30 #define CHANNEL_FLAGS_WRITE 1
31 #define CHANNEL_FLAGS_INUSE 2
32 #define CHANNEL_FLAGS_BUFSIZE_CHANGED 4
33 #define CHANNEL_FLAGS_FAILED 8
34 #define CHANNEL_FLAGS_WAITIRQ 16
35 #define CHANNEL_FLAGS_RWMASK 1
36 #define CHANNEL_DIRECTION(f) (f & CHANNEL_FLAGS_RWMASK)
38 #define LOG_FLAG_ILLEGALPKT 1
39 #define LOG_FLAG_ILLEGALSIZE 2
40 #define LOG_FLAG_OVERRUN 4
41 #define LOG_FLAG_NOMEM 8
43 #define ctcm_pr_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
44 #define ctcm_pr_info(fmt, arg...) printk(KERN_INFO fmt, ##arg)
45 #define ctcm_pr_notice(fmt, arg...) printk(KERN_NOTICE fmt, ##arg)
46 #define ctcm_pr_warn(fmt, arg...) printk(KERN_WARNING fmt, ##arg)
47 #define ctcm_pr_emerg(fmt, arg...) printk(KERN_EMERG fmt, ##arg)
48 #define ctcm_pr_err(fmt, arg...) printk(KERN_ERR fmt, ##arg)
49 #define ctcm_pr_crit(fmt, arg...) printk(KERN_CRIT fmt, ##arg)
51 #define CTCM_PR_DEBUG(fmt, arg...) \
54 printk(KERN_DEBUG fmt, ##arg); \
57 #define CTCM_PR_DBGDATA(fmt, arg...) \
60 printk(KERN_DEBUG fmt, ##arg); \
63 #define CTCM_D3_DUMP(buf, len) \
66 ctcmpc_dumpit(buf, len); \
69 #define CTCM_CCW_DUMP(buf, len) \
72 ctcmpc_dumpit(buf, len); \
76 * CCW commands, used in this driver.
78 #define CCW_CMD_WRITE 0x01
79 #define CCW_CMD_READ 0x02
80 #define CCW_CMD_NOOP 0x03
81 #define CCW_CMD_TIC 0x08
82 #define CCW_CMD_SENSE_CMD 0x14
83 #define CCW_CMD_WRITE_CTL 0x17
84 #define CCW_CMD_SET_EXTENDED 0xc3
85 #define CCW_CMD_PREPARE 0xe3
87 #define CTCM_PROTO_S390 0
88 #define CTCM_PROTO_LINUX 1
89 #define CTCM_PROTO_LINUX_TTY 2
90 #define CTCM_PROTO_OS390 3
91 #define CTCM_PROTO_MPC 4
92 #define CTCM_PROTO_MAX 4
94 #define CTCM_BUFSIZE_LIMIT 65535
95 #define CTCM_BUFSIZE_DEFAULT 32768
96 #define MPC_BUFSIZE_DEFAULT CTCM_BUFSIZE_LIMIT
98 #define CTCM_TIME_1_SEC 1000
99 #define CTCM_TIME_5_SEC 5000
100 #define CTCM_TIME_10_SEC 10000
102 #define CTCM_INITIAL_BLOCKLEN 2
107 #define CTCM_ID_SIZE BUS_ID_SIZE+3
109 struct ctcm_profile {
110 unsigned long maxmulti;
111 unsigned long maxcqueue;
112 unsigned long doios_single;
113 unsigned long doios_multi;
115 unsigned long tx_time;
116 struct timespec send_stamp;
120 * Definition of one channel
123 struct channel *next;
124 char id[CTCM_ID_SIZE];
125 struct ccw_device *cdev;
127 * Type of this channel.
128 * CTC/A or Escon for valid channels.
130 enum channel_types type;
132 * Misc. flags. See CHANNEL_FLAGS_... below
135 __u16 protocol; /* protocol of this channel (4 = MPC) */
137 * I/O and irq related stuff
145 struct sk_buff *trans_skb; /* transmit/receive buffer */
146 struct sk_buff_head io_queue; /* universal I/O queue */
147 struct tasklet_struct ch_tasklet; /* MPC ONLY */
149 * TX queue for collecting skb's during busy.
151 struct sk_buff_head collect_queue;
153 * Amount of data in collect_queue.
157 * spinlock for collect_queue and collect_len
159 spinlock_t collect_lock;
161 * Timer for detecting unresposive
165 /* MPC ONLY section begin */
166 __u32 th_seq_num; /* SNA TH seq number */
169 struct sk_buff *xid_skb;
171 struct th_header *xid_th;
174 struct th_header *rcvd_xid_th;
175 struct xid2 *rcvd_xid;
178 fsm_timer sweep_timer;
179 struct sk_buff_head sweep_queue;
180 struct th_header *discontact_th;
181 struct tasklet_struct ch_disc_tasklet;
182 /* MPC ONLY section end */
184 int retry; /* retry counter for misc. operations */
185 fsm_instance *fsm; /* finite state machine of this channel */
186 struct net_device *netdev; /* corresponding net_device */
187 struct ctcm_profile prof;
188 __u8 *trans_skb_data;
190 __u8 sense_rc; /* last unit check sense code report control */
194 struct net_device_stats stats;
197 /* The MPC group struct of this interface */
198 struct mpc_group *mpcg; /* MPC only */
199 struct xid2 *xid; /* MPC only */
201 /* The finite state machine of this interface */
204 /* The protocol of this device */
207 /* Timer for restarting after I/O Errors */
208 fsm_timer restart_timer;
210 int buffer_size; /* ctc only */
212 struct channel *channel[2];
215 int ctcm_open(struct net_device *dev);
216 int ctcm_close(struct net_device *dev);
219 * prototypes for non-static sysfs functions
221 int ctcm_add_attributes(struct device *dev);
222 void ctcm_remove_attributes(struct device *dev);
223 int ctcm_add_files(struct device *dev);
224 void ctcm_remove_files(struct device *dev);
227 * Compatibility macros for busy handling
228 * of network devices.
230 static inline void ctcm_clear_busy_do(struct net_device *dev)
232 clear_bit(0, &(((struct ctcm_priv *)dev->priv)->tbusy));
233 netif_wake_queue(dev);
236 static inline void ctcm_clear_busy(struct net_device *dev)
238 struct mpc_group *grp;
239 grp = ((struct ctcm_priv *)dev->priv)->mpcg;
241 if (!(grp && grp->in_sweep))
242 ctcm_clear_busy_do(dev);
246 static inline int ctcm_test_and_set_busy(struct net_device *dev)
248 netif_stop_queue(dev);
249 return test_and_set_bit(0, &(((struct ctcm_priv *)dev->priv)->tbusy));
253 extern struct channel *channels;
255 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb);
258 * Functions related to setup and device detection.
261 static inline int ctcm_less_than(char *id1, char *id2)
263 unsigned long dev1, dev2;
268 dev1 = simple_strtoul(id1, &id1, 16);
269 dev2 = simple_strtoul(id2, &id2, 16);
271 return (dev1 < dev2);
274 int ctcm_ch_alloc_buffer(struct channel *ch);
276 static inline int ctcm_checkalloc_buffer(struct channel *ch)
278 if (ch->trans_skb == NULL)
279 return ctcm_ch_alloc_buffer(ch);
280 if (ch->flags & CHANNEL_FLAGS_BUFSIZE_CHANGED) {
281 dev_kfree_skb(ch->trans_skb);
282 return ctcm_ch_alloc_buffer(ch);
287 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
289 /* test if protocol attribute (of struct ctcm_priv or struct channel)
290 * has MPC protocol setting. Type is not checked
292 #define IS_MPC(p) ((p)->protocol == CTCM_PROTO_MPC)
294 /* test if struct ctcm_priv of struct net_device has MPC protocol setting */
295 #define IS_MPCDEV(d) IS_MPC((struct ctcm_priv *)d->priv)
297 static inline gfp_t gfp_type(void)
299 return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
303 * Definition of our link level header.
310 #define LL_HEADER_LENGTH (sizeof(struct ll_header))