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