ctcm_main.c 44 KB

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