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