lcs.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337
  1. /*
  2. * linux/drivers/s390/net/lcs.c
  3. *
  4. * Linux for S/390 Lan Channel Station Network Driver
  5. *
  6. * Copyright (C) 1999-2001 IBM Deutschland Entwicklung GmbH,
  7. * IBM Corporation
  8. * Author(s): Original Code written by
  9. * DJ Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
  10. * Rewritten by
  11. * Frank Pavlic (fpavlic@de.ibm.com) and
  12. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #include <linux/module.h>
  29. #include <linux/if.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/trdevice.h>
  33. #include <linux/fddidevice.h>
  34. #include <linux/inetdevice.h>
  35. #include <linux/in.h>
  36. #include <linux/igmp.h>
  37. #include <linux/delay.h>
  38. #include <net/arp.h>
  39. #include <net/ip.h>
  40. #include <asm/debug.h>
  41. #include <asm/idals.h>
  42. #include <asm/timex.h>
  43. #include <linux/device.h>
  44. #include <asm/ccwgroup.h>
  45. #include "lcs.h"
  46. #include "cu3088.h"
  47. #if !defined(CONFIG_NET_ETHERNET) && \
  48. !defined(CONFIG_TR) && !defined(CONFIG_FDDI)
  49. #error Cannot compile lcs.c without some net devices switched on.
  50. #endif
  51. #define PRINTK_HEADER " lcs: "
  52. /**
  53. * initialization string for output
  54. */
  55. static char version[] __initdata = "LCS driver";
  56. static char debug_buffer[255];
  57. /**
  58. * Some prototypes.
  59. */
  60. static void lcs_tasklet(unsigned long);
  61. static void lcs_start_kernel_thread(struct work_struct *);
  62. static void lcs_get_frames_cb(struct lcs_channel *, struct lcs_buffer *);
  63. static int lcs_send_delipm(struct lcs_card *, struct lcs_ipm_list *);
  64. static int lcs_recovery(void *ptr);
  65. /**
  66. * Debug Facility Stuff
  67. */
  68. static debug_info_t *lcs_dbf_setup;
  69. static debug_info_t *lcs_dbf_trace;
  70. /**
  71. * LCS Debug Facility functions
  72. */
  73. static void
  74. lcs_unregister_debug_facility(void)
  75. {
  76. if (lcs_dbf_setup)
  77. debug_unregister(lcs_dbf_setup);
  78. if (lcs_dbf_trace)
  79. debug_unregister(lcs_dbf_trace);
  80. }
  81. static int
  82. lcs_register_debug_facility(void)
  83. {
  84. lcs_dbf_setup = debug_register("lcs_setup", 2, 1, 8);
  85. lcs_dbf_trace = debug_register("lcs_trace", 2, 2, 8);
  86. if (lcs_dbf_setup == NULL || lcs_dbf_trace == NULL) {
  87. PRINT_ERR("Not enough memory for debug facility.\n");
  88. lcs_unregister_debug_facility();
  89. return -ENOMEM;
  90. }
  91. debug_register_view(lcs_dbf_setup, &debug_hex_ascii_view);
  92. debug_set_level(lcs_dbf_setup, 2);
  93. debug_register_view(lcs_dbf_trace, &debug_hex_ascii_view);
  94. debug_set_level(lcs_dbf_trace, 2);
  95. return 0;
  96. }
  97. /**
  98. * Allocate io buffers.
  99. */
  100. static int
  101. lcs_alloc_channel(struct lcs_channel *channel)
  102. {
  103. int cnt;
  104. LCS_DBF_TEXT(2, setup, "ichalloc");
  105. for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
  106. /* alloc memory fo iobuffer */
  107. channel->iob[cnt].data =
  108. kzalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL);
  109. if (channel->iob[cnt].data == NULL)
  110. break;
  111. channel->iob[cnt].state = LCS_BUF_STATE_EMPTY;
  112. }
  113. if (cnt < LCS_NUM_BUFFS) {
  114. /* Not all io buffers could be allocated. */
  115. LCS_DBF_TEXT(2, setup, "echalloc");
  116. while (cnt-- > 0)
  117. kfree(channel->iob[cnt].data);
  118. return -ENOMEM;
  119. }
  120. return 0;
  121. }
  122. /**
  123. * Free io buffers.
  124. */
  125. static void
  126. lcs_free_channel(struct lcs_channel *channel)
  127. {
  128. int cnt;
  129. LCS_DBF_TEXT(2, setup, "ichfree");
  130. for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
  131. kfree(channel->iob[cnt].data);
  132. channel->iob[cnt].data = NULL;
  133. }
  134. }
  135. /*
  136. * Cleanup channel.
  137. */
  138. static void
  139. lcs_cleanup_channel(struct lcs_channel *channel)
  140. {
  141. LCS_DBF_TEXT(3, setup, "cleanch");
  142. /* Kill write channel tasklets. */
  143. tasklet_kill(&channel->irq_tasklet);
  144. /* Free channel buffers. */
  145. lcs_free_channel(channel);
  146. }
  147. /**
  148. * LCS free memory for card and channels.
  149. */
  150. static void
  151. lcs_free_card(struct lcs_card *card)
  152. {
  153. LCS_DBF_TEXT(2, setup, "remcard");
  154. LCS_DBF_HEX(2, setup, &card, sizeof(void*));
  155. kfree(card);
  156. }
  157. /**
  158. * LCS alloc memory for card and channels
  159. */
  160. static struct lcs_card *
  161. lcs_alloc_card(void)
  162. {
  163. struct lcs_card *card;
  164. int rc;
  165. LCS_DBF_TEXT(2, setup, "alloclcs");
  166. card = kzalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA);
  167. if (card == NULL)
  168. return NULL;
  169. card->lan_type = LCS_FRAME_TYPE_AUTO;
  170. card->pkt_seq = 0;
  171. card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT;
  172. /* Allocate io buffers for the read channel. */
  173. rc = lcs_alloc_channel(&card->read);
  174. if (rc){
  175. LCS_DBF_TEXT(2, setup, "iccwerr");
  176. lcs_free_card(card);
  177. return NULL;
  178. }
  179. /* Allocate io buffers for the write channel. */
  180. rc = lcs_alloc_channel(&card->write);
  181. if (rc) {
  182. LCS_DBF_TEXT(2, setup, "iccwerr");
  183. lcs_cleanup_channel(&card->read);
  184. lcs_free_card(card);
  185. return NULL;
  186. }
  187. #ifdef CONFIG_IP_MULTICAST
  188. INIT_LIST_HEAD(&card->ipm_list);
  189. #endif
  190. LCS_DBF_HEX(2, setup, &card, sizeof(void*));
  191. return card;
  192. }
  193. /*
  194. * Setup read channel.
  195. */
  196. static void
  197. lcs_setup_read_ccws(struct lcs_card *card)
  198. {
  199. int cnt;
  200. LCS_DBF_TEXT(2, setup, "ireadccw");
  201. /* Setup read ccws. */
  202. memset(card->read.ccws, 0, sizeof (struct ccw1) * (LCS_NUM_BUFFS + 1));
  203. for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
  204. card->read.ccws[cnt].cmd_code = LCS_CCW_READ;
  205. card->read.ccws[cnt].count = LCS_IOBUFFERSIZE;
  206. card->read.ccws[cnt].flags =
  207. CCW_FLAG_CC | CCW_FLAG_SLI | CCW_FLAG_PCI;
  208. /*
  209. * Note: we have allocated the buffer with GFP_DMA, so
  210. * we do not need to do set_normalized_cda.
  211. */
  212. card->read.ccws[cnt].cda =
  213. (__u32) __pa(card->read.iob[cnt].data);
  214. ((struct lcs_header *)
  215. card->read.iob[cnt].data)->offset = LCS_ILLEGAL_OFFSET;
  216. card->read.iob[cnt].callback = lcs_get_frames_cb;
  217. card->read.iob[cnt].state = LCS_BUF_STATE_READY;
  218. card->read.iob[cnt].count = LCS_IOBUFFERSIZE;
  219. }
  220. card->read.ccws[0].flags &= ~CCW_FLAG_PCI;
  221. card->read.ccws[LCS_NUM_BUFFS - 1].flags &= ~CCW_FLAG_PCI;
  222. card->read.ccws[LCS_NUM_BUFFS - 1].flags |= CCW_FLAG_SUSPEND;
  223. /* Last ccw is a tic (transfer in channel). */
  224. card->read.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER;
  225. card->read.ccws[LCS_NUM_BUFFS].cda =
  226. (__u32) __pa(card->read.ccws);
  227. /* Setg initial state of the read channel. */
  228. card->read.state = LCS_CH_STATE_INIT;
  229. card->read.io_idx = 0;
  230. card->read.buf_idx = 0;
  231. }
  232. static void
  233. lcs_setup_read(struct lcs_card *card)
  234. {
  235. LCS_DBF_TEXT(3, setup, "initread");
  236. lcs_setup_read_ccws(card);
  237. /* Initialize read channel tasklet. */
  238. card->read.irq_tasklet.data = (unsigned long) &card->read;
  239. card->read.irq_tasklet.func = lcs_tasklet;
  240. /* Initialize waitqueue. */
  241. init_waitqueue_head(&card->read.wait_q);
  242. }
  243. /*
  244. * Setup write channel.
  245. */
  246. static void
  247. lcs_setup_write_ccws(struct lcs_card *card)
  248. {
  249. int cnt;
  250. LCS_DBF_TEXT(3, setup, "iwritccw");
  251. /* Setup write ccws. */
  252. memset(card->write.ccws, 0, sizeof(struct ccw1) * LCS_NUM_BUFFS + 1);
  253. for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
  254. card->write.ccws[cnt].cmd_code = LCS_CCW_WRITE;
  255. card->write.ccws[cnt].count = 0;
  256. card->write.ccws[cnt].flags =
  257. CCW_FLAG_SUSPEND | CCW_FLAG_CC | CCW_FLAG_SLI;
  258. /*
  259. * Note: we have allocated the buffer with GFP_DMA, so
  260. * we do not need to do set_normalized_cda.
  261. */
  262. card->write.ccws[cnt].cda =
  263. (__u32) __pa(card->write.iob[cnt].data);
  264. }
  265. /* Last ccw is a tic (transfer in channel). */
  266. card->write.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER;
  267. card->write.ccws[LCS_NUM_BUFFS].cda =
  268. (__u32) __pa(card->write.ccws);
  269. /* Set initial state of the write channel. */
  270. card->read.state = LCS_CH_STATE_INIT;
  271. card->write.io_idx = 0;
  272. card->write.buf_idx = 0;
  273. }
  274. static void
  275. lcs_setup_write(struct lcs_card *card)
  276. {
  277. LCS_DBF_TEXT(3, setup, "initwrit");
  278. lcs_setup_write_ccws(card);
  279. /* Initialize write channel tasklet. */
  280. card->write.irq_tasklet.data = (unsigned long) &card->write;
  281. card->write.irq_tasklet.func = lcs_tasklet;
  282. /* Initialize waitqueue. */
  283. init_waitqueue_head(&card->write.wait_q);
  284. }
  285. static void
  286. lcs_set_allowed_threads(struct lcs_card *card, unsigned long threads)
  287. {
  288. unsigned long flags;
  289. spin_lock_irqsave(&card->mask_lock, flags);
  290. card->thread_allowed_mask = threads;
  291. spin_unlock_irqrestore(&card->mask_lock, flags);
  292. wake_up(&card->wait_q);
  293. }
  294. static inline int
  295. lcs_threads_running(struct lcs_card *card, unsigned long threads)
  296. {
  297. unsigned long flags;
  298. int rc = 0;
  299. spin_lock_irqsave(&card->mask_lock, flags);
  300. rc = (card->thread_running_mask & threads);
  301. spin_unlock_irqrestore(&card->mask_lock, flags);
  302. return rc;
  303. }
  304. static int
  305. lcs_wait_for_threads(struct lcs_card *card, unsigned long threads)
  306. {
  307. return wait_event_interruptible(card->wait_q,
  308. lcs_threads_running(card, threads) == 0);
  309. }
  310. static inline int
  311. lcs_set_thread_start_bit(struct lcs_card *card, unsigned long thread)
  312. {
  313. unsigned long flags;
  314. spin_lock_irqsave(&card->mask_lock, flags);
  315. if ( !(card->thread_allowed_mask & thread) ||
  316. (card->thread_start_mask & thread) ) {
  317. spin_unlock_irqrestore(&card->mask_lock, flags);
  318. return -EPERM;
  319. }
  320. card->thread_start_mask |= thread;
  321. spin_unlock_irqrestore(&card->mask_lock, flags);
  322. return 0;
  323. }
  324. static void
  325. lcs_clear_thread_running_bit(struct lcs_card *card, unsigned long thread)
  326. {
  327. unsigned long flags;
  328. spin_lock_irqsave(&card->mask_lock, flags);
  329. card->thread_running_mask &= ~thread;
  330. spin_unlock_irqrestore(&card->mask_lock, flags);
  331. wake_up(&card->wait_q);
  332. }
  333. static inline int
  334. __lcs_do_run_thread(struct lcs_card *card, unsigned long thread)
  335. {
  336. unsigned long flags;
  337. int rc = 0;
  338. spin_lock_irqsave(&card->mask_lock, flags);
  339. if (card->thread_start_mask & thread){
  340. if ((card->thread_allowed_mask & thread) &&
  341. !(card->thread_running_mask & thread)){
  342. rc = 1;
  343. card->thread_start_mask &= ~thread;
  344. card->thread_running_mask |= thread;
  345. } else
  346. rc = -EPERM;
  347. }
  348. spin_unlock_irqrestore(&card->mask_lock, flags);
  349. return rc;
  350. }
  351. static int
  352. lcs_do_run_thread(struct lcs_card *card, unsigned long thread)
  353. {
  354. int rc = 0;
  355. wait_event(card->wait_q,
  356. (rc = __lcs_do_run_thread(card, thread)) >= 0);
  357. return rc;
  358. }
  359. static int
  360. lcs_do_start_thread(struct lcs_card *card, unsigned long thread)
  361. {
  362. unsigned long flags;
  363. int rc = 0;
  364. spin_lock_irqsave(&card->mask_lock, flags);
  365. LCS_DBF_TEXT_(4, trace, " %02x%02x%02x",
  366. (u8) card->thread_start_mask,
  367. (u8) card->thread_allowed_mask,
  368. (u8) card->thread_running_mask);
  369. rc = (card->thread_start_mask & thread);
  370. spin_unlock_irqrestore(&card->mask_lock, flags);
  371. return rc;
  372. }
  373. /**
  374. * Initialize channels,card and state machines.
  375. */
  376. static void
  377. lcs_setup_card(struct lcs_card *card)
  378. {
  379. LCS_DBF_TEXT(2, setup, "initcard");
  380. LCS_DBF_HEX(2, setup, &card, sizeof(void*));
  381. lcs_setup_read(card);
  382. lcs_setup_write(card);
  383. /* Set cards initial state. */
  384. card->state = DEV_STATE_DOWN;
  385. card->tx_buffer = NULL;
  386. card->tx_emitted = 0;
  387. init_waitqueue_head(&card->wait_q);
  388. spin_lock_init(&card->lock);
  389. spin_lock_init(&card->ipm_lock);
  390. spin_lock_init(&card->mask_lock);
  391. #ifdef CONFIG_IP_MULTICAST
  392. INIT_LIST_HEAD(&card->ipm_list);
  393. #endif
  394. INIT_LIST_HEAD(&card->lancmd_waiters);
  395. }
  396. static inline void
  397. lcs_clear_multicast_list(struct lcs_card *card)
  398. {
  399. #ifdef CONFIG_IP_MULTICAST
  400. struct lcs_ipm_list *ipm;
  401. unsigned long flags;
  402. /* Free multicast list. */
  403. LCS_DBF_TEXT(3, setup, "clmclist");
  404. spin_lock_irqsave(&card->ipm_lock, flags);
  405. while (!list_empty(&card->ipm_list)){
  406. ipm = list_entry(card->ipm_list.next,
  407. struct lcs_ipm_list, list);
  408. list_del(&ipm->list);
  409. if (ipm->ipm_state != LCS_IPM_STATE_SET_REQUIRED){
  410. spin_unlock_irqrestore(&card->ipm_lock, flags);
  411. lcs_send_delipm(card, ipm);
  412. spin_lock_irqsave(&card->ipm_lock, flags);
  413. }
  414. kfree(ipm);
  415. }
  416. spin_unlock_irqrestore(&card->ipm_lock, flags);
  417. #endif
  418. }
  419. /**
  420. * Cleanup channels,card and state machines.
  421. */
  422. static void
  423. lcs_cleanup_card(struct lcs_card *card)
  424. {
  425. LCS_DBF_TEXT(3, setup, "cleancrd");
  426. LCS_DBF_HEX(2,setup,&card,sizeof(void*));
  427. if (card->dev != NULL)
  428. free_netdev(card->dev);
  429. /* Cleanup channels. */
  430. lcs_cleanup_channel(&card->write);
  431. lcs_cleanup_channel(&card->read);
  432. }
  433. /**
  434. * Start channel.
  435. */
  436. static int
  437. lcs_start_channel(struct lcs_channel *channel)
  438. {
  439. unsigned long flags;
  440. int rc;
  441. LCS_DBF_TEXT_(4,trace,"ssch%s", channel->ccwdev->dev.bus_id);
  442. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  443. rc = ccw_device_start(channel->ccwdev,
  444. channel->ccws + channel->io_idx, 0, 0,
  445. DOIO_DENY_PREFETCH | DOIO_ALLOW_SUSPEND);
  446. if (rc == 0)
  447. channel->state = LCS_CH_STATE_RUNNING;
  448. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  449. if (rc) {
  450. LCS_DBF_TEXT_(4,trace,"essh%s", channel->ccwdev->dev.bus_id);
  451. PRINT_ERR("Error in starting channel, rc=%d!\n", rc);
  452. }
  453. return rc;
  454. }
  455. static int
  456. lcs_clear_channel(struct lcs_channel *channel)
  457. {
  458. unsigned long flags;
  459. int rc;
  460. LCS_DBF_TEXT(4,trace,"clearch");
  461. LCS_DBF_TEXT_(4,trace,"%s", channel->ccwdev->dev.bus_id);
  462. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  463. rc = ccw_device_clear(channel->ccwdev, (addr_t) channel);
  464. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  465. if (rc) {
  466. LCS_DBF_TEXT_(4,trace,"ecsc%s", channel->ccwdev->dev.bus_id);
  467. return rc;
  468. }
  469. wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_CLEARED));
  470. channel->state = LCS_CH_STATE_STOPPED;
  471. return rc;
  472. }
  473. /**
  474. * Stop channel.
  475. */
  476. static int
  477. lcs_stop_channel(struct lcs_channel *channel)
  478. {
  479. unsigned long flags;
  480. int rc;
  481. if (channel->state == LCS_CH_STATE_STOPPED)
  482. return 0;
  483. LCS_DBF_TEXT(4,trace,"haltsch");
  484. LCS_DBF_TEXT_(4,trace,"%s", channel->ccwdev->dev.bus_id);
  485. channel->state = LCS_CH_STATE_INIT;
  486. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  487. rc = ccw_device_halt(channel->ccwdev, (addr_t) channel);
  488. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  489. if (rc) {
  490. LCS_DBF_TEXT_(4,trace,"ehsc%s", channel->ccwdev->dev.bus_id);
  491. return rc;
  492. }
  493. /* Asynchronous halt initialted. Wait for its completion. */
  494. wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_HALTED));
  495. lcs_clear_channel(channel);
  496. return 0;
  497. }
  498. /**
  499. * start read and write channel
  500. */
  501. static int
  502. lcs_start_channels(struct lcs_card *card)
  503. {
  504. int rc;
  505. LCS_DBF_TEXT(2, trace, "chstart");
  506. /* start read channel */
  507. rc = lcs_start_channel(&card->read);
  508. if (rc)
  509. return rc;
  510. /* start write channel */
  511. rc = lcs_start_channel(&card->write);
  512. if (rc)
  513. lcs_stop_channel(&card->read);
  514. return rc;
  515. }
  516. /**
  517. * stop read and write channel
  518. */
  519. static int
  520. lcs_stop_channels(struct lcs_card *card)
  521. {
  522. LCS_DBF_TEXT(2, trace, "chhalt");
  523. lcs_stop_channel(&card->read);
  524. lcs_stop_channel(&card->write);
  525. return 0;
  526. }
  527. /**
  528. * Get empty buffer.
  529. */
  530. static struct lcs_buffer *
  531. __lcs_get_buffer(struct lcs_channel *channel)
  532. {
  533. int index;
  534. LCS_DBF_TEXT(5, trace, "_getbuff");
  535. index = channel->io_idx;
  536. do {
  537. if (channel->iob[index].state == LCS_BUF_STATE_EMPTY) {
  538. channel->iob[index].state = LCS_BUF_STATE_LOCKED;
  539. return channel->iob + index;
  540. }
  541. index = (index + 1) & (LCS_NUM_BUFFS - 1);
  542. } while (index != channel->io_idx);
  543. return NULL;
  544. }
  545. static struct lcs_buffer *
  546. lcs_get_buffer(struct lcs_channel *channel)
  547. {
  548. struct lcs_buffer *buffer;
  549. unsigned long flags;
  550. LCS_DBF_TEXT(5, trace, "getbuff");
  551. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  552. buffer = __lcs_get_buffer(channel);
  553. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  554. return buffer;
  555. }
  556. /**
  557. * Resume channel program if the channel is suspended.
  558. */
  559. static int
  560. __lcs_resume_channel(struct lcs_channel *channel)
  561. {
  562. int rc;
  563. if (channel->state != LCS_CH_STATE_SUSPENDED)
  564. return 0;
  565. if (channel->ccws[channel->io_idx].flags & CCW_FLAG_SUSPEND)
  566. return 0;
  567. LCS_DBF_TEXT_(5, trace, "rsch%s", channel->ccwdev->dev.bus_id);
  568. rc = ccw_device_resume(channel->ccwdev);
  569. if (rc) {
  570. LCS_DBF_TEXT_(4, trace, "ersc%s", channel->ccwdev->dev.bus_id);
  571. PRINT_ERR("Error in lcs_resume_channel: rc=%d\n",rc);
  572. } else
  573. channel->state = LCS_CH_STATE_RUNNING;
  574. return rc;
  575. }
  576. /**
  577. * Make a buffer ready for processing.
  578. */
  579. static inline void
  580. __lcs_ready_buffer_bits(struct lcs_channel *channel, int index)
  581. {
  582. int prev, next;
  583. LCS_DBF_TEXT(5, trace, "rdybits");
  584. prev = (index - 1) & (LCS_NUM_BUFFS - 1);
  585. next = (index + 1) & (LCS_NUM_BUFFS - 1);
  586. /* Check if we may clear the suspend bit of this buffer. */
  587. if (channel->ccws[next].flags & CCW_FLAG_SUSPEND) {
  588. /* Check if we have to set the PCI bit. */
  589. if (!(channel->ccws[prev].flags & CCW_FLAG_SUSPEND))
  590. /* Suspend bit of the previous buffer is not set. */
  591. channel->ccws[index].flags |= CCW_FLAG_PCI;
  592. /* Suspend bit of the next buffer is set. */
  593. channel->ccws[index].flags &= ~CCW_FLAG_SUSPEND;
  594. }
  595. }
  596. static int
  597. lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
  598. {
  599. unsigned long flags;
  600. int index, rc;
  601. LCS_DBF_TEXT(5, trace, "rdybuff");
  602. BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED &&
  603. buffer->state != LCS_BUF_STATE_PROCESSED);
  604. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  605. buffer->state = LCS_BUF_STATE_READY;
  606. index = buffer - channel->iob;
  607. /* Set length. */
  608. channel->ccws[index].count = buffer->count;
  609. /* Check relevant PCI/suspend bits. */
  610. __lcs_ready_buffer_bits(channel, index);
  611. rc = __lcs_resume_channel(channel);
  612. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  613. return rc;
  614. }
  615. /**
  616. * Mark the buffer as processed. Take care of the suspend bit
  617. * of the previous buffer. This function is called from
  618. * interrupt context, so the lock must not be taken.
  619. */
  620. static int
  621. __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
  622. {
  623. int index, prev, next;
  624. LCS_DBF_TEXT(5, trace, "prcsbuff");
  625. BUG_ON(buffer->state != LCS_BUF_STATE_READY);
  626. buffer->state = LCS_BUF_STATE_PROCESSED;
  627. index = buffer - channel->iob;
  628. prev = (index - 1) & (LCS_NUM_BUFFS - 1);
  629. next = (index + 1) & (LCS_NUM_BUFFS - 1);
  630. /* Set the suspend bit and clear the PCI bit of this buffer. */
  631. channel->ccws[index].flags |= CCW_FLAG_SUSPEND;
  632. channel->ccws[index].flags &= ~CCW_FLAG_PCI;
  633. /* Check the suspend bit of the previous buffer. */
  634. if (channel->iob[prev].state == LCS_BUF_STATE_READY) {
  635. /*
  636. * Previous buffer is in state ready. It might have
  637. * happened in lcs_ready_buffer that the suspend bit
  638. * has not been cleared to avoid an endless loop.
  639. * Do it now.
  640. */
  641. __lcs_ready_buffer_bits(channel, prev);
  642. }
  643. /* Clear PCI bit of next buffer. */
  644. channel->ccws[next].flags &= ~CCW_FLAG_PCI;
  645. return __lcs_resume_channel(channel);
  646. }
  647. /**
  648. * Put a processed buffer back to state empty.
  649. */
  650. static void
  651. lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
  652. {
  653. unsigned long flags;
  654. LCS_DBF_TEXT(5, trace, "relbuff");
  655. BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED &&
  656. buffer->state != LCS_BUF_STATE_PROCESSED);
  657. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  658. buffer->state = LCS_BUF_STATE_EMPTY;
  659. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  660. }
  661. /**
  662. * Get buffer for a lan command.
  663. */
  664. static struct lcs_buffer *
  665. lcs_get_lancmd(struct lcs_card *card, int count)
  666. {
  667. struct lcs_buffer *buffer;
  668. struct lcs_cmd *cmd;
  669. LCS_DBF_TEXT(4, trace, "getlncmd");
  670. /* Get buffer and wait if none is available. */
  671. wait_event(card->write.wait_q,
  672. ((buffer = lcs_get_buffer(&card->write)) != NULL));
  673. count += sizeof(struct lcs_header);
  674. *(__u16 *)(buffer->data + count) = 0;
  675. buffer->count = count + sizeof(__u16);
  676. buffer->callback = lcs_release_buffer;
  677. cmd = (struct lcs_cmd *) buffer->data;
  678. cmd->offset = count;
  679. cmd->type = LCS_FRAME_TYPE_CONTROL;
  680. cmd->slot = 0;
  681. return buffer;
  682. }
  683. static void
  684. lcs_get_reply(struct lcs_reply *reply)
  685. {
  686. WARN_ON(atomic_read(&reply->refcnt) <= 0);
  687. atomic_inc(&reply->refcnt);
  688. }
  689. static void
  690. lcs_put_reply(struct lcs_reply *reply)
  691. {
  692. WARN_ON(atomic_read(&reply->refcnt) <= 0);
  693. if (atomic_dec_and_test(&reply->refcnt)) {
  694. kfree(reply);
  695. }
  696. }
  697. static struct lcs_reply *
  698. lcs_alloc_reply(struct lcs_cmd *cmd)
  699. {
  700. struct lcs_reply *reply;
  701. LCS_DBF_TEXT(4, trace, "getreply");
  702. reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC);
  703. if (!reply)
  704. return NULL;
  705. atomic_set(&reply->refcnt,1);
  706. reply->sequence_no = cmd->sequence_no;
  707. reply->received = 0;
  708. reply->rc = 0;
  709. init_waitqueue_head(&reply->wait_q);
  710. return reply;
  711. }
  712. /**
  713. * Notifier function for lancmd replies. Called from read irq.
  714. */
  715. static void
  716. lcs_notify_lancmd_waiters(struct lcs_card *card, struct lcs_cmd *cmd)
  717. {
  718. struct list_head *l, *n;
  719. struct lcs_reply *reply;
  720. LCS_DBF_TEXT(4, trace, "notiwait");
  721. spin_lock(&card->lock);
  722. list_for_each_safe(l, n, &card->lancmd_waiters) {
  723. reply = list_entry(l, struct lcs_reply, list);
  724. if (reply->sequence_no == cmd->sequence_no) {
  725. lcs_get_reply(reply);
  726. list_del_init(&reply->list);
  727. if (reply->callback != NULL)
  728. reply->callback(card, cmd);
  729. reply->received = 1;
  730. reply->rc = cmd->return_code;
  731. wake_up(&reply->wait_q);
  732. lcs_put_reply(reply);
  733. break;
  734. }
  735. }
  736. spin_unlock(&card->lock);
  737. }
  738. /**
  739. * Emit buffer of a lan comand.
  740. */
  741. static void
  742. lcs_lancmd_timeout(unsigned long data)
  743. {
  744. struct lcs_reply *reply, *list_reply, *r;
  745. unsigned long flags;
  746. LCS_DBF_TEXT(4, trace, "timeout");
  747. reply = (struct lcs_reply *) data;
  748. spin_lock_irqsave(&reply->card->lock, flags);
  749. list_for_each_entry_safe(list_reply, r,
  750. &reply->card->lancmd_waiters,list) {
  751. if (reply == list_reply) {
  752. lcs_get_reply(reply);
  753. list_del_init(&reply->list);
  754. spin_unlock_irqrestore(&reply->card->lock, flags);
  755. reply->received = 1;
  756. reply->rc = -ETIME;
  757. wake_up(&reply->wait_q);
  758. lcs_put_reply(reply);
  759. return;
  760. }
  761. }
  762. spin_unlock_irqrestore(&reply->card->lock, flags);
  763. }
  764. static int
  765. lcs_send_lancmd(struct lcs_card *card, struct lcs_buffer *buffer,
  766. void (*reply_callback)(struct lcs_card *, struct lcs_cmd *))
  767. {
  768. struct lcs_reply *reply;
  769. struct lcs_cmd *cmd;
  770. struct timer_list timer;
  771. unsigned long flags;
  772. int rc;
  773. LCS_DBF_TEXT(4, trace, "sendcmd");
  774. cmd = (struct lcs_cmd *) buffer->data;
  775. cmd->return_code = 0;
  776. cmd->sequence_no = card->sequence_no++;
  777. reply = lcs_alloc_reply(cmd);
  778. if (!reply)
  779. return -ENOMEM;
  780. reply->callback = reply_callback;
  781. reply->card = card;
  782. spin_lock_irqsave(&card->lock, flags);
  783. list_add_tail(&reply->list, &card->lancmd_waiters);
  784. spin_unlock_irqrestore(&card->lock, flags);
  785. buffer->callback = lcs_release_buffer;
  786. rc = lcs_ready_buffer(&card->write, buffer);
  787. if (rc)
  788. return rc;
  789. init_timer(&timer);
  790. timer.function = lcs_lancmd_timeout;
  791. timer.data = (unsigned long) reply;
  792. timer.expires = jiffies + HZ*card->lancmd_timeout;
  793. add_timer(&timer);
  794. wait_event(reply->wait_q, reply->received);
  795. del_timer_sync(&timer);
  796. LCS_DBF_TEXT_(4, trace, "rc:%d",reply->rc);
  797. rc = reply->rc;
  798. lcs_put_reply(reply);
  799. return rc ? -EIO : 0;
  800. }
  801. /**
  802. * LCS startup command
  803. */
  804. static int
  805. lcs_send_startup(struct lcs_card *card, __u8 initiator)
  806. {
  807. struct lcs_buffer *buffer;
  808. struct lcs_cmd *cmd;
  809. LCS_DBF_TEXT(2, trace, "startup");
  810. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  811. cmd = (struct lcs_cmd *) buffer->data;
  812. cmd->cmd_code = LCS_CMD_STARTUP;
  813. cmd->initiator = initiator;
  814. cmd->cmd.lcs_startup.buff_size = LCS_IOBUFFERSIZE;
  815. return lcs_send_lancmd(card, buffer, NULL);
  816. }
  817. /**
  818. * LCS shutdown command
  819. */
  820. static int
  821. lcs_send_shutdown(struct lcs_card *card)
  822. {
  823. struct lcs_buffer *buffer;
  824. struct lcs_cmd *cmd;
  825. LCS_DBF_TEXT(2, trace, "shutdown");
  826. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  827. cmd = (struct lcs_cmd *) buffer->data;
  828. cmd->cmd_code = LCS_CMD_SHUTDOWN;
  829. cmd->initiator = LCS_INITIATOR_TCPIP;
  830. return lcs_send_lancmd(card, buffer, NULL);
  831. }
  832. /**
  833. * LCS lanstat command
  834. */
  835. static void
  836. __lcs_lanstat_cb(struct lcs_card *card, struct lcs_cmd *cmd)
  837. {
  838. LCS_DBF_TEXT(2, trace, "statcb");
  839. memcpy(card->mac, cmd->cmd.lcs_lanstat_cmd.mac_addr, LCS_MAC_LENGTH);
  840. }
  841. static int
  842. lcs_send_lanstat(struct lcs_card *card)
  843. {
  844. struct lcs_buffer *buffer;
  845. struct lcs_cmd *cmd;
  846. LCS_DBF_TEXT(2,trace, "cmdstat");
  847. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  848. cmd = (struct lcs_cmd *) buffer->data;
  849. /* Setup lanstat command. */
  850. cmd->cmd_code = LCS_CMD_LANSTAT;
  851. cmd->initiator = LCS_INITIATOR_TCPIP;
  852. cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
  853. cmd->cmd.lcs_std_cmd.portno = card->portno;
  854. return lcs_send_lancmd(card, buffer, __lcs_lanstat_cb);
  855. }
  856. /**
  857. * send stoplan command
  858. */
  859. static int
  860. lcs_send_stoplan(struct lcs_card *card, __u8 initiator)
  861. {
  862. struct lcs_buffer *buffer;
  863. struct lcs_cmd *cmd;
  864. LCS_DBF_TEXT(2, trace, "cmdstpln");
  865. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  866. cmd = (struct lcs_cmd *) buffer->data;
  867. cmd->cmd_code = LCS_CMD_STOPLAN;
  868. cmd->initiator = initiator;
  869. cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
  870. cmd->cmd.lcs_std_cmd.portno = card->portno;
  871. return lcs_send_lancmd(card, buffer, NULL);
  872. }
  873. /**
  874. * send startlan command
  875. */
  876. static void
  877. __lcs_send_startlan_cb(struct lcs_card *card, struct lcs_cmd *cmd)
  878. {
  879. LCS_DBF_TEXT(2, trace, "srtlancb");
  880. card->lan_type = cmd->cmd.lcs_std_cmd.lan_type;
  881. card->portno = cmd->cmd.lcs_std_cmd.portno;
  882. }
  883. static int
  884. lcs_send_startlan(struct lcs_card *card, __u8 initiator)
  885. {
  886. struct lcs_buffer *buffer;
  887. struct lcs_cmd *cmd;
  888. LCS_DBF_TEXT(2, trace, "cmdstaln");
  889. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  890. cmd = (struct lcs_cmd *) buffer->data;
  891. cmd->cmd_code = LCS_CMD_STARTLAN;
  892. cmd->initiator = initiator;
  893. cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
  894. cmd->cmd.lcs_std_cmd.portno = card->portno;
  895. return lcs_send_lancmd(card, buffer, __lcs_send_startlan_cb);
  896. }
  897. #ifdef CONFIG_IP_MULTICAST
  898. /**
  899. * send setipm command (Multicast)
  900. */
  901. static int
  902. lcs_send_setipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list)
  903. {
  904. struct lcs_buffer *buffer;
  905. struct lcs_cmd *cmd;
  906. LCS_DBF_TEXT(2, trace, "cmdsetim");
  907. buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE);
  908. cmd = (struct lcs_cmd *) buffer->data;
  909. cmd->cmd_code = LCS_CMD_SETIPM;
  910. cmd->initiator = LCS_INITIATOR_TCPIP;
  911. cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
  912. cmd->cmd.lcs_qipassist.portno = card->portno;
  913. cmd->cmd.lcs_qipassist.version = 4;
  914. cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
  915. memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
  916. &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair));
  917. LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr);
  918. return lcs_send_lancmd(card, buffer, NULL);
  919. }
  920. /**
  921. * send delipm command (Multicast)
  922. */
  923. static int
  924. lcs_send_delipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list)
  925. {
  926. struct lcs_buffer *buffer;
  927. struct lcs_cmd *cmd;
  928. LCS_DBF_TEXT(2, trace, "cmddelim");
  929. buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE);
  930. cmd = (struct lcs_cmd *) buffer->data;
  931. cmd->cmd_code = LCS_CMD_DELIPM;
  932. cmd->initiator = LCS_INITIATOR_TCPIP;
  933. cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
  934. cmd->cmd.lcs_qipassist.portno = card->portno;
  935. cmd->cmd.lcs_qipassist.version = 4;
  936. cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
  937. memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
  938. &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair));
  939. LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr);
  940. return lcs_send_lancmd(card, buffer, NULL);
  941. }
  942. /**
  943. * check if multicast is supported by LCS
  944. */
  945. static void
  946. __lcs_check_multicast_cb(struct lcs_card *card, struct lcs_cmd *cmd)
  947. {
  948. LCS_DBF_TEXT(2, trace, "chkmccb");
  949. card->ip_assists_supported =
  950. cmd->cmd.lcs_qipassist.ip_assists_supported;
  951. card->ip_assists_enabled =
  952. cmd->cmd.lcs_qipassist.ip_assists_enabled;
  953. }
  954. static int
  955. lcs_check_multicast_support(struct lcs_card *card)
  956. {
  957. struct lcs_buffer *buffer;
  958. struct lcs_cmd *cmd;
  959. int rc;
  960. LCS_DBF_TEXT(2, trace, "cmdqipa");
  961. /* Send query ipassist. */
  962. buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
  963. cmd = (struct lcs_cmd *) buffer->data;
  964. cmd->cmd_code = LCS_CMD_QIPASSIST;
  965. cmd->initiator = LCS_INITIATOR_TCPIP;
  966. cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
  967. cmd->cmd.lcs_qipassist.portno = card->portno;
  968. cmd->cmd.lcs_qipassist.version = 4;
  969. cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
  970. rc = lcs_send_lancmd(card, buffer, __lcs_check_multicast_cb);
  971. if (rc != 0) {
  972. PRINT_ERR("Query IPAssist failed. Assuming unsupported!\n");
  973. return -EOPNOTSUPP;
  974. }
  975. if (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT)
  976. return 0;
  977. return -EOPNOTSUPP;
  978. }
  979. /**
  980. * set or del multicast address on LCS card
  981. */
  982. static void
  983. lcs_fix_multicast_list(struct lcs_card *card)
  984. {
  985. struct list_head failed_list;
  986. struct lcs_ipm_list *ipm, *tmp;
  987. unsigned long flags;
  988. int rc;
  989. LCS_DBF_TEXT(4,trace, "fixipm");
  990. INIT_LIST_HEAD(&failed_list);
  991. spin_lock_irqsave(&card->ipm_lock, flags);
  992. list_modified:
  993. list_for_each_entry_safe(ipm, tmp, &card->ipm_list, list){
  994. switch (ipm->ipm_state) {
  995. case LCS_IPM_STATE_SET_REQUIRED:
  996. /* del from ipm_list so noone else can tamper with
  997. * this entry */
  998. list_del_init(&ipm->list);
  999. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1000. rc = lcs_send_setipm(card, ipm);
  1001. spin_lock_irqsave(&card->ipm_lock, flags);
  1002. if (rc) {
  1003. PRINT_INFO("Adding multicast address failed."
  1004. "Table possibly full!\n");
  1005. /* store ipm in failed list -> will be added
  1006. * to ipm_list again, so a retry will be done
  1007. * during the next call of this function */
  1008. list_add_tail(&ipm->list, &failed_list);
  1009. } else {
  1010. ipm->ipm_state = LCS_IPM_STATE_ON_CARD;
  1011. /* re-insert into ipm_list */
  1012. list_add_tail(&ipm->list, &card->ipm_list);
  1013. }
  1014. goto list_modified;
  1015. case LCS_IPM_STATE_DEL_REQUIRED:
  1016. list_del(&ipm->list);
  1017. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1018. lcs_send_delipm(card, ipm);
  1019. spin_lock_irqsave(&card->ipm_lock, flags);
  1020. kfree(ipm);
  1021. goto list_modified;
  1022. case LCS_IPM_STATE_ON_CARD:
  1023. break;
  1024. }
  1025. }
  1026. /* re-insert all entries from the failed_list into ipm_list */
  1027. list_for_each_entry_safe(ipm, tmp, &failed_list, list)
  1028. list_move_tail(&ipm->list, &card->ipm_list);
  1029. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1030. }
  1031. /**
  1032. * get mac address for the relevant Multicast address
  1033. */
  1034. static void
  1035. lcs_get_mac_for_ipm(__be32 ipm, char *mac, struct net_device *dev)
  1036. {
  1037. LCS_DBF_TEXT(4,trace, "getmac");
  1038. if (dev->type == ARPHRD_IEEE802_TR)
  1039. ip_tr_mc_map(ipm, mac);
  1040. else
  1041. ip_eth_mc_map(ipm, mac);
  1042. }
  1043. /**
  1044. * function called by net device to handle multicast address relevant things
  1045. */
  1046. static inline void
  1047. lcs_remove_mc_addresses(struct lcs_card *card, struct in_device *in4_dev)
  1048. {
  1049. struct ip_mc_list *im4;
  1050. struct list_head *l;
  1051. struct lcs_ipm_list *ipm;
  1052. unsigned long flags;
  1053. char buf[MAX_ADDR_LEN];
  1054. LCS_DBF_TEXT(4, trace, "remmclst");
  1055. spin_lock_irqsave(&card->ipm_lock, flags);
  1056. list_for_each(l, &card->ipm_list) {
  1057. ipm = list_entry(l, struct lcs_ipm_list, list);
  1058. for (im4 = in4_dev->mc_list; im4 != NULL; im4 = im4->next) {
  1059. lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev);
  1060. if ( (ipm->ipm.ip_addr == im4->multiaddr) &&
  1061. (memcmp(buf, &ipm->ipm.mac_addr,
  1062. LCS_MAC_LENGTH) == 0) )
  1063. break;
  1064. }
  1065. if (im4 == NULL)
  1066. ipm->ipm_state = LCS_IPM_STATE_DEL_REQUIRED;
  1067. }
  1068. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1069. }
  1070. static inline struct lcs_ipm_list *
  1071. lcs_check_addr_entry(struct lcs_card *card, struct ip_mc_list *im4, char *buf)
  1072. {
  1073. struct lcs_ipm_list *tmp, *ipm = NULL;
  1074. struct list_head *l;
  1075. unsigned long flags;
  1076. LCS_DBF_TEXT(4, trace, "chkmcent");
  1077. spin_lock_irqsave(&card->ipm_lock, flags);
  1078. list_for_each(l, &card->ipm_list) {
  1079. tmp = list_entry(l, struct lcs_ipm_list, list);
  1080. if ( (tmp->ipm.ip_addr == im4->multiaddr) &&
  1081. (memcmp(buf, &tmp->ipm.mac_addr,
  1082. LCS_MAC_LENGTH) == 0) ) {
  1083. ipm = tmp;
  1084. break;
  1085. }
  1086. }
  1087. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1088. return ipm;
  1089. }
  1090. static inline void
  1091. lcs_set_mc_addresses(struct lcs_card *card, struct in_device *in4_dev)
  1092. {
  1093. struct ip_mc_list *im4;
  1094. struct lcs_ipm_list *ipm;
  1095. char buf[MAX_ADDR_LEN];
  1096. unsigned long flags;
  1097. LCS_DBF_TEXT(4, trace, "setmclst");
  1098. for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
  1099. lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev);
  1100. ipm = lcs_check_addr_entry(card, im4, buf);
  1101. if (ipm != NULL)
  1102. continue; /* Address already in list. */
  1103. ipm = (struct lcs_ipm_list *)
  1104. kzalloc(sizeof(struct lcs_ipm_list), GFP_ATOMIC);
  1105. if (ipm == NULL) {
  1106. PRINT_INFO("Not enough memory to add "
  1107. "new multicast entry!\n");
  1108. break;
  1109. }
  1110. memcpy(&ipm->ipm.mac_addr, buf, LCS_MAC_LENGTH);
  1111. ipm->ipm.ip_addr = im4->multiaddr;
  1112. ipm->ipm_state = LCS_IPM_STATE_SET_REQUIRED;
  1113. spin_lock_irqsave(&card->ipm_lock, flags);
  1114. LCS_DBF_HEX(2,trace,&ipm->ipm.ip_addr,4);
  1115. list_add(&ipm->list, &card->ipm_list);
  1116. spin_unlock_irqrestore(&card->ipm_lock, flags);
  1117. }
  1118. }
  1119. static int
  1120. lcs_register_mc_addresses(void *data)
  1121. {
  1122. struct lcs_card *card;
  1123. struct in_device *in4_dev;
  1124. card = (struct lcs_card *) data;
  1125. daemonize("regipm");
  1126. if (!lcs_do_run_thread(card, LCS_SET_MC_THREAD))
  1127. return 0;
  1128. LCS_DBF_TEXT(4, trace, "regmulti");
  1129. in4_dev = in_dev_get(card->dev);
  1130. if (in4_dev == NULL)
  1131. goto out;
  1132. read_lock(&in4_dev->mc_list_lock);
  1133. lcs_remove_mc_addresses(card,in4_dev);
  1134. lcs_set_mc_addresses(card, in4_dev);
  1135. read_unlock(&in4_dev->mc_list_lock);
  1136. in_dev_put(in4_dev);
  1137. netif_carrier_off(card->dev);
  1138. netif_tx_disable(card->dev);
  1139. wait_event(card->write.wait_q,
  1140. (card->write.state != LCS_CH_STATE_RUNNING));
  1141. lcs_fix_multicast_list(card);
  1142. if (card->state == DEV_STATE_UP) {
  1143. netif_carrier_on(card->dev);
  1144. netif_wake_queue(card->dev);
  1145. }
  1146. out:
  1147. lcs_clear_thread_running_bit(card, LCS_SET_MC_THREAD);
  1148. return 0;
  1149. }
  1150. /**
  1151. * function called by net device to
  1152. * handle multicast address relevant things
  1153. */
  1154. static void
  1155. lcs_set_multicast_list(struct net_device *dev)
  1156. {
  1157. struct lcs_card *card;
  1158. LCS_DBF_TEXT(4, trace, "setmulti");
  1159. card = (struct lcs_card *) dev->priv;
  1160. if (!lcs_set_thread_start_bit(card, LCS_SET_MC_THREAD))
  1161. schedule_work(&card->kernel_thread_starter);
  1162. }
  1163. #endif /* CONFIG_IP_MULTICAST */
  1164. static long
  1165. lcs_check_irb_error(struct ccw_device *cdev, struct irb *irb)
  1166. {
  1167. if (!IS_ERR(irb))
  1168. return 0;
  1169. switch (PTR_ERR(irb)) {
  1170. case -EIO:
  1171. PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
  1172. LCS_DBF_TEXT(2, trace, "ckirberr");
  1173. LCS_DBF_TEXT_(2, trace, " rc%d", -EIO);
  1174. break;
  1175. case -ETIMEDOUT:
  1176. PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
  1177. LCS_DBF_TEXT(2, trace, "ckirberr");
  1178. LCS_DBF_TEXT_(2, trace, " rc%d", -ETIMEDOUT);
  1179. break;
  1180. default:
  1181. PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
  1182. cdev->dev.bus_id);
  1183. LCS_DBF_TEXT(2, trace, "ckirberr");
  1184. LCS_DBF_TEXT(2, trace, " rc???");
  1185. }
  1186. return PTR_ERR(irb);
  1187. }
  1188. static int
  1189. lcs_get_problem(struct ccw_device *cdev, struct irb *irb)
  1190. {
  1191. int dstat, cstat;
  1192. char *sense;
  1193. sense = (char *) irb->ecw;
  1194. cstat = irb->scsw.cstat;
  1195. dstat = irb->scsw.dstat;
  1196. if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
  1197. SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
  1198. SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
  1199. LCS_DBF_TEXT(2, trace, "CGENCHK");
  1200. return 1;
  1201. }
  1202. if (dstat & DEV_STAT_UNIT_CHECK) {
  1203. if (sense[LCS_SENSE_BYTE_1] &
  1204. LCS_SENSE_RESETTING_EVENT) {
  1205. LCS_DBF_TEXT(2, trace, "REVIND");
  1206. return 1;
  1207. }
  1208. if (sense[LCS_SENSE_BYTE_0] &
  1209. LCS_SENSE_CMD_REJECT) {
  1210. LCS_DBF_TEXT(2, trace, "CMDREJ");
  1211. return 0;
  1212. }
  1213. if ((!sense[LCS_SENSE_BYTE_0]) &&
  1214. (!sense[LCS_SENSE_BYTE_1]) &&
  1215. (!sense[LCS_SENSE_BYTE_2]) &&
  1216. (!sense[LCS_SENSE_BYTE_3])) {
  1217. LCS_DBF_TEXT(2, trace, "ZEROSEN");
  1218. return 0;
  1219. }
  1220. LCS_DBF_TEXT(2, trace, "DGENCHK");
  1221. return 1;
  1222. }
  1223. return 0;
  1224. }
  1225. static void
  1226. lcs_schedule_recovery(struct lcs_card *card)
  1227. {
  1228. LCS_DBF_TEXT(2, trace, "startrec");
  1229. if (!lcs_set_thread_start_bit(card, LCS_RECOVERY_THREAD))
  1230. schedule_work(&card->kernel_thread_starter);
  1231. }
  1232. /**
  1233. * IRQ Handler for LCS channels
  1234. */
  1235. static void
  1236. lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
  1237. {
  1238. struct lcs_card *card;
  1239. struct lcs_channel *channel;
  1240. int rc, index;
  1241. int cstat, dstat;
  1242. if (lcs_check_irb_error(cdev, irb))
  1243. return;
  1244. card = CARD_FROM_DEV(cdev);
  1245. if (card->read.ccwdev == cdev)
  1246. channel = &card->read;
  1247. else
  1248. channel = &card->write;
  1249. cstat = irb->scsw.cstat;
  1250. dstat = irb->scsw.dstat;
  1251. LCS_DBF_TEXT_(5, trace, "Rint%s",cdev->dev.bus_id);
  1252. LCS_DBF_TEXT_(5, trace, "%4x%4x",irb->scsw.cstat, irb->scsw.dstat);
  1253. LCS_DBF_TEXT_(5, trace, "%4x%4x",irb->scsw.fctl, irb->scsw.actl);
  1254. /* Check for channel and device errors presented */
  1255. rc = lcs_get_problem(cdev, irb);
  1256. if (rc || (dstat & DEV_STAT_UNIT_EXCEP)) {
  1257. PRINT_WARN("check on device %s, dstat=0x%X, cstat=0x%X \n",
  1258. cdev->dev.bus_id, dstat, cstat);
  1259. if (rc) {
  1260. lcs_schedule_recovery(card);
  1261. wake_up(&card->wait_q);
  1262. return;
  1263. }
  1264. }
  1265. /* How far in the ccw chain have we processed? */
  1266. if ((channel->state != LCS_CH_STATE_INIT) &&
  1267. (irb->scsw.fctl & SCSW_FCTL_START_FUNC)) {
  1268. index = (struct ccw1 *) __va((addr_t) irb->scsw.cpa)
  1269. - channel->ccws;
  1270. if ((irb->scsw.actl & SCSW_ACTL_SUSPENDED) ||
  1271. (irb->scsw.cstat & SCHN_STAT_PCI))
  1272. /* Bloody io subsystem tells us lies about cpa... */
  1273. index = (index - 1) & (LCS_NUM_BUFFS - 1);
  1274. while (channel->io_idx != index) {
  1275. __lcs_processed_buffer(channel,
  1276. channel->iob + channel->io_idx);
  1277. channel->io_idx =
  1278. (channel->io_idx + 1) & (LCS_NUM_BUFFS - 1);
  1279. }
  1280. }
  1281. if ((irb->scsw.dstat & DEV_STAT_DEV_END) ||
  1282. (irb->scsw.dstat & DEV_STAT_CHN_END) ||
  1283. (irb->scsw.dstat & DEV_STAT_UNIT_CHECK))
  1284. /* Mark channel as stopped. */
  1285. channel->state = LCS_CH_STATE_STOPPED;
  1286. else if (irb->scsw.actl & SCSW_ACTL_SUSPENDED)
  1287. /* CCW execution stopped on a suspend bit. */
  1288. channel->state = LCS_CH_STATE_SUSPENDED;
  1289. if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) {
  1290. if (irb->scsw.cc != 0) {
  1291. ccw_device_halt(channel->ccwdev, (addr_t) channel);
  1292. return;
  1293. }
  1294. /* The channel has been stopped by halt_IO. */
  1295. channel->state = LCS_CH_STATE_HALTED;
  1296. }
  1297. if (irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
  1298. channel->state = LCS_CH_STATE_CLEARED;
  1299. }
  1300. /* Do the rest in the tasklet. */
  1301. tasklet_schedule(&channel->irq_tasklet);
  1302. }
  1303. /**
  1304. * Tasklet for IRQ handler
  1305. */
  1306. static void
  1307. lcs_tasklet(unsigned long data)
  1308. {
  1309. unsigned long flags;
  1310. struct lcs_channel *channel;
  1311. struct lcs_buffer *iob;
  1312. int buf_idx;
  1313. int rc;
  1314. channel = (struct lcs_channel *) data;
  1315. LCS_DBF_TEXT_(5, trace, "tlet%s",channel->ccwdev->dev.bus_id);
  1316. /* Check for processed buffers. */
  1317. iob = channel->iob;
  1318. buf_idx = channel->buf_idx;
  1319. while (iob[buf_idx].state == LCS_BUF_STATE_PROCESSED) {
  1320. /* Do the callback thing. */
  1321. if (iob[buf_idx].callback != NULL)
  1322. iob[buf_idx].callback(channel, iob + buf_idx);
  1323. buf_idx = (buf_idx + 1) & (LCS_NUM_BUFFS - 1);
  1324. }
  1325. channel->buf_idx = buf_idx;
  1326. if (channel->state == LCS_CH_STATE_STOPPED)
  1327. // FIXME: what if rc != 0 ??
  1328. rc = lcs_start_channel(channel);
  1329. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1330. if (channel->state == LCS_CH_STATE_SUSPENDED &&
  1331. channel->iob[channel->io_idx].state == LCS_BUF_STATE_READY) {
  1332. // FIXME: what if rc != 0 ??
  1333. rc = __lcs_resume_channel(channel);
  1334. }
  1335. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1336. /* Something happened on the channel. Wake up waiters. */
  1337. wake_up(&channel->wait_q);
  1338. }
  1339. /**
  1340. * Finish current tx buffer and make it ready for transmit.
  1341. */
  1342. static void
  1343. __lcs_emit_txbuffer(struct lcs_card *card)
  1344. {
  1345. LCS_DBF_TEXT(5, trace, "emittx");
  1346. *(__u16 *)(card->tx_buffer->data + card->tx_buffer->count) = 0;
  1347. card->tx_buffer->count += 2;
  1348. lcs_ready_buffer(&card->write, card->tx_buffer);
  1349. card->tx_buffer = NULL;
  1350. card->tx_emitted++;
  1351. }
  1352. /**
  1353. * Callback for finished tx buffers.
  1354. */
  1355. static void
  1356. lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
  1357. {
  1358. struct lcs_card *card;
  1359. LCS_DBF_TEXT(5, trace, "txbuffcb");
  1360. /* Put buffer back to pool. */
  1361. lcs_release_buffer(channel, buffer);
  1362. card = container_of(channel, struct lcs_card, write);
  1363. if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev))
  1364. netif_wake_queue(card->dev);
  1365. spin_lock(&card->lock);
  1366. card->tx_emitted--;
  1367. if (card->tx_emitted <= 0 && card->tx_buffer != NULL)
  1368. /*
  1369. * Last running tx buffer has finished. Submit partially
  1370. * filled current buffer.
  1371. */
  1372. __lcs_emit_txbuffer(card);
  1373. spin_unlock(&card->lock);
  1374. }
  1375. /**
  1376. * Packet transmit function called by network stack
  1377. */
  1378. static int
  1379. __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,
  1380. struct net_device *dev)
  1381. {
  1382. struct lcs_header *header;
  1383. int rc = 0;
  1384. LCS_DBF_TEXT(5, trace, "hardxmit");
  1385. if (skb == NULL) {
  1386. card->stats.tx_dropped++;
  1387. card->stats.tx_errors++;
  1388. return -EIO;
  1389. }
  1390. if (card->state != DEV_STATE_UP) {
  1391. dev_kfree_skb(skb);
  1392. card->stats.tx_dropped++;
  1393. card->stats.tx_errors++;
  1394. card->stats.tx_carrier_errors++;
  1395. return 0;
  1396. }
  1397. if (skb->protocol == htons(ETH_P_IPV6)) {
  1398. dev_kfree_skb(skb);
  1399. return 0;
  1400. }
  1401. netif_stop_queue(card->dev);
  1402. spin_lock(&card->lock);
  1403. if (card->tx_buffer != NULL &&
  1404. card->tx_buffer->count + sizeof(struct lcs_header) +
  1405. skb->len + sizeof(u16) > LCS_IOBUFFERSIZE)
  1406. /* skb too big for current tx buffer. */
  1407. __lcs_emit_txbuffer(card);
  1408. if (card->tx_buffer == NULL) {
  1409. /* Get new tx buffer */
  1410. card->tx_buffer = lcs_get_buffer(&card->write);
  1411. if (card->tx_buffer == NULL) {
  1412. card->stats.tx_dropped++;
  1413. rc = -EBUSY;
  1414. goto out;
  1415. }
  1416. card->tx_buffer->callback = lcs_txbuffer_cb;
  1417. card->tx_buffer->count = 0;
  1418. }
  1419. header = (struct lcs_header *)
  1420. (card->tx_buffer->data + card->tx_buffer->count);
  1421. card->tx_buffer->count += skb->len + sizeof(struct lcs_header);
  1422. header->offset = card->tx_buffer->count;
  1423. header->type = card->lan_type;
  1424. header->slot = card->portno;
  1425. skb_copy_from_linear_data(skb, header + 1, skb->len);
  1426. spin_unlock(&card->lock);
  1427. card->stats.tx_bytes += skb->len;
  1428. card->stats.tx_packets++;
  1429. dev_kfree_skb(skb);
  1430. netif_wake_queue(card->dev);
  1431. spin_lock(&card->lock);
  1432. if (card->tx_emitted <= 0 && card->tx_buffer != NULL)
  1433. /* If this is the first tx buffer emit it immediately. */
  1434. __lcs_emit_txbuffer(card);
  1435. out:
  1436. spin_unlock(&card->lock);
  1437. return rc;
  1438. }
  1439. static int
  1440. lcs_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1441. {
  1442. struct lcs_card *card;
  1443. int rc;
  1444. LCS_DBF_TEXT(5, trace, "pktxmit");
  1445. card = (struct lcs_card *) dev->priv;
  1446. rc = __lcs_start_xmit(card, skb, dev);
  1447. return rc;
  1448. }
  1449. /**
  1450. * send startlan and lanstat command to make LCS device ready
  1451. */
  1452. static int
  1453. lcs_startlan_auto(struct lcs_card *card)
  1454. {
  1455. int rc;
  1456. LCS_DBF_TEXT(2, trace, "strtauto");
  1457. #ifdef CONFIG_NET_ETHERNET
  1458. card->lan_type = LCS_FRAME_TYPE_ENET;
  1459. rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
  1460. if (rc == 0)
  1461. return 0;
  1462. #endif
  1463. #ifdef CONFIG_TR
  1464. card->lan_type = LCS_FRAME_TYPE_TR;
  1465. rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
  1466. if (rc == 0)
  1467. return 0;
  1468. #endif
  1469. #ifdef CONFIG_FDDI
  1470. card->lan_type = LCS_FRAME_TYPE_FDDI;
  1471. rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
  1472. if (rc == 0)
  1473. return 0;
  1474. #endif
  1475. return -EIO;
  1476. }
  1477. static int
  1478. lcs_startlan(struct lcs_card *card)
  1479. {
  1480. int rc, i;
  1481. LCS_DBF_TEXT(2, trace, "startlan");
  1482. rc = 0;
  1483. if (card->portno != LCS_INVALID_PORT_NO) {
  1484. if (card->lan_type == LCS_FRAME_TYPE_AUTO)
  1485. rc = lcs_startlan_auto(card);
  1486. else
  1487. rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
  1488. } else {
  1489. for (i = 0; i <= 16; i++) {
  1490. card->portno = i;
  1491. if (card->lan_type != LCS_FRAME_TYPE_AUTO)
  1492. rc = lcs_send_startlan(card,
  1493. LCS_INITIATOR_TCPIP);
  1494. else
  1495. /* autodetecting lan type */
  1496. rc = lcs_startlan_auto(card);
  1497. if (rc == 0)
  1498. break;
  1499. }
  1500. }
  1501. if (rc == 0)
  1502. return lcs_send_lanstat(card);
  1503. return rc;
  1504. }
  1505. /**
  1506. * LCS detect function
  1507. * setup channels and make them I/O ready
  1508. */
  1509. static int
  1510. lcs_detect(struct lcs_card *card)
  1511. {
  1512. int rc = 0;
  1513. LCS_DBF_TEXT(2, setup, "lcsdetct");
  1514. /* start/reset card */
  1515. if (card->dev)
  1516. netif_stop_queue(card->dev);
  1517. rc = lcs_stop_channels(card);
  1518. if (rc == 0) {
  1519. rc = lcs_start_channels(card);
  1520. if (rc == 0) {
  1521. rc = lcs_send_startup(card, LCS_INITIATOR_TCPIP);
  1522. if (rc == 0)
  1523. rc = lcs_startlan(card);
  1524. }
  1525. }
  1526. if (rc == 0) {
  1527. card->state = DEV_STATE_UP;
  1528. } else {
  1529. card->state = DEV_STATE_DOWN;
  1530. card->write.state = LCS_CH_STATE_INIT;
  1531. card->read.state = LCS_CH_STATE_INIT;
  1532. }
  1533. return rc;
  1534. }
  1535. /**
  1536. * LCS Stop card
  1537. */
  1538. static int
  1539. lcs_stopcard(struct lcs_card *card)
  1540. {
  1541. int rc;
  1542. LCS_DBF_TEXT(3, setup, "stopcard");
  1543. if (card->read.state != LCS_CH_STATE_STOPPED &&
  1544. card->write.state != LCS_CH_STATE_STOPPED &&
  1545. card->state == DEV_STATE_UP) {
  1546. lcs_clear_multicast_list(card);
  1547. rc = lcs_send_stoplan(card,LCS_INITIATOR_TCPIP);
  1548. rc = lcs_send_shutdown(card);
  1549. }
  1550. rc = lcs_stop_channels(card);
  1551. card->state = DEV_STATE_DOWN;
  1552. return rc;
  1553. }
  1554. /**
  1555. * Kernel Thread helper functions for LGW initiated commands
  1556. */
  1557. static void
  1558. lcs_start_kernel_thread(struct work_struct *work)
  1559. {
  1560. struct lcs_card *card = container_of(work, struct lcs_card, kernel_thread_starter);
  1561. LCS_DBF_TEXT(5, trace, "krnthrd");
  1562. if (lcs_do_start_thread(card, LCS_RECOVERY_THREAD))
  1563. kernel_thread(lcs_recovery, (void *) card, SIGCHLD);
  1564. #ifdef CONFIG_IP_MULTICAST
  1565. if (lcs_do_start_thread(card, LCS_SET_MC_THREAD))
  1566. kernel_thread(lcs_register_mc_addresses,
  1567. (void *) card, SIGCHLD);
  1568. #endif
  1569. }
  1570. /**
  1571. * Process control frames.
  1572. */
  1573. static void
  1574. lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd)
  1575. {
  1576. LCS_DBF_TEXT(5, trace, "getctrl");
  1577. if (cmd->initiator == LCS_INITIATOR_LGW) {
  1578. switch(cmd->cmd_code) {
  1579. case LCS_CMD_STARTUP:
  1580. case LCS_CMD_STARTLAN:
  1581. lcs_schedule_recovery(card);
  1582. break;
  1583. case LCS_CMD_STOPLAN:
  1584. PRINT_WARN("Stoplan for %s initiated by LGW.\n",
  1585. card->dev->name);
  1586. if (card->dev)
  1587. netif_carrier_off(card->dev);
  1588. break;
  1589. default:
  1590. PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
  1591. break;
  1592. }
  1593. } else
  1594. lcs_notify_lancmd_waiters(card, cmd);
  1595. }
  1596. /**
  1597. * Unpack network packet.
  1598. */
  1599. static void
  1600. lcs_get_skb(struct lcs_card *card, char *skb_data, unsigned int skb_len)
  1601. {
  1602. struct sk_buff *skb;
  1603. LCS_DBF_TEXT(5, trace, "getskb");
  1604. if (card->dev == NULL ||
  1605. card->state != DEV_STATE_UP)
  1606. /* The card isn't up. Ignore the packet. */
  1607. return;
  1608. skb = dev_alloc_skb(skb_len);
  1609. if (skb == NULL) {
  1610. PRINT_ERR("LCS: alloc_skb failed for device=%s\n",
  1611. card->dev->name);
  1612. card->stats.rx_dropped++;
  1613. return;
  1614. }
  1615. memcpy(skb_put(skb, skb_len), skb_data, skb_len);
  1616. skb->protocol = card->lan_type_trans(skb, card->dev);
  1617. card->stats.rx_bytes += skb_len;
  1618. card->stats.rx_packets++;
  1619. *((__u32 *)skb->cb) = ++card->pkt_seq;
  1620. netif_rx(skb);
  1621. }
  1622. /**
  1623. * LCS main routine to get packets and lancmd replies from the buffers
  1624. */
  1625. static void
  1626. lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
  1627. {
  1628. struct lcs_card *card;
  1629. struct lcs_header *lcs_hdr;
  1630. __u16 offset;
  1631. LCS_DBF_TEXT(5, trace, "lcsgtpkt");
  1632. lcs_hdr = (struct lcs_header *) buffer->data;
  1633. if (lcs_hdr->offset == LCS_ILLEGAL_OFFSET) {
  1634. LCS_DBF_TEXT(4, trace, "-eiogpkt");
  1635. return;
  1636. }
  1637. card = container_of(channel, struct lcs_card, read);
  1638. offset = 0;
  1639. while (lcs_hdr->offset != 0) {
  1640. if (lcs_hdr->offset <= 0 ||
  1641. lcs_hdr->offset > LCS_IOBUFFERSIZE ||
  1642. lcs_hdr->offset < offset) {
  1643. /* Offset invalid. */
  1644. card->stats.rx_length_errors++;
  1645. card->stats.rx_errors++;
  1646. return;
  1647. }
  1648. /* What kind of frame is it? */
  1649. if (lcs_hdr->type == LCS_FRAME_TYPE_CONTROL)
  1650. /* Control frame. */
  1651. lcs_get_control(card, (struct lcs_cmd *) lcs_hdr);
  1652. else if (lcs_hdr->type == LCS_FRAME_TYPE_ENET ||
  1653. lcs_hdr->type == LCS_FRAME_TYPE_TR ||
  1654. lcs_hdr->type == LCS_FRAME_TYPE_FDDI)
  1655. /* Normal network packet. */
  1656. lcs_get_skb(card, (char *)(lcs_hdr + 1),
  1657. lcs_hdr->offset - offset -
  1658. sizeof(struct lcs_header));
  1659. else
  1660. /* Unknown frame type. */
  1661. ; // FIXME: error message ?
  1662. /* Proceed to next frame. */
  1663. offset = lcs_hdr->offset;
  1664. lcs_hdr->offset = LCS_ILLEGAL_OFFSET;
  1665. lcs_hdr = (struct lcs_header *) (buffer->data + offset);
  1666. }
  1667. /* The buffer is now empty. Make it ready again. */
  1668. lcs_ready_buffer(&card->read, buffer);
  1669. }
  1670. /**
  1671. * get network statistics for ifconfig and other user programs
  1672. */
  1673. static struct net_device_stats *
  1674. lcs_getstats(struct net_device *dev)
  1675. {
  1676. struct lcs_card *card;
  1677. LCS_DBF_TEXT(4, trace, "netstats");
  1678. card = (struct lcs_card *) dev->priv;
  1679. return &card->stats;
  1680. }
  1681. /**
  1682. * stop lcs device
  1683. * This function will be called by user doing ifconfig xxx down
  1684. */
  1685. static int
  1686. lcs_stop_device(struct net_device *dev)
  1687. {
  1688. struct lcs_card *card;
  1689. int rc;
  1690. LCS_DBF_TEXT(2, trace, "stopdev");
  1691. card = (struct lcs_card *) dev->priv;
  1692. netif_carrier_off(dev);
  1693. netif_tx_disable(dev);
  1694. dev->flags &= ~IFF_UP;
  1695. wait_event(card->write.wait_q,
  1696. (card->write.state != LCS_CH_STATE_RUNNING));
  1697. rc = lcs_stopcard(card);
  1698. if (rc)
  1699. PRINT_ERR("Try it again!\n ");
  1700. return rc;
  1701. }
  1702. /**
  1703. * start lcs device and make it runnable
  1704. * This function will be called by user doing ifconfig xxx up
  1705. */
  1706. static int
  1707. lcs_open_device(struct net_device *dev)
  1708. {
  1709. struct lcs_card *card;
  1710. int rc;
  1711. LCS_DBF_TEXT(2, trace, "opendev");
  1712. card = (struct lcs_card *) dev->priv;
  1713. /* initialize statistics */
  1714. rc = lcs_detect(card);
  1715. if (rc) {
  1716. PRINT_ERR("LCS:Error in opening device!\n");
  1717. } else {
  1718. dev->flags |= IFF_UP;
  1719. netif_carrier_on(dev);
  1720. netif_wake_queue(dev);
  1721. card->state = DEV_STATE_UP;
  1722. }
  1723. return rc;
  1724. }
  1725. /**
  1726. * show function for portno called by cat or similar things
  1727. */
  1728. static ssize_t
  1729. lcs_portno_show (struct device *dev, struct device_attribute *attr, char *buf)
  1730. {
  1731. struct lcs_card *card;
  1732. card = (struct lcs_card *)dev->driver_data;
  1733. if (!card)
  1734. return 0;
  1735. return sprintf(buf, "%d\n", card->portno);
  1736. }
  1737. /**
  1738. * store the value which is piped to file portno
  1739. */
  1740. static ssize_t
  1741. lcs_portno_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1742. {
  1743. struct lcs_card *card;
  1744. int value;
  1745. card = (struct lcs_card *)dev->driver_data;
  1746. if (!card)
  1747. return 0;
  1748. sscanf(buf, "%u", &value);
  1749. /* TODO: sanity checks */
  1750. card->portno = value;
  1751. return count;
  1752. }
  1753. static DEVICE_ATTR(portno, 0644, lcs_portno_show, lcs_portno_store);
  1754. static ssize_t
  1755. lcs_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  1756. {
  1757. struct ccwgroup_device *cgdev;
  1758. cgdev = to_ccwgroupdev(dev);
  1759. if (!cgdev)
  1760. return -ENODEV;
  1761. return sprintf(buf, "%s\n", cu3088_type[cgdev->cdev[0]->id.driver_info]);
  1762. }
  1763. static DEVICE_ATTR(type, 0444, lcs_type_show, NULL);
  1764. static ssize_t
  1765. lcs_timeout_show(struct device *dev, struct device_attribute *attr, char *buf)
  1766. {
  1767. struct lcs_card *card;
  1768. card = (struct lcs_card *)dev->driver_data;
  1769. return card ? sprintf(buf, "%u\n", card->lancmd_timeout) : 0;
  1770. }
  1771. static ssize_t
  1772. lcs_timeout_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1773. {
  1774. struct lcs_card *card;
  1775. int value;
  1776. card = (struct lcs_card *)dev->driver_data;
  1777. if (!card)
  1778. return 0;
  1779. sscanf(buf, "%u", &value);
  1780. /* TODO: sanity checks */
  1781. card->lancmd_timeout = value;
  1782. return count;
  1783. }
  1784. static DEVICE_ATTR(lancmd_timeout, 0644, lcs_timeout_show, lcs_timeout_store);
  1785. static ssize_t
  1786. lcs_dev_recover_store(struct device *dev, struct device_attribute *attr,
  1787. const char *buf, size_t count)
  1788. {
  1789. struct lcs_card *card = dev->driver_data;
  1790. char *tmp;
  1791. int i;
  1792. if (!card)
  1793. return -EINVAL;
  1794. if (card->state != DEV_STATE_UP)
  1795. return -EPERM;
  1796. i = simple_strtoul(buf, &tmp, 16);
  1797. if (i == 1)
  1798. lcs_schedule_recovery(card);
  1799. return count;
  1800. }
  1801. static DEVICE_ATTR(recover, 0200, NULL, lcs_dev_recover_store);
  1802. static struct attribute * lcs_attrs[] = {
  1803. &dev_attr_portno.attr,
  1804. &dev_attr_type.attr,
  1805. &dev_attr_lancmd_timeout.attr,
  1806. &dev_attr_recover.attr,
  1807. NULL,
  1808. };
  1809. static struct attribute_group lcs_attr_group = {
  1810. .attrs = lcs_attrs,
  1811. };
  1812. /**
  1813. * lcs_probe_device is called on establishing a new ccwgroup_device.
  1814. */
  1815. static int
  1816. lcs_probe_device(struct ccwgroup_device *ccwgdev)
  1817. {
  1818. struct lcs_card *card;
  1819. int ret;
  1820. if (!get_device(&ccwgdev->dev))
  1821. return -ENODEV;
  1822. LCS_DBF_TEXT(2, setup, "add_dev");
  1823. card = lcs_alloc_card();
  1824. if (!card) {
  1825. PRINT_ERR("Allocation of lcs card failed\n");
  1826. put_device(&ccwgdev->dev);
  1827. return -ENOMEM;
  1828. }
  1829. ret = sysfs_create_group(&ccwgdev->dev.kobj, &lcs_attr_group);
  1830. if (ret) {
  1831. PRINT_ERR("Creating attributes failed");
  1832. lcs_free_card(card);
  1833. put_device(&ccwgdev->dev);
  1834. return ret;
  1835. }
  1836. ccwgdev->dev.driver_data = card;
  1837. ccwgdev->cdev[0]->handler = lcs_irq;
  1838. ccwgdev->cdev[1]->handler = lcs_irq;
  1839. card->gdev = ccwgdev;
  1840. INIT_WORK(&card->kernel_thread_starter, lcs_start_kernel_thread);
  1841. card->thread_start_mask = 0;
  1842. card->thread_allowed_mask = 0;
  1843. card->thread_running_mask = 0;
  1844. return 0;
  1845. }
  1846. static int
  1847. lcs_register_netdev(struct ccwgroup_device *ccwgdev)
  1848. {
  1849. struct lcs_card *card;
  1850. LCS_DBF_TEXT(2, setup, "regnetdv");
  1851. card = (struct lcs_card *)ccwgdev->dev.driver_data;
  1852. if (card->dev->reg_state != NETREG_UNINITIALIZED)
  1853. return 0;
  1854. SET_NETDEV_DEV(card->dev, &ccwgdev->dev);
  1855. return register_netdev(card->dev);
  1856. }
  1857. /**
  1858. * lcs_new_device will be called by setting the group device online.
  1859. */
  1860. static int
  1861. lcs_new_device(struct ccwgroup_device *ccwgdev)
  1862. {
  1863. struct lcs_card *card;
  1864. struct net_device *dev=NULL;
  1865. enum lcs_dev_states recover_state;
  1866. int rc;
  1867. card = (struct lcs_card *)ccwgdev->dev.driver_data;
  1868. if (!card)
  1869. return -ENODEV;
  1870. LCS_DBF_TEXT(2, setup, "newdev");
  1871. LCS_DBF_HEX(3, setup, &card, sizeof(void*));
  1872. card->read.ccwdev = ccwgdev->cdev[0];
  1873. card->write.ccwdev = ccwgdev->cdev[1];
  1874. recover_state = card->state;
  1875. ccw_device_set_online(card->read.ccwdev);
  1876. ccw_device_set_online(card->write.ccwdev);
  1877. LCS_DBF_TEXT(3, setup, "lcsnewdv");
  1878. lcs_setup_card(card);
  1879. rc = lcs_detect(card);
  1880. if (rc) {
  1881. LCS_DBF_TEXT(2, setup, "dtctfail");
  1882. PRINT_WARN("Detection of LCS card failed with return code "
  1883. "%d (0x%x)\n", rc, rc);
  1884. lcs_stopcard(card);
  1885. goto out;
  1886. }
  1887. if (card->dev) {
  1888. LCS_DBF_TEXT(2, setup, "samedev");
  1889. LCS_DBF_HEX(3, setup, &card, sizeof(void*));
  1890. goto netdev_out;
  1891. }
  1892. switch (card->lan_type) {
  1893. #ifdef CONFIG_NET_ETHERNET
  1894. case LCS_FRAME_TYPE_ENET:
  1895. card->lan_type_trans = eth_type_trans;
  1896. dev = alloc_etherdev(0);
  1897. break;
  1898. #endif
  1899. #ifdef CONFIG_TR
  1900. case LCS_FRAME_TYPE_TR:
  1901. card->lan_type_trans = tr_type_trans;
  1902. dev = alloc_trdev(0);
  1903. break;
  1904. #endif
  1905. #ifdef CONFIG_FDDI
  1906. case LCS_FRAME_TYPE_FDDI:
  1907. card->lan_type_trans = fddi_type_trans;
  1908. dev = alloc_fddidev(0);
  1909. break;
  1910. #endif
  1911. default:
  1912. LCS_DBF_TEXT(3, setup, "errinit");
  1913. PRINT_ERR("LCS: Initialization failed\n");
  1914. PRINT_ERR("LCS: No device found!\n");
  1915. goto out;
  1916. }
  1917. if (!dev)
  1918. goto out;
  1919. card->dev = dev;
  1920. card->dev->priv = card;
  1921. card->dev->open = lcs_open_device;
  1922. card->dev->stop = lcs_stop_device;
  1923. card->dev->hard_start_xmit = lcs_start_xmit;
  1924. card->dev->get_stats = lcs_getstats;
  1925. SET_MODULE_OWNER(dev);
  1926. memcpy(card->dev->dev_addr, card->mac, LCS_MAC_LENGTH);
  1927. #ifdef CONFIG_IP_MULTICAST
  1928. if (!lcs_check_multicast_support(card))
  1929. card->dev->set_multicast_list = lcs_set_multicast_list;
  1930. #endif
  1931. netdev_out:
  1932. lcs_set_allowed_threads(card,0xffffffff);
  1933. if (recover_state == DEV_STATE_RECOVER) {
  1934. lcs_set_multicast_list(card->dev);
  1935. card->dev->flags |= IFF_UP;
  1936. netif_carrier_on(card->dev);
  1937. netif_wake_queue(card->dev);
  1938. card->state = DEV_STATE_UP;
  1939. } else {
  1940. lcs_stopcard(card);
  1941. }
  1942. if (lcs_register_netdev(ccwgdev) != 0)
  1943. goto out;
  1944. /* Print out supported assists: IPv6 */
  1945. PRINT_INFO("LCS device %s %s IPv6 support\n", card->dev->name,
  1946. (card->ip_assists_supported & LCS_IPASS_IPV6_SUPPORT) ?
  1947. "with" : "without");
  1948. /* Print out supported assist: Multicast */
  1949. PRINT_INFO("LCS device %s %s Multicast support\n", card->dev->name,
  1950. (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) ?
  1951. "with" : "without");
  1952. return 0;
  1953. out:
  1954. ccw_device_set_offline(card->read.ccwdev);
  1955. ccw_device_set_offline(card->write.ccwdev);
  1956. return -ENODEV;
  1957. }
  1958. /**
  1959. * lcs_shutdown_device, called when setting the group device offline.
  1960. */
  1961. static int
  1962. __lcs_shutdown_device(struct ccwgroup_device *ccwgdev, int recovery_mode)
  1963. {
  1964. struct lcs_card *card;
  1965. enum lcs_dev_states recover_state;
  1966. int ret;
  1967. LCS_DBF_TEXT(3, setup, "shtdndev");
  1968. card = (struct lcs_card *)ccwgdev->dev.driver_data;
  1969. if (!card)
  1970. return -ENODEV;
  1971. if (recovery_mode == 0) {
  1972. lcs_set_allowed_threads(card, 0);
  1973. if (lcs_wait_for_threads(card, LCS_SET_MC_THREAD))
  1974. return -ERESTARTSYS;
  1975. }
  1976. LCS_DBF_HEX(3, setup, &card, sizeof(void*));
  1977. recover_state = card->state;
  1978. ret = lcs_stop_device(card->dev);
  1979. ret = ccw_device_set_offline(card->read.ccwdev);
  1980. ret = ccw_device_set_offline(card->write.ccwdev);
  1981. if (recover_state == DEV_STATE_UP) {
  1982. card->state = DEV_STATE_RECOVER;
  1983. }
  1984. if (ret)
  1985. return ret;
  1986. return 0;
  1987. }
  1988. static int
  1989. lcs_shutdown_device(struct ccwgroup_device *ccwgdev)
  1990. {
  1991. return __lcs_shutdown_device(ccwgdev, 0);
  1992. }
  1993. /**
  1994. * drive lcs recovery after startup and startlan initiated by Lan Gateway
  1995. */
  1996. static int
  1997. lcs_recovery(void *ptr)
  1998. {
  1999. struct lcs_card *card;
  2000. struct ccwgroup_device *gdev;
  2001. int rc;
  2002. card = (struct lcs_card *) ptr;
  2003. daemonize("lcs_recover");
  2004. LCS_DBF_TEXT(4, trace, "recover1");
  2005. if (!lcs_do_run_thread(card, LCS_RECOVERY_THREAD))
  2006. return 0;
  2007. LCS_DBF_TEXT(4, trace, "recover2");
  2008. gdev = card->gdev;
  2009. PRINT_WARN("Recovery of device %s started...\n", gdev->dev.bus_id);
  2010. rc = __lcs_shutdown_device(gdev, 1);
  2011. rc = lcs_new_device(gdev);
  2012. if (!rc)
  2013. PRINT_INFO("Device %s successfully recovered!\n",
  2014. card->dev->name);
  2015. else
  2016. PRINT_INFO("Device %s could not be recovered!\n",
  2017. card->dev->name);
  2018. lcs_clear_thread_running_bit(card, LCS_RECOVERY_THREAD);
  2019. return 0;
  2020. }
  2021. /**
  2022. * lcs_remove_device, free buffers and card
  2023. */
  2024. static void
  2025. lcs_remove_device(struct ccwgroup_device *ccwgdev)
  2026. {
  2027. struct lcs_card *card;
  2028. card = (struct lcs_card *)ccwgdev->dev.driver_data;
  2029. if (!card)
  2030. return;
  2031. PRINT_INFO("Removing lcs group device ....\n");
  2032. LCS_DBF_TEXT(3, setup, "remdev");
  2033. LCS_DBF_HEX(3, setup, &card, sizeof(void*));
  2034. if (ccwgdev->state == CCWGROUP_ONLINE) {
  2035. lcs_shutdown_device(ccwgdev);
  2036. }
  2037. if (card->dev)
  2038. unregister_netdev(card->dev);
  2039. sysfs_remove_group(&ccwgdev->dev.kobj, &lcs_attr_group);
  2040. lcs_cleanup_card(card);
  2041. lcs_free_card(card);
  2042. put_device(&ccwgdev->dev);
  2043. }
  2044. /**
  2045. * LCS ccwgroup driver registration
  2046. */
  2047. static struct ccwgroup_driver lcs_group_driver = {
  2048. .owner = THIS_MODULE,
  2049. .name = "lcs",
  2050. .max_slaves = 2,
  2051. .driver_id = 0xD3C3E2,
  2052. .probe = lcs_probe_device,
  2053. .remove = lcs_remove_device,
  2054. .set_online = lcs_new_device,
  2055. .set_offline = lcs_shutdown_device,
  2056. };
  2057. /**
  2058. * LCS Module/Kernel initialization function
  2059. */
  2060. static int
  2061. __init lcs_init_module(void)
  2062. {
  2063. int rc;
  2064. PRINT_INFO("Loading %s\n",version);
  2065. rc = lcs_register_debug_facility();
  2066. LCS_DBF_TEXT(0, setup, "lcsinit");
  2067. if (rc) {
  2068. PRINT_ERR("Initialization failed\n");
  2069. return rc;
  2070. }
  2071. rc = register_cu3088_discipline(&lcs_group_driver);
  2072. if (rc) {
  2073. PRINT_ERR("Initialization failed\n");
  2074. return rc;
  2075. }
  2076. return 0;
  2077. }
  2078. /**
  2079. * LCS module cleanup function
  2080. */
  2081. static void
  2082. __exit lcs_cleanup_module(void)
  2083. {
  2084. PRINT_INFO("Terminating lcs module.\n");
  2085. LCS_DBF_TEXT(0, trace, "cleanup");
  2086. unregister_cu3088_discipline(&lcs_group_driver);
  2087. lcs_unregister_debug_facility();
  2088. }
  2089. module_init(lcs_init_module);
  2090. module_exit(lcs_cleanup_module);
  2091. MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
  2092. MODULE_LICENSE("GPL");