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