ctcm_main.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. /*
  2. * drivers/s390/net/ctcm_main.c
  3. *
  4. * Copyright IBM Corp. 2001, 2007
  5. * Author(s):
  6. * Original CTC driver(s):
  7. * Fritz Elfert (felfert@millenux.com)
  8. * Dieter Wellerdiek (wel@de.ibm.com)
  9. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  10. * Denis Joseph Barrow (barrow_dj@yahoo.com)
  11. * Jochen Roehrig (roehrig@de.ibm.com)
  12. * Cornelia Huck <cornelia.huck@de.ibm.com>
  13. * MPC additions:
  14. * Belinda Thompson (belindat@us.ibm.com)
  15. * Andy Richter (richtera@us.ibm.com)
  16. * Revived by:
  17. * Peter Tiedemann (ptiedem@de.ibm.com)
  18. */
  19. #undef DEBUG
  20. #undef DEBUGDATA
  21. #undef DEBUGCCW
  22. #define KMSG_COMPONENT "ctcm"
  23. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/errno.h>
  29. #include <linux/types.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/timer.h>
  32. #include <linux/bitops.h>
  33. #include <linux/signal.h>
  34. #include <linux/string.h>
  35. #include <linux/ip.h>
  36. #include <linux/if_arp.h>
  37. #include <linux/tcp.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/ctype.h>
  40. #include <net/dst.h>
  41. #include <linux/io.h>
  42. #include <asm/ccwdev.h>
  43. #include <asm/ccwgroup.h>
  44. #include <linux/uaccess.h>
  45. #include <asm/idals.h>
  46. #include "cu3088.h"
  47. #include "ctcm_fsms.h"
  48. #include "ctcm_main.h"
  49. /* Some common global variables */
  50. /*
  51. * Linked list of all detected channels.
  52. */
  53. struct channel *channels;
  54. /**
  55. * Unpack a just received skb and hand it over to
  56. * upper layers.
  57. *
  58. * ch The channel where this skb has been received.
  59. * pskb The received skb.
  60. */
  61. void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb)
  62. {
  63. struct net_device *dev = ch->netdev;
  64. struct ctcm_priv *priv = dev->ml_priv;
  65. __u16 len = *((__u16 *) pskb->data);
  66. skb_put(pskb, 2 + LL_HEADER_LENGTH);
  67. skb_pull(pskb, 2);
  68. pskb->dev = dev;
  69. pskb->ip_summed = CHECKSUM_UNNECESSARY;
  70. while (len > 0) {
  71. struct sk_buff *skb;
  72. int skblen;
  73. struct ll_header *header = (struct ll_header *)pskb->data;
  74. skb_pull(pskb, LL_HEADER_LENGTH);
  75. if ((ch->protocol == CTCM_PROTO_S390) &&
  76. (header->type != ETH_P_IP)) {
  77. if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
  78. ch->logflags |= LOG_FLAG_ILLEGALPKT;
  79. /*
  80. * Check packet type only if we stick strictly
  81. * to S/390's protocol of OS390. This only
  82. * supports IP. Otherwise allow any packet
  83. * type.
  84. */
  85. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  86. "%s(%s): Illegal packet type 0x%04x"
  87. " - dropping",
  88. CTCM_FUNTAIL, dev->name, header->type);
  89. }
  90. priv->stats.rx_dropped++;
  91. priv->stats.rx_frame_errors++;
  92. return;
  93. }
  94. pskb->protocol = ntohs(header->type);
  95. if ((header->length <= LL_HEADER_LENGTH) ||
  96. (len <= LL_HEADER_LENGTH)) {
  97. if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
  98. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  99. "%s(%s): Illegal packet size %d(%d,%d)"
  100. "- dropping",
  101. CTCM_FUNTAIL, dev->name,
  102. header->length, dev->mtu, len);
  103. ch->logflags |= LOG_FLAG_ILLEGALSIZE;
  104. }
  105. priv->stats.rx_dropped++;
  106. priv->stats.rx_length_errors++;
  107. return;
  108. }
  109. header->length -= LL_HEADER_LENGTH;
  110. len -= LL_HEADER_LENGTH;
  111. if ((header->length > skb_tailroom(pskb)) ||
  112. (header->length > len)) {
  113. if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
  114. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  115. "%s(%s): Packet size %d (overrun)"
  116. " - dropping", CTCM_FUNTAIL,
  117. dev->name, header->length);
  118. ch->logflags |= LOG_FLAG_OVERRUN;
  119. }
  120. priv->stats.rx_dropped++;
  121. priv->stats.rx_length_errors++;
  122. return;
  123. }
  124. skb_put(pskb, header->length);
  125. skb_reset_mac_header(pskb);
  126. len -= header->length;
  127. skb = dev_alloc_skb(pskb->len);
  128. if (!skb) {
  129. if (!(ch->logflags & LOG_FLAG_NOMEM)) {
  130. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  131. "%s(%s): MEMORY allocation error",
  132. CTCM_FUNTAIL, dev->name);
  133. ch->logflags |= LOG_FLAG_NOMEM;
  134. }
  135. priv->stats.rx_dropped++;
  136. return;
  137. }
  138. skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
  139. pskb->len);
  140. skb_reset_mac_header(skb);
  141. skb->dev = pskb->dev;
  142. skb->protocol = pskb->protocol;
  143. pskb->ip_summed = CHECKSUM_UNNECESSARY;
  144. skblen = skb->len;
  145. /*
  146. * reset logflags
  147. */
  148. ch->logflags = 0;
  149. priv->stats.rx_packets++;
  150. priv->stats.rx_bytes += skblen;
  151. netif_rx_ni(skb);
  152. dev->last_rx = jiffies;
  153. if (len > 0) {
  154. skb_pull(pskb, header->length);
  155. if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
  156. if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
  157. CTCM_DBF_DEV_NAME(TRACE, dev,
  158. "Overrun in ctcm_unpack_skb");
  159. ch->logflags |= LOG_FLAG_OVERRUN;
  160. }
  161. return;
  162. }
  163. skb_put(pskb, LL_HEADER_LENGTH);
  164. }
  165. }
  166. }
  167. /**
  168. * Release a specific channel in the channel list.
  169. *
  170. * ch Pointer to channel struct to be released.
  171. */
  172. static void channel_free(struct channel *ch)
  173. {
  174. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id);
  175. ch->flags &= ~CHANNEL_FLAGS_INUSE;
  176. fsm_newstate(ch->fsm, CTC_STATE_IDLE);
  177. }
  178. /**
  179. * Remove a specific channel in the channel list.
  180. *
  181. * ch Pointer to channel struct to be released.
  182. */
  183. static void channel_remove(struct channel *ch)
  184. {
  185. struct channel **c = &channels;
  186. char chid[CTCM_ID_SIZE+1];
  187. int ok = 0;
  188. if (ch == NULL)
  189. return;
  190. else
  191. strncpy(chid, ch->id, CTCM_ID_SIZE);
  192. channel_free(ch);
  193. while (*c) {
  194. if (*c == ch) {
  195. *c = ch->next;
  196. fsm_deltimer(&ch->timer);
  197. if (IS_MPC(ch))
  198. fsm_deltimer(&ch->sweep_timer);
  199. kfree_fsm(ch->fsm);
  200. clear_normalized_cda(&ch->ccw[4]);
  201. if (ch->trans_skb != NULL) {
  202. clear_normalized_cda(&ch->ccw[1]);
  203. dev_kfree_skb_any(ch->trans_skb);
  204. }
  205. if (IS_MPC(ch)) {
  206. tasklet_kill(&ch->ch_tasklet);
  207. tasklet_kill(&ch->ch_disc_tasklet);
  208. kfree(ch->discontact_th);
  209. }
  210. kfree(ch->ccw);
  211. kfree(ch->irb);
  212. kfree(ch);
  213. ok = 1;
  214. break;
  215. }
  216. c = &((*c)->next);
  217. }
  218. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
  219. chid, ok ? "OK" : "failed");
  220. }
  221. /**
  222. * Get a specific channel from the channel list.
  223. *
  224. * type Type of channel we are interested in.
  225. * id Id of channel we are interested in.
  226. * direction Direction we want to use this channel for.
  227. *
  228. * returns Pointer to a channel or NULL if no matching channel available.
  229. */
  230. static struct channel *channel_get(enum channel_types type,
  231. char *id, int direction)
  232. {
  233. struct channel *ch = channels;
  234. while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
  235. ch = ch->next;
  236. if (!ch) {
  237. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  238. "%s(%d, %s, %d) not found in channel list\n",
  239. CTCM_FUNTAIL, type, id, direction);
  240. } else {
  241. if (ch->flags & CHANNEL_FLAGS_INUSE)
  242. ch = NULL;
  243. else {
  244. ch->flags |= CHANNEL_FLAGS_INUSE;
  245. ch->flags &= ~CHANNEL_FLAGS_RWMASK;
  246. ch->flags |= (direction == WRITE)
  247. ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
  248. fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
  249. }
  250. }
  251. return ch;
  252. }
  253. static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
  254. {
  255. if (!IS_ERR(irb))
  256. return 0;
  257. CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN,
  258. "irb error %ld on device %s\n",
  259. PTR_ERR(irb), dev_name(&cdev->dev));
  260. switch (PTR_ERR(irb)) {
  261. case -EIO:
  262. dev_err(&cdev->dev,
  263. "An I/O-error occurred on the CTCM device\n");
  264. break;
  265. case -ETIMEDOUT:
  266. dev_err(&cdev->dev,
  267. "An adapter hardware operation timed out\n");
  268. break;
  269. default:
  270. dev_err(&cdev->dev,
  271. "An error occurred on the adapter hardware\n");
  272. }
  273. return PTR_ERR(irb);
  274. }
  275. /**
  276. * Check sense of a unit check.
  277. *
  278. * ch The channel, the sense code belongs to.
  279. * sense The sense code to inspect.
  280. */
  281. static inline void ccw_unit_check(struct channel *ch, __u8 sense)
  282. {
  283. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  284. "%s(%s): %02x",
  285. CTCM_FUNTAIL, ch->id, sense);
  286. if (sense & SNS0_INTERVENTION_REQ) {
  287. if (sense & 0x01) {
  288. if (ch->sense_rc != 0x01) {
  289. pr_notice(
  290. "%s: The communication peer has "
  291. "disconnected\n", ch->id);
  292. ch->sense_rc = 0x01;
  293. }
  294. fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
  295. } else {
  296. if (ch->sense_rc != SNS0_INTERVENTION_REQ) {
  297. pr_notice(
  298. "%s: The remote operating system is "
  299. "not available\n", ch->id);
  300. ch->sense_rc = SNS0_INTERVENTION_REQ;
  301. }
  302. fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
  303. }
  304. } else if (sense & SNS0_EQUIPMENT_CHECK) {
  305. if (sense & SNS0_BUS_OUT_CHECK) {
  306. if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
  307. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  308. "%s(%s): remote HW error %02x",
  309. CTCM_FUNTAIL, ch->id, sense);
  310. ch->sense_rc = SNS0_BUS_OUT_CHECK;
  311. }
  312. fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
  313. } else {
  314. if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) {
  315. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  316. "%s(%s): remote read parity error %02x",
  317. CTCM_FUNTAIL, ch->id, sense);
  318. ch->sense_rc = SNS0_EQUIPMENT_CHECK;
  319. }
  320. fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
  321. }
  322. } else if (sense & SNS0_BUS_OUT_CHECK) {
  323. if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
  324. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  325. "%s(%s): BUS OUT error %02x",
  326. CTCM_FUNTAIL, ch->id, sense);
  327. ch->sense_rc = SNS0_BUS_OUT_CHECK;
  328. }
  329. if (sense & 0x04) /* data-streaming timeout */
  330. fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
  331. else /* Data-transfer parity error */
  332. fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
  333. } else if (sense & SNS0_CMD_REJECT) {
  334. if (ch->sense_rc != SNS0_CMD_REJECT) {
  335. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  336. "%s(%s): Command rejected",
  337. CTCM_FUNTAIL, ch->id);
  338. ch->sense_rc = SNS0_CMD_REJECT;
  339. }
  340. } else if (sense == 0) {
  341. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  342. "%s(%s): Unit check ZERO",
  343. CTCM_FUNTAIL, ch->id);
  344. fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
  345. } else {
  346. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  347. "%s(%s): Unit check code %02x unknown",
  348. CTCM_FUNTAIL, ch->id, sense);
  349. fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
  350. }
  351. }
  352. int ctcm_ch_alloc_buffer(struct channel *ch)
  353. {
  354. clear_normalized_cda(&ch->ccw[1]);
  355. ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
  356. if (ch->trans_skb == NULL) {
  357. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  358. "%s(%s): %s trans_skb allocation error",
  359. CTCM_FUNTAIL, ch->id,
  360. (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
  361. return -ENOMEM;
  362. }
  363. ch->ccw[1].count = ch->max_bufsize;
  364. if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
  365. dev_kfree_skb(ch->trans_skb);
  366. ch->trans_skb = NULL;
  367. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  368. "%s(%s): %s set norm_cda failed",
  369. CTCM_FUNTAIL, ch->id,
  370. (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
  371. return -ENOMEM;
  372. }
  373. ch->ccw[1].count = 0;
  374. ch->trans_skb_data = ch->trans_skb->data;
  375. ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
  376. return 0;
  377. }
  378. /*
  379. * Interface API for upper network layers
  380. */
  381. /**
  382. * Open an interface.
  383. * Called from generic network layer when ifconfig up is run.
  384. *
  385. * dev Pointer to interface struct.
  386. *
  387. * returns 0 on success, -ERRNO on failure. (Never fails.)
  388. */
  389. int ctcm_open(struct net_device *dev)
  390. {
  391. struct ctcm_priv *priv = dev->ml_priv;
  392. CTCMY_DBF_DEV_NAME(SETUP, dev, "");
  393. if (!IS_MPC(priv))
  394. fsm_event(priv->fsm, DEV_EVENT_START, dev);
  395. return 0;
  396. }
  397. /**
  398. * Close an interface.
  399. * Called from generic network layer when ifconfig down is run.
  400. *
  401. * dev Pointer to interface struct.
  402. *
  403. * returns 0 on success, -ERRNO on failure. (Never fails.)
  404. */
  405. int ctcm_close(struct net_device *dev)
  406. {
  407. struct ctcm_priv *priv = dev->ml_priv;
  408. CTCMY_DBF_DEV_NAME(SETUP, dev, "");
  409. if (!IS_MPC(priv))
  410. fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
  411. return 0;
  412. }
  413. /**
  414. * Transmit a packet.
  415. * This is a helper function for ctcm_tx().
  416. *
  417. * ch Channel to be used for sending.
  418. * skb Pointer to struct sk_buff of packet to send.
  419. * The linklevel header has already been set up
  420. * by ctcm_tx().
  421. *
  422. * returns 0 on success, -ERRNO on failure. (Never fails.)
  423. */
  424. static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
  425. {
  426. unsigned long saveflags;
  427. struct ll_header header;
  428. int rc = 0;
  429. __u16 block_len;
  430. int ccw_idx;
  431. struct sk_buff *nskb;
  432. unsigned long hi;
  433. /* we need to acquire the lock for testing the state
  434. * otherwise we can have an IRQ changing the state to
  435. * TXIDLE after the test but before acquiring the lock.
  436. */
  437. spin_lock_irqsave(&ch->collect_lock, saveflags);
  438. if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
  439. int l = skb->len + LL_HEADER_LENGTH;
  440. if (ch->collect_len + l > ch->max_bufsize - 2) {
  441. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  442. return -EBUSY;
  443. } else {
  444. atomic_inc(&skb->users);
  445. header.length = l;
  446. header.type = skb->protocol;
  447. header.unused = 0;
  448. memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
  449. LL_HEADER_LENGTH);
  450. skb_queue_tail(&ch->collect_queue, skb);
  451. ch->collect_len += l;
  452. }
  453. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  454. goto done;
  455. }
  456. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  457. /*
  458. * Protect skb against beeing free'd by upper
  459. * layers.
  460. */
  461. atomic_inc(&skb->users);
  462. ch->prof.txlen += skb->len;
  463. header.length = skb->len + LL_HEADER_LENGTH;
  464. header.type = skb->protocol;
  465. header.unused = 0;
  466. memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
  467. block_len = skb->len + 2;
  468. *((__u16 *)skb_push(skb, 2)) = block_len;
  469. /*
  470. * IDAL support in CTCM is broken, so we have to
  471. * care about skb's above 2G ourselves.
  472. */
  473. hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
  474. if (hi) {
  475. nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
  476. if (!nskb) {
  477. atomic_dec(&skb->users);
  478. skb_pull(skb, LL_HEADER_LENGTH + 2);
  479. ctcm_clear_busy(ch->netdev);
  480. return -ENOMEM;
  481. } else {
  482. memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
  483. atomic_inc(&nskb->users);
  484. atomic_dec(&skb->users);
  485. dev_kfree_skb_irq(skb);
  486. skb = nskb;
  487. }
  488. }
  489. ch->ccw[4].count = block_len;
  490. if (set_normalized_cda(&ch->ccw[4], skb->data)) {
  491. /*
  492. * idal allocation failed, try via copying to
  493. * trans_skb. trans_skb usually has a pre-allocated
  494. * idal.
  495. */
  496. if (ctcm_checkalloc_buffer(ch)) {
  497. /*
  498. * Remove our header. It gets added
  499. * again on retransmit.
  500. */
  501. atomic_dec(&skb->users);
  502. skb_pull(skb, LL_HEADER_LENGTH + 2);
  503. ctcm_clear_busy(ch->netdev);
  504. return -ENOMEM;
  505. }
  506. skb_reset_tail_pointer(ch->trans_skb);
  507. ch->trans_skb->len = 0;
  508. ch->ccw[1].count = skb->len;
  509. skb_copy_from_linear_data(skb,
  510. skb_put(ch->trans_skb, skb->len), skb->len);
  511. atomic_dec(&skb->users);
  512. dev_kfree_skb_irq(skb);
  513. ccw_idx = 0;
  514. } else {
  515. skb_queue_tail(&ch->io_queue, skb);
  516. ccw_idx = 3;
  517. }
  518. ch->retry = 0;
  519. fsm_newstate(ch->fsm, CTC_STATE_TX);
  520. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  521. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  522. ch->prof.send_stamp = current_kernel_time(); /* xtime */
  523. rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
  524. (unsigned long)ch, 0xff, 0);
  525. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  526. if (ccw_idx == 3)
  527. ch->prof.doios_single++;
  528. if (rc != 0) {
  529. fsm_deltimer(&ch->timer);
  530. ctcm_ccw_check_rc(ch, rc, "single skb TX");
  531. if (ccw_idx == 3)
  532. skb_dequeue_tail(&ch->io_queue);
  533. /*
  534. * Remove our header. It gets added
  535. * again on retransmit.
  536. */
  537. skb_pull(skb, LL_HEADER_LENGTH + 2);
  538. } else if (ccw_idx == 0) {
  539. struct net_device *dev = ch->netdev;
  540. struct ctcm_priv *priv = dev->ml_priv;
  541. priv->stats.tx_packets++;
  542. priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
  543. }
  544. done:
  545. ctcm_clear_busy(ch->netdev);
  546. return rc;
  547. }
  548. static void ctcmpc_send_sweep_req(struct channel *rch)
  549. {
  550. struct net_device *dev = rch->netdev;
  551. struct ctcm_priv *priv;
  552. struct mpc_group *grp;
  553. struct th_sweep *header;
  554. struct sk_buff *sweep_skb;
  555. struct channel *ch;
  556. /* int rc = 0; */
  557. priv = dev->ml_priv;
  558. grp = priv->mpcg;
  559. ch = priv->channel[WRITE];
  560. /* sweep processing is not complete until response and request */
  561. /* has completed for all read channels in group */
  562. if (grp->in_sweep == 0) {
  563. grp->in_sweep = 1;
  564. grp->sweep_rsp_pend_num = grp->active_channels[READ];
  565. grp->sweep_req_pend_num = grp->active_channels[READ];
  566. }
  567. sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
  568. if (sweep_skb == NULL) {
  569. /* rc = -ENOMEM; */
  570. goto nomem;
  571. }
  572. header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
  573. if (!header) {
  574. dev_kfree_skb_any(sweep_skb);
  575. /* rc = -ENOMEM; */
  576. goto nomem;
  577. }
  578. header->th.th_seg = 0x00 ;
  579. header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
  580. header->th.th_blk_flag = 0x00;
  581. header->th.th_is_xid = 0x00;
  582. header->th.th_seq_num = 0x00;
  583. header->sw.th_last_seq = ch->th_seq_num;
  584. memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
  585. kfree(header);
  586. dev->trans_start = jiffies;
  587. skb_queue_tail(&ch->sweep_queue, sweep_skb);
  588. fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
  589. return;
  590. nomem:
  591. grp->in_sweep = 0;
  592. ctcm_clear_busy(dev);
  593. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  594. return;
  595. }
  596. /*
  597. * MPC mode version of transmit_skb
  598. */
  599. static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
  600. {
  601. struct pdu *p_header;
  602. struct net_device *dev = ch->netdev;
  603. struct ctcm_priv *priv = dev->ml_priv;
  604. struct mpc_group *grp = priv->mpcg;
  605. struct th_header *header;
  606. struct sk_buff *nskb;
  607. int rc = 0;
  608. int ccw_idx;
  609. unsigned long hi;
  610. unsigned long saveflags = 0; /* avoids compiler warning */
  611. __u16 block_len;
  612. CTCM_PR_DEBUG("Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n",
  613. __func__, dev->name, smp_processor_id(), ch,
  614. ch->id, fsm_getstate_str(ch->fsm));
  615. if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
  616. spin_lock_irqsave(&ch->collect_lock, saveflags);
  617. atomic_inc(&skb->users);
  618. p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
  619. if (!p_header) {
  620. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  621. goto nomem_exit;
  622. }
  623. p_header->pdu_offset = skb->len;
  624. p_header->pdu_proto = 0x01;
  625. p_header->pdu_flag = 0x00;
  626. if (skb->protocol == ntohs(ETH_P_SNAP)) {
  627. p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
  628. } else {
  629. p_header->pdu_flag |= PDU_FIRST;
  630. }
  631. p_header->pdu_seq = 0;
  632. memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
  633. PDU_HEADER_LENGTH);
  634. CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n"
  635. "pdu header and data for up to 32 bytes:\n",
  636. __func__, dev->name, skb->len);
  637. CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
  638. skb_queue_tail(&ch->collect_queue, skb);
  639. ch->collect_len += skb->len;
  640. kfree(p_header);
  641. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  642. goto done;
  643. }
  644. /*
  645. * Protect skb against beeing free'd by upper
  646. * layers.
  647. */
  648. atomic_inc(&skb->users);
  649. block_len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
  650. /*
  651. * IDAL support in CTCM is broken, so we have to
  652. * care about skb's above 2G ourselves.
  653. */
  654. hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
  655. if (hi) {
  656. nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
  657. if (!nskb) {
  658. goto nomem_exit;
  659. } else {
  660. memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
  661. atomic_inc(&nskb->users);
  662. atomic_dec(&skb->users);
  663. dev_kfree_skb_irq(skb);
  664. skb = nskb;
  665. }
  666. }
  667. p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
  668. if (!p_header)
  669. goto nomem_exit;
  670. p_header->pdu_offset = skb->len;
  671. p_header->pdu_proto = 0x01;
  672. p_header->pdu_flag = 0x00;
  673. p_header->pdu_seq = 0;
  674. if (skb->protocol == ntohs(ETH_P_SNAP)) {
  675. p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
  676. } else {
  677. p_header->pdu_flag |= PDU_FIRST;
  678. }
  679. memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
  680. kfree(p_header);
  681. if (ch->collect_len > 0) {
  682. spin_lock_irqsave(&ch->collect_lock, saveflags);
  683. skb_queue_tail(&ch->collect_queue, skb);
  684. ch->collect_len += skb->len;
  685. skb = skb_dequeue(&ch->collect_queue);
  686. ch->collect_len -= skb->len;
  687. spin_unlock_irqrestore(&ch->collect_lock, saveflags);
  688. }
  689. p_header = (struct pdu *)skb->data;
  690. p_header->pdu_flag |= PDU_LAST;
  691. ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
  692. header = kmalloc(TH_HEADER_LENGTH, gfp_type());
  693. if (!header)
  694. goto nomem_exit;
  695. header->th_seg = 0x00;
  696. header->th_ch_flag = TH_HAS_PDU; /* Normal data */
  697. header->th_blk_flag = 0x00;
  698. header->th_is_xid = 0x00; /* Just data here */
  699. ch->th_seq_num++;
  700. header->th_seq_num = ch->th_seq_num;
  701. CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
  702. __func__, dev->name, ch->th_seq_num);
  703. /* put the TH on the packet */
  704. memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
  705. kfree(header);
  706. CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for "
  707. "up to 32 bytes sent to vtam:\n",
  708. __func__, dev->name, skb->len);
  709. CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
  710. ch->ccw[4].count = skb->len;
  711. if (set_normalized_cda(&ch->ccw[4], skb->data)) {
  712. /*
  713. * idal allocation failed, try via copying to trans_skb.
  714. * trans_skb usually has a pre-allocated idal.
  715. */
  716. if (ctcm_checkalloc_buffer(ch)) {
  717. /*
  718. * Remove our header.
  719. * It gets added again on retransmit.
  720. */
  721. goto nomem_exit;
  722. }
  723. skb_reset_tail_pointer(ch->trans_skb);
  724. ch->trans_skb->len = 0;
  725. ch->ccw[1].count = skb->len;
  726. memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
  727. atomic_dec(&skb->users);
  728. dev_kfree_skb_irq(skb);
  729. ccw_idx = 0;
  730. CTCM_PR_DBGDATA("%s(%s): trans_skb len: %04x\n"
  731. "up to 32 bytes sent to vtam:\n",
  732. __func__, dev->name, ch->trans_skb->len);
  733. CTCM_D3_DUMP((char *)ch->trans_skb->data,
  734. min_t(int, 32, ch->trans_skb->len));
  735. } else {
  736. skb_queue_tail(&ch->io_queue, skb);
  737. ccw_idx = 3;
  738. }
  739. ch->retry = 0;
  740. fsm_newstate(ch->fsm, CTC_STATE_TX);
  741. fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
  742. if (do_debug_ccw)
  743. ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
  744. sizeof(struct ccw1) * 3);
  745. spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
  746. ch->prof.send_stamp = current_kernel_time(); /* xtime */
  747. rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
  748. (unsigned long)ch, 0xff, 0);
  749. spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
  750. if (ccw_idx == 3)
  751. ch->prof.doios_single++;
  752. if (rc != 0) {
  753. fsm_deltimer(&ch->timer);
  754. ctcm_ccw_check_rc(ch, rc, "single skb TX");
  755. if (ccw_idx == 3)
  756. skb_dequeue_tail(&ch->io_queue);
  757. } else if (ccw_idx == 0) {
  758. priv->stats.tx_packets++;
  759. priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
  760. }
  761. if (ch->th_seq_num > 0xf0000000) /* Chose at random. */
  762. ctcmpc_send_sweep_req(ch);
  763. goto done;
  764. nomem_exit:
  765. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT,
  766. "%s(%s): MEMORY allocation ERROR\n",
  767. CTCM_FUNTAIL, ch->id);
  768. rc = -ENOMEM;
  769. atomic_dec(&skb->users);
  770. dev_kfree_skb_any(skb);
  771. fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
  772. done:
  773. CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name);
  774. return rc;
  775. }
  776. /**
  777. * Start transmission of a packet.
  778. * Called from generic network device layer.
  779. *
  780. * skb Pointer to buffer containing the packet.
  781. * dev Pointer to interface struct.
  782. *
  783. * returns 0 if packet consumed, !0 if packet rejected.
  784. * Note: If we return !0, then the packet is free'd by
  785. * the generic network layer.
  786. */
  787. /* first merge version - leaving both functions separated */
  788. static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
  789. {
  790. struct ctcm_priv *priv = dev->ml_priv;
  791. if (skb == NULL) {
  792. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  793. "%s(%s): NULL sk_buff passed",
  794. CTCM_FUNTAIL, dev->name);
  795. priv->stats.tx_dropped++;
  796. return 0;
  797. }
  798. if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
  799. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  800. "%s(%s): Got sk_buff with head room < %ld bytes",
  801. CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
  802. dev_kfree_skb(skb);
  803. priv->stats.tx_dropped++;
  804. return 0;
  805. }
  806. /*
  807. * If channels are not running, try to restart them
  808. * and throw away packet.
  809. */
  810. if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
  811. fsm_event(priv->fsm, DEV_EVENT_START, dev);
  812. dev_kfree_skb(skb);
  813. priv->stats.tx_dropped++;
  814. priv->stats.tx_errors++;
  815. priv->stats.tx_carrier_errors++;
  816. return 0;
  817. }
  818. if (ctcm_test_and_set_busy(dev))
  819. return NETDEV_TX_BUSY;
  820. dev->trans_start = jiffies;
  821. if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0)
  822. return NETDEV_TX_BUSY;
  823. return 0;
  824. }
  825. /* unmerged MPC variant of ctcm_tx */
  826. static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
  827. {
  828. int len = 0;
  829. struct ctcm_priv *priv = dev->ml_priv;
  830. struct mpc_group *grp = priv->mpcg;
  831. struct sk_buff *newskb = NULL;
  832. /*
  833. * Some sanity checks ...
  834. */
  835. if (skb == NULL) {
  836. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  837. "%s(%s): NULL sk_buff passed",
  838. CTCM_FUNTAIL, dev->name);
  839. priv->stats.tx_dropped++;
  840. goto done;
  841. }
  842. if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
  843. CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
  844. "%s(%s): Got sk_buff with head room < %ld bytes",
  845. CTCM_FUNTAIL, dev->name,
  846. TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
  847. CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
  848. len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
  849. newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
  850. if (!newskb) {
  851. CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
  852. "%s: %s: __dev_alloc_skb failed",
  853. __func__, dev->name);
  854. dev_kfree_skb_any(skb);
  855. priv->stats.tx_dropped++;
  856. priv->stats.tx_errors++;
  857. priv->stats.tx_carrier_errors++;
  858. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  859. goto done;
  860. }
  861. newskb->protocol = skb->protocol;
  862. skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
  863. memcpy(skb_put(newskb, skb->len), skb->data, skb->len);
  864. dev_kfree_skb_any(skb);
  865. skb = newskb;
  866. }
  867. /*
  868. * If channels are not running,
  869. * notify anybody about a link failure and throw
  870. * away packet.
  871. */
  872. if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
  873. (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
  874. dev_kfree_skb_any(skb);
  875. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  876. "%s(%s): inactive MPCGROUP - dropped",
  877. CTCM_FUNTAIL, dev->name);
  878. priv->stats.tx_dropped++;
  879. priv->stats.tx_errors++;
  880. priv->stats.tx_carrier_errors++;
  881. goto done;
  882. }
  883. if (ctcm_test_and_set_busy(dev)) {
  884. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  885. "%s(%s): device busy - dropped",
  886. CTCM_FUNTAIL, dev->name);
  887. dev_kfree_skb_any(skb);
  888. priv->stats.tx_dropped++;
  889. priv->stats.tx_errors++;
  890. priv->stats.tx_carrier_errors++;
  891. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  892. goto done;
  893. }
  894. dev->trans_start = jiffies;
  895. if (ctcmpc_transmit_skb(priv->channel[WRITE], skb) != 0) {
  896. CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
  897. "%s(%s): device error - dropped",
  898. CTCM_FUNTAIL, dev->name);
  899. dev_kfree_skb_any(skb);
  900. priv->stats.tx_dropped++;
  901. priv->stats.tx_errors++;
  902. priv->stats.tx_carrier_errors++;
  903. ctcm_clear_busy(dev);
  904. fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
  905. goto done;
  906. }
  907. ctcm_clear_busy(dev);
  908. done:
  909. if (do_debug)
  910. MPC_DBF_DEV_NAME(TRACE, dev, "exit");
  911. return 0; /* handle freeing of skb here */
  912. }
  913. /**
  914. * Sets MTU of an interface.
  915. *
  916. * dev Pointer to interface struct.
  917. * new_mtu The new MTU to use for this interface.
  918. *
  919. * returns 0 on success, -EINVAL if MTU is out of valid range.
  920. * (valid range is 576 .. 65527). If VM is on the
  921. * remote side, maximum MTU is 32760, however this is
  922. * not checked here.
  923. */
  924. static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
  925. {
  926. struct ctcm_priv *priv;
  927. int max_bufsize;
  928. if (new_mtu < 576 || new_mtu > 65527)
  929. return -EINVAL;
  930. priv = dev->ml_priv;
  931. max_bufsize = priv->channel[READ]->max_bufsize;
  932. if (IS_MPC(priv)) {
  933. if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
  934. return -EINVAL;
  935. dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
  936. } else {
  937. if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
  938. return -EINVAL;
  939. dev->hard_header_len = LL_HEADER_LENGTH + 2;
  940. }
  941. dev->mtu = new_mtu;
  942. return 0;
  943. }
  944. /**
  945. * Returns interface statistics of a device.
  946. *
  947. * dev Pointer to interface struct.
  948. *
  949. * returns Pointer to stats struct of this interface.
  950. */
  951. static struct net_device_stats *ctcm_stats(struct net_device *dev)
  952. {
  953. return &((struct ctcm_priv *)dev->ml_priv)->stats;
  954. }
  955. static void ctcm_free_netdevice(struct net_device *dev)
  956. {
  957. struct ctcm_priv *priv;
  958. struct mpc_group *grp;
  959. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  960. "%s(%s)", CTCM_FUNTAIL, dev->name);
  961. priv = dev->ml_priv;
  962. if (priv) {
  963. grp = priv->mpcg;
  964. if (grp) {
  965. if (grp->fsm)
  966. kfree_fsm(grp->fsm);
  967. if (grp->xid_skb)
  968. dev_kfree_skb(grp->xid_skb);
  969. if (grp->rcvd_xid_skb)
  970. dev_kfree_skb(grp->rcvd_xid_skb);
  971. tasklet_kill(&grp->mpc_tasklet2);
  972. kfree(grp);
  973. priv->mpcg = NULL;
  974. }
  975. if (priv->fsm) {
  976. kfree_fsm(priv->fsm);
  977. priv->fsm = NULL;
  978. }
  979. kfree(priv->xid);
  980. priv->xid = NULL;
  981. /*
  982. * Note: kfree(priv); is done in "opposite" function of
  983. * allocator function probe_device which is remove_device.
  984. */
  985. }
  986. #ifdef MODULE
  987. free_netdev(dev);
  988. #endif
  989. }
  990. struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
  991. static const struct net_device_ops ctcm_netdev_ops = {
  992. .ndo_open = ctcm_open,
  993. .ndo_stop = ctcm_close,
  994. .ndo_get_stats = ctcm_stats,
  995. .ndo_change_mtu = ctcm_change_mtu,
  996. .ndo_start_xmit = ctcm_tx,
  997. };
  998. static const struct net_device_ops ctcm_mpc_netdev_ops = {
  999. .ndo_open = ctcm_open,
  1000. .ndo_stop = ctcm_close,
  1001. .ndo_get_stats = ctcm_stats,
  1002. .ndo_change_mtu = ctcm_change_mtu,
  1003. .ndo_start_xmit = ctcmpc_tx,
  1004. };
  1005. void static ctcm_dev_setup(struct net_device *dev)
  1006. {
  1007. dev->type = ARPHRD_SLIP;
  1008. dev->tx_queue_len = 100;
  1009. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  1010. }
  1011. /*
  1012. * Initialize everything of the net device except the name and the
  1013. * channel structs.
  1014. */
  1015. static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
  1016. {
  1017. struct net_device *dev;
  1018. struct mpc_group *grp;
  1019. if (!priv)
  1020. return NULL;
  1021. if (IS_MPC(priv))
  1022. dev = alloc_netdev(0, MPC_DEVICE_GENE, ctcm_dev_setup);
  1023. else
  1024. dev = alloc_netdev(0, CTC_DEVICE_GENE, ctcm_dev_setup);
  1025. if (!dev) {
  1026. CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
  1027. "%s: MEMORY allocation ERROR",
  1028. CTCM_FUNTAIL);
  1029. return NULL;
  1030. }
  1031. dev->ml_priv = priv;
  1032. priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
  1033. CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
  1034. dev_fsm, dev_fsm_len, GFP_KERNEL);
  1035. if (priv->fsm == NULL) {
  1036. CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
  1037. kfree(dev);
  1038. return NULL;
  1039. }
  1040. fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
  1041. fsm_settimer(priv->fsm, &priv->restart_timer);
  1042. if (IS_MPC(priv)) {
  1043. /* MPC Group Initializations */
  1044. grp = ctcmpc_init_mpc_group(priv);
  1045. if (grp == NULL) {
  1046. MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
  1047. kfree(dev);
  1048. return NULL;
  1049. }
  1050. tasklet_init(&grp->mpc_tasklet2,
  1051. mpc_group_ready, (unsigned long)dev);
  1052. dev->mtu = MPC_BUFSIZE_DEFAULT -
  1053. TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
  1054. dev->netdev_ops = &ctcm_mpc_netdev_ops;
  1055. dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
  1056. priv->buffer_size = MPC_BUFSIZE_DEFAULT;
  1057. } else {
  1058. dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
  1059. dev->netdev_ops = &ctcm_netdev_ops;
  1060. dev->hard_header_len = LL_HEADER_LENGTH + 2;
  1061. }
  1062. CTCMY_DBF_DEV(SETUP, dev, "finished");
  1063. return dev;
  1064. }
  1065. /**
  1066. * Main IRQ handler.
  1067. *
  1068. * cdev The ccw_device the interrupt is for.
  1069. * intparm interruption parameter.
  1070. * irb interruption response block.
  1071. */
  1072. static void ctcm_irq_handler(struct ccw_device *cdev,
  1073. unsigned long intparm, struct irb *irb)
  1074. {
  1075. struct channel *ch;
  1076. struct net_device *dev;
  1077. struct ctcm_priv *priv;
  1078. struct ccwgroup_device *cgdev;
  1079. int cstat;
  1080. int dstat;
  1081. CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
  1082. "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
  1083. if (ctcm_check_irb_error(cdev, irb))
  1084. return;
  1085. cgdev = dev_get_drvdata(&cdev->dev);
  1086. cstat = irb->scsw.cmd.cstat;
  1087. dstat = irb->scsw.cmd.dstat;
  1088. /* Check for unsolicited interrupts. */
  1089. if (cgdev == NULL) {
  1090. CTCM_DBF_TEXT_(TRACE, CTC_DBF_ERROR,
  1091. "%s(%s) unsolicited irq: c-%02x d-%02x\n",
  1092. CTCM_FUNTAIL, dev_name(&cdev->dev), cstat, dstat);
  1093. dev_warn(&cdev->dev,
  1094. "The adapter received a non-specific IRQ\n");
  1095. return;
  1096. }
  1097. priv = dev_get_drvdata(&cgdev->dev);
  1098. /* Try to extract channel from driver data. */
  1099. if (priv->channel[READ]->cdev == cdev)
  1100. ch = priv->channel[READ];
  1101. else if (priv->channel[WRITE]->cdev == cdev)
  1102. ch = priv->channel[WRITE];
  1103. else {
  1104. dev_err(&cdev->dev,
  1105. "%s: Internal error: Can't determine channel for "
  1106. "interrupt device %s\n",
  1107. __func__, dev_name(&cdev->dev));
  1108. /* Explain: inconsistent internal structures */
  1109. return;
  1110. }
  1111. dev = ch->netdev;
  1112. if (dev == NULL) {
  1113. dev_err(&cdev->dev,
  1114. "%s Internal error: net_device is NULL, ch = 0x%p\n",
  1115. __func__, ch);
  1116. /* Explain: inconsistent internal structures */
  1117. return;
  1118. }
  1119. /* Copy interruption response block. */
  1120. memcpy(ch->irb, irb, sizeof(struct irb));
  1121. /* Issue error message and return on subchannel error code */
  1122. if (irb->scsw.cmd.cstat) {
  1123. fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
  1124. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  1125. "%s(%s): sub-ch check %s: cs=%02x ds=%02x",
  1126. CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat);
  1127. dev_warn(&cdev->dev,
  1128. "A check occurred on the subchannel\n");
  1129. return;
  1130. }
  1131. /* Check the reason-code of a unit check */
  1132. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  1133. if ((irb->ecw[0] & ch->sense_rc) == 0)
  1134. /* print it only once */
  1135. CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
  1136. "%s(%s): sense=%02x, ds=%02x",
  1137. CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat);
  1138. ccw_unit_check(ch, irb->ecw[0]);
  1139. return;
  1140. }
  1141. if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
  1142. if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
  1143. fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
  1144. else
  1145. fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
  1146. return;
  1147. }
  1148. if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
  1149. fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
  1150. return;
  1151. }
  1152. if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  1153. (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  1154. (irb->scsw.cmd.stctl ==
  1155. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
  1156. fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
  1157. else
  1158. fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
  1159. }
  1160. /**
  1161. * Add ctcm specific attributes.
  1162. * Add ctcm private data.
  1163. *
  1164. * cgdev pointer to ccwgroup_device just added
  1165. *
  1166. * returns 0 on success, !0 on failure.
  1167. */
  1168. static int ctcm_probe_device(struct ccwgroup_device *cgdev)
  1169. {
  1170. struct ctcm_priv *priv;
  1171. int rc;
  1172. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  1173. "%s %p",
  1174. __func__, cgdev);
  1175. if (!get_device(&cgdev->dev))
  1176. return -ENODEV;
  1177. priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
  1178. if (!priv) {
  1179. CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
  1180. "%s: memory allocation failure",
  1181. CTCM_FUNTAIL);
  1182. put_device(&cgdev->dev);
  1183. return -ENOMEM;
  1184. }
  1185. rc = ctcm_add_files(&cgdev->dev);
  1186. if (rc) {
  1187. kfree(priv);
  1188. put_device(&cgdev->dev);
  1189. return rc;
  1190. }
  1191. priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
  1192. cgdev->cdev[0]->handler = ctcm_irq_handler;
  1193. cgdev->cdev[1]->handler = ctcm_irq_handler;
  1194. dev_set_drvdata(&cgdev->dev, priv);
  1195. return 0;
  1196. }
  1197. /**
  1198. * Add a new channel to the list of channels.
  1199. * Keeps the channel list sorted.
  1200. *
  1201. * cdev The ccw_device to be added.
  1202. * type The type class of the new channel.
  1203. * priv Points to the private data of the ccwgroup_device.
  1204. *
  1205. * returns 0 on success, !0 on error.
  1206. */
  1207. static int add_channel(struct ccw_device *cdev, enum channel_types type,
  1208. struct ctcm_priv *priv)
  1209. {
  1210. struct channel **c = &channels;
  1211. struct channel *ch;
  1212. int ccw_num;
  1213. int rc = 0;
  1214. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  1215. "%s(%s), type %d, proto %d",
  1216. __func__, dev_name(&cdev->dev), type, priv->protocol);
  1217. ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
  1218. if (ch == NULL)
  1219. return -ENOMEM;
  1220. ch->protocol = priv->protocol;
  1221. if (IS_MPC(priv)) {
  1222. ch->discontact_th = (struct th_header *)
  1223. kzalloc(TH_HEADER_LENGTH, gfp_type());
  1224. if (ch->discontact_th == NULL)
  1225. goto nomem_return;
  1226. ch->discontact_th->th_blk_flag = TH_DISCONTACT;
  1227. tasklet_init(&ch->ch_disc_tasklet,
  1228. mpc_action_send_discontact, (unsigned long)ch);
  1229. tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
  1230. ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
  1231. ccw_num = 17;
  1232. } else
  1233. ccw_num = 8;
  1234. ch->ccw = (struct ccw1 *)
  1235. kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
  1236. if (ch->ccw == NULL)
  1237. goto nomem_return;
  1238. ch->cdev = cdev;
  1239. snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev));
  1240. ch->type = type;
  1241. /**
  1242. * "static" ccws are used in the following way:
  1243. *
  1244. * ccw[0..2] (Channel program for generic I/O):
  1245. * 0: prepare
  1246. * 1: read or write (depending on direction) with fixed
  1247. * buffer (idal allocated once when buffer is allocated)
  1248. * 2: nop
  1249. * ccw[3..5] (Channel program for direct write of packets)
  1250. * 3: prepare
  1251. * 4: write (idal allocated on every write).
  1252. * 5: nop
  1253. * ccw[6..7] (Channel program for initial channel setup):
  1254. * 6: set extended mode
  1255. * 7: nop
  1256. *
  1257. * ch->ccw[0..5] are initialized in ch_action_start because
  1258. * the channel's direction is yet unknown here.
  1259. *
  1260. * ccws used for xid2 negotiations
  1261. * ch-ccw[8-14] need to be used for the XID exchange either
  1262. * X side XID2 Processing
  1263. * 8: write control
  1264. * 9: write th
  1265. * 10: write XID
  1266. * 11: read th from secondary
  1267. * 12: read XID from secondary
  1268. * 13: read 4 byte ID
  1269. * 14: nop
  1270. * Y side XID Processing
  1271. * 8: sense
  1272. * 9: read th
  1273. * 10: read XID
  1274. * 11: write th
  1275. * 12: write XID
  1276. * 13: write 4 byte ID
  1277. * 14: nop
  1278. *
  1279. * ccws used for double noop due to VM timing issues
  1280. * which result in unrecoverable Busy on channel
  1281. * 15: nop
  1282. * 16: nop
  1283. */
  1284. ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
  1285. ch->ccw[6].flags = CCW_FLAG_SLI;
  1286. ch->ccw[7].cmd_code = CCW_CMD_NOOP;
  1287. ch->ccw[7].flags = CCW_FLAG_SLI;
  1288. if (IS_MPC(priv)) {
  1289. ch->ccw[15].cmd_code = CCW_CMD_WRITE;
  1290. ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1291. ch->ccw[15].count = TH_HEADER_LENGTH;
  1292. ch->ccw[15].cda = virt_to_phys(ch->discontact_th);
  1293. ch->ccw[16].cmd_code = CCW_CMD_NOOP;
  1294. ch->ccw[16].flags = CCW_FLAG_SLI;
  1295. ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
  1296. ctc_ch_event_names, CTC_MPC_NR_STATES,
  1297. CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
  1298. mpc_ch_fsm_len, GFP_KERNEL);
  1299. } else {
  1300. ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
  1301. ctc_ch_event_names, CTC_NR_STATES,
  1302. CTC_NR_EVENTS, ch_fsm,
  1303. ch_fsm_len, GFP_KERNEL);
  1304. }
  1305. if (ch->fsm == NULL)
  1306. goto free_return;
  1307. fsm_newstate(ch->fsm, CTC_STATE_IDLE);
  1308. ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
  1309. if (ch->irb == NULL)
  1310. goto nomem_return;
  1311. while (*c && ctcm_less_than((*c)->id, ch->id))
  1312. c = &(*c)->next;
  1313. if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
  1314. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  1315. "%s (%s) already in list, using old entry",
  1316. __func__, (*c)->id);
  1317. goto free_return;
  1318. }
  1319. spin_lock_init(&ch->collect_lock);
  1320. fsm_settimer(ch->fsm, &ch->timer);
  1321. skb_queue_head_init(&ch->io_queue);
  1322. skb_queue_head_init(&ch->collect_queue);
  1323. if (IS_MPC(priv)) {
  1324. fsm_settimer(ch->fsm, &ch->sweep_timer);
  1325. skb_queue_head_init(&ch->sweep_queue);
  1326. }
  1327. ch->next = *c;
  1328. *c = ch;
  1329. return 0;
  1330. nomem_return:
  1331. rc = -ENOMEM;
  1332. free_return: /* note that all channel pointers are 0 or valid */
  1333. kfree(ch->ccw);
  1334. kfree(ch->discontact_th);
  1335. kfree_fsm(ch->fsm);
  1336. kfree(ch->irb);
  1337. kfree(ch);
  1338. return rc;
  1339. }
  1340. /*
  1341. * Return type of a detected device.
  1342. */
  1343. static enum channel_types get_channel_type(struct ccw_device_id *id)
  1344. {
  1345. enum channel_types type;
  1346. type = (enum channel_types)id->driver_info;
  1347. if (type == channel_type_ficon)
  1348. type = channel_type_escon;
  1349. return type;
  1350. }
  1351. /**
  1352. *
  1353. * Setup an interface.
  1354. *
  1355. * cgdev Device to be setup.
  1356. *
  1357. * returns 0 on success, !0 on failure.
  1358. */
  1359. static int ctcm_new_device(struct ccwgroup_device *cgdev)
  1360. {
  1361. char read_id[CTCM_ID_SIZE];
  1362. char write_id[CTCM_ID_SIZE];
  1363. int direction;
  1364. enum channel_types type;
  1365. struct ctcm_priv *priv;
  1366. struct net_device *dev;
  1367. struct ccw_device *cdev0;
  1368. struct ccw_device *cdev1;
  1369. int ret;
  1370. priv = dev_get_drvdata(&cgdev->dev);
  1371. if (!priv)
  1372. return -ENODEV;
  1373. cdev0 = cgdev->cdev[0];
  1374. cdev1 = cgdev->cdev[1];
  1375. type = get_channel_type(&cdev0->id);
  1376. snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev));
  1377. snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev));
  1378. ret = add_channel(cdev0, type, priv);
  1379. if (ret)
  1380. return ret;
  1381. ret = add_channel(cdev1, type, priv);
  1382. if (ret)
  1383. return ret;
  1384. ret = ccw_device_set_online(cdev0);
  1385. if (ret != 0) {
  1386. /* may be ok to fail now - can be done later */
  1387. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  1388. "%s(%s) set_online rc=%d",
  1389. CTCM_FUNTAIL, read_id, ret);
  1390. }
  1391. ret = ccw_device_set_online(cdev1);
  1392. if (ret != 0) {
  1393. /* may be ok to fail now - can be done later */
  1394. CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
  1395. "%s(%s) set_online rc=%d",
  1396. CTCM_FUNTAIL, write_id, ret);
  1397. }
  1398. dev = ctcm_init_netdevice(priv);
  1399. if (dev == NULL)
  1400. goto out;
  1401. for (direction = READ; direction <= WRITE; direction++) {
  1402. priv->channel[direction] =
  1403. channel_get(type, direction == READ ? read_id : write_id,
  1404. direction);
  1405. if (priv->channel[direction] == NULL) {
  1406. if (direction == WRITE)
  1407. channel_free(priv->channel[READ]);
  1408. goto out_dev;
  1409. }
  1410. priv->channel[direction]->netdev = dev;
  1411. priv->channel[direction]->protocol = priv->protocol;
  1412. priv->channel[direction]->max_bufsize = priv->buffer_size;
  1413. }
  1414. /* sysfs magic */
  1415. SET_NETDEV_DEV(dev, &cgdev->dev);
  1416. if (register_netdev(dev))
  1417. goto out_dev;
  1418. if (ctcm_add_attributes(&cgdev->dev)) {
  1419. unregister_netdev(dev);
  1420. goto out_dev;
  1421. }
  1422. strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
  1423. dev_info(&dev->dev,
  1424. "setup OK : r/w = %s/%s, protocol : %d\n",
  1425. priv->channel[READ]->id,
  1426. priv->channel[WRITE]->id, priv->protocol);
  1427. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  1428. "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
  1429. priv->channel[READ]->id,
  1430. priv->channel[WRITE]->id, priv->protocol);
  1431. return 0;
  1432. out_dev:
  1433. ctcm_free_netdevice(dev);
  1434. out:
  1435. ccw_device_set_offline(cgdev->cdev[1]);
  1436. ccw_device_set_offline(cgdev->cdev[0]);
  1437. return -ENODEV;
  1438. }
  1439. /**
  1440. * Shutdown an interface.
  1441. *
  1442. * cgdev Device to be shut down.
  1443. *
  1444. * returns 0 on success, !0 on failure.
  1445. */
  1446. static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
  1447. {
  1448. struct ctcm_priv *priv;
  1449. struct net_device *dev;
  1450. priv = dev_get_drvdata(&cgdev->dev);
  1451. if (!priv)
  1452. return -ENODEV;
  1453. if (priv->channel[READ]) {
  1454. dev = priv->channel[READ]->netdev;
  1455. CTCM_DBF_DEV(SETUP, dev, "");
  1456. /* Close the device */
  1457. ctcm_close(dev);
  1458. dev->flags &= ~IFF_RUNNING;
  1459. ctcm_remove_attributes(&cgdev->dev);
  1460. channel_free(priv->channel[READ]);
  1461. } else
  1462. dev = NULL;
  1463. if (priv->channel[WRITE])
  1464. channel_free(priv->channel[WRITE]);
  1465. if (dev) {
  1466. unregister_netdev(dev);
  1467. ctcm_free_netdevice(dev);
  1468. }
  1469. if (priv->fsm)
  1470. kfree_fsm(priv->fsm);
  1471. ccw_device_set_offline(cgdev->cdev[1]);
  1472. ccw_device_set_offline(cgdev->cdev[0]);
  1473. if (priv->channel[READ])
  1474. channel_remove(priv->channel[READ]);
  1475. if (priv->channel[WRITE])
  1476. channel_remove(priv->channel[WRITE]);
  1477. priv->channel[READ] = priv->channel[WRITE] = NULL;
  1478. return 0;
  1479. }
  1480. static void ctcm_remove_device(struct ccwgroup_device *cgdev)
  1481. {
  1482. struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev);
  1483. BUG_ON(priv == NULL);
  1484. CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
  1485. "removing device %s, r/w = %s/%s, proto : %d",
  1486. priv->channel[READ]->netdev->name,
  1487. priv->channel[READ]->id, priv->channel[WRITE]->id,
  1488. priv->protocol);
  1489. if (cgdev->state == CCWGROUP_ONLINE)
  1490. ctcm_shutdown_device(cgdev);
  1491. ctcm_remove_files(&cgdev->dev);
  1492. dev_set_drvdata(&cgdev->dev, NULL);
  1493. kfree(priv);
  1494. put_device(&cgdev->dev);
  1495. }
  1496. static struct ccwgroup_driver ctcm_group_driver = {
  1497. .owner = THIS_MODULE,
  1498. .name = CTC_DRIVER_NAME,
  1499. .max_slaves = 2,
  1500. .driver_id = 0xC3E3C3D4, /* CTCM */
  1501. .probe = ctcm_probe_device,
  1502. .remove = ctcm_remove_device,
  1503. .set_online = ctcm_new_device,
  1504. .set_offline = ctcm_shutdown_device,
  1505. };
  1506. /*
  1507. * Module related routines
  1508. */
  1509. /*
  1510. * Prepare to be unloaded. Free IRQ's and release all resources.
  1511. * This is called just before this module is unloaded. It is
  1512. * not called, if the usage count is !0, so we don't need to check
  1513. * for that.
  1514. */
  1515. static void __exit ctcm_exit(void)
  1516. {
  1517. unregister_cu3088_discipline(&ctcm_group_driver);
  1518. ctcm_unregister_dbf_views();
  1519. pr_info("CTCM driver unloaded\n");
  1520. }
  1521. /*
  1522. * Print Banner.
  1523. */
  1524. static void print_banner(void)
  1525. {
  1526. pr_info("CTCM driver initialized\n");
  1527. }
  1528. /**
  1529. * Initialize module.
  1530. * This is called just after the module is loaded.
  1531. *
  1532. * returns 0 on success, !0 on error.
  1533. */
  1534. static int __init ctcm_init(void)
  1535. {
  1536. int ret;
  1537. channels = NULL;
  1538. ret = ctcm_register_dbf_views();
  1539. if (ret) {
  1540. return ret;
  1541. }
  1542. ret = register_cu3088_discipline(&ctcm_group_driver);
  1543. if (ret) {
  1544. ctcm_unregister_dbf_views();
  1545. pr_err("%s / register_cu3088_discipline failed, ret = %d\n",
  1546. __func__, ret);
  1547. return ret;
  1548. }
  1549. print_banner();
  1550. return ret;
  1551. }
  1552. module_init(ctcm_init);
  1553. module_exit(ctcm_exit);
  1554. MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
  1555. MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
  1556. MODULE_LICENSE("GPL");