lcs.c 59 KB

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