xref: /openbmc/linux/drivers/s390/net/lcs.h (revision 8730046c)
1 /*lcs.h*/
2 
3 #include <linux/interrupt.h>
4 #include <linux/netdevice.h>
5 #include <linux/skbuff.h>
6 #include <linux/workqueue.h>
7 #include <asm/ccwdev.h>
8 
9 #define LCS_DBF_TEXT(level, name, text) \
10 	do { \
11 		debug_text_event(lcs_dbf_##name, level, text); \
12 	} while (0)
13 
14 #define LCS_DBF_HEX(level,name,addr,len) \
15 do { \
16 	debug_event(lcs_dbf_##name,level,(void*)(addr),len); \
17 } while (0)
18 
19 #define LCS_DBF_TEXT_(level,name,text...) \
20 	do { \
21 		if (debug_level_enabled(lcs_dbf_##name, level)) { \
22 			sprintf(debug_buffer, text); \
23 			debug_text_event(lcs_dbf_##name, level, debug_buffer); \
24 		} \
25 	} while (0)
26 
27 /**
28  *	sysfs related stuff
29  */
30 #define CARD_FROM_DEV(cdev) \
31 	(struct lcs_card *) dev_get_drvdata( \
32 		&((struct ccwgroup_device *)dev_get_drvdata(&cdev->dev))->dev);
33 
34 /**
35  * Enum for classifying detected devices.
36  */
37 enum lcs_channel_types {
38 	/* Device is not a channel  */
39 	lcs_channel_type_none,
40 
41 	/* Device is a 2216 channel */
42 	lcs_channel_type_parallel,
43 
44 	/* Device is a 2216 channel */
45 	lcs_channel_type_2216,
46 
47 	/* Device is a OSA2 card */
48 	lcs_channel_type_osa2
49 };
50 
51 /**
52  * CCW commands used in this driver
53  */
54 #define LCS_CCW_WRITE		0x01
55 #define LCS_CCW_READ		0x02
56 #define LCS_CCW_TRANSFER	0x08
57 
58 /**
59  * LCS device status primitives
60  */
61 #define LCS_CMD_STARTLAN	0x01
62 #define LCS_CMD_STOPLAN		0x02
63 #define LCS_CMD_LANSTAT		0x04
64 #define LCS_CMD_STARTUP		0x07
65 #define LCS_CMD_SHUTDOWN	0x08
66 #define LCS_CMD_QIPASSIST	0xb2
67 #define LCS_CMD_SETIPM		0xb4
68 #define LCS_CMD_DELIPM		0xb5
69 
70 #define LCS_INITIATOR_TCPIP	0x00
71 #define LCS_INITIATOR_LGW	0x01
72 #define LCS_STD_CMD_SIZE	16
73 #define LCS_MULTICAST_CMD_SIZE	404
74 
75 /**
76  * LCS IPASSIST MASKS,only used when multicast is switched on
77  */
78 /* Not supported by LCS */
79 #define LCS_IPASS_ARP_PROCESSING	0x0001
80 #define LCS_IPASS_IN_CHECKSUM_SUPPORT	0x0002
81 #define LCS_IPASS_OUT_CHECKSUM_SUPPORT	0x0004
82 #define LCS_IPASS_IP_FRAG_REASSEMBLY	0x0008
83 #define LCS_IPASS_IP_FILTERING		0x0010
84 /* Supported by lcs 3172 */
85 #define LCS_IPASS_IPV6_SUPPORT		0x0020
86 #define LCS_IPASS_MULTICAST_SUPPORT	0x0040
87 
88 /**
89  * LCS sense byte definitions
90  */
91 #define LCS_SENSE_BYTE_0 		0
92 #define LCS_SENSE_BYTE_1 		1
93 #define LCS_SENSE_BYTE_2 		2
94 #define LCS_SENSE_BYTE_3 		3
95 #define LCS_SENSE_INTERFACE_DISCONNECT	0x01
96 #define LCS_SENSE_EQUIPMENT_CHECK	0x10
97 #define LCS_SENSE_BUS_OUT_CHECK		0x20
98 #define LCS_SENSE_INTERVENTION_REQUIRED 0x40
99 #define LCS_SENSE_CMD_REJECT		0x80
100 #define LCS_SENSE_RESETTING_EVENT	0x80
101 #define LCS_SENSE_DEVICE_ONLINE		0x20
102 
103 /**
104  * LCS packet type definitions
105  */
106 #define LCS_FRAME_TYPE_CONTROL		0
107 #define LCS_FRAME_TYPE_ENET		1
108 #define LCS_FRAME_TYPE_TR		2
109 #define LCS_FRAME_TYPE_FDDI		7
110 #define LCS_FRAME_TYPE_AUTO		-1
111 
112 /**
113  * some more definitions,we will sort them later
114  */
115 #define LCS_ILLEGAL_OFFSET		0xffff
116 #define LCS_IOBUFFERSIZE		0x5000
117 #define LCS_NUM_BUFFS			32	/* needs to be power of 2 */
118 #define LCS_MAC_LENGTH			6
119 #define LCS_INVALID_PORT_NO		-1
120 #define LCS_LANCMD_TIMEOUT_DEFAULT      5
121 
122 /**
123  * Multicast state
124  */
125 #define	 LCS_IPM_STATE_SET_REQUIRED	0
126 #define	 LCS_IPM_STATE_DEL_REQUIRED	1
127 #define	 LCS_IPM_STATE_ON_CARD		2
128 
129 /**
130  * LCS IP Assist declarations
131  * seems to be only used for multicast
132  */
133 #define	 LCS_IPASS_ARP_PROCESSING	0x0001
134 #define	 LCS_IPASS_INBOUND_CSUM_SUPP	0x0002
135 #define	 LCS_IPASS_OUTBOUND_CSUM_SUPP	0x0004
136 #define	 LCS_IPASS_IP_FRAG_REASSEMBLY	0x0008
137 #define	 LCS_IPASS_IP_FILTERING		0x0010
138 #define	 LCS_IPASS_IPV6_SUPPORT		0x0020
139 #define	 LCS_IPASS_MULTICAST_SUPPORT	0x0040
140 
141 /**
142  * LCS Buffer states
143  */
144 enum lcs_buffer_states {
145 	LCS_BUF_STATE_EMPTY,	/* buffer is empty */
146 	LCS_BUF_STATE_LOCKED,	/* buffer is locked, don't touch */
147 	LCS_BUF_STATE_READY,	/* buffer is ready for read/write */
148 	LCS_BUF_STATE_PROCESSED,
149 };
150 
151 /**
152  * LCS Channel State Machine declarations
153  */
154 enum lcs_channel_states {
155 	LCS_CH_STATE_INIT,
156 	LCS_CH_STATE_HALTED,
157 	LCS_CH_STATE_STOPPED,
158 	LCS_CH_STATE_RUNNING,
159 	LCS_CH_STATE_SUSPENDED,
160 	LCS_CH_STATE_CLEARED,
161 	LCS_CH_STATE_ERROR,
162 };
163 
164 /**
165  * LCS device state machine
166  */
167 enum lcs_dev_states {
168 	DEV_STATE_DOWN,
169 	DEV_STATE_UP,
170 	DEV_STATE_RECOVER,
171 };
172 
173 enum lcs_threads {
174 	LCS_SET_MC_THREAD 	= 1,
175 	LCS_RECOVERY_THREAD 	= 2,
176 };
177 
178 /**
179  * LCS struct declarations
180  */
181 struct lcs_header {
182 	__u16  offset;
183 	__u8   type;
184 	__u8   slot;
185 }  __attribute__ ((packed));
186 
187 struct lcs_ip_mac_pair {
188 	__be32  ip_addr;
189 	__u8   mac_addr[LCS_MAC_LENGTH];
190 	__u8   reserved[2];
191 }  __attribute__ ((packed));
192 
193 struct lcs_ipm_list {
194 	struct list_head list;
195 	struct lcs_ip_mac_pair ipm;
196 	__u8 ipm_state;
197 };
198 
199 struct lcs_cmd {
200 	__u16  offset;
201 	__u8   type;
202 	__u8   slot;
203 	__u8   cmd_code;
204 	__u8   initiator;
205 	__u16  sequence_no;
206 	__u16  return_code;
207 	union {
208 		struct {
209 			__u8   lan_type;
210 			__u8   portno;
211 			__u16  parameter_count;
212 			__u8   operator_flags[3];
213 			__u8   reserved[3];
214 		} lcs_std_cmd;
215 		struct {
216 			__u16  unused1;
217 			__u16  buff_size;
218 			__u8   unused2[6];
219 		} lcs_startup;
220 		struct {
221 			__u8   lan_type;
222 			__u8   portno;
223 			__u8   unused[10];
224 			__u8   mac_addr[LCS_MAC_LENGTH];
225 			__u32  num_packets_deblocked;
226 			__u32  num_packets_blocked;
227 			__u32  num_packets_tx_on_lan;
228 			__u32  num_tx_errors_detected;
229 			__u32  num_tx_packets_disgarded;
230 			__u32  num_packets_rx_from_lan;
231 			__u32  num_rx_errors_detected;
232 			__u32  num_rx_discarded_nobuffs_avail;
233 			__u32  num_rx_packets_too_large;
234 		} lcs_lanstat_cmd;
235 #ifdef CONFIG_IP_MULTICAST
236 		struct {
237 			__u8   lan_type;
238 			__u8   portno;
239 			__u16  num_ip_pairs;
240 			__u16  ip_assists_supported;
241 			__u16  ip_assists_enabled;
242 			__u16  version;
243 			struct {
244 				struct lcs_ip_mac_pair
245 				ip_mac_pair[32];
246 				__u32	  response_data;
247 			} lcs_ipass_ctlmsg __attribute ((packed));
248 		} lcs_qipassist __attribute__ ((packed));
249 #endif /*CONFIG_IP_MULTICAST */
250 	} cmd __attribute__ ((packed));
251 }  __attribute__ ((packed));
252 
253 /**
254  * Forward declarations.
255  */
256 struct lcs_card;
257 struct lcs_channel;
258 
259 /**
260  * Definition of an lcs buffer.
261  */
262 struct lcs_buffer {
263 	enum lcs_buffer_states state;
264 	void *data;
265 	int count;
266 	/* Callback for completion notification. */
267 	void (*callback)(struct lcs_channel *, struct lcs_buffer *);
268 };
269 
270 struct lcs_reply {
271 	struct list_head list;
272 	__u16 sequence_no;
273 	atomic_t refcnt;
274 	/* Callback for completion notification. */
275 	void (*callback)(struct lcs_card *, struct lcs_cmd *);
276 	wait_queue_head_t wait_q;
277 	struct lcs_card *card;
278 	int received;
279 	int rc;
280 };
281 
282 /**
283  * Definition of an lcs channel
284  */
285 struct lcs_channel {
286 	enum lcs_channel_states state;
287 	struct ccw_device *ccwdev;
288 	struct ccw1 ccws[LCS_NUM_BUFFS + 1];
289 	wait_queue_head_t wait_q;
290 	struct tasklet_struct irq_tasklet;
291 	struct lcs_buffer iob[LCS_NUM_BUFFS];
292 	int io_idx;
293 	int buf_idx;
294 };
295 
296 
297 /**
298  * definition of the lcs card
299  */
300 struct lcs_card {
301 	spinlock_t lock;
302 	spinlock_t ipm_lock;
303 	enum lcs_dev_states state;
304 	struct net_device *dev;
305 	struct net_device_stats stats;
306 	__be16 (*lan_type_trans)(struct sk_buff *skb,
307 					 struct net_device *dev);
308 	struct ccwgroup_device *gdev;
309 	struct lcs_channel read;
310 	struct lcs_channel write;
311 	struct lcs_buffer *tx_buffer;
312 	int tx_emitted;
313 	struct list_head lancmd_waiters;
314 	int lancmd_timeout;
315 
316 	struct work_struct kernel_thread_starter;
317 	spinlock_t mask_lock;
318 	unsigned long thread_start_mask;
319 	unsigned long thread_running_mask;
320 	unsigned long thread_allowed_mask;
321 	wait_queue_head_t wait_q;
322 
323 #ifdef CONFIG_IP_MULTICAST
324 	struct list_head ipm_list;
325 #endif
326 	__u8 mac[LCS_MAC_LENGTH];
327 	__u16 ip_assists_supported;
328 	__u16 ip_assists_enabled;
329 	__s8 lan_type;
330 	__u32 pkt_seq;
331 	__u16 sequence_no;
332 	__s16 portno;
333 	/* Some info copied from probeinfo */
334 	u8 device_forced;
335 	u8 max_port_no;
336 	u8 hint_port_no;
337 	s16 port_protocol_no;
338 }  __attribute__ ((aligned(8)));
339 
340