lcs.c 59 KB

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