ctcm_main.c 44 KB

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