lcs.c 59 KB

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