lcs.c 58 KB

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