lcs.c 60 KB

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