lcs.c 59 KB

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