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