blob: 5978b390153f82210a67650852643518c9fd0dae [file] [log] [blame]
Peter Tiedemann293d9842008-02-08 00:03:49 +01001/*
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
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +010022#define KMSG_COMPONENT "ctcm"
23#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24
Peter Tiedemann293d9842008-02-08 00:03:49 +010025#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/slab.h>
29#include <linux/errno.h>
30#include <linux/types.h>
31#include <linux/interrupt.h>
32#include <linux/timer.h>
33#include <linux/sched.h>
34
35#include <linux/signal.h>
36#include <linux/string.h>
37#include <linux/proc_fs.h>
38
39#include <linux/ip.h>
40#include <linux/if_arp.h>
41#include <linux/tcp.h>
42#include <linux/skbuff.h>
43#include <linux/ctype.h>
44#include <linux/netdevice.h>
45#include <net/dst.h>
46
47#include <linux/io.h> /* instead of <asm/io.h> ok ? */
48#include <asm/ccwdev.h>
49#include <asm/ccwgroup.h>
50#include <linux/bitops.h> /* instead of <asm/bitops.h> ok ? */
51#include <linux/uaccess.h> /* instead of <asm/uaccess.h> ok ? */
52#include <linux/wait.h>
53#include <linux/moduleparam.h>
54#include <asm/idals.h>
55
Peter Tiedemann293d9842008-02-08 00:03:49 +010056#include "ctcm_mpc.h"
57#include "ctcm_main.h"
58#include "ctcm_fsms.h"
59
60static const struct xid2 init_xid = {
61 .xid2_type_id = XID_FM2,
62 .xid2_len = 0x45,
63 .xid2_adj_id = 0,
64 .xid2_rlen = 0x31,
65 .xid2_resv1 = 0,
66 .xid2_flag1 = 0,
67 .xid2_fmtt = 0,
68 .xid2_flag4 = 0x80,
69 .xid2_resv2 = 0,
70 .xid2_tgnum = 0,
71 .xid2_sender_id = 0,
72 .xid2_flag2 = 0,
73 .xid2_option = XID2_0,
74 .xid2_resv3 = "\x00",
75 .xid2_resv4 = 0,
76 .xid2_dlc_type = XID2_READ_SIDE,
77 .xid2_resv5 = 0,
78 .xid2_mpc_flag = 0,
79 .xid2_resv6 = 0,
80 .xid2_buf_len = (MPC_BUFSIZE_DEFAULT - 35),
81};
82
83static const struct th_header thnorm = {
84 .th_seg = 0x00,
85 .th_ch_flag = TH_IS_XID,
86 .th_blk_flag = TH_DATA_IS_XID,
87 .th_is_xid = 0x01,
88 .th_seq_num = 0x00000000,
89};
90
91static const struct th_header thdummy = {
92 .th_seg = 0x00,
93 .th_ch_flag = 0x00,
94 .th_blk_flag = TH_DATA_IS_XID,
95 .th_is_xid = 0x01,
96 .th_seq_num = 0x00000000,
97};
98
99/*
100 * Definition of one MPC group
101 */
102
103/*
104 * Compatibility macros for busy handling
105 * of network devices.
106 */
107
108static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb);
109
110/*
111 * MPC Group state machine actions (static prototypes)
112 */
113static void mpc_action_nop(fsm_instance *fsm, int event, void *arg);
114static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg);
115static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg);
116static void mpc_action_timeout(fsm_instance *fi, int event, void *arg);
117static int mpc_validate_xid(struct mpcg_info *mpcginfo);
118static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg);
119static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg);
120static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg);
121static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg);
122static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg);
123static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg);
124
125#ifdef DEBUGDATA
126/*-------------------------------------------------------------------*
127* Dump buffer format *
128* *
129*--------------------------------------------------------------------*/
130void ctcmpc_dumpit(char *buf, int len)
131{
132 __u32 ct, sw, rm, dup;
133 char *ptr, *rptr;
134 char tbuf[82], tdup[82];
135 #if (UTS_MACHINE == s390x)
136 char addr[22];
137 #else
138 char addr[12];
139 #endif
140 char boff[12];
141 char bhex[82], duphex[82];
142 char basc[40];
143
144 sw = 0;
145 rptr = ptr = buf;
146 rm = 16;
147 duphex[0] = 0x00;
148 dup = 0;
149
150 for (ct = 0; ct < len; ct++, ptr++, rptr++) {
151 if (sw == 0) {
152 #if (UTS_MACHINE == s390x)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200153 sprintf(addr, "%16.16lx", (__u64)rptr);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100154 #else
155 sprintf(addr, "%8.8X", (__u32)rptr);
156 #endif
157
158 sprintf(boff, "%4.4X", (__u32)ct);
159 bhex[0] = '\0';
160 basc[0] = '\0';
161 }
162 if ((sw == 4) || (sw == 12))
163 strcat(bhex, " ");
164 if (sw == 8)
165 strcat(bhex, " ");
166
167 #if (UTS_MACHINE == s390x)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200168 sprintf(tbuf, "%2.2lX", (__u64)*ptr);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100169 #else
170 sprintf(tbuf, "%2.2X", (__u32)*ptr);
171 #endif
172
173 tbuf[2] = '\0';
174 strcat(bhex, tbuf);
175 if ((0 != isprint(*ptr)) && (*ptr >= 0x20))
176 basc[sw] = *ptr;
177 else
178 basc[sw] = '.';
179
180 basc[sw+1] = '\0';
181 sw++;
182 rm--;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200183 if (sw != 16)
184 continue;
185 if ((strcmp(duphex, bhex)) != 0) {
186 if (dup != 0) {
187 sprintf(tdup,
188 "Duplicate as above to %s", addr);
189 ctcm_pr_debug(" --- %s ---\n",
190 tdup);
191 }
192 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
Peter Tiedemann293d9842008-02-08 00:03:49 +0100193 addr, boff, bhex, basc);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200194 dup = 0;
195 strcpy(duphex, bhex);
196 } else
197 dup++;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100198
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200199 sw = 0;
200 rm = 16;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100201 } /* endfor */
202
203 if (sw != 0) {
204 for ( ; rm > 0; rm--, sw++) {
205 if ((sw == 4) || (sw == 12))
206 strcat(bhex, " ");
207 if (sw == 8)
208 strcat(bhex, " ");
209 strcat(bhex, " ");
210 strcat(basc, " ");
211 }
212 if (dup != 0) {
213 sprintf(tdup, "Duplicate as above to %s", addr);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200214 ctcm_pr_debug(" --- %s ---\n", tdup);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100215 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200216 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
217 addr, boff, bhex, basc);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100218 } else {
219 if (dup >= 1) {
220 sprintf(tdup, "Duplicate as above to %s", addr);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200221 ctcm_pr_debug(" --- %s ---\n", tdup);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100222 }
223 if (dup != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200224 ctcm_pr_debug(" %s (+%s) : %s [%s]\n",
Peter Tiedemann293d9842008-02-08 00:03:49 +0100225 addr, boff, bhex, basc);
226 }
227 }
228
229 return;
230
231} /* end of ctcmpc_dumpit */
232#endif
233
234#ifdef DEBUGDATA
235/*
236 * Dump header and first 16 bytes of an sk_buff for debugging purposes.
237 *
238 * skb The sk_buff to dump.
239 * offset Offset relative to skb-data, where to start the dump.
240 */
241void ctcmpc_dump_skb(struct sk_buff *skb, int offset)
242{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200243 __u8 *p = skb->data;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100244 struct th_header *header;
245 struct pdu *pheader;
246 int bl = skb->len;
247 int i;
248
249 if (p == NULL)
250 return;
251
252 p += offset;
253 header = (struct th_header *)p;
254
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200255 ctcm_pr_debug("dump:\n");
256 ctcm_pr_debug("skb len=%d \n", skb->len);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100257 if (skb->len > 2) {
258 switch (header->th_ch_flag) {
259 case TH_HAS_PDU:
260 break;
261 case 0x00:
262 case TH_IS_XID:
263 if ((header->th_blk_flag == TH_DATA_IS_XID) &&
264 (header->th_is_xid == 0x01))
265 goto dumpth;
266 case TH_SWEEP_REQ:
267 goto dumpth;
268 case TH_SWEEP_RESP:
269 goto dumpth;
270 default:
271 break;
272 }
273
274 pheader = (struct pdu *)p;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200275 ctcm_pr_debug("pdu->offset: %d hex: %04x\n",
276 pheader->pdu_offset, pheader->pdu_offset);
277 ctcm_pr_debug("pdu->flag : %02x\n", pheader->pdu_flag);
278 ctcm_pr_debug("pdu->proto : %02x\n", pheader->pdu_proto);
279 ctcm_pr_debug("pdu->seq : %02x\n", pheader->pdu_seq);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100280 goto dumpdata;
281
282dumpth:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200283 ctcm_pr_debug("th->seg : %02x\n", header->th_seg);
284 ctcm_pr_debug("th->ch : %02x\n", header->th_ch_flag);
285 ctcm_pr_debug("th->blk_flag: %02x\n", header->th_blk_flag);
286 ctcm_pr_debug("th->type : %s\n",
287 (header->th_is_xid) ? "DATA" : "XID");
288 ctcm_pr_debug("th->seqnum : %04x\n", header->th_seq_num);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100289
290 }
291dumpdata:
292 if (bl > 32)
293 bl = 32;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200294 ctcm_pr_debug("data: ");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100295 for (i = 0; i < bl; i++)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200296 ctcm_pr_debug("%02x%s", *p++, (i % 16) ? " " : "\n");
297 ctcm_pr_debug("\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100298}
299#endif
300
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200301static struct net_device *ctcmpc_get_dev(int port_num)
302{
303 char device[20];
304 struct net_device *dev;
305 struct ctcm_priv *priv;
306
307 sprintf(device, "%s%i", MPC_DEVICE_NAME, port_num);
308
309 dev = __dev_get_by_name(&init_net, device);
310
311 if (dev == NULL) {
312 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
313 "%s: Device not found by name: %s",
314 CTCM_FUNTAIL, device);
315 return NULL;
316 }
Peter Tiedemann261893d2008-08-21 17:10:24 +0200317 priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200318 if (priv == NULL) {
319 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
Peter Tiedemann261893d2008-08-21 17:10:24 +0200320 "%s(%s): dev->ml_priv is NULL",
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200321 CTCM_FUNTAIL, device);
322 return NULL;
323 }
324 if (priv->mpcg == NULL) {
325 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
326 "%s(%s): priv->mpcg is NULL",
327 CTCM_FUNTAIL, device);
328 return NULL;
329 }
330 return dev;
331}
332
Peter Tiedemann293d9842008-02-08 00:03:49 +0100333/*
334 * ctc_mpc_alloc_channel
335 * (exported interface)
336 *
337 * Device Initialization :
338 * ACTPATH driven IO operations
339 */
340int ctc_mpc_alloc_channel(int port_num, void (*callback)(int, int))
341{
Peter Tiedemann293d9842008-02-08 00:03:49 +0100342 struct net_device *dev;
343 struct mpc_group *grp;
344 struct ctcm_priv *priv;
345
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200346 dev = ctcmpc_get_dev(port_num);
347 if (dev == NULL)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100348 return 1;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200349 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100350 grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100351
352 grp->allochanfunc = callback;
353 grp->port_num = port_num;
354 grp->port_persist = 1;
355
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200356 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
357 "%s(%s): state=%s",
358 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100359
360 switch (fsm_getstate(grp->fsm)) {
361 case MPCG_STATE_INOP:
362 /* Group is in the process of terminating */
363 grp->alloc_called = 1;
364 break;
365 case MPCG_STATE_RESET:
366 /* MPC Group will transition to state */
367 /* MPCG_STATE_XID2INITW iff the minimum number */
368 /* of 1 read and 1 write channel have successfully*/
369 /* activated */
370 /*fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);*/
371 if (callback)
372 grp->send_qllc_disc = 1;
373 case MPCG_STATE_XID0IOWAIT:
374 fsm_deltimer(&grp->timer);
375 grp->outstanding_xid2 = 0;
376 grp->outstanding_xid7 = 0;
377 grp->outstanding_xid7_p2 = 0;
378 grp->saved_xid2 = NULL;
379 if (callback)
380 ctcm_open(dev);
381 fsm_event(priv->fsm, DEV_EVENT_START, dev);
382 break;
383 case MPCG_STATE_READY:
384 /* XID exchanges completed after PORT was activated */
385 /* Link station already active */
386 /* Maybe timing issue...retry callback */
387 grp->allocchan_callback_retries++;
388 if (grp->allocchan_callback_retries < 4) {
389 if (grp->allochanfunc)
390 grp->allochanfunc(grp->port_num,
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100391 grp->group_max_buflen);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100392 } else {
393 /* there are problems...bail out */
394 /* there may be a state mismatch so restart */
Peter Tiedemann293d9842008-02-08 00:03:49 +0100395 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
396 grp->allocchan_callback_retries = 0;
397 }
398 break;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100399 }
400
Peter Tiedemann293d9842008-02-08 00:03:49 +0100401 return 0;
402}
403EXPORT_SYMBOL(ctc_mpc_alloc_channel);
404
405/*
406 * ctc_mpc_establish_connectivity
407 * (exported interface)
408 */
409void ctc_mpc_establish_connectivity(int port_num,
410 void (*callback)(int, int, int))
411{
Peter Tiedemann293d9842008-02-08 00:03:49 +0100412 struct net_device *dev;
413 struct mpc_group *grp;
414 struct ctcm_priv *priv;
415 struct channel *rch, *wch;
416
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200417 dev = ctcmpc_get_dev(port_num);
418 if (dev == NULL)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100419 return;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200420 priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200421 grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100422 rch = priv->channel[READ];
423 wch = priv->channel[WRITE];
424
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
426 "%s(%s): state=%s",
427 CTCM_FUNTAIL, dev->name, fsm_getstate_str(grp->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100428
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*/
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200455
456 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
457 "%s(%s): REJECTED - inactive channels",
458 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100459 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 */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200468
Peter Tiedemann293d9842008-02-08 00:03:49 +0100469 if ((fsm_getstate(rch->fsm) > CH_XID0_PENDING) ||
470 (fsm_getstate(wch->fsm) > CH_XID0_PENDING)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200471 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
472 "%s(%s): ABORT - PASSIVE XID",
473 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100474 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 {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200488 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);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100491 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 {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200502 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);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100505 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
519done:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200520 CTCM_PR_DEBUG("Exit %s()\n", __func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100521 return;
522}
523EXPORT_SYMBOL(ctc_mpc_establish_connectivity);
524
525/*
526 * ctc_mpc_dealloc_ch
527 * (exported interface)
528 */
529void ctc_mpc_dealloc_ch(int port_num)
530{
531 struct net_device *dev;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100532 struct ctcm_priv *priv;
533 struct mpc_group *grp;
534
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200535 dev = ctcmpc_get_dev(port_num);
536 if (dev == NULL)
537 return;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200538 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100539 grp = priv->mpcg;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200540
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);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100546 grp->channels_terminating = 0;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100547 fsm_deltimer(&grp->timer);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100548 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);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100555 return;
556}
557EXPORT_SYMBOL(ctc_mpc_dealloc_ch);
558
559/*
560 * ctc_mpc_flow_control
561 * (exported interface)
562 */
563void ctc_mpc_flow_control(int port_num, int flowc)
564{
Peter Tiedemann293d9842008-02-08 00:03:49 +0100565 struct ctcm_priv *priv;
566 struct mpc_group *grp;
567 struct net_device *dev;
568 struct channel *rch;
569 int mpcg_state;
570
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200571 dev = ctcmpc_get_dev(port_num);
572 if (dev == NULL)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100573 return;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200574 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100575 grp = priv->mpcg;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200576
577 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
578 "%s: %s: flowc = %d",
579 CTCM_FUNTAIL, dev->name, flowc);
580
Peter Tiedemann293d9842008-02-08 00:03:49 +0100581 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
Peter Tiedemann293d9842008-02-08 00:03:49 +0100611}
612EXPORT_SYMBOL(ctc_mpc_flow_control);
613
614static int mpc_send_qllc_discontact(struct net_device *);
615
616/*
617 * helper function of ctcmpc_unpack_skb
618*/
619static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
620{
621 struct channel *rch = mpcginfo->ch;
622 struct net_device *dev = rch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200623 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100624 struct mpc_group *grp = priv->mpcg;
625 struct channel *ch = priv->channel[WRITE];
626
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100629
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 */
651static void ctcmpc_send_sweep_resp(struct channel *rch)
652{
653 struct net_device *dev = rch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200654 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100655 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
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100662
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200663 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100664 if (sweep_skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200665 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
666 "%s(%s): sweep_skb allocation ERROR\n",
667 CTCM_FUNTAIL, rch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100668 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
699done:
Joel A. Fowlere2fc8cb2009-03-24 03:27:49 +0000700 grp->in_sweep = 0;
701 ctcm_clear_busy_do(dev);
702 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100703
704 return;
705}
706
707/*
708 * helper function of ctcmpc_unpack_skb
709 */
710static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
711{
712 struct channel *rch = mpcginfo->ch;
713 struct net_device *dev = rch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200714 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100715 struct mpc_group *grp = priv->mpcg;
716 struct channel *ch = priv->channel[WRITE];
717
718 if (do_debug)
719 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200720 " %s(): ch=0x%p id=%s\n", __func__, ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100721
722 if (grp->in_sweep == 0) {
723 grp->in_sweep = 1;
724 ctcm_test_and_set_busy(dev);
725 grp->sweep_req_pend_num = grp->active_channels[READ];
726 grp->sweep_rsp_pend_num = grp->active_channels[READ];
727 }
728
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200729 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100730
731 grp->sweep_req_pend_num--;
732 ctcmpc_send_sweep_resp(ch);
733 kfree(mpcginfo);
734 return;
735}
736
737/*
738 * MPC Group Station FSM definitions
739 */
740static const char *mpcg_event_names[] = {
741 [MPCG_EVENT_INOP] = "INOP Condition",
742 [MPCG_EVENT_DISCONC] = "Discontact Received",
743 [MPCG_EVENT_XID0DO] = "Channel Active - Start XID",
744 [MPCG_EVENT_XID2] = "XID2 Received",
745 [MPCG_EVENT_XID2DONE] = "XID0 Complete",
746 [MPCG_EVENT_XID7DONE] = "XID7 Complete",
747 [MPCG_EVENT_TIMER] = "XID Setup Timer",
748 [MPCG_EVENT_DOIO] = "XID DoIO",
749};
750
751static const char *mpcg_state_names[] = {
752 [MPCG_STATE_RESET] = "Reset",
753 [MPCG_STATE_INOP] = "INOP",
754 [MPCG_STATE_XID2INITW] = "Passive XID- XID0 Pending Start",
755 [MPCG_STATE_XID2INITX] = "Passive XID- XID0 Pending Complete",
756 [MPCG_STATE_XID7INITW] = "Passive XID- XID7 Pending P1 Start",
757 [MPCG_STATE_XID7INITX] = "Passive XID- XID7 Pending P2 Complete",
758 [MPCG_STATE_XID0IOWAIT] = "Active XID- XID0 Pending Start",
759 [MPCG_STATE_XID0IOWAIX] = "Active XID- XID0 Pending Complete",
760 [MPCG_STATE_XID7INITI] = "Active XID- XID7 Pending Start",
761 [MPCG_STATE_XID7INITZ] = "Active XID- XID7 Pending Complete ",
762 [MPCG_STATE_XID7INITF] = "XID - XID7 Complete ",
763 [MPCG_STATE_FLOWC] = "FLOW CONTROL ON",
764 [MPCG_STATE_READY] = "READY",
765};
766
767/*
768 * The MPC Group Station FSM
769 * 22 events
770 */
771static const fsm_node mpcg_fsm[] = {
772 { MPCG_STATE_RESET, MPCG_EVENT_INOP, mpc_action_go_inop },
773 { MPCG_STATE_INOP, MPCG_EVENT_INOP, mpc_action_nop },
774 { MPCG_STATE_FLOWC, MPCG_EVENT_INOP, mpc_action_go_inop },
775
776 { MPCG_STATE_READY, MPCG_EVENT_DISCONC, mpc_action_discontact },
777 { MPCG_STATE_READY, MPCG_EVENT_INOP, mpc_action_go_inop },
778
779 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
780 { MPCG_STATE_XID2INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
781 { MPCG_STATE_XID2INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
782 { MPCG_STATE_XID2INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
783 { MPCG_STATE_XID2INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
784
785 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
786 { MPCG_STATE_XID2INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
787 { MPCG_STATE_XID2INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
788 { MPCG_STATE_XID2INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
789 { MPCG_STATE_XID2INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
790
791 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
792 { MPCG_STATE_XID7INITW, MPCG_EVENT_DISCONC, mpc_action_discontact },
793 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
794 { MPCG_STATE_XID7INITW, MPCG_EVENT_INOP, mpc_action_go_inop },
795 { MPCG_STATE_XID7INITW, MPCG_EVENT_TIMER, mpc_action_timeout },
796 { MPCG_STATE_XID7INITW, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
797 { MPCG_STATE_XID7INITW, MPCG_EVENT_DOIO, mpc_action_yside_xid },
798
799 { MPCG_STATE_XID7INITX, MPCG_EVENT_DISCONC, mpc_action_discontact },
800 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
801 { MPCG_STATE_XID7INITX, MPCG_EVENT_INOP, mpc_action_go_inop },
802 { MPCG_STATE_XID7INITX, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
803 { MPCG_STATE_XID7INITX, MPCG_EVENT_TIMER, mpc_action_timeout },
804 { MPCG_STATE_XID7INITX, MPCG_EVENT_DOIO, mpc_action_yside_xid },
805
806 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
807 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DISCONC, mpc_action_discontact },
808 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
809 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_INOP, mpc_action_go_inop },
810 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_TIMER, mpc_action_timeout },
811 { MPCG_STATE_XID0IOWAIT, MPCG_EVENT_DOIO, mpc_action_xside_xid },
812
813 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID0DO, mpc_action_doxid0 },
814 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DISCONC, mpc_action_discontact },
815 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_XID2, mpc_action_rcvd_xid0 },
816 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_INOP, mpc_action_go_inop },
817 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_TIMER, mpc_action_timeout },
818 { MPCG_STATE_XID0IOWAIX, MPCG_EVENT_DOIO, mpc_action_xside_xid },
819
820 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2DONE, mpc_action_doxid7 },
821 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
822 { MPCG_STATE_XID7INITI, MPCG_EVENT_DISCONC, mpc_action_discontact },
823 { MPCG_STATE_XID7INITI, MPCG_EVENT_INOP, mpc_action_go_inop },
824 { MPCG_STATE_XID7INITI, MPCG_EVENT_TIMER, mpc_action_timeout },
825 { MPCG_STATE_XID7INITI, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
826 { MPCG_STATE_XID7INITI, MPCG_EVENT_DOIO, mpc_action_xside_xid },
827
828 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID2, mpc_action_rcvd_xid7 },
829 { MPCG_STATE_XID7INITZ, MPCG_EVENT_XID7DONE, mpc_action_doxid7 },
830 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DISCONC, mpc_action_discontact },
831 { MPCG_STATE_XID7INITZ, MPCG_EVENT_INOP, mpc_action_go_inop },
832 { MPCG_STATE_XID7INITZ, MPCG_EVENT_TIMER, mpc_action_timeout },
833 { MPCG_STATE_XID7INITZ, MPCG_EVENT_DOIO, mpc_action_xside_xid },
834
835 { MPCG_STATE_XID7INITF, MPCG_EVENT_INOP, mpc_action_go_inop },
836 { MPCG_STATE_XID7INITF, MPCG_EVENT_XID7DONE, mpc_action_go_ready },
837};
838
839static int mpcg_fsm_len = ARRAY_SIZE(mpcg_fsm);
840
841/*
842 * MPC Group Station FSM action
843 * CTCM_PROTO_MPC only
844 */
845static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
846{
847 struct net_device *dev = arg;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200848 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200849 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100850
Peter Tiedemann293d9842008-02-08 00:03:49 +0100851 if (grp == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200852 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
853 "%s(%s): No MPC group",
854 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100855 return;
856 }
857
858 fsm_deltimer(&grp->timer);
859
860 if (grp->saved_xid2->xid2_flag2 == 0x40) {
861 priv->xid->xid2_flag2 = 0x00;
862 if (grp->estconnfunc) {
863 grp->estconnfunc(grp->port_num, 1,
864 grp->group_max_buflen);
865 grp->estconnfunc = NULL;
866 } else if (grp->allochanfunc)
867 grp->send_qllc_disc = 1;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200868
869 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
870 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
871 "%s(%s): fails",
872 CTCM_FUNTAIL, dev->name);
873 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100874 }
875
876 grp->port_persist = 1;
877 grp->out_of_sequence = 0;
878 grp->estconn_called = 0;
879
880 tasklet_hi_schedule(&grp->mpc_tasklet2);
881
Peter Tiedemann293d9842008-02-08 00:03:49 +0100882 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100883}
884
885/*
886 * helper of ctcm_init_netdevice
887 * CTCM_PROTO_MPC only
888 */
889void mpc_group_ready(unsigned long adev)
890{
891 struct net_device *dev = (struct net_device *)adev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200892 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200893 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100894 struct channel *ch = NULL;
895
Peter Tiedemann293d9842008-02-08 00:03:49 +0100896 if (grp == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200897 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
898 "%s(%s): No MPC group",
899 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100900 return;
901 }
902
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200903 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
904 "%s: %s: GROUP TRANSITIONED TO READY, maxbuf = %d\n",
905 CTCM_FUNTAIL, dev->name, grp->group_max_buflen);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100906
907 fsm_newstate(grp->fsm, MPCG_STATE_READY);
908
909 /* Put up a read on the channel */
910 ch = priv->channel[READ];
911 ch->pdu_seq = 0;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200912 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
913 __func__, ch->pdu_seq);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100914
915 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
916 /* Put the write channel in idle state */
917 ch = priv->channel[WRITE];
918 if (ch->collect_len > 0) {
919 spin_lock(&ch->collect_lock);
920 ctcm_purge_skb_queue(&ch->collect_queue);
921 ch->collect_len = 0;
922 spin_unlock(&ch->collect_lock);
923 }
924 ctcm_chx_txidle(ch->fsm, CTC_EVENT_START, ch);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100925 ctcm_clear_busy(dev);
926
927 if (grp->estconnfunc) {
928 grp->estconnfunc(grp->port_num, 0,
929 grp->group_max_buflen);
930 grp->estconnfunc = NULL;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200931 } else if (grp->allochanfunc)
932 grp->allochanfunc(grp->port_num, grp->group_max_buflen);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100933
934 grp->send_qllc_disc = 1;
935 grp->changed_side = 0;
936
Peter Tiedemann293d9842008-02-08 00:03:49 +0100937 return;
938
939}
940
941/*
942 * Increment the MPC Group Active Channel Counts
943 * helper of dev_action (called from channel fsm)
944 */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200945void mpc_channel_action(struct channel *ch, int direction, int action)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100946{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200947 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200948 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200949 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100950
951 if (grp == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200952 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
953 "%s(%s): No MPC group",
954 CTCM_FUNTAIL, dev->name);
955 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100956 }
957
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200958 CTCM_PR_DEBUG("enter %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
959
960 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
961 "%s: %i / Grp:%s total_channels=%i, active_channels: "
962 "read=%i, write=%i\n", __func__, action,
963 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
964 grp->active_channels[READ], grp->active_channels[WRITE]);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100965
966 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
967 grp->num_channel_paths++;
968 grp->active_channels[direction]++;
969 grp->outstanding_xid2++;
970 ch->in_mpcgroup = 1;
971
972 if (ch->xid_skb != NULL)
973 dev_kfree_skb_any(ch->xid_skb);
974
975 ch->xid_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT,
976 GFP_ATOMIC | GFP_DMA);
977 if (ch->xid_skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200978 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
979 "%s(%s): Couldn't alloc ch xid_skb\n",
980 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100981 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200982 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100983 }
984 ch->xid_skb_data = ch->xid_skb->data;
985 ch->xid_th = (struct th_header *)ch->xid_skb->data;
986 skb_put(ch->xid_skb, TH_HEADER_LENGTH);
987 ch->xid = (struct xid2 *)skb_tail_pointer(ch->xid_skb);
988 skb_put(ch->xid_skb, XID2_LENGTH);
989 ch->xid_id = skb_tail_pointer(ch->xid_skb);
990 ch->xid_skb->data = ch->xid_skb_data;
991 skb_reset_tail_pointer(ch->xid_skb);
992 ch->xid_skb->len = 0;
993
994 memcpy(skb_put(ch->xid_skb, grp->xid_skb->len),
995 grp->xid_skb->data,
996 grp->xid_skb->len);
997
998 ch->xid->xid2_dlc_type = ((CHANNEL_DIRECTION(ch->flags) == READ)
999 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
1000
1001 if (CHANNEL_DIRECTION(ch->flags) == WRITE)
1002 ch->xid->xid2_buf_len = 0x00;
1003
1004 ch->xid_skb->data = ch->xid_skb_data;
1005 skb_reset_tail_pointer(ch->xid_skb);
1006 ch->xid_skb->len = 0;
1007
1008 fsm_newstate(ch->fsm, CH_XID0_PENDING);
1009
1010 if ((grp->active_channels[READ] > 0) &&
1011 (grp->active_channels[WRITE] > 0) &&
1012 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
1013 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001014 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
1015 "%s: %s: MPC GROUP CHANNELS ACTIVE\n",
1016 __func__, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001017 }
1018 } else if ((action == MPC_CHANNEL_REMOVE) &&
1019 (ch->in_mpcgroup == 1)) {
1020 ch->in_mpcgroup = 0;
1021 grp->num_channel_paths--;
1022 grp->active_channels[direction]--;
1023
1024 if (ch->xid_skb != NULL)
1025 dev_kfree_skb_any(ch->xid_skb);
1026 ch->xid_skb = NULL;
1027
1028 if (grp->channels_terminating)
1029 goto done;
1030
1031 if (((grp->active_channels[READ] == 0) &&
1032 (grp->active_channels[WRITE] > 0))
1033 || ((grp->active_channels[WRITE] == 0) &&
1034 (grp->active_channels[READ] > 0)))
1035 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1036 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001037done:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001038 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1039 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1040 "read=%i, write=%i\n", __func__, action,
1041 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1042 grp->active_channels[READ], grp->active_channels[WRITE]);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001043
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001044 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001045}
1046
1047/**
1048 * Unpack a just received skb and hand it over to
1049 * upper layers.
1050 * special MPC version of unpack_skb.
1051 *
1052 * ch The channel where this skb has been received.
1053 * pskb The received skb.
1054 */
1055static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
1056{
1057 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001058 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001059 struct mpc_group *grp = priv->mpcg;
1060 struct pdu *curr_pdu;
1061 struct mpcg_info *mpcginfo;
1062 struct th_header *header = NULL;
1063 struct th_sweep *sweep = NULL;
1064 int pdu_last_seen = 0;
1065 __u32 new_len;
1066 struct sk_buff *skb;
1067 int skblen;
1068 int sendrc = 0;
1069
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001070 CTCM_PR_DEBUG("ctcmpc enter: %s() %s cp:%i ch:%s\n",
1071 __func__, dev->name, smp_processor_id(), ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001072
1073 header = (struct th_header *)pskb->data;
1074 if ((header->th_seg == 0) &&
1075 (header->th_ch_flag == 0) &&
1076 (header->th_blk_flag == 0) &&
1077 (header->th_seq_num == 0))
1078 /* nothing for us */ goto done;
1079
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001080 CTCM_PR_DBGDATA("%s: th_header\n", __func__);
1081 CTCM_D3_DUMP((char *)header, TH_HEADER_LENGTH);
1082 CTCM_PR_DBGDATA("%s: pskb len: %04x \n", __func__, pskb->len);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001083
1084 pskb->dev = dev;
1085 pskb->ip_summed = CHECKSUM_UNNECESSARY;
1086 skb_pull(pskb, TH_HEADER_LENGTH);
1087
1088 if (likely(header->th_ch_flag == TH_HAS_PDU)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001089 CTCM_PR_DBGDATA("%s: came into th_has_pdu\n", __func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001090 if ((fsm_getstate(grp->fsm) == MPCG_STATE_FLOWC) ||
1091 ((fsm_getstate(grp->fsm) == MPCG_STATE_READY) &&
1092 (header->th_seq_num != ch->th_seq_num + 1) &&
1093 (ch->th_seq_num != 0))) {
1094 /* This is NOT the next segment *
1095 * we are not the correct race winner *
1096 * go away and let someone else win *
1097 * BUT..this only applies if xid negot *
1098 * is done *
1099 */
1100 grp->out_of_sequence += 1;
1101 __skb_push(pskb, TH_HEADER_LENGTH);
1102 skb_queue_tail(&ch->io_queue, pskb);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001103 CTCM_PR_DBGDATA("%s: th_seq_num expect:%08x "
1104 "got:%08x\n", __func__,
1105 ch->th_seq_num + 1, header->th_seq_num);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001106
1107 return;
1108 }
1109 grp->out_of_sequence = 0;
1110 ch->th_seq_num = header->th_seq_num;
1111
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001112 CTCM_PR_DBGDATA("ctcmpc: %s() FromVTAM_th_seq=%08x\n",
1113 __func__, ch->th_seq_num);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001114
1115 if (unlikely(fsm_getstate(grp->fsm) != MPCG_STATE_READY))
1116 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001117 while ((pskb->len > 0) && !pdu_last_seen) {
1118 curr_pdu = (struct pdu *)pskb->data;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001119
1120 CTCM_PR_DBGDATA("%s: pdu_header\n", __func__);
1121 CTCM_D3_DUMP((char *)pskb->data, PDU_HEADER_LENGTH);
1122 CTCM_PR_DBGDATA("%s: pskb len: %04x \n",
1123 __func__, pskb->len);
1124
Peter Tiedemann293d9842008-02-08 00:03:49 +01001125 skb_pull(pskb, PDU_HEADER_LENGTH);
1126
1127 if (curr_pdu->pdu_flag & PDU_LAST)
1128 pdu_last_seen = 1;
1129 if (curr_pdu->pdu_flag & PDU_CNTL)
1130 pskb->protocol = htons(ETH_P_SNAP);
1131 else
1132 pskb->protocol = htons(ETH_P_SNA_DIX);
1133
1134 if ((pskb->len <= 0) || (pskb->len > ch->max_bufsize)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001135 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1136 "%s(%s): Dropping packet with "
1137 "illegal siize %d",
1138 CTCM_FUNTAIL, dev->name, pskb->len);
1139
Peter Tiedemann293d9842008-02-08 00:03:49 +01001140 priv->stats.rx_dropped++;
1141 priv->stats.rx_length_errors++;
1142 goto done;
1143 }
1144 skb_reset_mac_header(pskb);
1145 new_len = curr_pdu->pdu_offset;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001146 CTCM_PR_DBGDATA("%s: new_len: %04x \n",
1147 __func__, new_len);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001148 if ((new_len == 0) || (new_len > pskb->len)) {
1149 /* should never happen */
1150 /* pskb len must be hosed...bail out */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001151 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1152 "%s(%s): non valid pdu_offset: %04x",
1153 /* "data may be lost", */
1154 CTCM_FUNTAIL, dev->name, new_len);
1155 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001156 }
1157 skb = __dev_alloc_skb(new_len+4, GFP_ATOMIC);
1158
1159 if (!skb) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001160 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1161 "%s(%s): MEMORY allocation error",
1162 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001163 priv->stats.rx_dropped++;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001164 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001165 goto done;
1166 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001167 memcpy(skb_put(skb, new_len), pskb->data, new_len);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001168
1169 skb_reset_mac_header(skb);
1170 skb->dev = pskb->dev;
1171 skb->protocol = pskb->protocol;
1172 skb->ip_summed = CHECKSUM_UNNECESSARY;
1173 *((__u32 *) skb_push(skb, 4)) = ch->pdu_seq;
1174 ch->pdu_seq++;
1175
Peter Tiedemann293d9842008-02-08 00:03:49 +01001176 if (do_debug_data) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001177 ctcm_pr_debug("%s: ToDCM_pdu_seq= %08x\n",
1178 __func__, ch->pdu_seq);
1179 ctcm_pr_debug("%s: skb:%0lx "
1180 "skb len: %d \n", __func__,
1181 (unsigned long)skb, skb->len);
1182 ctcm_pr_debug("%s: up to 32 bytes "
1183 "of pdu_data sent\n", __func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001184 ctcmpc_dump32((char *)skb->data, skb->len);
1185 }
1186
1187 skblen = skb->len;
1188 sendrc = netif_rx(skb);
1189 priv->stats.rx_packets++;
1190 priv->stats.rx_bytes += skblen;
1191 skb_pull(pskb, new_len); /* point to next PDU */
1192 }
1193 } else {
1194 mpcginfo = (struct mpcg_info *)
1195 kmalloc(sizeof(struct mpcg_info), gfp_type());
1196 if (mpcginfo == NULL)
1197 goto done;
1198
1199 mpcginfo->ch = ch;
1200 mpcginfo->th = header;
1201 mpcginfo->skb = pskb;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001202 CTCM_PR_DEBUG("%s: Not PDU - may be control pkt\n",
1203 __func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001204 /* it's a sweep? */
1205 sweep = (struct th_sweep *)pskb->data;
1206 mpcginfo->sweep = sweep;
1207 if (header->th_ch_flag == TH_SWEEP_REQ)
1208 mpc_rcvd_sweep_req(mpcginfo);
1209 else if (header->th_ch_flag == TH_SWEEP_RESP)
1210 mpc_rcvd_sweep_resp(mpcginfo);
1211 else if (header->th_blk_flag == TH_DATA_IS_XID) {
1212 struct xid2 *thisxid = (struct xid2 *)pskb->data;
1213 skb_pull(pskb, XID2_LENGTH);
1214 mpcginfo->xid = thisxid;
1215 fsm_event(grp->fsm, MPCG_EVENT_XID2, mpcginfo);
1216 } else if (header->th_blk_flag == TH_DISCONTACT)
1217 fsm_event(grp->fsm, MPCG_EVENT_DISCONC, mpcginfo);
1218 else if (header->th_seq_num != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001219 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1220 "%s(%s): control pkt expected\n",
1221 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001222 priv->stats.rx_dropped++;
1223 /* mpcginfo only used for non-data transfers */
1224 kfree(mpcginfo);
1225 if (do_debug_data)
1226 ctcmpc_dump_skb(pskb, -8);
1227 }
1228 }
1229done:
1230
1231 dev_kfree_skb_any(pskb);
1232 if (sendrc == NET_RX_DROP) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001233 dev_warn(&dev->dev,
1234 "The network backlog for %s is exceeded, "
1235 "package dropped\n", __func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001236 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1237 }
1238
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001239 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1240 __func__, dev->name, ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001241}
1242
1243/**
1244 * tasklet helper for mpc's skb unpacking.
1245 *
1246 * ch The channel to work on.
1247 * Allow flow control back pressure to occur here.
1248 * Throttling back channel can result in excessive
1249 * channel inactivity and system deact of channel
1250 */
1251void ctcmpc_bh(unsigned long thischan)
1252{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001253 struct channel *ch = (struct channel *)thischan;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001254 struct sk_buff *skb;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001255 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001256 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001257 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001258
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001259 CTCM_PR_DEBUG("%s cp:%i enter: %s() %s\n",
1260 dev->name, smp_processor_id(), __func__, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001261 /* caller has requested driver to throttle back */
1262 while ((fsm_getstate(grp->fsm) != MPCG_STATE_FLOWC) &&
1263 (skb = skb_dequeue(&ch->io_queue))) {
1264 ctcmpc_unpack_skb(ch, skb);
1265 if (grp->out_of_sequence > 20) {
1266 /* assume data loss has occurred if */
1267 /* missing seq_num for extended */
1268 /* period of time */
1269 grp->out_of_sequence = 0;
1270 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1271 break;
1272 }
1273 if (skb == skb_peek(&ch->io_queue))
1274 break;
1275 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001276 CTCM_PR_DEBUG("exit %s: %s: ch=0x%p id=%s\n",
1277 __func__, dev->name, ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001278 return;
1279}
1280
1281/*
1282 * MPC Group Initializations
1283 */
1284struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv)
1285{
1286 struct mpc_group *grp;
1287
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001288 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
1289 "Enter %s(%p)", CTCM_FUNTAIL, priv);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001290
1291 grp = kzalloc(sizeof(struct mpc_group), GFP_KERNEL);
1292 if (grp == NULL)
1293 return NULL;
1294
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001295 grp->fsm = init_fsm("mpcg", mpcg_state_names, mpcg_event_names,
1296 MPCG_NR_STATES, MPCG_NR_EVENTS, mpcg_fsm,
1297 mpcg_fsm_len, GFP_KERNEL);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001298 if (grp->fsm == NULL) {
1299 kfree(grp);
1300 return NULL;
1301 }
1302
1303 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1304 fsm_settimer(grp->fsm, &grp->timer);
1305
1306 grp->xid_skb =
1307 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC | GFP_DMA);
1308 if (grp->xid_skb == NULL) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001309 kfree_fsm(grp->fsm);
1310 kfree(grp);
1311 return NULL;
1312 }
1313 /* base xid for all channels in group */
1314 grp->xid_skb_data = grp->xid_skb->data;
1315 grp->xid_th = (struct th_header *)grp->xid_skb->data;
1316 memcpy(skb_put(grp->xid_skb, TH_HEADER_LENGTH),
1317 &thnorm, TH_HEADER_LENGTH);
1318
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001319 grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001320 memcpy(skb_put(grp->xid_skb, XID2_LENGTH), &init_xid, XID2_LENGTH);
1321 grp->xid->xid2_adj_id = jiffies | 0xfff00000;
1322 grp->xid->xid2_sender_id = jiffies;
1323
1324 grp->xid_id = skb_tail_pointer(grp->xid_skb);
1325 memcpy(skb_put(grp->xid_skb, 4), "VTAM", 4);
1326
1327 grp->rcvd_xid_skb =
1328 __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
1329 if (grp->rcvd_xid_skb == NULL) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001330 kfree_fsm(grp->fsm);
1331 dev_kfree_skb(grp->xid_skb);
1332 kfree(grp);
1333 return NULL;
1334 }
1335 grp->rcvd_xid_data = grp->rcvd_xid_skb->data;
1336 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1337 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH),
1338 &thnorm, TH_HEADER_LENGTH);
1339 grp->saved_xid2 = NULL;
1340 priv->xid = grp->xid;
1341 priv->mpcg = grp;
1342 return grp;
1343}
1344
1345/*
1346 * The MPC Group Station FSM
1347 */
1348
1349/*
1350 * MPC Group Station FSM actions
1351 * CTCM_PROTO_MPC only
1352 */
1353
1354/**
1355 * NOP action for statemachines
1356 */
1357static void mpc_action_nop(fsm_instance *fi, int event, void *arg)
1358{
1359}
1360
1361/*
1362 * invoked when the device transitions to dev_stopped
1363 * MPC will stop each individual channel if a single XID failure
1364 * occurs, or will intitiate all channels be stopped if a GROUP
1365 * level failure occurs.
1366 */
1367static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1368{
1369 struct net_device *dev = arg;
1370 struct ctcm_priv *priv;
1371 struct mpc_group *grp;
1372 int rc = 0;
1373 struct channel *wch, *rch;
1374
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001375 BUG_ON(dev == NULL);
1376 CTCM_PR_DEBUG("Enter %s: %s\n", __func__, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001377
Peter Tiedemann261893d2008-08-21 17:10:24 +02001378 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001379 grp = priv->mpcg;
1380 grp->flow_off_called = 0;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001381 fsm_deltimer(&grp->timer);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001382 if (grp->channels_terminating)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001383 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001384
1385 grp->channels_terminating = 1;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001386 grp->saved_state = fsm_getstate(grp->fsm);
1387 fsm_newstate(grp->fsm, MPCG_STATE_INOP);
1388 if (grp->saved_state > MPCG_STATE_XID7INITF)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001389 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1390 "%s(%s): MPC GROUP INOPERATIVE",
1391 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001392 if ((grp->saved_state != MPCG_STATE_RESET) ||
1393 /* dealloc_channel has been called */
Joel A. Fowlere2fc8cb2009-03-24 03:27:49 +00001394 (grp->port_persist == 0))
Peter Tiedemann293d9842008-02-08 00:03:49 +01001395 fsm_deltimer(&priv->restart_timer);
1396
1397 wch = priv->channel[WRITE];
1398 rch = priv->channel[READ];
1399
1400 switch (grp->saved_state) {
1401 case MPCG_STATE_RESET:
1402 case MPCG_STATE_INOP:
1403 case MPCG_STATE_XID2INITW:
1404 case MPCG_STATE_XID0IOWAIT:
1405 case MPCG_STATE_XID2INITX:
1406 case MPCG_STATE_XID7INITW:
1407 case MPCG_STATE_XID7INITX:
1408 case MPCG_STATE_XID0IOWAIX:
1409 case MPCG_STATE_XID7INITI:
1410 case MPCG_STATE_XID7INITZ:
1411 case MPCG_STATE_XID7INITF:
1412 break;
1413 case MPCG_STATE_FLOWC:
1414 case MPCG_STATE_READY:
1415 default:
1416 tasklet_hi_schedule(&wch->ch_disc_tasklet);
1417 }
1418
1419 grp->xid2_tgnum = 0;
1420 grp->group_max_buflen = 0; /*min of all received */
1421 grp->outstanding_xid2 = 0;
1422 grp->outstanding_xid7 = 0;
1423 grp->outstanding_xid7_p2 = 0;
1424 grp->saved_xid2 = NULL;
1425 grp->xidnogood = 0;
1426 grp->changed_side = 0;
1427
1428 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1429 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1430 grp->rcvd_xid_skb->len = 0;
1431 grp->rcvd_xid_th = (struct th_header *)grp->rcvd_xid_skb->data;
1432 memcpy(skb_put(grp->rcvd_xid_skb, TH_HEADER_LENGTH), &thnorm,
1433 TH_HEADER_LENGTH);
1434
1435 if (grp->send_qllc_disc == 1) {
1436 grp->send_qllc_disc = 0;
1437 rc = mpc_send_qllc_discontact(dev);
1438 }
1439
1440 /* DO NOT issue DEV_EVENT_STOP directly out of this code */
1441 /* This can result in INOP of VTAM PU due to halting of */
1442 /* outstanding IO which causes a sense to be returned */
1443 /* Only about 3 senses are allowed and then IOS/VTAM will*/
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001444 /* become unreachable without manual intervention */
1445 if ((grp->port_persist == 1) || (grp->alloc_called)) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001446 grp->alloc_called = 0;
1447 fsm_deltimer(&priv->restart_timer);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001448 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_RESTART, dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001449 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
1450 if (grp->saved_state > MPCG_STATE_XID7INITF)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001451 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1452 "%s(%s): MPC GROUP RECOVERY SCHEDULED",
1453 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001454 } else {
1455 fsm_deltimer(&priv->restart_timer);
1456 fsm_addtimer(&priv->restart_timer, 500, DEV_EVENT_STOP, dev);
1457 fsm_newstate(grp->fsm, MPCG_STATE_RESET);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001458 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ALWAYS,
1459 "%s(%s): NO MPC GROUP RECOVERY ATTEMPTED",
1460 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001461 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001462}
1463
1464/**
1465 * Handle mpc group action timeout.
1466 * MPC Group Station FSM action
1467 * CTCM_PROTO_MPC only
1468 *
1469 * fi An instance of an mpc_group fsm.
1470 * event The event, just happened.
1471 * arg Generic pointer, casted from net_device * upon call.
1472 */
1473static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1474{
1475 struct net_device *dev = arg;
1476 struct ctcm_priv *priv;
1477 struct mpc_group *grp;
1478 struct channel *wch;
1479 struct channel *rch;
1480
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001481 BUG_ON(dev == NULL);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001482
Peter Tiedemann261893d2008-08-21 17:10:24 +02001483 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001484 grp = priv->mpcg;
1485 wch = priv->channel[WRITE];
1486 rch = priv->channel[READ];
1487
1488 switch (fsm_getstate(grp->fsm)) {
1489 case MPCG_STATE_XID2INITW:
1490 /* Unless there is outstanding IO on the */
1491 /* channel just return and wait for ATTN */
1492 /* interrupt to begin XID negotiations */
1493 if ((fsm_getstate(rch->fsm) == CH_XID0_PENDING) &&
1494 (fsm_getstate(wch->fsm) == CH_XID0_PENDING))
1495 break;
1496 default:
1497 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1498 }
1499
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001500 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
1501 "%s: dev=%s exit",
1502 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001503 return;
1504}
1505
1506/*
1507 * MPC Group Station FSM action
1508 * CTCM_PROTO_MPC only
1509 */
1510void mpc_action_discontact(fsm_instance *fi, int event, void *arg)
1511{
1512 struct mpcg_info *mpcginfo = arg;
1513 struct channel *ch = mpcginfo->ch;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001514 struct net_device *dev;
1515 struct ctcm_priv *priv;
1516 struct mpc_group *grp;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001517
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001518 if (ch) {
1519 dev = ch->netdev;
1520 if (dev) {
Peter Tiedemann261893d2008-08-21 17:10:24 +02001521 priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001522 if (priv) {
1523 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1524 "%s: %s: %s\n",
1525 CTCM_FUNTAIL, dev->name, ch->id);
1526 grp = priv->mpcg;
1527 grp->send_qllc_disc = 1;
1528 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1529 }
1530 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001531 }
1532
Peter Tiedemann293d9842008-02-08 00:03:49 +01001533 return;
1534}
1535
1536/*
1537 * MPC Group Station - not part of FSM
1538 * CTCM_PROTO_MPC only
1539 * called from add_channel in ctcm_main.c
1540 */
1541void mpc_action_send_discontact(unsigned long thischan)
1542{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001543 int rc;
1544 struct channel *ch = (struct channel *)thischan;
1545 unsigned long saveflags = 0;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001546
1547 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1548 rc = ccw_device_start(ch->cdev, &ch->ccw[15],
1549 (unsigned long)ch, 0xff, 0);
1550 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1551
1552 if (rc != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001553 ctcm_ccw_check_rc(ch, rc, (char *)__func__);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001554 }
1555
Peter Tiedemann293d9842008-02-08 00:03:49 +01001556 return;
1557}
1558
1559
1560/*
1561 * helper function of mpc FSM
1562 * CTCM_PROTO_MPC only
1563 * mpc_action_rcvd_xid7
1564*/
1565static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1566{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001567 struct channel *ch = mpcginfo->ch;
1568 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001569 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001570 struct mpc_group *grp = priv->mpcg;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001571 struct xid2 *xid = mpcginfo->xid;
1572 int rc = 0;
1573 __u64 our_id = 0;
1574 __u64 their_id = 0;
1575 int len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001576
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001577 CTCM_PR_DEBUG("Enter %s: xid=%p\n", __func__, xid);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001578
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001579 if (xid == NULL) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001580 rc = 1;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001581 /* XID REJECTED: xid == NULL */
1582 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1583 "%s(%s): xid = NULL",
1584 CTCM_FUNTAIL, ch->id);
1585 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001586 }
1587
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001588 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001589
1590 /*the received direction should be the opposite of ours */
1591 if (((CHANNEL_DIRECTION(ch->flags) == READ) ? XID2_WRITE_SIDE :
1592 XID2_READ_SIDE) != xid->xid2_dlc_type) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001593 rc = 2;
1594 /* XID REJECTED: r/w channel pairing mismatch */
1595 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1596 "%s(%s): r/w channel pairing mismatch",
1597 CTCM_FUNTAIL, ch->id);
1598 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001599 }
1600
1601 if (xid->xid2_dlc_type == XID2_READ_SIDE) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001602 CTCM_PR_DEBUG("%s: grpmaxbuf:%d xid2buflen:%d\n", __func__,
1603 grp->group_max_buflen, xid->xid2_buf_len);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001604
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001605 if (grp->group_max_buflen == 0 || grp->group_max_buflen >
1606 xid->xid2_buf_len - len)
Peter Tiedemann293d9842008-02-08 00:03:49 +01001607 grp->group_max_buflen = xid->xid2_buf_len - len;
1608 }
1609
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001610 if (grp->saved_xid2 == NULL) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001611 grp->saved_xid2 =
1612 (struct xid2 *)skb_tail_pointer(grp->rcvd_xid_skb);
1613
1614 memcpy(skb_put(grp->rcvd_xid_skb,
1615 XID2_LENGTH), xid, XID2_LENGTH);
1616 grp->rcvd_xid_skb->data = grp->rcvd_xid_data;
1617
1618 skb_reset_tail_pointer(grp->rcvd_xid_skb);
1619 grp->rcvd_xid_skb->len = 0;
1620
1621 /* convert two 32 bit numbers into 1 64 bit for id compare */
1622 our_id = (__u64)priv->xid->xid2_adj_id;
1623 our_id = our_id << 32;
1624 our_id = our_id + priv->xid->xid2_sender_id;
1625 their_id = (__u64)xid->xid2_adj_id;
1626 their_id = their_id << 32;
1627 their_id = their_id + xid->xid2_sender_id;
1628 /* lower id assume the xside role */
1629 if (our_id < their_id) {
1630 grp->roll = XSIDE;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001631 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1632 "%s(%s): WE HAVE LOW ID - TAKE XSIDE",
1633 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001634 } else {
1635 grp->roll = YSIDE;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001636 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_NOTICE,
1637 "%s(%s): WE HAVE HIGH ID - TAKE YSIDE",
1638 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001639 }
1640
1641 } else {
1642 if (xid->xid2_flag4 != grp->saved_xid2->xid2_flag4) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001643 rc = 3;
1644 /* XID REJECTED: xid flag byte4 mismatch */
1645 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1646 "%s(%s): xid flag byte4 mismatch",
1647 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001648 }
1649 if (xid->xid2_flag2 == 0x40) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001650 rc = 4;
1651 /* XID REJECTED - xid NOGOOD */
1652 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1653 "%s(%s): xid NOGOOD",
1654 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001655 }
1656 if (xid->xid2_adj_id != grp->saved_xid2->xid2_adj_id) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001657 rc = 5;
1658 /* XID REJECTED - Adjacent Station ID Mismatch */
1659 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1660 "%s(%s): Adjacent Station ID Mismatch",
1661 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001662 }
1663 if (xid->xid2_sender_id != grp->saved_xid2->xid2_sender_id) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001664 rc = 6;
1665 /* XID REJECTED - Sender Address Mismatch */
1666 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1667 "%s(%s): Sender Address Mismatch",
1668 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001669 }
1670 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001671done:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001672 if (rc) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001673 dev_warn(&dev->dev,
1674 "The XID used in the MPC protocol is not valid, "
1675 "rc = %d\n", rc);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001676 priv->xid->xid2_flag2 = 0x40;
1677 grp->saved_xid2->xid2_flag2 = 0x40;
1678 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001679
Peter Tiedemann293d9842008-02-08 00:03:49 +01001680 return rc;
1681}
1682
1683/*
1684 * MPC Group Station FSM action
1685 * CTCM_PROTO_MPC only
1686 */
1687static void mpc_action_side_xid(fsm_instance *fsm, void *arg, int side)
1688{
1689 struct channel *ch = arg;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001690 int rc = 0;
1691 int gotlock = 0;
1692 unsigned long saveflags = 0; /* avoids compiler warning with
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001693 spin_unlock_irqrestore */
Peter Tiedemann293d9842008-02-08 00:03:49 +01001694
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001695 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1696 __func__, smp_processor_id(), ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001697
1698 if (ctcm_checkalloc_buffer(ch))
1699 goto done;
1700
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001701 /*
1702 * skb data-buffer referencing:
1703 */
Peter Tiedemann293d9842008-02-08 00:03:49 +01001704 ch->trans_skb->data = ch->trans_skb_data;
1705 skb_reset_tail_pointer(ch->trans_skb);
1706 ch->trans_skb->len = 0;
1707 /* result of the previous 3 statements is NOT always
1708 * already set after ctcm_checkalloc_buffer
1709 * because of possible reuse of the trans_skb
1710 */
1711 memset(ch->trans_skb->data, 0, 16);
1712 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1713 /* check is main purpose here: */
1714 skb_put(ch->trans_skb, TH_HEADER_LENGTH);
1715 ch->rcvd_xid = (struct xid2 *)skb_tail_pointer(ch->trans_skb);
1716 /* check is main purpose here: */
1717 skb_put(ch->trans_skb, XID2_LENGTH);
1718 ch->rcvd_xid_id = skb_tail_pointer(ch->trans_skb);
1719 /* cleanup back to startpoint */
1720 ch->trans_skb->data = ch->trans_skb_data;
1721 skb_reset_tail_pointer(ch->trans_skb);
1722 ch->trans_skb->len = 0;
1723
1724 /* non-checking rewrite of above skb data-buffer referencing: */
1725 /*
1726 memset(ch->trans_skb->data, 0, 16);
1727 ch->rcvd_xid_th = (struct th_header *)ch->trans_skb_data;
1728 ch->rcvd_xid = (struct xid2 *)(ch->trans_skb_data + TH_HEADER_LENGTH);
1729 ch->rcvd_xid_id = ch->trans_skb_data + TH_HEADER_LENGTH + XID2_LENGTH;
1730 */
1731
1732 ch->ccw[8].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1733 ch->ccw[8].count = 0;
1734 ch->ccw[8].cda = 0x00;
1735
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001736 if (!(ch->xid_th && ch->xid && ch->xid_id))
1737 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_INFO,
1738 "%s(%s): xid_th=%p, xid=%p, xid_id=%p",
1739 CTCM_FUNTAIL, ch->id, ch->xid_th, ch->xid, ch->xid_id);
1740
Peter Tiedemann293d9842008-02-08 00:03:49 +01001741 if (side == XSIDE) {
1742 /* mpc_action_xside_xid */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001743 if (ch->xid_th == NULL)
1744 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001745 ch->ccw[9].cmd_code = CCW_CMD_WRITE;
1746 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1747 ch->ccw[9].count = TH_HEADER_LENGTH;
1748 ch->ccw[9].cda = virt_to_phys(ch->xid_th);
1749
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001750 if (ch->xid == NULL)
1751 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001752 ch->ccw[10].cmd_code = CCW_CMD_WRITE;
1753 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1754 ch->ccw[10].count = XID2_LENGTH;
1755 ch->ccw[10].cda = virt_to_phys(ch->xid);
1756
1757 ch->ccw[11].cmd_code = CCW_CMD_READ;
1758 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1759 ch->ccw[11].count = TH_HEADER_LENGTH;
1760 ch->ccw[11].cda = virt_to_phys(ch->rcvd_xid_th);
1761
1762 ch->ccw[12].cmd_code = CCW_CMD_READ;
1763 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1764 ch->ccw[12].count = XID2_LENGTH;
1765 ch->ccw[12].cda = virt_to_phys(ch->rcvd_xid);
1766
1767 ch->ccw[13].cmd_code = CCW_CMD_READ;
1768 ch->ccw[13].cda = virt_to_phys(ch->rcvd_xid_id);
1769
1770 } else { /* side == YSIDE : mpc_action_yside_xid */
1771 ch->ccw[9].cmd_code = CCW_CMD_READ;
1772 ch->ccw[9].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1773 ch->ccw[9].count = TH_HEADER_LENGTH;
1774 ch->ccw[9].cda = virt_to_phys(ch->rcvd_xid_th);
1775
1776 ch->ccw[10].cmd_code = CCW_CMD_READ;
1777 ch->ccw[10].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1778 ch->ccw[10].count = XID2_LENGTH;
1779 ch->ccw[10].cda = virt_to_phys(ch->rcvd_xid);
1780
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001781 if (ch->xid_th == NULL)
1782 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001783 ch->ccw[11].cmd_code = CCW_CMD_WRITE;
1784 ch->ccw[11].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1785 ch->ccw[11].count = TH_HEADER_LENGTH;
1786 ch->ccw[11].cda = virt_to_phys(ch->xid_th);
1787
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001788 if (ch->xid == NULL)
1789 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001790 ch->ccw[12].cmd_code = CCW_CMD_WRITE;
1791 ch->ccw[12].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1792 ch->ccw[12].count = XID2_LENGTH;
1793 ch->ccw[12].cda = virt_to_phys(ch->xid);
1794
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001795 if (ch->xid_id == NULL)
1796 goto done;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001797 ch->ccw[13].cmd_code = CCW_CMD_WRITE;
1798 ch->ccw[13].cda = virt_to_phys(ch->xid_id);
1799
1800 }
1801 ch->ccw[13].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1802 ch->ccw[13].count = 4;
1803
1804 ch->ccw[14].cmd_code = CCW_CMD_NOOP;
1805 ch->ccw[14].flags = CCW_FLAG_SLI;
1806 ch->ccw[14].count = 0;
1807 ch->ccw[14].cda = 0;
1808
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001809 CTCM_CCW_DUMP((char *)&ch->ccw[8], sizeof(struct ccw1) * 7);
1810 CTCM_D3_DUMP((char *)ch->xid_th, TH_HEADER_LENGTH);
1811 CTCM_D3_DUMP((char *)ch->xid, XID2_LENGTH);
1812 CTCM_D3_DUMP((char *)ch->xid_id, 4);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001813
Peter Tiedemann293d9842008-02-08 00:03:49 +01001814 if (!in_irq()) {
1815 /* Such conditional locking is a known problem for
1816 * sparse because its static undeterministic.
1817 * Warnings should be ignored here. */
1818 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
1819 gotlock = 1;
1820 }
1821
1822 fsm_addtimer(&ch->timer, 5000 , CTC_EVENT_TIMER, ch);
1823 rc = ccw_device_start(ch->cdev, &ch->ccw[8],
1824 (unsigned long)ch, 0xff, 0);
1825
1826 if (gotlock) /* see remark above about conditional locking */
1827 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
1828
1829 if (rc != 0) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001830 ctcm_ccw_check_rc(ch, rc,
1831 (side == XSIDE) ? "x-side XID" : "y-side XID");
1832 }
1833
1834done:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001835 CTCM_PR_DEBUG("Exit %s: ch=0x%p id=%s\n",
1836 __func__, ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001837 return;
1838
1839}
1840
1841/*
1842 * MPC Group Station FSM action
1843 * CTCM_PROTO_MPC only
1844 */
1845static void mpc_action_xside_xid(fsm_instance *fsm, int event, void *arg)
1846{
1847 mpc_action_side_xid(fsm, arg, XSIDE);
1848}
1849
1850/*
1851 * MPC Group Station FSM action
1852 * CTCM_PROTO_MPC only
1853 */
1854static void mpc_action_yside_xid(fsm_instance *fsm, int event, void *arg)
1855{
1856 mpc_action_side_xid(fsm, arg, YSIDE);
1857}
1858
1859/*
1860 * MPC Group Station FSM action
1861 * CTCM_PROTO_MPC only
1862 */
1863static void mpc_action_doxid0(fsm_instance *fsm, int event, void *arg)
1864{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001865 struct channel *ch = arg;
1866 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001867 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001868 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001869
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001870 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
1871 __func__, smp_processor_id(), ch, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001872
1873 if (ch->xid == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001874 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1875 "%s(%s): ch->xid == NULL",
1876 CTCM_FUNTAIL, dev->name);
1877 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001878 }
1879
1880 fsm_newstate(ch->fsm, CH_XID0_INPROGRESS);
1881
1882 ch->xid->xid2_option = XID2_0;
1883
1884 switch (fsm_getstate(grp->fsm)) {
1885 case MPCG_STATE_XID2INITW:
1886 case MPCG_STATE_XID2INITX:
1887 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1888 break;
1889 case MPCG_STATE_XID0IOWAIT:
1890 case MPCG_STATE_XID0IOWAIX:
1891 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1892 break;
1893 }
1894
1895 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1896
Peter Tiedemann293d9842008-02-08 00:03:49 +01001897 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001898}
1899
1900/*
1901 * MPC Group Station FSM action
1902 * CTCM_PROTO_MPC only
1903*/
1904static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1905{
1906 struct net_device *dev = arg;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001907 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001908 struct mpc_group *grp = NULL;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001909 int direction;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001910 int send = 0;
1911
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001912 if (priv)
1913 grp = priv->mpcg;
Joel A. Fowlere2fc8cb2009-03-24 03:27:49 +00001914 if (grp == NULL)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001915 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001916
1917 for (direction = READ; direction <= WRITE; direction++) {
1918 struct channel *ch = priv->channel[direction];
1919 struct xid2 *thisxid = ch->xid;
1920 ch->xid_skb->data = ch->xid_skb_data;
1921 skb_reset_tail_pointer(ch->xid_skb);
1922 ch->xid_skb->len = 0;
1923 thisxid->xid2_option = XID2_7;
1924 send = 0;
1925
1926 /* xid7 phase 1 */
1927 if (grp->outstanding_xid7_p2 > 0) {
1928 if (grp->roll == YSIDE) {
1929 if (fsm_getstate(ch->fsm) == CH_XID7_PENDING1) {
1930 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1931 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1932 memcpy(skb_put(ch->xid_skb,
1933 TH_HEADER_LENGTH),
1934 &thdummy, TH_HEADER_LENGTH);
1935 send = 1;
1936 }
1937 } else if (fsm_getstate(ch->fsm) < CH_XID7_PENDING2) {
1938 fsm_newstate(ch->fsm, CH_XID7_PENDING2);
1939 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1940 memcpy(skb_put(ch->xid_skb,
1941 TH_HEADER_LENGTH),
1942 &thnorm, TH_HEADER_LENGTH);
1943 send = 1;
1944 }
1945 } else {
1946 /* xid7 phase 2 */
1947 if (grp->roll == YSIDE) {
1948 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING4) {
1949 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1950 memcpy(skb_put(ch->xid_skb,
1951 TH_HEADER_LENGTH),
1952 &thnorm, TH_HEADER_LENGTH);
1953 ch->ccw[8].cmd_code = CCW_CMD_WRITE_CTL;
1954 send = 1;
1955 }
1956 } else if (fsm_getstate(ch->fsm) == CH_XID7_PENDING3) {
1957 fsm_newstate(ch->fsm, CH_XID7_PENDING4);
1958 ch->ccw[8].cmd_code = CCW_CMD_SENSE_CMD;
1959 memcpy(skb_put(ch->xid_skb, TH_HEADER_LENGTH),
1960 &thdummy, TH_HEADER_LENGTH);
1961 send = 1;
1962 }
1963 }
1964
1965 if (send)
1966 fsm_event(grp->fsm, MPCG_EVENT_DOIO, ch);
1967 }
1968
Peter Tiedemann293d9842008-02-08 00:03:49 +01001969 return;
1970}
1971
1972/*
1973 * MPC Group Station FSM action
1974 * CTCM_PROTO_MPC only
1975 */
1976static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
1977{
1978
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001979 struct mpcg_info *mpcginfo = arg;
1980 struct channel *ch = mpcginfo->ch;
1981 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02001982 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001983 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001984
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001985 CTCM_PR_DEBUG("%s: ch-id:%s xid2:%i xid7:%i xidt_p2:%i \n",
1986 __func__, ch->id, grp->outstanding_xid2,
1987 grp->outstanding_xid7, grp->outstanding_xid7_p2);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001988
1989 if (fsm_getstate(ch->fsm) < CH_XID7_PENDING)
1990 fsm_newstate(ch->fsm, CH_XID7_PENDING);
1991
1992 grp->outstanding_xid2--;
1993 grp->outstanding_xid7++;
1994 grp->outstanding_xid7_p2++;
1995
1996 /* must change state before validating xid to */
1997 /* properly handle interim interrupts received*/
1998 switch (fsm_getstate(grp->fsm)) {
1999 case MPCG_STATE_XID2INITW:
2000 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITX);
2001 mpc_validate_xid(mpcginfo);
2002 break;
2003 case MPCG_STATE_XID0IOWAIT:
2004 fsm_newstate(grp->fsm, MPCG_STATE_XID0IOWAIX);
2005 mpc_validate_xid(mpcginfo);
2006 break;
2007 case MPCG_STATE_XID2INITX:
2008 if (grp->outstanding_xid2 == 0) {
2009 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITW);
2010 mpc_validate_xid(mpcginfo);
2011 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2012 }
2013 break;
2014 case MPCG_STATE_XID0IOWAIX:
2015 if (grp->outstanding_xid2 == 0) {
2016 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITI);
2017 mpc_validate_xid(mpcginfo);
2018 fsm_event(grp->fsm, MPCG_EVENT_XID2DONE, dev);
2019 }
2020 break;
2021 }
2022 kfree(mpcginfo);
2023
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002024 CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
2025 __func__, ch->id, grp->outstanding_xid2,
2026 grp->outstanding_xid7, grp->outstanding_xid7_p2);
2027 CTCM_PR_DEBUG("ctcmpc:%s() %s grpstate: %s chanstate: %s \n",
2028 __func__, ch->id,
2029 fsm_getstate_str(grp->fsm), fsm_getstate_str(ch->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +01002030 return;
2031
2032}
2033
2034
2035/*
2036 * MPC Group Station FSM action
2037 * CTCM_PROTO_MPC only
2038 */
2039static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
2040{
2041 struct mpcg_info *mpcginfo = arg;
2042 struct channel *ch = mpcginfo->ch;
2043 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +02002044 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002045 struct mpc_group *grp = priv->mpcg;
2046
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002047 CTCM_PR_DEBUG("Enter %s: cp=%i ch=0x%p id=%s\n",
2048 __func__, smp_processor_id(), ch, ch->id);
2049 CTCM_PR_DEBUG("%s: outstanding_xid7: %i, outstanding_xid7_p2: %i\n",
2050 __func__, grp->outstanding_xid7, grp->outstanding_xid7_p2);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002051
2052 grp->outstanding_xid7--;
2053 ch->xid_skb->data = ch->xid_skb_data;
2054 skb_reset_tail_pointer(ch->xid_skb);
2055 ch->xid_skb->len = 0;
2056
2057 switch (fsm_getstate(grp->fsm)) {
2058 case MPCG_STATE_XID7INITI:
2059 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITZ);
2060 mpc_validate_xid(mpcginfo);
2061 break;
2062 case MPCG_STATE_XID7INITW:
2063 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITX);
2064 mpc_validate_xid(mpcginfo);
2065 break;
2066 case MPCG_STATE_XID7INITZ:
2067 case MPCG_STATE_XID7INITX:
2068 if (grp->outstanding_xid7 == 0) {
2069 if (grp->outstanding_xid7_p2 > 0) {
2070 grp->outstanding_xid7 =
2071 grp->outstanding_xid7_p2;
2072 grp->outstanding_xid7_p2 = 0;
2073 } else
2074 fsm_newstate(grp->fsm, MPCG_STATE_XID7INITF);
2075
2076 mpc_validate_xid(mpcginfo);
2077 fsm_event(grp->fsm, MPCG_EVENT_XID7DONE, dev);
2078 break;
2079 }
2080 mpc_validate_xid(mpcginfo);
2081 break;
2082 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01002083 kfree(mpcginfo);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002084 return;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002085}
2086
2087/*
2088 * mpc_action helper of an MPC Group Station FSM action
2089 * CTCM_PROTO_MPC only
2090 */
2091static int mpc_send_qllc_discontact(struct net_device *dev)
2092{
Peter Tiedemann293d9842008-02-08 00:03:49 +01002093 __u32 new_len = 0;
2094 struct sk_buff *skb;
2095 struct qllc *qllcptr;
Peter Tiedemann261893d2008-08-21 17:10:24 +02002096 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002097 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002098
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002099 CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
2100 __func__, mpcg_state_names[grp->saved_state]);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002101
2102 switch (grp->saved_state) {
2103 /*
2104 * establish conn callback function is
2105 * preferred method to report failure
2106 */
2107 case MPCG_STATE_XID0IOWAIT:
2108 case MPCG_STATE_XID0IOWAIX:
2109 case MPCG_STATE_XID7INITI:
2110 case MPCG_STATE_XID7INITZ:
2111 case MPCG_STATE_XID2INITW:
2112 case MPCG_STATE_XID2INITX:
2113 case MPCG_STATE_XID7INITW:
2114 case MPCG_STATE_XID7INITX:
2115 if (grp->estconnfunc) {
2116 grp->estconnfunc(grp->port_num, -1, 0);
2117 grp->estconnfunc = NULL;
2118 break;
2119 }
2120 case MPCG_STATE_FLOWC:
2121 case MPCG_STATE_READY:
2122 grp->send_qllc_disc = 2;
2123 new_len = sizeof(struct qllc);
2124 qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
2125 if (qllcptr == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002126 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2127 "%s(%s): qllcptr allocation error",
2128 CTCM_FUNTAIL, dev->name);
2129 return -ENOMEM;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002130 }
2131
2132 qllcptr->qllc_address = 0xcc;
2133 qllcptr->qllc_commands = 0x03;
2134
2135 skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
2136
2137 if (skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002138 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2139 "%s(%s): skb allocation error",
2140 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002141 priv->stats.rx_dropped++;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002142 kfree(qllcptr);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002143 return -ENOMEM;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002144 }
2145
2146 memcpy(skb_put(skb, new_len), qllcptr, new_len);
2147 kfree(qllcptr);
2148
2149 if (skb_headroom(skb) < 4) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002150 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
2151 "%s(%s): skb_headroom error",
2152 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002153 dev_kfree_skb_any(skb);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002154 return -ENOMEM;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002155 }
2156
2157 *((__u32 *)skb_push(skb, 4)) = priv->channel[READ]->pdu_seq;
2158 priv->channel[READ]->pdu_seq++;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002159 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2160 __func__, priv->channel[READ]->pdu_seq);
Peter Tiedemann293d9842008-02-08 00:03:49 +01002161
2162 /* receipt of CC03 resets anticipated sequence number on
2163 receiving side */
2164 priv->channel[READ]->pdu_seq = 0x00;
2165 skb_reset_mac_header(skb);
2166 skb->dev = dev;
2167 skb->protocol = htons(ETH_P_SNAP);
2168 skb->ip_summed = CHECKSUM_UNNECESSARY;
2169
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002170 CTCM_D3_DUMP(skb->data, (sizeof(struct qllc) + 4));
Peter Tiedemann293d9842008-02-08 00:03:49 +01002171
2172 netif_rx(skb);
2173 break;
2174 default:
2175 break;
2176
2177 }
2178
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02002179 return 0;
Peter Tiedemann293d9842008-02-08 00:03:49 +01002180}
2181/* --- This is the END my friend --- */
2182