lcs.c 59 KB

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