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