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