lcs.c 60 KB

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