media: stv06xx: add missing descriptor sanity checks
[linux/fpc-iii.git] / drivers / s390 / net / ctcm_mpc.c
blobab316baa828433ed71390aa96c04f8600c641101
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 */
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);
17 #undef DEBUG
18 #undef DEBUGDATA
19 #undef DEBUGCCW
21 #define KMSG_COMPONENT "ctcm"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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>
34 #include <linux/signal.h>
35 #include <linux/string.h>
36 #include <linux/proc_fs.h>
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>
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>
55 #include "ctcm_main.h"
56 #include "ctcm_mpc.h"
57 #include "ctcm_fsms.h"
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),
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,
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,
99 * Definition of one MPC group
103 * Compatibility macros for busy handling
104 * of network devices.
107 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
110 * MPC Group state machine actions (static prototypes)
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);
124 #ifdef DEBUGDATA
125 /*-------------------------------------------------------------------*
126 * Dump buffer format *
128 *--------------------------------------------------------------------*/
129 void ctcmpc_dumpit(char *buf, int len)
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];
139 sw = 0;
140 rptr = ptr = buf;
141 rm = 16;
142 duphex[0] = 0x00;
143 dup = 0;
145 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
146 if (sw == 0) {
147 sprintf(addr, "%16.16llx", (__u64)rptr);
149 sprintf(boff, "%4.4X", (__u32)ct);
150 bhex[0] = '\0';
151 basc[0] = '\0';
153 if ((sw == 4) || (sw == 12))
154 strcat(bhex, " ");
155 if (sw == 8)
156 strcat(bhex, " ");
158 sprintf(tbuf, "%2.2llX", (__u64)*ptr);
160 tbuf[2] = '\0';
161 strcat(bhex, tbuf);
162 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
163 basc[sw] = *ptr;
164 else
165 basc[sw] = '.';
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);
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++;
186 sw = 0;
187 rm = 16;
188 } /* endfor */
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, " ");
199 if (dup != 0) {
200 sprintf(tdup, "Duplicate as above to %s", addr);
201 ctcm_pr_debug(" --- %s ---\n", tdup);
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);
210 if (dup != 0) {
211 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
212 addr, boff, bhex, basc);
216 return;
218 } /* end of ctcmpc_dumpit */
219 #endif
221 #ifdef DEBUGDATA
223 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
225 * skb The sk_buff to dump.
226 * offset Offset relative to skb-data, where to start the dump.
228 void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
230 __u8 *p = skb->data;
231 struct th_header *header;
232 struct pdu *pheader;
233 int bl = skb->len;
234 int i;
236 if (p == NULL)
237 return;
239 p += offset;
240 header = (struct th_header *)p;
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;
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;
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);
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");
286 #endif
288 static struct net_device *ctcmpc_get_dev(int port_num)
290 char device[20];
291 struct net_device *dev;
292 struct ctcm_priv *priv;
294 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
296 dev = __dev_get_by_name(&init_net, device);
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;
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;
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;
317 return dev;
321 * ctc_mpc_alloc_channel
322 * (exported interface)
324 * Device Initialization :
325 * ACTPATH driven IO operations
327 int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
329 struct net_device *dev;
330 struct mpc_group *grp;
331 struct ctcm_priv *priv;
333 dev = ctcmpc_get_dev(port_num);
334 if (dev == NULL)
335 return 1;
336 priv = dev->ml_priv;
337 grp = priv->mpcg;
339 grp->allochanfunc = callback;
340 grp->port_num = port_num;
341 grp->port_persist = 1;
343 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
344 "%s(%s): state=%s",
345 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
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 /* Else, fall through */
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;
386 break;
389 return 0;
391 EXPORT_SYMBOL(ctc_mpc_alloc_channel);
394 * ctc_mpc_establish_connectivity
395 * (exported interface)
397 void ctc_mpc_establish_connectivity(int port_num,
398 void (*callback)(int, int, int))
400 struct net_device *dev;
401 struct mpc_group *grp;
402 struct ctcm_priv *priv;
403 struct channel *rch, *wch;
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];
413 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
414 "%s(%s): state=%s",
415 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
417 grp->estconnfunc = callback;
418 grp->port_num = port_num;
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;
433 } else {
434 /* there are problems...bail out */
435 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
436 grp->estconn_callback_retries = 0;
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*/
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;
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 */
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;
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;
483 fsm_deltimer(&grp->timer);
484 goto done;
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;
497 fsm_deltimer(&grp->timer);
498 goto done;
500 break;
501 case MPCG_STATE_XID0IOWAIT:
502 /* already in active XID negotiations */
503 default:
504 break;
507 done:
508 CTCM_PR_DEBUG("Exit %s()\n", __func__);
509 return;
511 EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
514 * ctc_mpc_dealloc_ch
515 * (exported interface)
517 void ctc_mpc_dealloc_ch(int port_num)
519 struct net_device *dev;
520 struct ctcm_priv *priv;
521 struct mpc_group *grp;
523 dev = ctcmpc_get_dev(port_num);
524 if (dev == NULL)
525 return;
526 priv = dev->ml_priv;
527 grp = priv->mpcg;
529 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_DEBUG,
530 "%s: %s: refcount = %d\n",
531 CTCM_FUNTAIL, dev->name, netdev_refcnt_read(dev));
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);
542 ctcm_close(dev);
543 return;
545 EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
548 * ctc_mpc_flow_control
549 * (exported interface)
551 void ctc_mpc_flow_control(int port_num, int flowc)
553 struct ctcm_priv *priv;
554 struct mpc_group *grp;
555 struct net_device *dev;
556 struct channel *rch;
557 int mpcg_state;
559 dev = ctcmpc_get_dev(port_num);
560 if (dev == NULL)
561 return;
562 priv = dev->ml_priv;
563 grp = priv->mpcg;
565 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
566 "%s: %s: flowc = %d",
567 CTCM_FUNTAIL, dev->name, flowc);
569 rch = priv->channel[CTCM_READ];
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;
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);
591 /* possible race condition */
592 if (mpcg_state == MPCG_STATE_READY) {
593 grp->flow_off_called = 1;
594 break;
596 break;
600 EXPORT_SYMBOL(ctc_mpc_flow_control);
602 static int mpc_send_qllc_discontact(struct net_device *);
605 * helper function of ctcmpc_unpack_skb
607 static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
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];
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);
618 grp->sweep_rsp_pend_num--;
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);
629 kfree(mpcginfo);
631 return;
636 * helper function of mpc_rcvd_sweep_req
637 * which is a helper of ctcmpc_unpack_skb
639 static void ctcmpc_send_sweep_resp(struct channel *rch)
641 struct net_device *dev = rch->netdev;
642 struct ctcm_priv *priv = dev->ml_priv;
643 struct mpc_group *grp = priv->mpcg;
644 struct th_sweep *header;
645 struct sk_buff *sweep_skb;
646 struct channel *ch = priv->channel[CTCM_WRITE];
648 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
650 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
651 if (sweep_skb == NULL) {
652 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
653 "%s(%s): sweep_skb allocation ERROR\n",
654 CTCM_FUNTAIL, rch->id);
655 goto done;
658 header = kmalloc(sizeof(struct th_sweep), gfp_type());
660 if (!header) {
661 dev_kfree_skb_any(sweep_skb);
662 goto done;
665 header->th.th_seg = 0x00 ;
666 header->th.th_ch_flag = TH_SWEEP_RESP;
667 header->th.th_blk_flag = 0x00;
668 header->th.th_is_xid = 0x00;
669 header->th.th_seq_num = 0x00;
670 header->sw.th_last_seq = ch->th_seq_num;
672 skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
674 kfree(header);
676 netif_trans_update(dev);
677 skb_queue_tail(&ch->sweep_queue, sweep_skb);
679 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
681 return;
683 done:
684 grp->in_sweep = 0;
685 ctcm_clear_busy_do(dev);
686 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
688 return;
692 * helper function of ctcmpc_unpack_skb
694 static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
696 struct channel *rch = mpcginfo->ch;
697 struct net_device *dev = rch->netdev;
698 struct ctcm_priv *priv = dev->ml_priv;
699 struct mpc_group *grp = priv->mpcg;
700 struct channel *ch = priv->channel[CTCM_WRITE];
702 if (do_debug)
703 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
704 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
706 if (grp->in_sweep == 0) {
707 grp->in_sweep = 1;
708 ctcm_test_and_set_busy(dev);
709 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
710 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
713 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
715 grp->sweep_req_pend_num--;
716 ctcmpc_send_sweep_resp(ch);
717 kfree(mpcginfo);
718 return;
722 * MPC Group Station FSM definitions
724 static const char *mpcg_event_names[] = {
725 [MPCG_EVENT_INOP] = "INOP Condition",
726 [MPCG_EVENT_DISCONC] = "Discontact Received",
727 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
728 [MPCG_EVENT_XID2] = "XID2 Received",
729 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
730 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
731 [MPCG_EVENT_TIMER] = "XID Setup Timer",
732 [MPCG_EVENT_DOIO] = "XID DoIO",
735 static const char *mpcg_state_names[] = {
736 [MPCG_STATE_RESET] = "Reset",
737 [MPCG_STATE_INOP] = "INOP",
738 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
739 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
740 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
741 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
742 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
743 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
744 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
745 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
746 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
747 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
748 [MPCG_STATE_READY] = "READY",
752 * The MPC Group Station FSM
753 * 22 events
755 static const fsm_node mpcg_fsm[] = {
756 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
757 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
758 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
760 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
761 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
763 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
764 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
765 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
766 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
767 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
769 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
770 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
771 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
772 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
773 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
775 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
776 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
777 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
778 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
779 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
780 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
781 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
783 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
784 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
785 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
786 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
787 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
788 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
790 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
791 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
792 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
793 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
794 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
795 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
797 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
798 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
799 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
800 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
801 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
802 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
804 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
805 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
806 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
807 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
808 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
809 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
810 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
812 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
813 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
814 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
815 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
816 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
817 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
819 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
820 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
823 static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
826 * MPC Group Station FSM action
827 * CTCM_PROTO_MPC only
829 static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
831 struct net_device *dev = arg;
832 struct ctcm_priv *priv = dev->ml_priv;
833 struct mpc_group *grp = priv->mpcg;
835 if (grp == NULL) {
836 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
837 "%s(%s): No MPC group",
838 CTCM_FUNTAIL, dev->name);
839 return;
842 fsm_deltimer(&grp->timer);
844 if (grp->saved_xid2->xid2_flag2 == 0x40) {
845 priv->xid->xid2_flag2 = 0x00;
846 if (grp->estconnfunc) {
847 grp->estconnfunc(grp->port_num, 1,
848 grp->group_max_buflen);
849 grp->estconnfunc = NULL;
850 } else if (grp->allochanfunc)
851 grp->send_qllc_disc = 1;
853 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
854 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
855 "%s(%s): fails",
856 CTCM_FUNTAIL, dev->name);
857 return;
860 grp->port_persist = 1;
861 grp->out_of_sequence = 0;
862 grp->estconn_called = 0;
864 tasklet_hi_schedule(&grp->mpc_tasklet2);
866 return;
870 * helper of ctcm_init_netdevice
871 * CTCM_PROTO_MPC only
873 void mpc_group_ready(unsigned long adev)
875 struct net_device *dev = (struct net_device *)adev;
876 struct ctcm_priv *priv = dev->ml_priv;
877 struct mpc_group *grp = priv->mpcg;
878 struct channel *ch = NULL;
880 if (grp == NULL) {
881 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
882 "%s(%s): No MPC group",
883 CTCM_FUNTAIL, dev->name);
884 return;
887 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
888 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
889 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
891 fsm_newstate(grp->fsm, MPCG_STATE_READY);
893 /* Put up a read on the channel */
894 ch = priv->channel[CTCM_READ];
895 ch->pdu_seq = 0;
896 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
897 __func__, ch->pdu_seq);
899 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
900 /* Put the write channel in idle state */
901 ch = priv->channel[CTCM_WRITE];
902 if (ch->collect_len > 0) {
903 spin_lock(&ch->collect_lock);
904 ctcm_purge_skb_queue(&ch->collect_queue);
905 ch->collect_len = 0;
906 spin_unlock(&ch->collect_lock);
908 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
909 ctcm_clear_busy(dev);
911 if (grp->estconnfunc) {
912 grp->estconnfunc(grp->port_num, 0,
913 grp->group_max_buflen);
914 grp->estconnfunc = NULL;
915 } else if (grp->allochanfunc)
916 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
918 grp->send_qllc_disc = 1;
919 grp->changed_side = 0;
921 return;
926 * Increment the MPC Group Active Channel Counts
927 * helper of dev_action (called from channel fsm)
929 void mpc_channel_action(struct channel *ch, int direction, int action)
931 struct net_device *dev = ch->netdev;
932 struct ctcm_priv *priv = dev->ml_priv;
933 struct mpc_group *grp = priv->mpcg;
935 if (grp == NULL) {
936 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
937 "%s(%s): No MPC group",
938 CTCM_FUNTAIL, dev->name);
939 return;
942 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
944 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
945 "%s: %i / Grp:%s total_channels=%i, active_channels: "
946 "read=%i, write=%i\n", __func__, action,
947 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
948 grp->active_channels[CTCM_READ],
949 grp->active_channels[CTCM_WRITE]);
951 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
952 grp->num_channel_paths++;
953 grp->active_channels[direction]++;
954 grp->outstanding_xid2++;
955 ch->in_mpcgroup = 1;
957 if (ch->xid_skb != NULL)
958 dev_kfree_skb_any(ch->xid_skb);
960 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
961 GFP_ATOMIC | GFP_DMA);
962 if (ch->xid_skb == NULL) {
963 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
964 "%s(%s): Couldn't alloc ch xid_skb\n",
965 CTCM_FUNTAIL, dev->name);
966 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
967 return;
969 ch->xid_skb_data = ch->xid_skb->data;
970 ch->xid_th = (struct th_header *)ch->xid_skb->data;
971 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
972 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
973 skb_put(ch->xid_skb, XID2_LENGTH);
974 ch->xid_id = skb_tail_pointer(ch->xid_skb);
975 ch->xid_skb->data = ch->xid_skb_data;
976 skb_reset_tail_pointer(ch->xid_skb);
977 ch->xid_skb->len = 0;
979 skb_put_data(ch->xid_skb, grp->xid_skb->data,
980 grp->xid_skb->len);
982 ch->xid->xid2_dlc_type =
983 ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
984 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
986 if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
987 ch->xid->xid2_buf_len = 0x00;
989 ch->xid_skb->data = ch->xid_skb_data;
990 skb_reset_tail_pointer(ch->xid_skb);
991 ch->xid_skb->len = 0;
993 fsm_newstate(ch->fsm, CH_XID0_PENDING);
995 if ((grp->active_channels[CTCM_READ] > 0) &&
996 (grp->active_channels[CTCM_WRITE] > 0) &&
997 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
998 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
999 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
1000 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1001 __func__, dev->name);
1003 } else if ((action == MPC_CHANNEL_REMOVE) &&
1004 (ch->in_mpcgroup == 1)) {
1005 ch->in_mpcgroup = 0;
1006 grp->num_channel_paths--;
1007 grp->active_channels[direction]--;
1009 if (ch->xid_skb != NULL)
1010 dev_kfree_skb_any(ch->xid_skb);
1011 ch->xid_skb = NULL;
1013 if (grp->channels_terminating)
1014 goto done;
1016 if (((grp->active_channels[CTCM_READ] == 0) &&
1017 (grp->active_channels[CTCM_WRITE] > 0))
1018 || ((grp->active_channels[CTCM_WRITE] == 0) &&
1019 (grp->active_channels[CTCM_READ] > 0)))
1020 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1022 done:
1023 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1024 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1025 "read=%i, write=%i\n", __func__, action,
1026 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1027 grp->active_channels[CTCM_READ],
1028 grp->active_channels[CTCM_WRITE]);
1030 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1034 * Unpack a just received skb and hand it over to
1035 * upper layers.
1036 * special MPC version of unpack_skb.
1038 * ch The channel where this skb has been received.
1039 * pskb The received skb.
1041 static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1043 struct net_device *dev = ch->netdev;
1044 struct ctcm_priv *priv = dev->ml_priv;
1045 struct mpc_group *grp = priv->mpcg;
1046 struct pdu *curr_pdu;
1047 struct mpcg_info *mpcginfo;
1048 struct th_header *header = NULL;
1049 struct th_sweep *sweep = NULL;
1050 int pdu_last_seen = 0;
1051 __u32 new_len;
1052 struct sk_buff *skb;
1053 int skblen;
1054 int sendrc = 0;
1056 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1057 __func__, dev->name, smp_processor_id(), ch->id);
1059 header = (struct th_header *)pskb->data;
1060 if ((header->th_seg == 0) &&
1061 (header->th_ch_flag == 0) &&
1062 (header->th_blk_flag == 0) &&
1063 (header->th_seq_num == 0))
1064 /* nothing for us */ goto done;
1066 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1067 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1068 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
1070 pskb->dev = dev;
1071 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1072 skb_pull(pskb, TH_HEADER_LENGTH);
1074 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
1075 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
1076 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1077 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1078 (header->th_seq_num != ch->th_seq_num + 1) &&
1079 (ch->th_seq_num != 0))) {
1080 /* This is NOT the next segment *
1081 * we are not the correct race winner *
1082 * go away and let someone else win *
1083 * BUT..this only applies if xid negot *
1084 * is done *
1086 grp->out_of_sequence += 1;
1087 __skb_push(pskb, TH_HEADER_LENGTH);
1088 skb_queue_tail(&ch->io_queue, pskb);
1089 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1090 "got:%08x\n", __func__,
1091 ch->th_seq_num + 1, header->th_seq_num);
1093 return;
1095 grp->out_of_sequence = 0;
1096 ch->th_seq_num = header->th_seq_num;
1098 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1099 __func__, ch->th_seq_num);
1101 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1102 goto done;
1103 while ((pskb->len > 0) && !pdu_last_seen) {
1104 curr_pdu = (struct pdu *)pskb->data;
1106 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1107 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1108 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1109 __func__, pskb->len);
1111 skb_pull(pskb, PDU_HEADER_LENGTH);
1113 if (curr_pdu->pdu_flag & PDU_LAST)
1114 pdu_last_seen = 1;
1115 if (curr_pdu->pdu_flag & PDU_CNTL)
1116 pskb->protocol = htons(ETH_P_SNAP);
1117 else
1118 pskb->protocol = htons(ETH_P_SNA_DIX);
1120 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
1121 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1122 "%s(%s): Dropping packet with "
1123 "illegal siize %d",
1124 CTCM_FUNTAIL, dev->name, pskb->len);
1126 priv->stats.rx_dropped++;
1127 priv->stats.rx_length_errors++;
1128 goto done;
1130 skb_reset_mac_header(pskb);
1131 new_len = curr_pdu->pdu_offset;
1132 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1133 __func__, new_len);
1134 if ((new_len == 0) || (new_len > pskb->len)) {
1135 /* should never happen */
1136 /* pskb len must be hosed...bail out */
1137 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1138 "%s(%s): non valid pdu_offset: %04x",
1139 /* "data may be lost", */
1140 CTCM_FUNTAIL, dev->name, new_len);
1141 goto done;
1143 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1145 if (!skb) {
1146 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1147 "%s(%s): MEMORY allocation error",
1148 CTCM_FUNTAIL, dev->name);
1149 priv->stats.rx_dropped++;
1150 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1151 goto done;
1153 skb_put_data(skb, pskb->data, new_len);
1155 skb_reset_mac_header(skb);
1156 skb->dev = pskb->dev;
1157 skb->protocol = pskb->protocol;
1158 skb->ip_summed = CHECKSUM_UNNECESSARY;
1159 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1160 ch->pdu_seq++;
1162 if (do_debug_data) {
1163 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1164 __func__, ch->pdu_seq);
1165 ctcm_pr_debug("%s: skb:%0lx "
1166 "skb len: %d \n", __func__,
1167 (unsigned long)skb, skb->len);
1168 ctcm_pr_debug("%s: up to 32 bytes "
1169 "of pdu_data sent\n", __func__);
1170 ctcmpc_dump32((char *)skb->data, skb->len);
1173 skblen = skb->len;
1174 sendrc = netif_rx(skb);
1175 priv->stats.rx_packets++;
1176 priv->stats.rx_bytes += skblen;
1177 skb_pull(pskb, new_len); /* point to next PDU */
1179 } else {
1180 mpcginfo = kmalloc(sizeof(struct mpcg_info), gfp_type());
1181 if (mpcginfo == NULL)
1182 goto done;
1184 mpcginfo->ch = ch;
1185 mpcginfo->th = header;
1186 mpcginfo->skb = pskb;
1187 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1188 __func__);
1189 /* it's a sweep? */
1190 sweep = (struct th_sweep *)pskb->data;
1191 mpcginfo->sweep = sweep;
1192 if (header->th_ch_flag == TH_SWEEP_REQ)
1193 mpc_rcvd_sweep_req(mpcginfo);
1194 else if (header->th_ch_flag == TH_SWEEP_RESP)
1195 mpc_rcvd_sweep_resp(mpcginfo);
1196 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1197 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1198 skb_pull(pskb, XID2_LENGTH);
1199 mpcginfo->xid = thisxid;
1200 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1201 } else if (header->th_blk_flag == TH_DISCONTACT)
1202 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1203 else if (header->th_seq_num != 0) {
1204 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1205 "%s(%s): control pkt expected\n",
1206 CTCM_FUNTAIL, dev->name);
1207 priv->stats.rx_dropped++;
1208 /* mpcginfo only used for non-data transfers */
1209 kfree(mpcginfo);
1210 if (do_debug_data)
1211 ctcmpc_dump_skb(pskb, -8);
1214 done:
1216 dev_kfree_skb_any(pskb);
1217 if (sendrc == NET_RX_DROP) {
1218 dev_warn(&dev->dev,
1219 "The network backlog for %s is exceeded, "
1220 "package dropped\n", __func__);
1221 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1224 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1225 __func__, dev->name, ch, ch->id);
1229 * tasklet helper for mpc's skb unpacking.
1231 * ch The channel to work on.
1232 * Allow flow control back pressure to occur here.
1233 * Throttling back channel can result in excessive
1234 * channel inactivity and system deact of channel
1236 void ctcmpc_bh(unsigned long thischan)
1238 struct channel *ch = (struct channel *)thischan;
1239 struct sk_buff *skb;
1240 struct net_device *dev = ch->netdev;
1241 struct ctcm_priv *priv = dev->ml_priv;
1242 struct mpc_group *grp = priv->mpcg;
1244 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1245 dev->name, smp_processor_id(), __func__, ch->id);
1246 /* caller has requested driver to throttle back */
1247 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1248 (skb = skb_dequeue(&ch->io_queue))) {
1249 ctcmpc_unpack_skb(ch, skb);
1250 if (grp->out_of_sequence > 20) {
1251 /* assume data loss has occurred if */
1252 /* missing seq_num for extended */
1253 /* period of time */
1254 grp->out_of_sequence = 0;
1255 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1256 break;
1258 if (skb == skb_peek(&ch->io_queue))
1259 break;
1261 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1262 __func__, dev->name, ch, ch->id);
1263 return;
1267 * MPC Group Initializations
1269 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1271 struct mpc_group *grp;
1273 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1274 "Enter %s(%p)", CTCM_FUNTAIL, priv);
1276 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1277 if (grp == NULL)
1278 return NULL;
1280 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1281 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1282 mpcg_fsm_len, GFP_KERNEL);
1283 if (grp->fsm == NULL) {
1284 kfree(grp);
1285 return NULL;
1288 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1289 fsm_settimer(grp->fsm, &grp->timer);
1291 grp->xid_skb =
1292 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1293 if (grp->xid_skb == NULL) {
1294 kfree_fsm(grp->fsm);
1295 kfree(grp);
1296 return NULL;
1298 /* base xid for all channels in group */
1299 grp->xid_skb_data = grp->xid_skb->data;
1300 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1301 skb_put_data(grp->xid_skb, &thnorm, TH_HEADER_LENGTH);
1303 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
1304 skb_put_data(grp->xid_skb, &init_xid, XID2_LENGTH);
1305 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1306 grp->xid->xid2_sender_id = jiffies;
1308 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1309 skb_put_data(grp->xid_skb, "VTAM", 4);
1311 grp->rcvd_xid_skb =
1312 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1313 if (grp->rcvd_xid_skb == NULL) {
1314 kfree_fsm(grp->fsm);
1315 dev_kfree_skb(grp->xid_skb);
1316 kfree(grp);
1317 return NULL;
1319 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1320 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1321 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1322 grp->saved_xid2 = NULL;
1323 priv->xid = grp->xid;
1324 priv->mpcg = grp;
1325 return grp;
1329 * The MPC Group Station FSM
1333 * MPC Group Station FSM actions
1334 * CTCM_PROTO_MPC only
1338 * NOP action for statemachines
1340 static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1345 * invoked when the device transitions to dev_stopped
1346 * MPC will stop each individual channel if a single XID failure
1347 * occurs, or will intitiate all channels be stopped if a GROUP
1348 * level failure occurs.
1350 static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1352 struct net_device *dev = arg;
1353 struct ctcm_priv *priv;
1354 struct mpc_group *grp;
1355 struct channel *wch;
1357 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
1359 priv = dev->ml_priv;
1360 grp = priv->mpcg;
1361 grp->flow_off_called = 0;
1362 fsm_deltimer(&grp->timer);
1363 if (grp->channels_terminating)
1364 return;
1366 grp->channels_terminating = 1;
1367 grp->saved_state = fsm_getstate(grp->fsm);
1368 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1369 if (grp->saved_state > MPCG_STATE_XID7INITF)
1370 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1371 "%s(%s): MPC GROUP INOPERATIVE",
1372 CTCM_FUNTAIL, dev->name);
1373 if ((grp->saved_state != MPCG_STATE_RESET) ||
1374 /* dealloc_channel has been called */
1375 (grp->port_persist == 0))
1376 fsm_deltimer(&priv->restart_timer);
1378 wch = priv->channel[CTCM_WRITE];
1380 switch (grp->saved_state) {
1381 case MPCG_STATE_RESET:
1382 case MPCG_STATE_INOP:
1383 case MPCG_STATE_XID2INITW:
1384 case MPCG_STATE_XID0IOWAIT:
1385 case MPCG_STATE_XID2INITX:
1386 case MPCG_STATE_XID7INITW:
1387 case MPCG_STATE_XID7INITX:
1388 case MPCG_STATE_XID0IOWAIX:
1389 case MPCG_STATE_XID7INITI:
1390 case MPCG_STATE_XID7INITZ:
1391 case MPCG_STATE_XID7INITF:
1392 break;
1393 case MPCG_STATE_FLOWC:
1394 case MPCG_STATE_READY:
1395 default:
1396 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1399 grp->xid2_tgnum = 0;
1400 grp->group_max_buflen = 0; /*min of all received */
1401 grp->outstanding_xid2 = 0;
1402 grp->outstanding_xid7 = 0;
1403 grp->outstanding_xid7_p2 = 0;
1404 grp->saved_xid2 = NULL;
1405 grp->xidnogood = 0;
1406 grp->changed_side = 0;
1408 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1409 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1410 grp->rcvd_xid_skb->len = 0;
1411 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1412 skb_put_data(grp->rcvd_xid_skb, &thnorm, TH_HEADER_LENGTH);
1414 if (grp->send_qllc_disc == 1) {
1415 grp->send_qllc_disc = 0;
1416 mpc_send_qllc_discontact(dev);
1419 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1420 /* This can result in INOP of VTAM PU due to halting of */
1421 /* outstanding IO which causes a sense to be returned */
1422 /* Only about 3 senses are allowed and then IOS/VTAM will*/
1423 /* become unreachable without manual intervention */
1424 if ((grp->port_persist == 1) || (grp->alloc_called)) {
1425 grp->alloc_called = 0;
1426 fsm_deltimer(&priv->restart_timer);
1427 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
1428 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1429 if (grp->saved_state > MPCG_STATE_XID7INITF)
1430 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1431 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1432 CTCM_FUNTAIL, dev->name);
1433 } else {
1434 fsm_deltimer(&priv->restart_timer);
1435 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1436 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1437 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1438 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1439 CTCM_FUNTAIL, dev->name);
1444 * Handle mpc group action timeout.
1445 * MPC Group Station FSM action
1446 * CTCM_PROTO_MPC only
1448 * fi An instance of an mpc_group fsm.
1449 * event The event, just happened.
1450 * arg Generic pointer, casted from net_device * upon call.
1452 static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1454 struct net_device *dev = arg;
1455 struct ctcm_priv *priv;
1456 struct mpc_group *grp;
1457 struct channel *wch;
1458 struct channel *rch;
1460 priv = dev->ml_priv;
1461 grp = priv->mpcg;
1462 wch = priv->channel[CTCM_WRITE];
1463 rch = priv->channel[CTCM_READ];
1465 switch (fsm_getstate(grp->fsm)) {
1466 case MPCG_STATE_XID2INITW:
1467 /* Unless there is outstanding IO on the */
1468 /* channel just return and wait for ATTN */
1469 /* interrupt to begin XID negotiations */
1470 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1471 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1472 break;
1473 /* Else, fall through */
1474 default:
1475 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1478 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1479 "%s: dev=%s exit",
1480 CTCM_FUNTAIL, dev->name);
1481 return;
1485 * MPC Group Station FSM action
1486 * CTCM_PROTO_MPC only
1488 void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1490 struct mpcg_info *mpcginfo = arg;
1491 struct channel *ch = mpcginfo->ch;
1492 struct net_device *dev;
1493 struct ctcm_priv *priv;
1494 struct mpc_group *grp;
1496 if (ch) {
1497 dev = ch->netdev;
1498 if (dev) {
1499 priv = dev->ml_priv;
1500 if (priv) {
1501 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1502 "%s: %s: %s\n",
1503 CTCM_FUNTAIL, dev->name, ch->id);
1504 grp = priv->mpcg;
1505 grp->send_qllc_disc = 1;
1506 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1511 return;
1515 * MPC Group Station - not part of FSM
1516 * CTCM_PROTO_MPC only
1517 * called from add_channel in ctcm_main.c
1519 void mpc_action_send_discontact(unsigned long thischan)
1521 int rc;
1522 struct channel *ch = (struct channel *)thischan;
1523 unsigned long saveflags = 0;
1525 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1526 rc = ccw_device_start(ch->cdev, &ch->ccw[15], 0, 0xff, 0);
1527 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1529 if (rc != 0) {
1530 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
1533 return;
1538 * helper function of mpc FSM
1539 * CTCM_PROTO_MPC only
1540 * mpc_action_rcvd_xid7
1542 static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1544 struct channel *ch = mpcginfo->ch;
1545 struct net_device *dev = ch->netdev;
1546 struct ctcm_priv *priv = dev->ml_priv;
1547 struct mpc_group *grp = priv->mpcg;
1548 struct xid2 *xid = mpcginfo->xid;
1549 int rc = 0;
1550 __u64 our_id = 0;
1551 __u64 their_id = 0;
1552 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1554 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
1556 if (xid == NULL) {
1557 rc = 1;
1558 /* XID REJECTED: xid == NULL */
1559 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1560 "%s(%s): xid = NULL",
1561 CTCM_FUNTAIL, ch->id);
1562 goto done;
1565 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1567 /*the received direction should be the opposite of ours */
1568 if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1569 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1570 rc = 2;
1571 /* XID REJECTED: r/w channel pairing mismatch */
1572 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1573 "%s(%s): r/w channel pairing mismatch",
1574 CTCM_FUNTAIL, ch->id);
1575 goto done;
1578 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
1579 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1580 grp->group_max_buflen, xid->xid2_buf_len);
1582 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1583 xid->xid2_buf_len - len)
1584 grp->group_max_buflen = xid->xid2_buf_len - len;
1587 if (grp->saved_xid2 == NULL) {
1588 grp->saved_xid2 =
1589 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1591 skb_put_data(grp->rcvd_xid_skb, xid, XID2_LENGTH);
1592 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1594 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1595 grp->rcvd_xid_skb->len = 0;
1597 /* convert two 32 bit numbers into 1 64 bit for id compare */
1598 our_id = (__u64)priv->xid->xid2_adj_id;
1599 our_id = our_id << 32;
1600 our_id = our_id + priv->xid->xid2_sender_id;
1601 their_id = (__u64)xid->xid2_adj_id;
1602 their_id = their_id << 32;
1603 their_id = their_id + xid->xid2_sender_id;
1604 /* lower id assume the xside role */
1605 if (our_id < their_id) {
1606 grp->roll = XSIDE;
1607 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1608 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1609 CTCM_FUNTAIL, ch->id);
1610 } else {
1611 grp->roll = YSIDE;
1612 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1613 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1614 CTCM_FUNTAIL, ch->id);
1617 } else {
1618 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
1619 rc = 3;
1620 /* XID REJECTED: xid flag byte4 mismatch */
1621 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1622 "%s(%s): xid flag byte4 mismatch",
1623 CTCM_FUNTAIL, ch->id);
1625 if (xid->xid2_flag2 == 0x40) {
1626 rc = 4;
1627 /* XID REJECTED - xid NOGOOD */
1628 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1629 "%s(%s): xid NOGOOD",
1630 CTCM_FUNTAIL, ch->id);
1632 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
1633 rc = 5;
1634 /* XID REJECTED - Adjacent Station ID Mismatch */
1635 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1636 "%s(%s): Adjacent Station ID Mismatch",
1637 CTCM_FUNTAIL, ch->id);
1639 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
1640 rc = 6;
1641 /* XID REJECTED - Sender Address Mismatch */
1642 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1643 "%s(%s): Sender Address Mismatch",
1644 CTCM_FUNTAIL, ch->id);
1647 done:
1648 if (rc) {
1649 dev_warn(&dev->dev,
1650 "The XID used in the MPC protocol is not valid, "
1651 "rc = %d\n", rc);
1652 priv->xid->xid2_flag2 = 0x40;
1653 grp->saved_xid2->xid2_flag2 = 0x40;
1656 return rc;
1660 * MPC Group Station FSM action
1661 * CTCM_PROTO_MPC only
1663 static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1665 struct channel *ch = arg;
1666 int rc = 0;
1667 int gotlock = 0;
1668 unsigned long saveflags = 0; /* avoids compiler warning with
1669 spin_unlock_irqrestore */
1671 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1672 __func__, smp_processor_id(), ch, ch->id);
1674 if (ctcm_checkalloc_buffer(ch))
1675 goto done;
1678 * skb data-buffer referencing:
1680 ch->trans_skb->data = ch->trans_skb_data;
1681 skb_reset_tail_pointer(ch->trans_skb);
1682 ch->trans_skb->len = 0;
1683 /* result of the previous 3 statements is NOT always
1684 * already set after ctcm_checkalloc_buffer
1685 * because of possible reuse of the trans_skb
1687 memset(ch->trans_skb->data, 0, 16);
1688 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1689 /* check is main purpose here: */
1690 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1691 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1692 /* check is main purpose here: */
1693 skb_put(ch->trans_skb, XID2_LENGTH);
1694 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1695 /* cleanup back to startpoint */
1696 ch->trans_skb->data = ch->trans_skb_data;
1697 skb_reset_tail_pointer(ch->trans_skb);
1698 ch->trans_skb->len = 0;
1700 /* non-checking rewrite of above skb data-buffer referencing: */
1702 memset(ch->trans_skb->data, 0, 16);
1703 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1704 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1705 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1708 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1709 ch->ccw[8].count = 0;
1710 ch->ccw[8].cda = 0x00;
1712 if (!(ch->xid_th && ch->xid && ch->xid_id))
1713 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1714 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1715 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1717 if (side == XSIDE) {
1718 /* mpc_action_xside_xid */
1719 if (ch->xid_th == NULL)
1720 goto done;
1721 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1722 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1723 ch->ccw[9].count = TH_HEADER_LENGTH;
1724 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1726 if (ch->xid == NULL)
1727 goto done;
1728 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1729 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1730 ch->ccw[10].count = XID2_LENGTH;
1731 ch->ccw[10].cda = virt_to_phys(ch->xid);
1733 ch->ccw[11].cmd_code = CCW_CMD_READ;
1734 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1735 ch->ccw[11].count = TH_HEADER_LENGTH;
1736 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1738 ch->ccw[12].cmd_code = CCW_CMD_READ;
1739 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1740 ch->ccw[12].count = XID2_LENGTH;
1741 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1743 ch->ccw[13].cmd_code = CCW_CMD_READ;
1744 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1746 } else { /* side == YSIDE : mpc_action_yside_xid */
1747 ch->ccw[9].cmd_code = CCW_CMD_READ;
1748 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1749 ch->ccw[9].count = TH_HEADER_LENGTH;
1750 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1752 ch->ccw[10].cmd_code = CCW_CMD_READ;
1753 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1754 ch->ccw[10].count = XID2_LENGTH;
1755 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1757 if (ch->xid_th == NULL)
1758 goto done;
1759 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1760 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1761 ch->ccw[11].count = TH_HEADER_LENGTH;
1762 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1764 if (ch->xid == NULL)
1765 goto done;
1766 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1767 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1768 ch->ccw[12].count = XID2_LENGTH;
1769 ch->ccw[12].cda = virt_to_phys(ch->xid);
1771 if (ch->xid_id == NULL)
1772 goto done;
1773 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1774 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1777 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1778 ch->ccw[13].count = 4;
1780 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1781 ch->ccw[14].flags = CCW_FLAG_SLI;
1782 ch->ccw[14].count = 0;
1783 ch->ccw[14].cda = 0;
1785 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1786 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1787 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1788 CTCM_D3_DUMP((char *)ch->xid_id, 4);
1790 if (!in_irq()) {
1791 /* Such conditional locking is a known problem for
1792 * sparse because its static undeterministic.
1793 * Warnings should be ignored here. */
1794 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1795 gotlock = 1;
1798 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1799 rc = ccw_device_start(ch->cdev, &ch->ccw[8], 0, 0xff, 0);
1801 if (gotlock) /* see remark above about conditional locking */
1802 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1804 if (rc != 0) {
1805 ctcm_ccw_check_rc(ch, rc,
1806 (side == XSIDE) ? "x-side XID" : "y-side XID");
1809 done:
1810 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1811 __func__, ch, ch->id);
1812 return;
1817 * MPC Group Station FSM action
1818 * CTCM_PROTO_MPC only
1820 static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1822 mpc_action_side_xid(fsm, arg, XSIDE);
1826 * MPC Group Station FSM action
1827 * CTCM_PROTO_MPC only
1829 static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1831 mpc_action_side_xid(fsm, arg, YSIDE);
1835 * MPC Group Station FSM action
1836 * CTCM_PROTO_MPC only
1838 static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1840 struct channel *ch = arg;
1841 struct net_device *dev = ch->netdev;
1842 struct ctcm_priv *priv = dev->ml_priv;
1843 struct mpc_group *grp = priv->mpcg;
1845 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1846 __func__, smp_processor_id(), ch, ch->id);
1848 if (ch->xid == NULL) {
1849 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1850 "%s(%s): ch->xid == NULL",
1851 CTCM_FUNTAIL, dev->name);
1852 return;
1855 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1857 ch->xid->xid2_option = XID2_0;
1859 switch (fsm_getstate(grp->fsm)) {
1860 case MPCG_STATE_XID2INITW:
1861 case MPCG_STATE_XID2INITX:
1862 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1863 break;
1864 case MPCG_STATE_XID0IOWAIT:
1865 case MPCG_STATE_XID0IOWAIX:
1866 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1867 break;
1870 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1872 return;
1876 * MPC Group Station FSM action
1877 * CTCM_PROTO_MPC only
1879 static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1881 struct net_device *dev = arg;
1882 struct ctcm_priv *priv = dev->ml_priv;
1883 struct mpc_group *grp = NULL;
1884 int direction;
1885 int send = 0;
1887 if (priv)
1888 grp = priv->mpcg;
1889 if (grp == NULL)
1890 return;
1892 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1893 struct channel *ch = priv->channel[direction];
1894 struct xid2 *thisxid = ch->xid;
1895 ch->xid_skb->data = ch->xid_skb_data;
1896 skb_reset_tail_pointer(ch->xid_skb);
1897 ch->xid_skb->len = 0;
1898 thisxid->xid2_option = XID2_7;
1899 send = 0;
1901 /* xid7 phase 1 */
1902 if (grp->outstanding_xid7_p2 > 0) {
1903 if (grp->roll == YSIDE) {
1904 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1905 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1906 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1907 skb_put_data(ch->xid_skb, &thdummy,
1908 TH_HEADER_LENGTH);
1909 send = 1;
1911 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1912 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1913 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1914 skb_put_data(ch->xid_skb, &thnorm,
1915 TH_HEADER_LENGTH);
1916 send = 1;
1918 } else {
1919 /* xid7 phase 2 */
1920 if (grp->roll == YSIDE) {
1921 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1922 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1923 skb_put_data(ch->xid_skb, &thnorm,
1924 TH_HEADER_LENGTH);
1925 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1926 send = 1;
1928 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1929 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1930 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1931 skb_put_data(ch->xid_skb, &thdummy,
1932 TH_HEADER_LENGTH);
1933 send = 1;
1937 if (send)
1938 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1941 return;
1945 * MPC Group Station FSM action
1946 * CTCM_PROTO_MPC only
1948 static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1951 struct mpcg_info *mpcginfo = arg;
1952 struct channel *ch = mpcginfo->ch;
1953 struct net_device *dev = ch->netdev;
1954 struct ctcm_priv *priv = dev->ml_priv;
1955 struct mpc_group *grp = priv->mpcg;
1957 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1958 __func__, ch->id, grp->outstanding_xid2,
1959 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1961 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1962 fsm_newstate(ch->fsm, CH_XID7_PENDING);
1964 grp->outstanding_xid2--;
1965 grp->outstanding_xid7++;
1966 grp->outstanding_xid7_p2++;
1968 /* must change state before validating xid to */
1969 /* properly handle interim interrupts received*/
1970 switch (fsm_getstate(grp->fsm)) {
1971 case MPCG_STATE_XID2INITW:
1972 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
1973 mpc_validate_xid(mpcginfo);
1974 break;
1975 case MPCG_STATE_XID0IOWAIT:
1976 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
1977 mpc_validate_xid(mpcginfo);
1978 break;
1979 case MPCG_STATE_XID2INITX:
1980 if (grp->outstanding_xid2 == 0) {
1981 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
1982 mpc_validate_xid(mpcginfo);
1983 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1985 break;
1986 case MPCG_STATE_XID0IOWAIX:
1987 if (grp->outstanding_xid2 == 0) {
1988 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
1989 mpc_validate_xid(mpcginfo);
1990 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
1992 break;
1994 kfree(mpcginfo);
1996 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
1997 __func__, ch->id, grp->outstanding_xid2,
1998 grp->outstanding_xid7, grp->outstanding_xid7_p2);
1999 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2000 __func__, ch->id,
2001 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
2002 return;
2008 * MPC Group Station FSM action
2009 * CTCM_PROTO_MPC only
2011 static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
2013 struct mpcg_info *mpcginfo = arg;
2014 struct channel *ch = mpcginfo->ch;
2015 struct net_device *dev = ch->netdev;
2016 struct ctcm_priv *priv = dev->ml_priv;
2017 struct mpc_group *grp = priv->mpcg;
2019 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2020 __func__, smp_processor_id(), ch, ch->id);
2021 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2022 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
2024 grp->outstanding_xid7--;
2025 ch->xid_skb->data = ch->xid_skb_data;
2026 skb_reset_tail_pointer(ch->xid_skb);
2027 ch->xid_skb->len = 0;
2029 switch (fsm_getstate(grp->fsm)) {
2030 case MPCG_STATE_XID7INITI:
2031 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2032 mpc_validate_xid(mpcginfo);
2033 break;
2034 case MPCG_STATE_XID7INITW:
2035 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2036 mpc_validate_xid(mpcginfo);
2037 break;
2038 case MPCG_STATE_XID7INITZ:
2039 case MPCG_STATE_XID7INITX:
2040 if (grp->outstanding_xid7 == 0) {
2041 if (grp->outstanding_xid7_p2 > 0) {
2042 grp->outstanding_xid7 =
2043 grp->outstanding_xid7_p2;
2044 grp->outstanding_xid7_p2 = 0;
2045 } else
2046 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2048 mpc_validate_xid(mpcginfo);
2049 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2050 break;
2052 mpc_validate_xid(mpcginfo);
2053 break;
2055 kfree(mpcginfo);
2056 return;
2060 * mpc_action helper of an MPC Group Station FSM action
2061 * CTCM_PROTO_MPC only
2063 static int mpc_send_qllc_discontact(struct net_device *dev)
2065 __u32 new_len = 0;
2066 struct sk_buff *skb;
2067 struct qllc *qllcptr;
2068 struct ctcm_priv *priv = dev->ml_priv;
2069 struct mpc_group *grp = priv->mpcg;
2071 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2072 __func__, mpcg_state_names[grp->saved_state]);
2074 switch (grp->saved_state) {
2076 * establish conn callback function is
2077 * preferred method to report failure
2079 case MPCG_STATE_XID0IOWAIT:
2080 case MPCG_STATE_XID0IOWAIX:
2081 case MPCG_STATE_XID7INITI:
2082 case MPCG_STATE_XID7INITZ:
2083 case MPCG_STATE_XID2INITW:
2084 case MPCG_STATE_XID2INITX:
2085 case MPCG_STATE_XID7INITW:
2086 case MPCG_STATE_XID7INITX:
2087 if (grp->estconnfunc) {
2088 grp->estconnfunc(grp->port_num, -1, 0);
2089 grp->estconnfunc = NULL;
2090 break;
2092 /* Else, fall through */
2093 case MPCG_STATE_FLOWC:
2094 case MPCG_STATE_READY:
2095 grp->send_qllc_disc = 2;
2096 new_len = sizeof(struct qllc);
2097 qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
2098 if (qllcptr == NULL) {
2099 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2100 "%s(%s): qllcptr allocation error",
2101 CTCM_FUNTAIL, dev->name);
2102 return -ENOMEM;
2105 qllcptr->qllc_address = 0xcc;
2106 qllcptr->qllc_commands = 0x03;
2108 skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
2110 if (skb == NULL) {
2111 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2112 "%s(%s): skb allocation error",
2113 CTCM_FUNTAIL, dev->name);
2114 priv->stats.rx_dropped++;
2115 kfree(qllcptr);
2116 return -ENOMEM;
2119 skb_put_data(skb, qllcptr, new_len);
2120 kfree(qllcptr);
2122 if (skb_headroom(skb) < 4) {
2123 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2124 "%s(%s): skb_headroom error",
2125 CTCM_FUNTAIL, dev->name);
2126 dev_kfree_skb_any(skb);
2127 return -ENOMEM;
2130 *((__u32 *)skb_push(skb, 4)) =
2131 priv->channel[CTCM_READ]->pdu_seq;
2132 priv->channel[CTCM_READ]->pdu_seq++;
2133 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2134 __func__, priv->channel[CTCM_READ]->pdu_seq);
2136 /* receipt of CC03 resets anticipated sequence number on
2137 receiving side */
2138 priv->channel[CTCM_READ]->pdu_seq = 0x00;
2139 skb_reset_mac_header(skb);
2140 skb->dev = dev;
2141 skb->protocol = htons(ETH_P_SNAP);
2142 skb->ip_summed = CHECKSUM_UNNECESSARY;
2144 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
2146 netif_rx(skb);
2147 break;
2148 default:
2149 break;
2153 return 0;
2155 /* --- This is the END my friend --- */