ctcm_mpc.c 59 KB

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