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