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