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