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