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