lcs.c 60 KB

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