xref: /openbmc/linux/drivers/s390/net/ctcm_mpc.c (revision 724ba675)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *	Copyright IBM Corp. 2004, 2007
4  *	Authors:	Belinda Thompson (belindat@us.ibm.com)
5  *			Andy Richter (richtera@us.ibm.com)
6  *			Peter Tiedemann (ptiedem@de.ibm.com)
7  */
8 
9 /*
10 	This module exports functions to be used by CCS:
11 	EXPORT_SYMBOL(ctc_mpc_alloc_channel);
12 	EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
13 	EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
14 	EXPORT_SYMBOL(ctc_mpc_flow_control);
15 */
16 
17 #undef DEBUG
18 #undef DEBUGDATA
19 #undef DEBUGCCW
20 
21 #define KMSG_COMPONENT "ctcm"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23 
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
29 #include <linux/types.h>
30 #include <linux/interrupt.h>
31 #include <linux/timer.h>
32 #include <linux/sched.h>
33 
34 #include <linux/signal.h>
35 #include <linux/string.h>
36 #include <linux/proc_fs.h>
37 
38 #include <linux/ip.h>
39 #include <linux/if_arp.h>
40 #include <linux/tcp.h>
41 #include <linux/skbuff.h>
42 #include <linux/ctype.h>
43 #include <linux/netdevice.h>
44 #include <net/dst.h>
45 
46 #include <linux/io.h>		/* instead of <asm/io.h> ok ? */
47 #include <asm/ccwdev.h>
48 #include <asm/ccwgroup.h>
49 #include <linux/bitops.h>	/* instead of <asm/bitops.h> ok ? */
50 #include <linux/uaccess.h>	/* instead of <asm/uaccess.h> ok ? */
51 #include <linux/wait.h>
52 #include <linux/moduleparam.h>
53 #include <asm/idals.h>
54 
55 #include "ctcm_main.h"
56 #include "ctcm_mpc.h"
57 #include "ctcm_fsms.h"
58 
59 static const struct xid2 init_xid = {
60 	.xid2_type_id	=	XID_FM2,
61 	.xid2_len	=	0x45,
62 	.xid2_adj_id	=	0,
63 	.xid2_rlen	=	0x31,
64 	.xid2_resv1	=	0,
65 	.xid2_flag1	=	0,
66 	.xid2_fmtt	=	0,
67 	.xid2_flag4	=	0x80,
68 	.xid2_resv2	=	0,
69 	.xid2_tgnum	=	0,
70 	.xid2_sender_id	=	0,
71 	.xid2_flag2	=	0,
72 	.xid2_option	=	XID2_0,
73 	.xid2_resv3	=	"\x00",
74 	.xid2_resv4	=	0,
75 	.xid2_dlc_type	=	XID2_READ_SIDE,
76 	.xid2_resv5	=	0,
77 	.xid2_mpc_flag	=	0,
78 	.xid2_resv6	=	0,
79 	.xid2_buf_len	=	(MPC_BUFSIZE_DEFAULT - 35),
80 };
81 
82 static const struct th_header thnorm = {
83 	.th_seg		=	0x00,
84 	.th_ch_flag	=	TH_IS_XID,
85 	.th_blk_flag	=	TH_DATA_IS_XID,
86 	.th_is_xid	=	0x01,
87 	.th_seq_num	=	0x00000000,
88 };
89 
90 static const struct th_header thdummy = {
91 	.th_seg		=	0x00,
92 	.th_ch_flag	=	0x00,
93 	.th_blk_flag	=	TH_DATA_IS_XID,
94 	.th_is_xid	=	0x01,
95 	.th_seq_num	=	0x00000000,
96 };
97 
98 /*
99  * Definition of one MPC group
100  */
101 
102 /*
103  * Compatibility macros for busy handling
104  * of network devices.
105  */
106 
107 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
108 
109 /*
110  * MPC Group state machine actions (static prototypes)
111  */
112 static void mpc_action_nop(fsm_instance *fsm, int event, void *arg);
113 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg);
114 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg);
115 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg);
116 static int  mpc_validate_xid(struct mpcg_info *mpcginfo);
117 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg);
118 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg);
119 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg);
120 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg);
121 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg);
122 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg);
123 
124 #ifdef DEBUGDATA
125 /*-------------------------------------------------------------------*
126 * Dump buffer format						     *
127 *								     *
128 *--------------------------------------------------------------------*/
129 void ctcmpc_dumpit(char *buf, int len)
130 {
131 	__u32	ct, sw, rm, dup;
132 	char	*ptr, *rptr;
133 	char	tbuf[82], tdup[82];
134 	char	addr[22];
135 	char	boff[12];
136 	char	bhex[82], duphex[82];
137 	char	basc[40];
138 
139 	sw  = 0;
140 	rptr = ptr = buf;
141 	rm  = 16;
142 	duphex[0] = 0x00;
143 	dup = 0;
144 
145 	for (ct = 0; ct < len; ct++, ptr++, rptr++) {
146 		if (sw == 0) {
147 			sprintf(addr, "%16.16llx", (__u64)rptr);
148 
149 			sprintf(boff, "%4.4X", (__u32)ct);
150 			bhex[0] = '\0';
151 			basc[0] = '\0';
152 		}
153 		if ((sw == 4) || (sw == 12))
154 			strcat(bhex, " ");
155 		if (sw == 8)
156 			strcat(bhex, "	");
157 
158 		sprintf(tbuf, "%2.2llX", (__u64)*ptr);
159 
160 		tbuf[2] = '\0';
161 		strcat(bhex, tbuf);
162 		if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
163 			basc[sw] = *ptr;
164 		else
165 			basc[sw] = '.';
166 
167 		basc[sw+1] = '\0';
168 		sw++;
169 		rm--;
170 		if (sw != 16)
171 			continue;
172 		if ((strcmp(duphex, bhex)) != 0) {
173 			if (dup != 0) {
174 				sprintf(tdup,
175 					"Duplicate as above to %s", addr);
176 				ctcm_pr_debug("		       --- %s ---\n",
177 						tdup);
178 			}
179 			ctcm_pr_debug("   %s (+%s) : %s  [%s]\n",
180 					addr, boff, bhex, basc);
181 			dup = 0;
182 			strcpy(duphex, bhex);
183 		} else
184 			dup++;
185 
186 		sw = 0;
187 		rm = 16;
188 	}  /* endfor */
189 
190 	if (sw != 0) {
191 		for ( ; rm > 0; rm--, sw++) {
192 			if ((sw == 4) || (sw == 12))
193 				strcat(bhex, " ");
194 			if (sw == 8)
195 				strcat(bhex, "	");
196 			strcat(bhex, "	");
197 			strcat(basc, " ");
198 		}
199 		if (dup != 0) {
200 			sprintf(tdup, "Duplicate as above to %s", addr);
201 			ctcm_pr_debug("		       --- %s ---\n", tdup);
202 		}
203 		ctcm_pr_debug("   %s (+%s) : %s  [%s]\n",
204 					addr, boff, bhex, basc);
205 	} else {
206 		if (dup >= 1) {
207 			sprintf(tdup, "Duplicate as above to %s", addr);
208 			ctcm_pr_debug("		       --- %s ---\n", tdup);
209 		}
210 		if (dup != 0) {
211 			ctcm_pr_debug("   %s (+%s) : %s  [%s]\n",
212 				addr, boff, bhex, basc);
213 		}
214 	}
215 
216 	return;
217 
218 }   /*	 end of ctcmpc_dumpit  */
219 #endif
220 
221 #ifdef DEBUGDATA
222 /*
223  * Dump header and first 16 bytes of an sk_buff for debugging purposes.
224  *
225  * skb		The sk_buff to dump.
226  * offset	Offset relative to skb-data, where to start the dump.
227  */
228 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
229 {
230 	__u8 *p = skb->data;
231 	struct th_header *header;
232 	struct pdu *pheader;
233 	int bl = skb->len;
234 	int i;
235 
236 	if (p == NULL)
237 		return;
238 
239 	p += offset;
240 	header = (struct th_header *)p;
241 
242 	ctcm_pr_debug("dump:\n");
243 	ctcm_pr_debug("skb len=%d \n", skb->len);
244 	if (skb->len > 2) {
245 		switch (header->th_ch_flag) {
246 		case TH_HAS_PDU:
247 			break;
248 		case 0x00:
249 		case TH_IS_XID:
250 			if ((header->th_blk_flag == TH_DATA_IS_XID) &&
251 			   (header->th_is_xid == 0x01))
252 				goto dumpth;
253 		case TH_SWEEP_REQ:
254 				goto dumpth;
255 		case TH_SWEEP_RESP:
256 				goto dumpth;
257 		default:
258 			break;
259 		}
260 
261 		pheader = (struct pdu *)p;
262 		ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
263 			       pheader->pdu_offset, pheader->pdu_offset);
264 		ctcm_pr_debug("pdu->flag  : %02x\n", pheader->pdu_flag);
265 		ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
266 		ctcm_pr_debug("pdu->seq   : %02x\n", pheader->pdu_seq);
267 					goto dumpdata;
268 
269 dumpth:
270 		ctcm_pr_debug("th->seg     : %02x\n", header->th_seg);
271 		ctcm_pr_debug("th->ch      : %02x\n", header->th_ch_flag);
272 		ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
273 		ctcm_pr_debug("th->type    : %s\n",
274 			       (header->th_is_xid) ? "DATA" : "XID");
275 		ctcm_pr_debug("th->seqnum  : %04x\n", header->th_seq_num);
276 
277 	}
278 dumpdata:
279 	if (bl > 32)
280 		bl = 32;
281 	ctcm_pr_debug("data: ");
282 	for (i = 0; i < bl; i++)
283 		ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
284 	ctcm_pr_debug("\n");
285 }
286 #endif
287 
288 static struct net_device *ctcmpc_get_dev(int port_num)
289 {
290 	char device[20];
291 	struct net_device *dev;
292 	struct ctcm_priv *priv;
293 
294 	sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
295 
296 	dev = __dev_get_by_name(&init_net, device);
297 
298 	if (dev == NULL) {
299 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
300 			"%s: Device not found by name: %s",
301 					CTCM_FUNTAIL, device);
302 		return NULL;
303 	}
304 	priv = dev->ml_priv;
305 	if (priv == NULL) {
306 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
307 			"%s(%s): dev->ml_priv is NULL",
308 					CTCM_FUNTAIL, device);
309 		return NULL;
310 	}
311 	if (priv->mpcg == NULL) {
312 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
313 			"%s(%s): priv->mpcg is NULL",
314 					CTCM_FUNTAIL, device);
315 		return NULL;
316 	}
317 	return dev;
318 }
319 
320 /*
321  * ctc_mpc_alloc_channel
322  *	(exported interface)
323  *
324  * Device Initialization :
325  *	ACTPATH  driven IO operations
326  */
327 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
328 {
329 	struct net_device *dev;
330 	struct mpc_group *grp;
331 	struct ctcm_priv *priv;
332 
333 	dev = ctcmpc_get_dev(port_num);
334 	if (dev == NULL)
335 		return 1;
336 	priv = dev->ml_priv;
337 	grp = priv->mpcg;
338 
339 	grp->allochanfunc = callback;
340 	grp->port_num = port_num;
341 	grp->port_persist = 1;
342 
343 	CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
344 			"%s(%s): state=%s",
345 			CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
346 
347 	switch (fsm_getstate(grp->fsm)) {
348 	case MPCG_STATE_INOP:
349 		/* Group is in the process of terminating */
350 		grp->alloc_called = 1;
351 		break;
352 	case MPCG_STATE_RESET:
353 		/* MPC Group will transition to state		  */
354 		/* MPCG_STATE_XID2INITW iff the minimum number	  */
355 		/* of 1 read and 1 write channel have successfully*/
356 		/* activated					  */
357 		/*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
358 		if (callback)
359 			grp->send_qllc_disc = 1;
360 		fallthrough;
361 	case MPCG_STATE_XID0IOWAIT:
362 		fsm_deltimer(&grp->timer);
363 		grp->outstanding_xid2 = 0;
364 		grp->outstanding_xid7 = 0;
365 		grp->outstanding_xid7_p2 = 0;
366 		grp->saved_xid2 = NULL;
367 		if (callback)
368 			ctcm_open(dev);
369 		fsm_event(priv->fsm, DEV_EVENT_START, dev);
370 		break;
371 	case MPCG_STATE_READY:
372 		/* XID exchanges completed after PORT was activated */
373 		/* Link station already active			    */
374 		/* Maybe timing issue...retry callback		    */
375 		grp->allocchan_callback_retries++;
376 		if (grp->allocchan_callback_retries < 4) {
377 			if (grp->allochanfunc)
378 				grp->allochanfunc(grp->port_num,
379 						  grp->group_max_buflen);
380 		} else {
381 			/* there are problems...bail out	    */
382 			/* there may be a state mismatch so restart */
383 			fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
384 			grp->allocchan_callback_retries = 0;
385 		}
386 		break;
387 	}
388 
389 	return 0;
390 }
391 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
392 
393 /*
394  * ctc_mpc_establish_connectivity
395  *	(exported interface)
396  */
397 void ctc_mpc_establish_connectivity(int port_num,
398 				void (*callback)(int, int, int))
399 {
400 	struct net_device *dev;
401 	struct mpc_group *grp;
402 	struct ctcm_priv *priv;
403 	struct channel *rch, *wch;
404 
405 	dev = ctcmpc_get_dev(port_num);
406 	if (dev == NULL)
407 		return;
408 	priv = dev->ml_priv;
409 	grp = priv->mpcg;
410 	rch = priv->channel[CTCM_READ];
411 	wch = priv->channel[CTCM_WRITE];
412 
413 	CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
414 			"%s(%s): state=%s",
415 			CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
416 
417 	grp->estconnfunc = callback;
418 	grp->port_num = port_num;
419 
420 	switch (fsm_getstate(grp->fsm)) {
421 	case MPCG_STATE_READY:
422 		/* XID exchanges completed after PORT was activated */
423 		/* Link station already active			    */
424 		/* Maybe timing issue...retry callback		    */
425 		fsm_deltimer(&grp->timer);
426 		grp->estconn_callback_retries++;
427 		if (grp->estconn_callback_retries < 4) {
428 			if (grp->estconnfunc) {
429 				grp->estconnfunc(grp->port_num, 0,
430 						grp->group_max_buflen);
431 				grp->estconnfunc = NULL;
432 			}
433 		} else {
434 			/* there are problems...bail out	 */
435 			fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
436 			grp->estconn_callback_retries = 0;
437 		}
438 		break;
439 	case MPCG_STATE_INOP:
440 	case MPCG_STATE_RESET:
441 		/* MPC Group is not ready to start XID - min num of */
442 		/* 1 read and 1 write channel have not been acquired*/
443 
444 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
445 			"%s(%s): REJECTED - inactive channels",
446 					CTCM_FUNTAIL, dev->name);
447 		if (grp->estconnfunc) {
448 			grp->estconnfunc(grp->port_num, -1, 0);
449 			grp->estconnfunc = NULL;
450 		}
451 		break;
452 	case MPCG_STATE_XID2INITW:
453 		/* alloc channel was called but no XID exchange    */
454 		/* has occurred. initiate xside XID exchange	   */
455 		/* make sure yside XID0 processing has not started */
456 
457 		if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
458 			(fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
459 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
460 				"%s(%s): ABORT - PASSIVE XID",
461 					CTCM_FUNTAIL, dev->name);
462 			break;
463 		}
464 		grp->send_qllc_disc = 1;
465 		fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIT);
466 		fsm_deltimer(&grp->timer);
467 		fsm_addtimer(&grp->timer, MPC_XID_TIMEOUT_VALUE,
468 						MPCG_EVENT_TIMER, dev);
469 		grp->outstanding_xid7 = 0;
470 		grp->outstanding_xid7_p2 = 0;
471 		grp->saved_xid2 = NULL;
472 		if ((rch->in_mpcgroup) &&
473 				(fsm_getstate(rch->fsm) == CH_XID0_PENDING))
474 			fsm_event(grp->fsm, MPCG_EVENT_XID0DO, rch);
475 		else {
476 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
477 				"%s(%s): RX-%s not ready for ACTIVE XID0",
478 					CTCM_FUNTAIL, dev->name, rch->id);
479 			if (grp->estconnfunc) {
480 				grp->estconnfunc(grp->port_num, -1, 0);
481 				grp->estconnfunc = NULL;
482 			}
483 			fsm_deltimer(&grp->timer);
484 			goto done;
485 		}
486 		if ((wch->in_mpcgroup) &&
487 				(fsm_getstate(wch->fsm) == CH_XID0_PENDING))
488 			fsm_event(grp->fsm, MPCG_EVENT_XID0DO, wch);
489 		else {
490 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
491 				"%s(%s): WX-%s not ready for ACTIVE XID0",
492 					CTCM_FUNTAIL, dev->name, wch->id);
493 			if (grp->estconnfunc) {
494 				grp->estconnfunc(grp->port_num, -1, 0);
495 				grp->estconnfunc = NULL;
496 			}
497 			fsm_deltimer(&grp->timer);
498 			goto done;
499 			}
500 		break;
501 	case MPCG_STATE_XID0IOWAIT:
502 		/* already in active XID negotiations */
503 	default:
504 		break;
505 	}
506 
507 done:
508 	CTCM_PR_DEBUG("Exit %s()\n", __func__);
509 	return;
510 }
511 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
512 
513 /*
514  * ctc_mpc_dealloc_ch
515  *	(exported interface)
516  */
517 void ctc_mpc_dealloc_ch(int port_num)
518 {
519 	struct net_device *dev;
520 	struct ctcm_priv *priv;
521 	struct mpc_group *grp;
522 
523 	dev = ctcmpc_get_dev(port_num);
524 	if (dev == NULL)
525 		return;
526 	priv = dev->ml_priv;
527 	grp = priv->mpcg;
528 
529 	CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
530 			"%s: %s: refcount = %d\n",
531 			CTCM_FUNTAIL, dev->name, netdev_refcnt_read(dev));
532 
533 	fsm_deltimer(&priv->restart_timer);
534 	grp->channels_terminating = 0;
535 	fsm_deltimer(&grp->timer);
536 	grp->allochanfunc = NULL;
537 	grp->estconnfunc = NULL;
538 	grp->port_persist = 0;
539 	grp->send_qllc_disc = 0;
540 	fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
541 
542 	ctcm_close(dev);
543 	return;
544 }
545 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
546 
547 /*
548  * ctc_mpc_flow_control
549  *	(exported interface)
550  */
551 void ctc_mpc_flow_control(int port_num, int flowc)
552 {
553 	struct ctcm_priv *priv;
554 	struct mpc_group *grp;
555 	struct net_device *dev;
556 	struct channel *rch;
557 	int mpcg_state;
558 
559 	dev = ctcmpc_get_dev(port_num);
560 	if (dev == NULL)
561 		return;
562 	priv = dev->ml_priv;
563 	grp = priv->mpcg;
564 
565 	CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
566 			"%s: %s: flowc = %d",
567 				CTCM_FUNTAIL, dev->name, flowc);
568 
569 	rch = priv->channel[CTCM_READ];
570 
571 	mpcg_state = fsm_getstate(grp->fsm);
572 	switch (flowc) {
573 	case 1:
574 		if (mpcg_state == MPCG_STATE_FLOWC)
575 			break;
576 		if (mpcg_state == MPCG_STATE_READY) {
577 			if (grp->flow_off_called == 1)
578 				grp->flow_off_called = 0;
579 			else
580 				fsm_newstate(grp->fsm, MPCG_STATE_FLOWC);
581 			break;
582 		}
583 		break;
584 	case 0:
585 		if (mpcg_state == MPCG_STATE_FLOWC) {
586 			fsm_newstate(grp->fsm, MPCG_STATE_READY);
587 			/* ensure any data that has accumulated */
588 			/* on the io_queue will now be sen t	*/
589 			tasklet_schedule(&rch->ch_tasklet);
590 		}
591 		/* possible race condition			*/
592 		if (mpcg_state == MPCG_STATE_READY) {
593 			grp->flow_off_called = 1;
594 			break;
595 		}
596 		break;
597 	}
598 
599 }
600 EXPORT_SYMBOL(ctc_mpc_flow_control);
601 
602 static int mpc_send_qllc_discontact(struct net_device *);
603 
604 /*
605  * helper function of ctcmpc_unpack_skb
606 */
607 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
608 {
609 	struct channel	  *rch = mpcginfo->ch;
610 	struct net_device *dev = rch->netdev;
611 	struct ctcm_priv   *priv = dev->ml_priv;
612 	struct mpc_group  *grp = priv->mpcg;
613 	struct channel	  *ch = priv->channel[CTCM_WRITE];
614 
615 	CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
616 	CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
617 
618 	grp->sweep_rsp_pend_num--;
619 
620 	if ((grp->sweep_req_pend_num == 0) &&
621 			(grp->sweep_rsp_pend_num == 0)) {
622 		fsm_deltimer(&ch->sweep_timer);
623 		grp->in_sweep = 0;
624 		rch->th_seq_num = 0x00;
625 		ch->th_seq_num = 0x00;
626 		ctcm_clear_busy_do(dev);
627 	}
628 
629 	return;
630 
631 }
632 
633 /*
634  * helper function of mpc_rcvd_sweep_req
635  * which is a helper of ctcmpc_unpack_skb
636  */
637 static void ctcmpc_send_sweep_resp(struct channel *rch)
638 {
639 	struct net_device *dev = rch->netdev;
640 	struct ctcm_priv *priv = dev->ml_priv;
641 	struct mpc_group *grp = priv->mpcg;
642 	struct th_sweep *header;
643 	struct sk_buff *sweep_skb;
644 	struct channel *ch  = priv->channel[CTCM_WRITE];
645 
646 	CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
647 
648 	sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
649 	if (sweep_skb == NULL) {
650 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
651 			"%s(%s): sweep_skb allocation ERROR\n",
652 			CTCM_FUNTAIL, rch->id);
653 		goto done;
654 	}
655 
656 	header = skb_put_zero(sweep_skb, TH_SWEEP_LENGTH);
657 	header->th.th_ch_flag	= TH_SWEEP_RESP;
658 	header->sw.th_last_seq	= ch->th_seq_num;
659 
660 	netif_trans_update(dev);
661 	skb_queue_tail(&ch->sweep_queue, sweep_skb);
662 
663 	fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
664 
665 	return;
666 
667 done:
668 	grp->in_sweep = 0;
669 	ctcm_clear_busy_do(dev);
670 	fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
671 
672 	return;
673 }
674 
675 /*
676  * helper function of ctcmpc_unpack_skb
677  */
678 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
679 {
680 	struct channel	  *rch     = mpcginfo->ch;
681 	struct net_device *dev     = rch->netdev;
682 	struct ctcm_priv  *priv = dev->ml_priv;
683 	struct mpc_group  *grp  = priv->mpcg;
684 	struct channel	  *ch	   = priv->channel[CTCM_WRITE];
685 
686 	if (do_debug)
687 		CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
688 			" %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
689 
690 	if (grp->in_sweep == 0) {
691 		grp->in_sweep = 1;
692 		ctcm_test_and_set_busy(dev);
693 		grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
694 		grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
695 	}
696 
697 	CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
698 
699 	grp->sweep_req_pend_num--;
700 	ctcmpc_send_sweep_resp(ch);
701 	kfree(mpcginfo);
702 	return;
703 }
704 
705 /*
706   * MPC Group Station FSM definitions
707  */
708 static const char *mpcg_event_names[] = {
709 	[MPCG_EVENT_INOP]	= "INOP Condition",
710 	[MPCG_EVENT_DISCONC]	= "Discontact Received",
711 	[MPCG_EVENT_XID0DO]	= "Channel Active - Start XID",
712 	[MPCG_EVENT_XID2]	= "XID2 Received",
713 	[MPCG_EVENT_XID2DONE]	= "XID0 Complete",
714 	[MPCG_EVENT_XID7DONE]	= "XID7 Complete",
715 	[MPCG_EVENT_TIMER]	= "XID Setup Timer",
716 	[MPCG_EVENT_DOIO]	= "XID DoIO",
717 };
718 
719 static const char *mpcg_state_names[] = {
720 	[MPCG_STATE_RESET]	= "Reset",
721 	[MPCG_STATE_INOP]	= "INOP",
722 	[MPCG_STATE_XID2INITW]	= "Passive XID- XID0 Pending Start",
723 	[MPCG_STATE_XID2INITX]	= "Passive XID- XID0 Pending Complete",
724 	[MPCG_STATE_XID7INITW]	= "Passive XID- XID7 Pending P1 Start",
725 	[MPCG_STATE_XID7INITX]	= "Passive XID- XID7 Pending P2 Complete",
726 	[MPCG_STATE_XID0IOWAIT]	= "Active  XID- XID0 Pending Start",
727 	[MPCG_STATE_XID0IOWAIX]	= "Active  XID- XID0 Pending Complete",
728 	[MPCG_STATE_XID7INITI]	= "Active  XID- XID7 Pending Start",
729 	[MPCG_STATE_XID7INITZ]	= "Active  XID- XID7 Pending Complete ",
730 	[MPCG_STATE_XID7INITF]	= "XID        - XID7 Complete ",
731 	[MPCG_STATE_FLOWC]	= "FLOW CONTROL ON",
732 	[MPCG_STATE_READY]	= "READY",
733 };
734 
735 /*
736  * The MPC Group Station FSM
737  *   22 events
738  */
739 static const fsm_node mpcg_fsm[] = {
740 	{ MPCG_STATE_RESET,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
741 	{ MPCG_STATE_INOP,	MPCG_EVENT_INOP,	mpc_action_nop        },
742 	{ MPCG_STATE_FLOWC,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
743 
744 	{ MPCG_STATE_READY,	MPCG_EVENT_DISCONC,	mpc_action_discontact },
745 	{ MPCG_STATE_READY,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
746 
747 	{ MPCG_STATE_XID2INITW,	MPCG_EVENT_XID0DO,	mpc_action_doxid0     },
748 	{ MPCG_STATE_XID2INITW,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid0  },
749 	{ MPCG_STATE_XID2INITW,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
750 	{ MPCG_STATE_XID2INITW,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
751 	{ MPCG_STATE_XID2INITW,	MPCG_EVENT_DOIO,	mpc_action_yside_xid  },
752 
753 	{ MPCG_STATE_XID2INITX,	MPCG_EVENT_XID0DO,	mpc_action_doxid0     },
754 	{ MPCG_STATE_XID2INITX,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid0  },
755 	{ MPCG_STATE_XID2INITX,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
756 	{ MPCG_STATE_XID2INITX,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
757 	{ MPCG_STATE_XID2INITX,	MPCG_EVENT_DOIO,	mpc_action_yside_xid  },
758 
759 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_XID2DONE,	mpc_action_doxid7     },
760 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_DISCONC,	mpc_action_discontact },
761 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid7  },
762 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
763 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
764 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_XID7DONE,	mpc_action_doxid7     },
765 	{ MPCG_STATE_XID7INITW,	MPCG_EVENT_DOIO,	mpc_action_yside_xid  },
766 
767 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_DISCONC,	mpc_action_discontact },
768 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid7  },
769 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
770 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_XID7DONE,	mpc_action_doxid7     },
771 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
772 	{ MPCG_STATE_XID7INITX,	MPCG_EVENT_DOIO,	mpc_action_yside_xid  },
773 
774 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO,	mpc_action_doxid0     },
775 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC,	mpc_action_discontact },
776 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2,	mpc_action_rcvd_xid0  },
777 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP,	mpc_action_go_inop    },
778 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER,	mpc_action_timeout    },
779 	{ MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO,	mpc_action_xside_xid  },
780 
781 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO,	mpc_action_doxid0     },
782 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC,	mpc_action_discontact },
783 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2,	mpc_action_rcvd_xid0  },
784 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP,	mpc_action_go_inop    },
785 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER,	mpc_action_timeout    },
786 	{ MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO,	mpc_action_xside_xid  },
787 
788 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_XID2DONE,	mpc_action_doxid7     },
789 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid7  },
790 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_DISCONC,	mpc_action_discontact },
791 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
792 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
793 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_XID7DONE,	mpc_action_doxid7     },
794 	{ MPCG_STATE_XID7INITI,	MPCG_EVENT_DOIO,	mpc_action_xside_xid  },
795 
796 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_XID2,	mpc_action_rcvd_xid7  },
797 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_XID7DONE,	mpc_action_doxid7     },
798 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_DISCONC,	mpc_action_discontact },
799 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
800 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_TIMER,	mpc_action_timeout    },
801 	{ MPCG_STATE_XID7INITZ,	MPCG_EVENT_DOIO,	mpc_action_xside_xid  },
802 
803 	{ MPCG_STATE_XID7INITF,	MPCG_EVENT_INOP,	mpc_action_go_inop    },
804 	{ MPCG_STATE_XID7INITF,	MPCG_EVENT_XID7DONE,	mpc_action_go_ready   },
805 };
806 
807 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
808 
809 /*
810  * MPC Group Station FSM action
811  * CTCM_PROTO_MPC only
812  */
813 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
814 {
815 	struct net_device *dev = arg;
816 	struct ctcm_priv *priv = dev->ml_priv;
817 	struct mpc_group *grp = priv->mpcg;
818 
819 	if (grp == NULL) {
820 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
821 			"%s(%s): No MPC group",
822 				CTCM_FUNTAIL, dev->name);
823 		return;
824 	}
825 
826 	fsm_deltimer(&grp->timer);
827 
828 	if (grp->saved_xid2->xid2_flag2 == 0x40) {
829 		priv->xid->xid2_flag2 = 0x00;
830 		if (grp->estconnfunc) {
831 			grp->estconnfunc(grp->port_num, 1,
832 					grp->group_max_buflen);
833 			grp->estconnfunc = NULL;
834 		} else if (grp->allochanfunc)
835 			grp->send_qllc_disc = 1;
836 
837 		fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
838 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
839 				"%s(%s): fails",
840 					CTCM_FUNTAIL, dev->name);
841 		return;
842 	}
843 
844 	grp->port_persist = 1;
845 	grp->out_of_sequence = 0;
846 	grp->estconn_called = 0;
847 
848 	tasklet_hi_schedule(&grp->mpc_tasklet2);
849 
850 	return;
851 }
852 
853 /*
854  * helper of ctcm_init_netdevice
855  * CTCM_PROTO_MPC only
856  */
857 void mpc_group_ready(unsigned long adev)
858 {
859 	struct net_device *dev = (struct net_device *)adev;
860 	struct ctcm_priv *priv = dev->ml_priv;
861 	struct mpc_group *grp = priv->mpcg;
862 	struct channel *ch = NULL;
863 
864 	if (grp == NULL) {
865 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
866 			"%s(%s): No MPC group",
867 				CTCM_FUNTAIL, dev->name);
868 		return;
869 	}
870 
871 	CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
872 		"%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
873 			CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
874 
875 	fsm_newstate(grp->fsm, MPCG_STATE_READY);
876 
877 	/* Put up a read on the channel */
878 	ch = priv->channel[CTCM_READ];
879 	ch->pdu_seq = 0;
880 	CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
881 			__func__, ch->pdu_seq);
882 
883 	ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
884 	/* Put the write channel in idle state */
885 	ch = priv->channel[CTCM_WRITE];
886 	if (ch->collect_len > 0) {
887 		spin_lock(&ch->collect_lock);
888 		ctcm_purge_skb_queue(&ch->collect_queue);
889 		ch->collect_len = 0;
890 		spin_unlock(&ch->collect_lock);
891 	}
892 	ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
893 	ctcm_clear_busy(dev);
894 
895 	if (grp->estconnfunc) {
896 		grp->estconnfunc(grp->port_num, 0,
897 				    grp->group_max_buflen);
898 		grp->estconnfunc = NULL;
899 	} else if (grp->allochanfunc) {
900 		grp->allochanfunc(grp->port_num, grp->group_max_buflen);
901 	}
902 
903 	grp->send_qllc_disc = 1;
904 	grp->changed_side = 0;
905 
906 	return;
907 
908 }
909 
910 /*
911  * Increment the MPC Group Active Channel Counts
912  * helper of dev_action (called from channel fsm)
913  */
914 void mpc_channel_action(struct channel *ch, int direction, int action)
915 {
916 	struct net_device  *dev  = ch->netdev;
917 	struct ctcm_priv   *priv = dev->ml_priv;
918 	struct mpc_group   *grp  = priv->mpcg;
919 
920 	if (grp == NULL) {
921 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
922 			"%s(%s): No MPC group",
923 				CTCM_FUNTAIL, dev->name);
924 		return;
925 	}
926 
927 	CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
928 
929 	CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
930 		"%s: %i / Grp:%s total_channels=%i, active_channels: "
931 		"read=%i, write=%i\n", __func__, action,
932 		fsm_getstate_str(grp->fsm), grp->num_channel_paths,
933 		grp->active_channels[CTCM_READ],
934 		grp->active_channels[CTCM_WRITE]);
935 
936 	if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
937 		grp->num_channel_paths++;
938 		grp->active_channels[direction]++;
939 		grp->outstanding_xid2++;
940 		ch->in_mpcgroup = 1;
941 
942 		if (ch->xid_skb != NULL)
943 			dev_kfree_skb_any(ch->xid_skb);
944 
945 		ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
946 					GFP_ATOMIC | GFP_DMA);
947 		if (ch->xid_skb == NULL) {
948 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
949 				"%s(%s): Couldn't alloc ch xid_skb\n",
950 				CTCM_FUNTAIL, dev->name);
951 			fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
952 			return;
953 		}
954 		ch->xid_skb_data = ch->xid_skb->data;
955 		ch->xid_th = (struct th_header *)ch->xid_skb->data;
956 		skb_put(ch->xid_skb, TH_HEADER_LENGTH);
957 		ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
958 		skb_put(ch->xid_skb, XID2_LENGTH);
959 		ch->xid_id = skb_tail_pointer(ch->xid_skb);
960 		ch->xid_skb->data = ch->xid_skb_data;
961 		skb_reset_tail_pointer(ch->xid_skb);
962 		ch->xid_skb->len = 0;
963 
964 		skb_put_data(ch->xid_skb, grp->xid_skb->data,
965 			     grp->xid_skb->len);
966 
967 		ch->xid->xid2_dlc_type =
968 			((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
969 				? XID2_READ_SIDE : XID2_WRITE_SIDE);
970 
971 		if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
972 			ch->xid->xid2_buf_len = 0x00;
973 
974 		ch->xid_skb->data = ch->xid_skb_data;
975 		skb_reset_tail_pointer(ch->xid_skb);
976 		ch->xid_skb->len = 0;
977 
978 		fsm_newstate(ch->fsm, CH_XID0_PENDING);
979 
980 		if ((grp->active_channels[CTCM_READ] > 0) &&
981 		    (grp->active_channels[CTCM_WRITE] > 0) &&
982 			(fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
983 			fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
984 			CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
985 				"%s: %s: MPC GROUP CHANNELS ACTIVE\n",
986 						__func__, dev->name);
987 		}
988 	} else if ((action == MPC_CHANNEL_REMOVE) &&
989 			(ch->in_mpcgroup == 1)) {
990 		ch->in_mpcgroup = 0;
991 		grp->num_channel_paths--;
992 		grp->active_channels[direction]--;
993 
994 		if (ch->xid_skb != NULL)
995 			dev_kfree_skb_any(ch->xid_skb);
996 		ch->xid_skb = NULL;
997 
998 		if (grp->channels_terminating)
999 					goto done;
1000 
1001 		if (((grp->active_channels[CTCM_READ] == 0) &&
1002 					(grp->active_channels[CTCM_WRITE] > 0))
1003 			|| ((grp->active_channels[CTCM_WRITE] == 0) &&
1004 					(grp->active_channels[CTCM_READ] > 0)))
1005 			fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1006 	}
1007 done:
1008 	CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1009 		"exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1010 		"read=%i, write=%i\n", __func__, action,
1011 		fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1012 		grp->active_channels[CTCM_READ],
1013 		grp->active_channels[CTCM_WRITE]);
1014 
1015 	CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1016 }
1017 
1018 /*
1019  * Unpack a just received skb and hand it over to
1020  * upper layers.
1021  * special MPC version of unpack_skb.
1022  *
1023  * ch		The channel where this skb has been received.
1024  * pskb		The received skb.
1025  */
1026 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1027 {
1028 	struct net_device *dev	= ch->netdev;
1029 	struct ctcm_priv *priv = dev->ml_priv;
1030 	struct mpc_group *grp = priv->mpcg;
1031 	struct pdu *curr_pdu;
1032 	struct mpcg_info *mpcginfo;
1033 	struct th_header *header = NULL;
1034 	struct th_sweep *sweep = NULL;
1035 	int pdu_last_seen = 0;
1036 	__u32 new_len;
1037 	struct sk_buff *skb;
1038 	int skblen;
1039 	int sendrc = 0;
1040 
1041 	CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1042 			__func__, dev->name, smp_processor_id(), ch->id);
1043 
1044 	header = (struct th_header *)pskb->data;
1045 	if ((header->th_seg == 0) &&
1046 		(header->th_ch_flag == 0) &&
1047 		(header->th_blk_flag == 0) &&
1048 		(header->th_seq_num == 0))
1049 		/* nothing for us */	goto done;
1050 
1051 	CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1052 	CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1053 	CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1054 
1055 	pskb->dev = dev;
1056 	pskb->ip_summed = CHECKSUM_UNNECESSARY;
1057 	skb_pull(pskb, TH_HEADER_LENGTH);
1058 
1059 	if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1060 		CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1061 		if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1062 		   ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1063 		    (header->th_seq_num != ch->th_seq_num + 1) &&
1064 		    (ch->th_seq_num != 0))) {
1065 			/* This is NOT the next segment		*
1066 			 * we are not the correct race winner	*
1067 			 * go away and let someone else win	*
1068 			 * BUT..this only applies if xid negot	*
1069 			 * is done				*
1070 			*/
1071 			grp->out_of_sequence += 1;
1072 			__skb_push(pskb, TH_HEADER_LENGTH);
1073 			skb_queue_tail(&ch->io_queue, pskb);
1074 			CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1075 					"got:%08x\n", __func__,
1076 				ch->th_seq_num + 1, header->th_seq_num);
1077 
1078 			return;
1079 		}
1080 		grp->out_of_sequence = 0;
1081 		ch->th_seq_num = header->th_seq_num;
1082 
1083 		CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1084 					__func__, ch->th_seq_num);
1085 
1086 		if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1087 					goto done;
1088 		while ((pskb->len > 0) && !pdu_last_seen) {
1089 			curr_pdu = (struct pdu *)pskb->data;
1090 
1091 			CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1092 			CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1093 			CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1094 						__func__, pskb->len);
1095 
1096 			skb_pull(pskb, PDU_HEADER_LENGTH);
1097 
1098 			if (curr_pdu->pdu_flag & PDU_LAST)
1099 				pdu_last_seen = 1;
1100 			if (curr_pdu->pdu_flag & PDU_CNTL)
1101 				pskb->protocol = htons(ETH_P_SNAP);
1102 			else
1103 				pskb->protocol = htons(ETH_P_SNA_DIX);
1104 
1105 			if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1106 				CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1107 					"%s(%s): Dropping packet with "
1108 					"illegal siize %d",
1109 					CTCM_FUNTAIL, dev->name, pskb->len);
1110 
1111 				priv->stats.rx_dropped++;
1112 				priv->stats.rx_length_errors++;
1113 				goto done;
1114 			}
1115 			skb_reset_mac_header(pskb);
1116 			new_len = curr_pdu->pdu_offset;
1117 			CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1118 						__func__, new_len);
1119 			if ((new_len == 0) || (new_len > pskb->len)) {
1120 				/* should never happen		    */
1121 				/* pskb len must be hosed...bail out */
1122 				CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1123 					"%s(%s): non valid pdu_offset: %04x",
1124 					/* "data may be lost", */
1125 					CTCM_FUNTAIL, dev->name, new_len);
1126 				goto done;
1127 			}
1128 			skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1129 
1130 			if (!skb) {
1131 				CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1132 					"%s(%s): MEMORY allocation error",
1133 						CTCM_FUNTAIL, dev->name);
1134 				priv->stats.rx_dropped++;
1135 				fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1136 				goto done;
1137 			}
1138 			skb_put_data(skb, pskb->data, new_len);
1139 
1140 			skb_reset_mac_header(skb);
1141 			skb->dev = pskb->dev;
1142 			skb->protocol = pskb->protocol;
1143 			skb->ip_summed = CHECKSUM_UNNECESSARY;
1144 			*((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1145 			ch->pdu_seq++;
1146 
1147 			if (do_debug_data) {
1148 				ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1149 						__func__, ch->pdu_seq);
1150 				ctcm_pr_debug("%s: skb:%0lx "
1151 					"skb len: %d \n", __func__,
1152 					(unsigned long)skb, skb->len);
1153 				ctcm_pr_debug("%s: up to 32 bytes "
1154 					"of pdu_data sent\n", __func__);
1155 				ctcmpc_dump32((char *)skb->data, skb->len);
1156 			}
1157 
1158 			skblen = skb->len;
1159 			sendrc = netif_rx(skb);
1160 			priv->stats.rx_packets++;
1161 			priv->stats.rx_bytes += skblen;
1162 			skb_pull(pskb, new_len); /* point to next PDU */
1163 		}
1164 	} else {
1165 		mpcginfo = kmalloc(sizeof(struct mpcg_info), GFP_ATOMIC);
1166 		if (mpcginfo == NULL)
1167 					goto done;
1168 
1169 		mpcginfo->ch = ch;
1170 		mpcginfo->th = header;
1171 		mpcginfo->skb = pskb;
1172 		CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1173 					__func__);
1174 		/*  it's a sweep?   */
1175 		sweep = (struct th_sweep *)pskb->data;
1176 		mpcginfo->sweep = sweep;
1177 		if (header->th_ch_flag == TH_SWEEP_REQ)
1178 			mpc_rcvd_sweep_req(mpcginfo);
1179 		else if (header->th_ch_flag == TH_SWEEP_RESP)
1180 			mpc_rcvd_sweep_resp(mpcginfo);
1181 		else if (header->th_blk_flag == TH_DATA_IS_XID) {
1182 			struct xid2 *thisxid = (struct xid2 *)pskb->data;
1183 			skb_pull(pskb, XID2_LENGTH);
1184 			mpcginfo->xid = thisxid;
1185 			fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1186 		} else if (header->th_blk_flag == TH_DISCONTACT)
1187 			fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1188 		else if (header->th_seq_num != 0) {
1189 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1190 				"%s(%s): control pkt expected\n",
1191 						CTCM_FUNTAIL, dev->name);
1192 			priv->stats.rx_dropped++;
1193 			/* mpcginfo only used for non-data transfers */
1194 			if (do_debug_data)
1195 				ctcmpc_dump_skb(pskb, -8);
1196 		}
1197 		kfree(mpcginfo);
1198 	}
1199 done:
1200 
1201 	dev_kfree_skb_any(pskb);
1202 	if (sendrc == NET_RX_DROP) {
1203 		dev_warn(&dev->dev,
1204 			"The network backlog for %s is exceeded, "
1205 			"package dropped\n", __func__);
1206 		fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1207 	}
1208 
1209 	CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1210 			__func__, dev->name, ch, ch->id);
1211 }
1212 
1213 /*
1214  * tasklet helper for mpc's skb unpacking.
1215  *
1216  * ch		The channel to work on.
1217  * Allow flow control back pressure to occur here.
1218  * Throttling back channel can result in excessive
1219  * channel inactivity and system deact of channel
1220  */
1221 void ctcmpc_bh(unsigned long thischan)
1222 {
1223 	struct channel	  *ch	= (struct channel *)thischan;
1224 	struct sk_buff	  *skb;
1225 	struct net_device *dev	= ch->netdev;
1226 	struct ctcm_priv  *priv	= dev->ml_priv;
1227 	struct mpc_group  *grp	= priv->mpcg;
1228 
1229 	CTCM_PR_DEBUG("%s cp:%i enter:  %s() %s\n",
1230 	       dev->name, smp_processor_id(), __func__, ch->id);
1231 	/* caller has requested driver to throttle back */
1232 	while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1233 			(skb = skb_dequeue(&ch->io_queue))) {
1234 		ctcmpc_unpack_skb(ch, skb);
1235 		if (grp->out_of_sequence > 20) {
1236 			/* assume data loss has occurred if */
1237 			/* missing seq_num for extended     */
1238 			/* period of time		    */
1239 			grp->out_of_sequence = 0;
1240 			fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1241 			break;
1242 		}
1243 		if (skb == skb_peek(&ch->io_queue))
1244 			break;
1245 	}
1246 	CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1247 			__func__, dev->name, ch, ch->id);
1248 	return;
1249 }
1250 
1251 /*
1252  *  MPC Group Initializations
1253  */
1254 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1255 {
1256 	struct mpc_group *grp;
1257 
1258 	CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1259 			"Enter %s(%p)", CTCM_FUNTAIL, priv);
1260 
1261 	grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1262 	if (grp == NULL)
1263 		return NULL;
1264 
1265 	grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1266 			MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1267 			mpcg_fsm_len, GFP_KERNEL);
1268 	if (grp->fsm == NULL) {
1269 		kfree(grp);
1270 		return NULL;
1271 	}
1272 
1273 	fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1274 	fsm_settimer(grp->fsm, &grp->timer);
1275 
1276 	grp->xid_skb =
1277 		 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1278 	if (grp->xid_skb == NULL) {
1279 		kfree_fsm(grp->fsm);
1280 		kfree(grp);
1281 		return NULL;
1282 	}
1283 	/*  base xid for all channels in group  */
1284 	grp->xid_skb_data = grp->xid_skb->data;
1285 	grp->xid_th = (struct th_header *)grp->xid_skb->data;
1286 	skb_put_data(grp->xid_skb, &thnorm, TH_HEADER_LENGTH);
1287 
1288 	grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1289 	skb_put_data(grp->xid_skb, &init_xid, XID2_LENGTH);
1290 	grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1291 	grp->xid->xid2_sender_id = jiffies;
1292 
1293 	grp->xid_id = skb_tail_pointer(grp->xid_skb);
1294 	skb_put_data(grp->xid_skb, "VTAM", 4);
1295 
1296 	grp->rcvd_xid_skb =
1297 		__dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1298 	if (grp->rcvd_xid_skb == NULL) {
1299 		kfree_fsm(grp->fsm);
1300 		dev_kfree_skb(grp->xid_skb);
1301 		kfree(grp);
1302 		return NULL;
1303 	}
1304 	grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1305 	grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1306 	skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1307 	grp->saved_xid2 = NULL;
1308 	priv->xid = grp->xid;
1309 	priv->mpcg = grp;
1310 	return grp;
1311 }
1312 
1313 /*
1314  * The MPC Group Station FSM
1315  */
1316 
1317 /*
1318  * MPC Group Station FSM actions
1319  * CTCM_PROTO_MPC only
1320  */
1321 
1322 /*
1323  * NOP action for statemachines
1324  */
1325 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1326 {
1327 }
1328 
1329 /*
1330  * invoked when the device transitions to dev_stopped
1331  * MPC will stop each individual channel if a single XID failure
1332  * occurs, or will intitiate all channels be stopped if a GROUP
1333  * level failure occurs.
1334  */
1335 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1336 {
1337 	struct net_device  *dev = arg;
1338 	struct ctcm_priv    *priv;
1339 	struct mpc_group *grp;
1340 	struct channel *wch;
1341 
1342 	CTCM_PR_DEBUG("Enter %s: %s\n",	__func__, dev->name);
1343 
1344 	priv  = dev->ml_priv;
1345 	grp =  priv->mpcg;
1346 	grp->flow_off_called = 0;
1347 	fsm_deltimer(&grp->timer);
1348 	if (grp->channels_terminating)
1349 			return;
1350 
1351 	grp->channels_terminating = 1;
1352 	grp->saved_state = fsm_getstate(grp->fsm);
1353 	fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1354 	if (grp->saved_state > MPCG_STATE_XID7INITF)
1355 		CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1356 			"%s(%s): MPC GROUP INOPERATIVE",
1357 				CTCM_FUNTAIL, dev->name);
1358 	if ((grp->saved_state != MPCG_STATE_RESET) ||
1359 		/* dealloc_channel has been called */
1360 		(grp->port_persist == 0))
1361 		fsm_deltimer(&priv->restart_timer);
1362 
1363 	wch = priv->channel[CTCM_WRITE];
1364 
1365 	switch (grp->saved_state) {
1366 	case MPCG_STATE_RESET:
1367 	case MPCG_STATE_INOP:
1368 	case MPCG_STATE_XID2INITW:
1369 	case MPCG_STATE_XID0IOWAIT:
1370 	case MPCG_STATE_XID2INITX:
1371 	case MPCG_STATE_XID7INITW:
1372 	case MPCG_STATE_XID7INITX:
1373 	case MPCG_STATE_XID0IOWAIX:
1374 	case MPCG_STATE_XID7INITI:
1375 	case MPCG_STATE_XID7INITZ:
1376 	case MPCG_STATE_XID7INITF:
1377 		break;
1378 	case MPCG_STATE_FLOWC:
1379 	case MPCG_STATE_READY:
1380 	default:
1381 		tasklet_hi_schedule(&wch->ch_disc_tasklet);
1382 	}
1383 
1384 	grp->xid2_tgnum = 0;
1385 	grp->group_max_buflen = 0;  /*min of all received */
1386 	grp->outstanding_xid2 = 0;
1387 	grp->outstanding_xid7 = 0;
1388 	grp->outstanding_xid7_p2 = 0;
1389 	grp->saved_xid2 = NULL;
1390 	grp->xidnogood = 0;
1391 	grp->changed_side = 0;
1392 
1393 	grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1394 	skb_reset_tail_pointer(grp->rcvd_xid_skb);
1395 	grp->rcvd_xid_skb->len = 0;
1396 	grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1397 	skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1398 
1399 	if (grp->send_qllc_disc == 1) {
1400 		grp->send_qllc_disc = 0;
1401 		mpc_send_qllc_discontact(dev);
1402 	}
1403 
1404 	/* DO NOT issue DEV_EVENT_STOP directly out of this code */
1405 	/* This can result in INOP of VTAM PU due to halting of  */
1406 	/* outstanding IO which causes a sense to be returned	 */
1407 	/* Only about 3 senses are allowed and then IOS/VTAM will*/
1408 	/* become unreachable without manual intervention	 */
1409 	if ((grp->port_persist == 1) || (grp->alloc_called)) {
1410 		grp->alloc_called = 0;
1411 		fsm_deltimer(&priv->restart_timer);
1412 		fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1413 		fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1414 		if (grp->saved_state > MPCG_STATE_XID7INITF)
1415 			CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1416 				"%s(%s): MPC GROUP RECOVERY SCHEDULED",
1417 					CTCM_FUNTAIL, dev->name);
1418 	} else {
1419 		fsm_deltimer(&priv->restart_timer);
1420 		fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1421 		fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1422 		CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1423 			"%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1424 						CTCM_FUNTAIL, dev->name);
1425 	}
1426 }
1427 
1428 /*
1429  * Handle mpc group  action timeout.
1430  * MPC Group Station FSM action
1431  * CTCM_PROTO_MPC only
1432  *
1433  * fi		An instance of an mpc_group fsm.
1434  * event	The event, just happened.
1435  * arg		Generic pointer, casted from net_device * upon call.
1436  */
1437 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1438 {
1439 	struct net_device *dev = arg;
1440 	struct ctcm_priv *priv;
1441 	struct mpc_group *grp;
1442 	struct channel *wch;
1443 	struct channel *rch;
1444 
1445 	priv = dev->ml_priv;
1446 	grp = priv->mpcg;
1447 	wch = priv->channel[CTCM_WRITE];
1448 	rch = priv->channel[CTCM_READ];
1449 
1450 	switch (fsm_getstate(grp->fsm)) {
1451 	case MPCG_STATE_XID2INITW:
1452 		/* Unless there is outstanding IO on the  */
1453 		/* channel just return and wait for ATTN  */
1454 		/* interrupt to begin XID negotiations	  */
1455 		if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1456 		   (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1457 			break;
1458 		fallthrough;
1459 	default:
1460 		fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1461 	}
1462 
1463 	CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1464 			"%s: dev=%s exit",
1465 			CTCM_FUNTAIL, dev->name);
1466 	return;
1467 }
1468 
1469 /*
1470  * MPC Group Station FSM action
1471  * CTCM_PROTO_MPC only
1472  */
1473 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1474 {
1475 	struct mpcg_info   *mpcginfo   = arg;
1476 	struct channel	   *ch	       = mpcginfo->ch;
1477 	struct net_device  *dev;
1478 	struct ctcm_priv   *priv;
1479 	struct mpc_group   *grp;
1480 
1481 	if (ch) {
1482 		dev = ch->netdev;
1483 		if (dev) {
1484 			priv = dev->ml_priv;
1485 			if (priv) {
1486 				CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1487 					"%s: %s: %s\n",
1488 					CTCM_FUNTAIL, dev->name, ch->id);
1489 				grp = priv->mpcg;
1490 				grp->send_qllc_disc = 1;
1491 				fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1492 			}
1493 		}
1494 	}
1495 
1496 	return;
1497 }
1498 
1499 /*
1500  * MPC Group Station - not part of FSM
1501  * CTCM_PROTO_MPC only
1502  * called from add_channel in ctcm_main.c
1503  */
1504 void mpc_action_send_discontact(unsigned long thischan)
1505 {
1506 	int rc;
1507 	struct channel	*ch = (struct channel *)thischan;
1508 	unsigned long	saveflags = 0;
1509 
1510 	spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1511 	rc = ccw_device_start(ch->cdev, &ch->ccw[15], 0, 0xff, 0);
1512 	spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1513 
1514 	if (rc != 0) {
1515 		ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1516 	}
1517 
1518 	return;
1519 }
1520 
1521 
1522 /*
1523  * helper function of mpc FSM
1524  * CTCM_PROTO_MPC only
1525  * mpc_action_rcvd_xid7
1526 */
1527 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1528 {
1529 	struct channel	   *ch	 = mpcginfo->ch;
1530 	struct net_device  *dev  = ch->netdev;
1531 	struct ctcm_priv   *priv = dev->ml_priv;
1532 	struct mpc_group   *grp  = priv->mpcg;
1533 	struct xid2	   *xid  = mpcginfo->xid;
1534 	int	rc	 = 0;
1535 	__u64	our_id   = 0;
1536 	__u64   their_id = 0;
1537 	int	len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1538 
1539 	CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1540 
1541 	if (xid == NULL) {
1542 		rc = 1;
1543 		/* XID REJECTED: xid == NULL */
1544 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1545 			"%s(%s): xid = NULL",
1546 				CTCM_FUNTAIL, ch->id);
1547 		goto done;
1548 	}
1549 
1550 	CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1551 
1552 	/*the received direction should be the opposite of ours  */
1553 	if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1554 				XID2_READ_SIDE) != xid->xid2_dlc_type) {
1555 		rc = 2;
1556 		/* XID REJECTED: r/w channel pairing mismatch */
1557 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1558 			"%s(%s): r/w channel pairing mismatch",
1559 				CTCM_FUNTAIL, ch->id);
1560 		goto done;
1561 	}
1562 
1563 	if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1564 		CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1565 				grp->group_max_buflen, xid->xid2_buf_len);
1566 
1567 		if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1568 						xid->xid2_buf_len - len)
1569 			grp->group_max_buflen = xid->xid2_buf_len - len;
1570 	}
1571 
1572 	if (grp->saved_xid2 == NULL) {
1573 		grp->saved_xid2 =
1574 			(struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1575 
1576 		skb_put_data(grp->rcvd_xid_skb, xid, XID2_LENGTH);
1577 		grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1578 
1579 		skb_reset_tail_pointer(grp->rcvd_xid_skb);
1580 		grp->rcvd_xid_skb->len = 0;
1581 
1582 		/* convert two 32 bit numbers into 1 64 bit for id compare */
1583 		our_id = (__u64)priv->xid->xid2_adj_id;
1584 		our_id = our_id << 32;
1585 		our_id = our_id + priv->xid->xid2_sender_id;
1586 		their_id = (__u64)xid->xid2_adj_id;
1587 		their_id = their_id << 32;
1588 		their_id = their_id + xid->xid2_sender_id;
1589 		/* lower id assume the xside role */
1590 		if (our_id < their_id) {
1591 			grp->roll = XSIDE;
1592 			CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1593 				"%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1594 					CTCM_FUNTAIL, ch->id);
1595 		} else {
1596 			grp->roll = YSIDE;
1597 			CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1598 				"%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1599 					CTCM_FUNTAIL, ch->id);
1600 		}
1601 
1602 	} else {
1603 		if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1604 			rc = 3;
1605 			/* XID REJECTED: xid flag byte4 mismatch */
1606 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1607 				"%s(%s): xid flag byte4 mismatch",
1608 					CTCM_FUNTAIL, ch->id);
1609 		}
1610 		if (xid->xid2_flag2 == 0x40) {
1611 			rc = 4;
1612 			/* XID REJECTED - xid NOGOOD */
1613 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1614 				"%s(%s): xid NOGOOD",
1615 					CTCM_FUNTAIL, ch->id);
1616 		}
1617 		if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1618 			rc = 5;
1619 			/* XID REJECTED - Adjacent Station ID Mismatch */
1620 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1621 				"%s(%s): Adjacent Station ID Mismatch",
1622 					CTCM_FUNTAIL, ch->id);
1623 		}
1624 		if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1625 			rc = 6;
1626 			/* XID REJECTED - Sender Address Mismatch */
1627 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1628 				"%s(%s): Sender Address Mismatch",
1629 					CTCM_FUNTAIL, ch->id);
1630 		}
1631 	}
1632 done:
1633 	if (rc) {
1634 		dev_warn(&dev->dev,
1635 			"The XID used in the MPC protocol is not valid, "
1636 			"rc = %d\n", rc);
1637 		priv->xid->xid2_flag2 = 0x40;
1638 		grp->saved_xid2->xid2_flag2 = 0x40;
1639 	}
1640 
1641 	return rc;
1642 }
1643 
1644 /*
1645  * MPC Group Station FSM action
1646  * CTCM_PROTO_MPC only
1647  */
1648 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1649 {
1650 	struct channel *ch = arg;
1651 	int rc = 0;
1652 	int gotlock = 0;
1653 	unsigned long saveflags = 0;	/* avoids compiler warning with
1654 					   spin_unlock_irqrestore */
1655 
1656 	CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1657 			__func__, smp_processor_id(), ch, ch->id);
1658 
1659 	if (ctcm_checkalloc_buffer(ch))
1660 					goto done;
1661 
1662 	/*
1663 	 * skb data-buffer referencing:
1664 	 */
1665 	ch->trans_skb->data = ch->trans_skb_data;
1666 	skb_reset_tail_pointer(ch->trans_skb);
1667 	ch->trans_skb->len = 0;
1668 	/* result of the previous 3 statements is NOT always
1669 	 * already set after ctcm_checkalloc_buffer
1670 	 * because of possible reuse of the trans_skb
1671 	 */
1672 	memset(ch->trans_skb->data, 0, 16);
1673 	ch->rcvd_xid_th =  (struct th_header *)ch->trans_skb_data;
1674 	/* check is main purpose here: */
1675 	skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1676 	ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1677 	/* check is main purpose here: */
1678 	skb_put(ch->trans_skb, XID2_LENGTH);
1679 	ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1680 	/* cleanup back to startpoint */
1681 	ch->trans_skb->data = ch->trans_skb_data;
1682 	skb_reset_tail_pointer(ch->trans_skb);
1683 	ch->trans_skb->len = 0;
1684 
1685 	/* non-checking rewrite of above skb data-buffer referencing: */
1686 	/*
1687 	memset(ch->trans_skb->data, 0, 16);
1688 	ch->rcvd_xid_th =  (struct th_header *)ch->trans_skb_data;
1689 	ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1690 	ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1691 	 */
1692 
1693 	ch->ccw[8].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1694 	ch->ccw[8].count	= 0;
1695 	ch->ccw[8].cda		= 0x00;
1696 
1697 	if (!(ch->xid_th && ch->xid && ch->xid_id))
1698 		CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1699 			"%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1700 			CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1701 
1702 	if (side == XSIDE) {
1703 		/* mpc_action_xside_xid */
1704 		if (ch->xid_th == NULL)
1705 				goto done;
1706 		ch->ccw[9].cmd_code	= CCW_CMD_WRITE;
1707 		ch->ccw[9].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1708 		ch->ccw[9].count	= TH_HEADER_LENGTH;
1709 		ch->ccw[9].cda		= virt_to_phys(ch->xid_th);
1710 
1711 		if (ch->xid == NULL)
1712 				goto done;
1713 		ch->ccw[10].cmd_code	= CCW_CMD_WRITE;
1714 		ch->ccw[10].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1715 		ch->ccw[10].count	= XID2_LENGTH;
1716 		ch->ccw[10].cda		= virt_to_phys(ch->xid);
1717 
1718 		ch->ccw[11].cmd_code	= CCW_CMD_READ;
1719 		ch->ccw[11].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1720 		ch->ccw[11].count	= TH_HEADER_LENGTH;
1721 		ch->ccw[11].cda		= virt_to_phys(ch->rcvd_xid_th);
1722 
1723 		ch->ccw[12].cmd_code	= CCW_CMD_READ;
1724 		ch->ccw[12].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1725 		ch->ccw[12].count	= XID2_LENGTH;
1726 		ch->ccw[12].cda		= virt_to_phys(ch->rcvd_xid);
1727 
1728 		ch->ccw[13].cmd_code	= CCW_CMD_READ;
1729 		ch->ccw[13].cda		= virt_to_phys(ch->rcvd_xid_id);
1730 
1731 	} else { /* side == YSIDE : mpc_action_yside_xid */
1732 		ch->ccw[9].cmd_code	= CCW_CMD_READ;
1733 		ch->ccw[9].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1734 		ch->ccw[9].count	= TH_HEADER_LENGTH;
1735 		ch->ccw[9].cda		= virt_to_phys(ch->rcvd_xid_th);
1736 
1737 		ch->ccw[10].cmd_code	= CCW_CMD_READ;
1738 		ch->ccw[10].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1739 		ch->ccw[10].count	= XID2_LENGTH;
1740 		ch->ccw[10].cda		= virt_to_phys(ch->rcvd_xid);
1741 
1742 		if (ch->xid_th == NULL)
1743 				goto done;
1744 		ch->ccw[11].cmd_code	= CCW_CMD_WRITE;
1745 		ch->ccw[11].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1746 		ch->ccw[11].count	= TH_HEADER_LENGTH;
1747 		ch->ccw[11].cda		= virt_to_phys(ch->xid_th);
1748 
1749 		if (ch->xid == NULL)
1750 				goto done;
1751 		ch->ccw[12].cmd_code	= CCW_CMD_WRITE;
1752 		ch->ccw[12].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1753 		ch->ccw[12].count	= XID2_LENGTH;
1754 		ch->ccw[12].cda		= virt_to_phys(ch->xid);
1755 
1756 		if (ch->xid_id == NULL)
1757 				goto done;
1758 		ch->ccw[13].cmd_code	= CCW_CMD_WRITE;
1759 		ch->ccw[13].cda		= virt_to_phys(ch->xid_id);
1760 
1761 	}
1762 	ch->ccw[13].flags	= CCW_FLAG_SLI | CCW_FLAG_CC;
1763 	ch->ccw[13].count	= 4;
1764 
1765 	ch->ccw[14].cmd_code	= CCW_CMD_NOOP;
1766 	ch->ccw[14].flags	= CCW_FLAG_SLI;
1767 	ch->ccw[14].count	= 0;
1768 	ch->ccw[14].cda		= 0;
1769 
1770 	CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1771 	CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1772 	CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1773 	CTCM_D3_DUMP((char *)ch->xid_id, 4);
1774 
1775 	if (!in_hardirq()) {
1776 			 /* Such conditional locking is a known problem for
1777 			  * sparse because its static undeterministic.
1778 			  * Warnings should be ignored here. */
1779 		spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1780 		gotlock = 1;
1781 	}
1782 
1783 	fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1784 	rc = ccw_device_start(ch->cdev, &ch->ccw[8], 0, 0xff, 0);
1785 
1786 	if (gotlock)	/* see remark above about conditional locking */
1787 		spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1788 
1789 	if (rc != 0) {
1790 		ctcm_ccw_check_rc(ch, rc,
1791 				(side == XSIDE) ? "x-side XID" : "y-side XID");
1792 	}
1793 
1794 done:
1795 	CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1796 				__func__, ch, ch->id);
1797 	return;
1798 
1799 }
1800 
1801 /*
1802  * MPC Group Station FSM action
1803  * CTCM_PROTO_MPC only
1804  */
1805 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1806 {
1807 	mpc_action_side_xid(fsm, arg, XSIDE);
1808 }
1809 
1810 /*
1811  * MPC Group Station FSM action
1812  * CTCM_PROTO_MPC only
1813  */
1814 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1815 {
1816 	mpc_action_side_xid(fsm, arg, YSIDE);
1817 }
1818 
1819 /*
1820  * MPC Group Station FSM action
1821  * CTCM_PROTO_MPC only
1822  */
1823 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1824 {
1825 	struct channel	   *ch   = arg;
1826 	struct net_device  *dev  = ch->netdev;
1827 	struct ctcm_priv   *priv = dev->ml_priv;
1828 	struct mpc_group   *grp  = priv->mpcg;
1829 
1830 	CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1831 			__func__, smp_processor_id(), ch, ch->id);
1832 
1833 	if (ch->xid == NULL) {
1834 		CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1835 			"%s(%s): ch->xid == NULL",
1836 				CTCM_FUNTAIL, dev->name);
1837 		return;
1838 	}
1839 
1840 	fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1841 
1842 	ch->xid->xid2_option =	XID2_0;
1843 
1844 	switch (fsm_getstate(grp->fsm)) {
1845 	case MPCG_STATE_XID2INITW:
1846 	case MPCG_STATE_XID2INITX:
1847 		ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1848 		break;
1849 	case MPCG_STATE_XID0IOWAIT:
1850 	case MPCG_STATE_XID0IOWAIX:
1851 		ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1852 		break;
1853 	}
1854 
1855 	fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1856 
1857 	return;
1858 }
1859 
1860 /*
1861  * MPC Group Station FSM action
1862  * CTCM_PROTO_MPC only
1863 */
1864 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1865 {
1866 	struct net_device *dev = arg;
1867 	struct ctcm_priv  *priv = dev->ml_priv;
1868 	struct mpc_group  *grp  = NULL;
1869 	int direction;
1870 	int send = 0;
1871 
1872 	if (priv)
1873 		grp = priv->mpcg;
1874 	if (grp == NULL)
1875 		return;
1876 
1877 	for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1878 		struct channel *ch = priv->channel[direction];
1879 		struct xid2 *thisxid = ch->xid;
1880 		ch->xid_skb->data = ch->xid_skb_data;
1881 		skb_reset_tail_pointer(ch->xid_skb);
1882 		ch->xid_skb->len = 0;
1883 		thisxid->xid2_option = XID2_7;
1884 		send = 0;
1885 
1886 		/* xid7 phase 1 */
1887 		if (grp->outstanding_xid7_p2 > 0) {
1888 			if (grp->roll == YSIDE) {
1889 				if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1890 					fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1891 					ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1892 					skb_put_data(ch->xid_skb, &thdummy,
1893 						     TH_HEADER_LENGTH);
1894 					send = 1;
1895 				}
1896 			} else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1897 					fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1898 					ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1899 					skb_put_data(ch->xid_skb, &thnorm,
1900 						     TH_HEADER_LENGTH);
1901 					send = 1;
1902 			}
1903 		} else {
1904 			/* xid7 phase 2 */
1905 			if (grp->roll == YSIDE) {
1906 				if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1907 					fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1908 					skb_put_data(ch->xid_skb, &thnorm,
1909 						     TH_HEADER_LENGTH);
1910 					ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1911 					send = 1;
1912 				}
1913 			} else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1914 				fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1915 				ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1916 				skb_put_data(ch->xid_skb, &thdummy,
1917 					     TH_HEADER_LENGTH);
1918 				send = 1;
1919 			}
1920 		}
1921 
1922 		if (send)
1923 			fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1924 	}
1925 
1926 	return;
1927 }
1928 
1929 /*
1930  * MPC Group Station FSM action
1931  * CTCM_PROTO_MPC only
1932  */
1933 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1934 {
1935 
1936 	struct mpcg_info   *mpcginfo  = arg;
1937 	struct channel	   *ch   = mpcginfo->ch;
1938 	struct net_device  *dev  = ch->netdev;
1939 	struct ctcm_priv   *priv = dev->ml_priv;
1940 	struct mpc_group   *grp  = priv->mpcg;
1941 
1942 	CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1943 			__func__, ch->id, grp->outstanding_xid2,
1944 			grp->outstanding_xid7, grp->outstanding_xid7_p2);
1945 
1946 	if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1947 		fsm_newstate(ch->fsm, CH_XID7_PENDING);
1948 
1949 	grp->outstanding_xid2--;
1950 	grp->outstanding_xid7++;
1951 	grp->outstanding_xid7_p2++;
1952 
1953 	/* must change state before validating xid to */
1954 	/* properly handle interim interrupts received*/
1955 	switch (fsm_getstate(grp->fsm)) {
1956 	case MPCG_STATE_XID2INITW:
1957 		fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
1958 		mpc_validate_xid(mpcginfo);
1959 		break;
1960 	case MPCG_STATE_XID0IOWAIT:
1961 		fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
1962 		mpc_validate_xid(mpcginfo);
1963 		break;
1964 	case MPCG_STATE_XID2INITX:
1965 		if (grp->outstanding_xid2 == 0) {
1966 			fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
1967 			mpc_validate_xid(mpcginfo);
1968 			fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1969 		}
1970 		break;
1971 	case MPCG_STATE_XID0IOWAIX:
1972 		if (grp->outstanding_xid2 == 0) {
1973 			fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
1974 			mpc_validate_xid(mpcginfo);
1975 			fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1976 		}
1977 		break;
1978 	}
1979 
1980 	CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
1981 		__func__, ch->id, grp->outstanding_xid2,
1982 		grp->outstanding_xid7, grp->outstanding_xid7_p2);
1983 	CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
1984 		__func__, ch->id,
1985 		fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
1986 	return;
1987 
1988 }
1989 
1990 
1991 /*
1992  * MPC Group Station FSM action
1993  * CTCM_PROTO_MPC only
1994  */
1995 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
1996 {
1997 	struct mpcg_info   *mpcginfo   = arg;
1998 	struct channel	   *ch	       = mpcginfo->ch;
1999 	struct net_device  *dev        = ch->netdev;
2000 	struct ctcm_priv   *priv    = dev->ml_priv;
2001 	struct mpc_group   *grp     = priv->mpcg;
2002 
2003 	CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2004 		__func__, smp_processor_id(), ch, ch->id);
2005 	CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2006 		__func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2007 
2008 	grp->outstanding_xid7--;
2009 	ch->xid_skb->data = ch->xid_skb_data;
2010 	skb_reset_tail_pointer(ch->xid_skb);
2011 	ch->xid_skb->len = 0;
2012 
2013 	switch (fsm_getstate(grp->fsm)) {
2014 	case MPCG_STATE_XID7INITI:
2015 		fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2016 		mpc_validate_xid(mpcginfo);
2017 		break;
2018 	case MPCG_STATE_XID7INITW:
2019 		fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2020 		mpc_validate_xid(mpcginfo);
2021 		break;
2022 	case MPCG_STATE_XID7INITZ:
2023 	case MPCG_STATE_XID7INITX:
2024 		if (grp->outstanding_xid7 == 0) {
2025 			if (grp->outstanding_xid7_p2 > 0) {
2026 				grp->outstanding_xid7 =
2027 					grp->outstanding_xid7_p2;
2028 				grp->outstanding_xid7_p2 = 0;
2029 			} else
2030 				fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2031 
2032 			mpc_validate_xid(mpcginfo);
2033 			fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2034 			break;
2035 		}
2036 		mpc_validate_xid(mpcginfo);
2037 		break;
2038 	}
2039 	return;
2040 }
2041 
2042 /*
2043  * mpc_action helper of an MPC Group Station FSM action
2044  * CTCM_PROTO_MPC only
2045  */
2046 static int mpc_send_qllc_discontact(struct net_device *dev)
2047 {
2048 	struct sk_buff   *skb;
2049 	struct qllc      *qllcptr;
2050 	struct ctcm_priv *priv = dev->ml_priv;
2051 	struct mpc_group *grp = priv->mpcg;
2052 
2053 	CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2054 		__func__, mpcg_state_names[grp->saved_state]);
2055 
2056 	switch (grp->saved_state) {
2057 	/*
2058 	 * establish conn callback function is
2059 	 * preferred method to report failure
2060 	 */
2061 	case MPCG_STATE_XID0IOWAIT:
2062 	case MPCG_STATE_XID0IOWAIX:
2063 	case MPCG_STATE_XID7INITI:
2064 	case MPCG_STATE_XID7INITZ:
2065 	case MPCG_STATE_XID2INITW:
2066 	case MPCG_STATE_XID2INITX:
2067 	case MPCG_STATE_XID7INITW:
2068 	case MPCG_STATE_XID7INITX:
2069 		if (grp->estconnfunc) {
2070 			grp->estconnfunc(grp->port_num, -1, 0);
2071 			grp->estconnfunc = NULL;
2072 			break;
2073 		}
2074 		fallthrough;
2075 	case MPCG_STATE_FLOWC:
2076 	case MPCG_STATE_READY:
2077 		grp->send_qllc_disc = 2;
2078 
2079 		skb = __dev_alloc_skb(sizeof(struct qllc), GFP_ATOMIC);
2080 		if (skb == NULL) {
2081 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2082 				"%s(%s): skb allocation error",
2083 						CTCM_FUNTAIL, dev->name);
2084 			priv->stats.rx_dropped++;
2085 			return -ENOMEM;
2086 		}
2087 
2088 		qllcptr = skb_put(skb, sizeof(struct qllc));
2089 		qllcptr->qllc_address = 0xcc;
2090 		qllcptr->qllc_commands = 0x03;
2091 
2092 		if (skb_headroom(skb) < 4) {
2093 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2094 				"%s(%s): skb_headroom error",
2095 						CTCM_FUNTAIL, dev->name);
2096 			dev_kfree_skb_any(skb);
2097 			return -ENOMEM;
2098 		}
2099 
2100 		*((__u32 *)skb_push(skb, 4)) =
2101 			priv->channel[CTCM_READ]->pdu_seq;
2102 		priv->channel[CTCM_READ]->pdu_seq++;
2103 		CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2104 				__func__, priv->channel[CTCM_READ]->pdu_seq);
2105 
2106 		/* receipt of CC03 resets anticipated sequence number on
2107 		      receiving side */
2108 		priv->channel[CTCM_READ]->pdu_seq = 0x00;
2109 		skb_reset_mac_header(skb);
2110 		skb->dev = dev;
2111 		skb->protocol = htons(ETH_P_SNAP);
2112 		skb->ip_summed = CHECKSUM_UNNECESSARY;
2113 
2114 		CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2115 
2116 		netif_rx(skb);
2117 		break;
2118 	default:
2119 		break;
2120 
2121 	}
2122 
2123 	return 0;
2124 }
2125 /* --- This is the END my friend --- */
2126 
2127