lcs.c 59 KB

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