lcs.c 59 KB

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