claw.c 153 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421
  1. /*
  2. * drivers/s390/net/claw.c
  3. * ESCON CLAW network driver
  4. *
  5. * Linux for zSeries version
  6. * Copyright (C) 2002,2005 IBM Corporation
  7. * Author(s) Original code written by:
  8. * Kazuo Iimura (iimura@jp.ibm.com)
  9. * Rewritten by
  10. * Andy Richter (richtera@us.ibm.com)
  11. * Marc Price (mwprice@us.ibm.com)
  12. *
  13. * sysfs parms:
  14. * group x.x.rrrr,x.x.wwww
  15. * read_buffer nnnnnnn
  16. * write_buffer nnnnnn
  17. * host_name aaaaaaaa
  18. * adapter_name aaaaaaaa
  19. * api_type aaaaaaaa
  20. *
  21. * eg.
  22. * group 0.0.0200 0.0.0201
  23. * read_buffer 25
  24. * write_buffer 20
  25. * host_name LINUX390
  26. * adapter_name RS6K
  27. * api_type TCPIP
  28. *
  29. * where
  30. *
  31. * The device id is decided by the order entries
  32. * are added to the group the first is claw0 the second claw1
  33. * up to CLAW_MAX_DEV
  34. *
  35. * rrrr - the first of 2 consecutive device addresses used for the
  36. * CLAW protocol.
  37. * The specified address is always used as the input (Read)
  38. * channel and the next address is used as the output channel.
  39. *
  40. * wwww - the second of 2 consecutive device addresses used for
  41. * the CLAW protocol.
  42. * The specified address is always used as the output
  43. * channel and the previous address is used as the input channel.
  44. *
  45. * read_buffer - specifies number of input buffers to allocate.
  46. * write_buffer - specifies number of output buffers to allocate.
  47. * host_name - host name
  48. * adaptor_name - adaptor name
  49. * api_type - API type TCPIP or API will be sent and expected
  50. * as ws_name
  51. *
  52. * Note the following requirements:
  53. * 1) host_name must match the configured adapter_name on the remote side
  54. * 2) adaptor_name must match the configured host name on the remote side
  55. *
  56. * Change History
  57. * 1.00 Initial release shipped
  58. * 1.10 Changes for Buffer allocation
  59. * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
  60. * 1.25 Added Packing support
  61. */
  62. #include <asm/ccwdev.h>
  63. #include <asm/ccwgroup.h>
  64. #include <asm/debug.h>
  65. #include <asm/idals.h>
  66. #include <asm/io.h>
  67. #include <linux/bitops.h>
  68. #include <linux/ctype.h>
  69. #include <linux/delay.h>
  70. #include <linux/errno.h>
  71. #include <linux/if_arp.h>
  72. #include <linux/init.h>
  73. #include <linux/interrupt.h>
  74. #include <linux/ip.h>
  75. #include <linux/kernel.h>
  76. #include <linux/module.h>
  77. #include <linux/netdevice.h>
  78. #include <linux/etherdevice.h>
  79. #include <linux/proc_fs.h>
  80. #include <linux/sched.h>
  81. #include <linux/signal.h>
  82. #include <linux/skbuff.h>
  83. #include <linux/slab.h>
  84. #include <linux/string.h>
  85. #include <linux/tcp.h>
  86. #include <linux/timer.h>
  87. #include <linux/types.h>
  88. #include "cu3088.h"
  89. #include "claw.h"
  90. MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
  91. MODULE_DESCRIPTION("Linux for zSeries CLAW Driver\n" \
  92. "Copyright 2000,2005 IBM Corporation\n");
  93. MODULE_LICENSE("GPL");
  94. /* Debugging is based on DEBUGMSG, IOTRACE, or FUNCTRACE options:
  95. DEBUGMSG - Enables output of various debug messages in the code
  96. IOTRACE - Enables output of CCW and other IO related traces
  97. FUNCTRACE - Enables output of function entry/exit trace
  98. Define any combination of above options to enable tracing
  99. CLAW also uses the s390dbf file system see claw_trace and claw_setup
  100. */
  101. /* following enables tracing */
  102. //#define DEBUGMSG
  103. //#define IOTRACE
  104. //#define FUNCTRACE
  105. #ifdef DEBUGMSG
  106. #define DEBUG
  107. #endif
  108. #ifdef IOTRACE
  109. #define DEBUG
  110. #endif
  111. #ifdef FUNCTRACE
  112. #define DEBUG
  113. #endif
  114. static char debug_buffer[255];
  115. /**
  116. * Debug Facility Stuff
  117. */
  118. static debug_info_t *claw_dbf_setup;
  119. static debug_info_t *claw_dbf_trace;
  120. /**
  121. * CLAW Debug Facility functions
  122. */
  123. static void
  124. claw_unregister_debug_facility(void)
  125. {
  126. if (claw_dbf_setup)
  127. debug_unregister(claw_dbf_setup);
  128. if (claw_dbf_trace)
  129. debug_unregister(claw_dbf_trace);
  130. }
  131. static int
  132. claw_register_debug_facility(void)
  133. {
  134. claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
  135. claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
  136. if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
  137. printk(KERN_WARNING "Not enough memory for debug facility.\n");
  138. claw_unregister_debug_facility();
  139. return -ENOMEM;
  140. }
  141. debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
  142. debug_set_level(claw_dbf_setup, 2);
  143. debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
  144. debug_set_level(claw_dbf_trace, 2);
  145. return 0;
  146. }
  147. static inline void
  148. claw_set_busy(struct net_device *dev)
  149. {
  150. ((struct claw_privbk *) dev->priv)->tbusy=1;
  151. eieio();
  152. }
  153. static inline void
  154. claw_clear_busy(struct net_device *dev)
  155. {
  156. clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
  157. netif_wake_queue(dev);
  158. eieio();
  159. }
  160. static inline int
  161. claw_check_busy(struct net_device *dev)
  162. {
  163. eieio();
  164. return ((struct claw_privbk *) dev->priv)->tbusy;
  165. }
  166. static inline void
  167. claw_setbit_busy(int nr,struct net_device *dev)
  168. {
  169. netif_stop_queue(dev);
  170. set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
  171. }
  172. static inline void
  173. claw_clearbit_busy(int nr,struct net_device *dev)
  174. {
  175. clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
  176. netif_wake_queue(dev);
  177. }
  178. static inline int
  179. claw_test_and_setbit_busy(int nr,struct net_device *dev)
  180. {
  181. netif_stop_queue(dev);
  182. return test_and_set_bit(nr,
  183. (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
  184. }
  185. /* Functions for the DEV methods */
  186. static int claw_probe(struct ccwgroup_device *cgdev);
  187. static void claw_remove_device(struct ccwgroup_device *cgdev);
  188. static void claw_purge_skb_queue(struct sk_buff_head *q);
  189. static int claw_new_device(struct ccwgroup_device *cgdev);
  190. static int claw_shutdown_device(struct ccwgroup_device *cgdev);
  191. static int claw_tx(struct sk_buff *skb, struct net_device *dev);
  192. static int claw_change_mtu( struct net_device *dev, int new_mtu);
  193. static int claw_open(struct net_device *dev);
  194. static void claw_irq_handler(struct ccw_device *cdev,
  195. unsigned long intparm, struct irb *irb);
  196. static void claw_irq_tasklet ( unsigned long data );
  197. static int claw_release(struct net_device *dev);
  198. static void claw_write_retry ( struct chbk * p_ch );
  199. static void claw_write_next ( struct chbk * p_ch );
  200. static void claw_timer ( struct chbk * p_ch );
  201. /* Functions */
  202. static int add_claw_reads(struct net_device *dev,
  203. struct ccwbk* p_first, struct ccwbk* p_last);
  204. static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
  205. static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
  206. static int find_link(struct net_device *dev, char *host_name, char *ws_name );
  207. static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
  208. static int init_ccw_bk(struct net_device *dev);
  209. static void probe_error( struct ccwgroup_device *cgdev);
  210. static struct net_device_stats *claw_stats(struct net_device *dev);
  211. static int pages_to_order_of_mag(int num_of_pages);
  212. static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
  213. #ifdef DEBUG
  214. static void dumpit (char *buf, int len);
  215. #endif
  216. /* sysfs Functions */
  217. static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
  218. static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
  219. const char *buf, size_t count);
  220. static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
  221. static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
  222. const char *buf, size_t count);
  223. static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
  224. static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
  225. const char *buf, size_t count);
  226. static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  227. static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
  228. const char *buf, size_t count);
  229. static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  230. static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
  231. const char *buf, size_t count);
  232. static int claw_add_files(struct device *dev);
  233. static void claw_remove_files(struct device *dev);
  234. /* Functions for System Validate */
  235. static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
  236. static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  237. __u8 correlator, __u8 rc , char *local_name, char *remote_name);
  238. static int claw_snd_conn_req(struct net_device *dev, __u8 link);
  239. static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
  240. static int claw_snd_sys_validate_rsp(struct net_device *dev,
  241. struct clawctl * p_ctl, __u32 return_code);
  242. static int claw_strt_conn_req(struct net_device *dev );
  243. static void claw_strt_read ( struct net_device *dev, int lock );
  244. static void claw_strt_out_IO( struct net_device *dev );
  245. static void claw_free_wrt_buf( struct net_device *dev );
  246. /* Functions for unpack reads */
  247. static void unpack_read (struct net_device *dev );
  248. /* ccwgroup table */
  249. static struct ccwgroup_driver claw_group_driver = {
  250. .owner = THIS_MODULE,
  251. .name = "claw",
  252. .max_slaves = 2,
  253. .driver_id = 0xC3D3C1E6,
  254. .probe = claw_probe,
  255. .remove = claw_remove_device,
  256. .set_online = claw_new_device,
  257. .set_offline = claw_shutdown_device,
  258. };
  259. /*
  260. *
  261. * Key functions
  262. */
  263. /*----------------------------------------------------------------*
  264. * claw_probe *
  265. * this function is called for each CLAW device. *
  266. *----------------------------------------------------------------*/
  267. static int
  268. claw_probe(struct ccwgroup_device *cgdev)
  269. {
  270. int rc;
  271. struct claw_privbk *privptr=NULL;
  272. #ifdef FUNCTRACE
  273. printk(KERN_INFO "%s Enter\n",__FUNCTION__);
  274. #endif
  275. CLAW_DBF_TEXT(2,setup,"probe");
  276. if (!get_device(&cgdev->dev))
  277. return -ENODEV;
  278. #ifdef DEBUGMSG
  279. printk(KERN_INFO "claw: variable cgdev =\n");
  280. dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
  281. #endif
  282. privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
  283. if (privptr == NULL) {
  284. probe_error(cgdev);
  285. put_device(&cgdev->dev);
  286. printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
  287. cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
  288. CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
  289. return -ENOMEM;
  290. }
  291. privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
  292. privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
  293. if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
  294. probe_error(cgdev);
  295. put_device(&cgdev->dev);
  296. printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
  297. cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
  298. CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
  299. return -ENOMEM;
  300. }
  301. memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
  302. memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
  303. memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
  304. privptr->p_env->packing = 0;
  305. privptr->p_env->write_buffers = 5;
  306. privptr->p_env->read_buffers = 5;
  307. privptr->p_env->read_size = CLAW_FRAME_SIZE;
  308. privptr->p_env->write_size = CLAW_FRAME_SIZE;
  309. rc = claw_add_files(&cgdev->dev);
  310. if (rc) {
  311. probe_error(cgdev);
  312. put_device(&cgdev->dev);
  313. printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
  314. cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
  315. CLAW_DBF_TEXT_(2,setup,"probex%d",rc);
  316. return rc;
  317. }
  318. printk(KERN_INFO "claw: sysfs files added for %s\n",cgdev->cdev[0]->dev.bus_id);
  319. privptr->p_env->p_priv = privptr;
  320. cgdev->cdev[0]->handler = claw_irq_handler;
  321. cgdev->cdev[1]->handler = claw_irq_handler;
  322. cgdev->dev.driver_data = privptr;
  323. #ifdef FUNCTRACE
  324. printk(KERN_INFO "claw:%s exit on line %d, "
  325. "rc = 0\n",__FUNCTION__,__LINE__);
  326. #endif
  327. CLAW_DBF_TEXT(2,setup,"prbext 0");
  328. return 0;
  329. } /* end of claw_probe */
  330. /*-------------------------------------------------------------------*
  331. * claw_tx *
  332. *-------------------------------------------------------------------*/
  333. static int
  334. claw_tx(struct sk_buff *skb, struct net_device *dev)
  335. {
  336. int rc;
  337. struct claw_privbk *privptr=dev->priv;
  338. unsigned long saveflags;
  339. struct chbk *p_ch;
  340. #ifdef FUNCTRACE
  341. printk(KERN_INFO "%s:%s enter\n",dev->name,__FUNCTION__);
  342. #endif
  343. CLAW_DBF_TEXT(4,trace,"claw_tx");
  344. p_ch=&privptr->channel[WRITE];
  345. if (skb == NULL) {
  346. printk(KERN_WARNING "%s: null pointer passed as sk_buffer\n",
  347. dev->name);
  348. privptr->stats.tx_dropped++;
  349. #ifdef FUNCTRACE
  350. printk(KERN_INFO "%s: %s() exit on line %d, rc = EIO\n",
  351. dev->name,__FUNCTION__, __LINE__);
  352. #endif
  353. CLAW_DBF_TEXT_(2,trace,"clawtx%d",-EIO);
  354. return -EIO;
  355. }
  356. #ifdef IOTRACE
  357. printk(KERN_INFO "%s: variable sk_buff=\n",dev->name);
  358. dumpit((char *) skb, sizeof(struct sk_buff));
  359. printk(KERN_INFO "%s: variable dev=\n",dev->name);
  360. dumpit((char *) dev, sizeof(struct net_device));
  361. #endif
  362. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  363. rc=claw_hw_tx( skb, dev, 1 );
  364. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  365. #ifdef FUNCTRACE
  366. printk(KERN_INFO "%s:%s exit on line %d, rc = %d\n",
  367. dev->name, __FUNCTION__, __LINE__, rc);
  368. #endif
  369. CLAW_DBF_TEXT_(4,trace,"clawtx%d",rc);
  370. return rc;
  371. } /* end of claw_tx */
  372. /*------------------------------------------------------------------*
  373. * pack the collect queue into an skb and return it *
  374. * If not packing just return the top skb from the queue *
  375. *------------------------------------------------------------------*/
  376. static struct sk_buff *
  377. claw_pack_skb(struct claw_privbk *privptr)
  378. {
  379. struct sk_buff *new_skb,*held_skb;
  380. struct chbk *p_ch = &privptr->channel[WRITE];
  381. struct claw_env *p_env = privptr->p_env;
  382. int pkt_cnt,pk_ind,so_far;
  383. new_skb = NULL; /* assume no dice */
  384. pkt_cnt = 0;
  385. CLAW_DBF_TEXT(4,trace,"PackSKBe");
  386. if (!skb_queue_empty(&p_ch->collect_queue)) {
  387. /* some data */
  388. held_skb = skb_dequeue(&p_ch->collect_queue);
  389. if (held_skb)
  390. dev_kfree_skb_any(held_skb);
  391. else
  392. return NULL;
  393. if (p_env->packing != DO_PACKED)
  394. return held_skb;
  395. /* get a new SKB we will pack at least one */
  396. new_skb = dev_alloc_skb(p_env->write_size);
  397. if (new_skb == NULL) {
  398. atomic_inc(&held_skb->users);
  399. skb_queue_head(&p_ch->collect_queue,held_skb);
  400. return NULL;
  401. }
  402. /* we have packed packet and a place to put it */
  403. pk_ind = 1;
  404. so_far = 0;
  405. new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
  406. while ((pk_ind) && (held_skb != NULL)) {
  407. if (held_skb->len+so_far <= p_env->write_size-8) {
  408. memcpy(skb_put(new_skb,held_skb->len),
  409. held_skb->data,held_skb->len);
  410. privptr->stats.tx_packets++;
  411. so_far += held_skb->len;
  412. pkt_cnt++;
  413. dev_kfree_skb_any(held_skb);
  414. held_skb = skb_dequeue(&p_ch->collect_queue);
  415. if (held_skb)
  416. atomic_dec(&held_skb->users);
  417. } else {
  418. pk_ind = 0;
  419. atomic_inc(&held_skb->users);
  420. skb_queue_head(&p_ch->collect_queue,held_skb);
  421. }
  422. }
  423. #ifdef IOTRACE
  424. printk(KERN_INFO "%s: %s() Packed %d len %d\n",
  425. p_env->ndev->name,
  426. __FUNCTION__,pkt_cnt,new_skb->len);
  427. #endif
  428. }
  429. CLAW_DBF_TEXT(4,trace,"PackSKBx");
  430. return new_skb;
  431. }
  432. /*-------------------------------------------------------------------*
  433. * claw_change_mtu *
  434. * *
  435. *-------------------------------------------------------------------*/
  436. static int
  437. claw_change_mtu(struct net_device *dev, int new_mtu)
  438. {
  439. struct claw_privbk *privptr=dev->priv;
  440. int buff_size;
  441. #ifdef FUNCTRACE
  442. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  443. #endif
  444. #ifdef DEBUGMSG
  445. printk(KERN_INFO "variable dev =\n");
  446. dumpit((char *) dev, sizeof(struct net_device));
  447. printk(KERN_INFO "variable new_mtu = %d\n", new_mtu);
  448. #endif
  449. CLAW_DBF_TEXT(4,trace,"setmtu");
  450. buff_size = privptr->p_env->write_size;
  451. if ((new_mtu < 60) || (new_mtu > buff_size)) {
  452. #ifdef FUNCTRACE
  453. printk(KERN_INFO "%s:%s Exit on line %d, rc=EINVAL\n",
  454. dev->name,
  455. __FUNCTION__, __LINE__);
  456. #endif
  457. return -EINVAL;
  458. }
  459. dev->mtu = new_mtu;
  460. #ifdef FUNCTRACE
  461. printk(KERN_INFO "%s:%s Exit on line %d\n",dev->name,
  462. __FUNCTION__, __LINE__);
  463. #endif
  464. return 0;
  465. } /* end of claw_change_mtu */
  466. /*-------------------------------------------------------------------*
  467. * claw_open *
  468. * *
  469. *-------------------------------------------------------------------*/
  470. static int
  471. claw_open(struct net_device *dev)
  472. {
  473. int rc;
  474. int i;
  475. unsigned long saveflags=0;
  476. unsigned long parm;
  477. struct claw_privbk *privptr;
  478. DECLARE_WAITQUEUE(wait, current);
  479. struct timer_list timer;
  480. struct ccwbk *p_buf;
  481. #ifdef FUNCTRACE
  482. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  483. #endif
  484. CLAW_DBF_TEXT(4,trace,"open");
  485. if (!dev || (dev->name[0] == 0x00)) {
  486. CLAW_DBF_TEXT(2,trace,"BadDev");
  487. printk(KERN_WARNING "claw: Bad device at open failing \n");
  488. return -ENODEV;
  489. }
  490. privptr = (struct claw_privbk *)dev->priv;
  491. /* allocate and initialize CCW blocks */
  492. if (privptr->buffs_alloc == 0) {
  493. rc=init_ccw_bk(dev);
  494. if (rc) {
  495. printk(KERN_INFO "%s:%s Exit on line %d, rc=ENOMEM\n",
  496. dev->name,
  497. __FUNCTION__, __LINE__);
  498. CLAW_DBF_TEXT(2,trace,"openmem");
  499. return -ENOMEM;
  500. }
  501. }
  502. privptr->system_validate_comp=0;
  503. privptr->release_pend=0;
  504. if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  505. privptr->p_env->read_size=DEF_PACK_BUFSIZE;
  506. privptr->p_env->write_size=DEF_PACK_BUFSIZE;
  507. privptr->p_env->packing=PACKING_ASK;
  508. } else {
  509. privptr->p_env->packing=0;
  510. privptr->p_env->read_size=CLAW_FRAME_SIZE;
  511. privptr->p_env->write_size=CLAW_FRAME_SIZE;
  512. }
  513. claw_set_busy(dev);
  514. tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
  515. (unsigned long) &privptr->channel[READ]);
  516. for ( i = 0; i < 2; i++) {
  517. CLAW_DBF_TEXT_(2,trace,"opn_ch%d",i);
  518. init_waitqueue_head(&privptr->channel[i].wait);
  519. /* skb_queue_head_init(&p_ch->io_queue); */
  520. if (i == WRITE)
  521. skb_queue_head_init(
  522. &privptr->channel[WRITE].collect_queue);
  523. privptr->channel[i].flag_a = 0;
  524. privptr->channel[i].IO_active = 0;
  525. privptr->channel[i].flag &= ~CLAW_TIMER;
  526. init_timer(&timer);
  527. timer.function = (void *)claw_timer;
  528. timer.data = (unsigned long)(&privptr->channel[i]);
  529. timer.expires = jiffies + 15*HZ;
  530. add_timer(&timer);
  531. spin_lock_irqsave(get_ccwdev_lock(
  532. privptr->channel[i].cdev), saveflags);
  533. parm = (unsigned long) &privptr->channel[i];
  534. privptr->channel[i].claw_state = CLAW_START_HALT_IO;
  535. rc = 0;
  536. add_wait_queue(&privptr->channel[i].wait, &wait);
  537. rc = ccw_device_halt(
  538. (struct ccw_device *)privptr->channel[i].cdev,parm);
  539. set_current_state(TASK_INTERRUPTIBLE);
  540. spin_unlock_irqrestore(
  541. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  542. schedule();
  543. set_current_state(TASK_RUNNING);
  544. remove_wait_queue(&privptr->channel[i].wait, &wait);
  545. if(rc != 0)
  546. ccw_check_return_code(privptr->channel[i].cdev, rc);
  547. if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
  548. del_timer(&timer);
  549. }
  550. if ((((privptr->channel[READ].last_dstat |
  551. privptr->channel[WRITE].last_dstat) &
  552. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
  553. (((privptr->channel[READ].flag |
  554. privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
  555. #ifdef DEBUGMSG
  556. printk(KERN_INFO "%s: channel problems during open - read:"
  557. " %02x - write: %02x\n",
  558. dev->name,
  559. privptr->channel[READ].last_dstat,
  560. privptr->channel[WRITE].last_dstat);
  561. #endif
  562. printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
  563. CLAW_DBF_TEXT(2,trace,"notrdy");
  564. for ( i = 0; i < 2; i++) {
  565. spin_lock_irqsave(
  566. get_ccwdev_lock(privptr->channel[i].cdev),
  567. saveflags);
  568. parm = (unsigned long) &privptr->channel[i];
  569. privptr->channel[i].claw_state = CLAW_STOP;
  570. rc = ccw_device_halt(
  571. (struct ccw_device *)&privptr->channel[i].cdev,
  572. parm);
  573. spin_unlock_irqrestore(
  574. get_ccwdev_lock(privptr->channel[i].cdev),
  575. saveflags);
  576. if (rc != 0) {
  577. ccw_check_return_code(
  578. privptr->channel[i].cdev, rc);
  579. }
  580. }
  581. free_pages((unsigned long)privptr->p_buff_ccw,
  582. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  583. if (privptr->p_env->read_size < PAGE_SIZE) {
  584. free_pages((unsigned long)privptr->p_buff_read,
  585. (int)pages_to_order_of_mag(
  586. privptr->p_buff_read_num));
  587. }
  588. else {
  589. p_buf=privptr->p_read_active_first;
  590. while (p_buf!=NULL) {
  591. free_pages((unsigned long)p_buf->p_buffer,
  592. (int)pages_to_order_of_mag(
  593. privptr->p_buff_pages_perread ));
  594. p_buf=p_buf->next;
  595. }
  596. }
  597. if (privptr->p_env->write_size < PAGE_SIZE ) {
  598. free_pages((unsigned long)privptr->p_buff_write,
  599. (int)pages_to_order_of_mag(
  600. privptr->p_buff_write_num));
  601. }
  602. else {
  603. p_buf=privptr->p_write_active_first;
  604. while (p_buf!=NULL) {
  605. free_pages((unsigned long)p_buf->p_buffer,
  606. (int)pages_to_order_of_mag(
  607. privptr->p_buff_pages_perwrite ));
  608. p_buf=p_buf->next;
  609. }
  610. }
  611. privptr->buffs_alloc = 0;
  612. privptr->channel[READ].flag= 0x00;
  613. privptr->channel[WRITE].flag = 0x00;
  614. privptr->p_buff_ccw=NULL;
  615. privptr->p_buff_read=NULL;
  616. privptr->p_buff_write=NULL;
  617. claw_clear_busy(dev);
  618. #ifdef FUNCTRACE
  619. printk(KERN_INFO "%s:%s Exit on line %d, rc=EIO\n",
  620. dev->name,__FUNCTION__,__LINE__);
  621. #endif
  622. CLAW_DBF_TEXT(2,trace,"open EIO");
  623. return -EIO;
  624. }
  625. /* Send SystemValidate command */
  626. claw_clear_busy(dev);
  627. #ifdef FUNCTRACE
  628. printk(KERN_INFO "%s:%s Exit on line %d, rc=0\n",
  629. dev->name,__FUNCTION__,__LINE__);
  630. #endif
  631. CLAW_DBF_TEXT(4,trace,"openok");
  632. return 0;
  633. } /* end of claw_open */
  634. /*-------------------------------------------------------------------*
  635. * *
  636. * claw_irq_handler *
  637. * *
  638. *--------------------------------------------------------------------*/
  639. static void
  640. claw_irq_handler(struct ccw_device *cdev,
  641. unsigned long intparm, struct irb *irb)
  642. {
  643. struct chbk *p_ch = NULL;
  644. struct claw_privbk *privptr = NULL;
  645. struct net_device *dev = NULL;
  646. struct claw_env *p_env;
  647. struct chbk *p_ch_r=NULL;
  648. #ifdef FUNCTRACE
  649. printk(KERN_INFO "%s enter \n",__FUNCTION__);
  650. #endif
  651. CLAW_DBF_TEXT(4,trace,"clawirq");
  652. /* Bypass all 'unsolicited interrupts' */
  653. if (!cdev->dev.driver_data) {
  654. printk(KERN_WARNING "claw: unsolicited interrupt for device:"
  655. "%s received c-%02x d-%02x\n",
  656. cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
  657. #ifdef FUNCTRACE
  658. printk(KERN_INFO "claw: %s() "
  659. "exit on line %d\n",__FUNCTION__,__LINE__);
  660. #endif
  661. CLAW_DBF_TEXT(2,trace,"badirq");
  662. return;
  663. }
  664. privptr = (struct claw_privbk *)cdev->dev.driver_data;
  665. /* Try to extract channel from driver data. */
  666. if (privptr->channel[READ].cdev == cdev)
  667. p_ch = &privptr->channel[READ];
  668. else if (privptr->channel[WRITE].cdev == cdev)
  669. p_ch = &privptr->channel[WRITE];
  670. else {
  671. printk(KERN_WARNING "claw: Can't determine channel for "
  672. "interrupt, device %s\n", cdev->dev.bus_id);
  673. CLAW_DBF_TEXT(2,trace,"badchan");
  674. return;
  675. }
  676. CLAW_DBF_TEXT_(4,trace,"IRQCH=%d",p_ch->flag);
  677. dev = (struct net_device *) (p_ch->ndev);
  678. p_env=privptr->p_env;
  679. #ifdef IOTRACE
  680. printk(KERN_INFO "%s: interrupt for device: %04x "
  681. "received c-%02x d-%02x state-%02x\n",
  682. dev->name, p_ch->devno, irb->scsw.cstat,
  683. irb->scsw.dstat, p_ch->claw_state);
  684. #endif
  685. /* Copy interruption response block. */
  686. memcpy(p_ch->irb, irb, sizeof(struct irb));
  687. /* Check for good subchannel return code, otherwise error message */
  688. if (irb->scsw.cstat && !(irb->scsw.cstat & SCHN_STAT_PCI)) {
  689. printk(KERN_INFO "%s: subchannel check for device: %04x -"
  690. " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
  691. dev->name, p_ch->devno,
  692. irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
  693. #ifdef IOTRACE
  694. dumpit((char *)irb,sizeof(struct irb));
  695. dumpit((char *)(unsigned long)irb->scsw.cpa,
  696. sizeof(struct ccw1));
  697. #endif
  698. #ifdef FUNCTRACE
  699. printk(KERN_INFO "%s:%s Exit on line %d\n",
  700. dev->name,__FUNCTION__,__LINE__);
  701. #endif
  702. CLAW_DBF_TEXT(2,trace,"chanchk");
  703. /* return; */
  704. }
  705. /* Check the reason-code of a unit check */
  706. if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
  707. ccw_check_unit_check(p_ch, irb->ecw[0]);
  708. }
  709. /* State machine to bring the connection up, down and to restart */
  710. p_ch->last_dstat = irb->scsw.dstat;
  711. switch (p_ch->claw_state) {
  712. case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
  713. #ifdef DEBUGMSG
  714. printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
  715. #endif
  716. if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
  717. (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
  718. (p_ch->irb->scsw.stctl ==
  719. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  720. #ifdef FUNCTRACE
  721. printk(KERN_INFO "%s:%s Exit on line %d\n",
  722. dev->name,__FUNCTION__,__LINE__);
  723. #endif
  724. return;
  725. }
  726. wake_up(&p_ch->wait); /* wake up claw_release */
  727. #ifdef DEBUGMSG
  728. printk(KERN_INFO "%s: CLAW_STOP exit\n", dev->name);
  729. #endif
  730. #ifdef FUNCTRACE
  731. printk(KERN_INFO "%s:%s Exit on line %d\n",
  732. dev->name,__FUNCTION__,__LINE__);
  733. #endif
  734. CLAW_DBF_TEXT(4,trace,"stop");
  735. return;
  736. case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
  737. #ifdef DEBUGMSG
  738. printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
  739. dev->name);
  740. #endif
  741. if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
  742. (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
  743. (p_ch->irb->scsw.stctl ==
  744. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  745. #ifdef FUNCTRACE
  746. printk(KERN_INFO "%s:%s Exit on line %d\n",
  747. dev->name,__FUNCTION__,__LINE__);
  748. #endif
  749. CLAW_DBF_TEXT(4,trace,"haltio");
  750. return;
  751. }
  752. if (p_ch->flag == CLAW_READ) {
  753. p_ch->claw_state = CLAW_START_READ;
  754. wake_up(&p_ch->wait); /* wake claw_open (READ)*/
  755. }
  756. else
  757. if (p_ch->flag == CLAW_WRITE) {
  758. p_ch->claw_state = CLAW_START_WRITE;
  759. /* send SYSTEM_VALIDATE */
  760. claw_strt_read(dev, LOCK_NO);
  761. claw_send_control(dev,
  762. SYSTEM_VALIDATE_REQUEST,
  763. 0, 0, 0,
  764. p_env->host_name,
  765. p_env->adapter_name );
  766. } else {
  767. printk(KERN_WARNING "claw: unsolicited "
  768. "interrupt for device:"
  769. "%s received c-%02x d-%02x\n",
  770. cdev->dev.bus_id,
  771. irb->scsw.cstat,
  772. irb->scsw.dstat);
  773. return;
  774. }
  775. #ifdef DEBUGMSG
  776. printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO exit\n",
  777. dev->name);
  778. #endif
  779. #ifdef FUNCTRACE
  780. printk(KERN_INFO "%s:%s Exit on line %d\n",
  781. dev->name,__FUNCTION__,__LINE__);
  782. #endif
  783. CLAW_DBF_TEXT(4,trace,"haltio");
  784. return;
  785. case CLAW_START_READ:
  786. CLAW_DBF_TEXT(4,trace,"ReadIRQ");
  787. if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
  788. clear_bit(0, (void *)&p_ch->IO_active);
  789. if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
  790. (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
  791. (p_ch->irb->ecw[0]) == 0)
  792. {
  793. privptr->stats.rx_errors++;
  794. printk(KERN_INFO "%s: Restart is "
  795. "required after remote "
  796. "side recovers \n",
  797. dev->name);
  798. }
  799. #ifdef FUNCTRACE
  800. printk(KERN_INFO "%s:%s Exit on line %d\n",
  801. dev->name,__FUNCTION__,__LINE__);
  802. #endif
  803. CLAW_DBF_TEXT(4,trace,"notrdy");
  804. return;
  805. }
  806. if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
  807. (p_ch->irb->scsw.dstat==0)) {
  808. if (test_and_set_bit(CLAW_BH_ACTIVE,
  809. (void *)&p_ch->flag_a) == 0) {
  810. tasklet_schedule(&p_ch->tasklet);
  811. }
  812. else {
  813. CLAW_DBF_TEXT(4,trace,"PCINoBH");
  814. }
  815. #ifdef FUNCTRACE
  816. printk(KERN_INFO "%s:%s Exit on line %d\n",
  817. dev->name,__FUNCTION__,__LINE__);
  818. #endif
  819. CLAW_DBF_TEXT(4,trace,"PCI_read");
  820. return;
  821. }
  822. if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
  823. (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
  824. (p_ch->irb->scsw.stctl ==
  825. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  826. #ifdef FUNCTRACE
  827. printk(KERN_INFO "%s:%s Exit on line %d\n",
  828. dev->name,__FUNCTION__,__LINE__);
  829. #endif
  830. CLAW_DBF_TEXT(4,trace,"SPend_rd");
  831. return;
  832. }
  833. clear_bit(0, (void *)&p_ch->IO_active);
  834. claw_clearbit_busy(TB_RETRY,dev);
  835. if (test_and_set_bit(CLAW_BH_ACTIVE,
  836. (void *)&p_ch->flag_a) == 0) {
  837. tasklet_schedule(&p_ch->tasklet);
  838. }
  839. else {
  840. CLAW_DBF_TEXT(4,trace,"RdBHAct");
  841. }
  842. #ifdef DEBUGMSG
  843. printk(KERN_INFO "%s: process CLAW_START_READ exit\n",
  844. dev->name);
  845. #endif
  846. #ifdef FUNCTRACE
  847. printk(KERN_INFO "%s:%s Exit on line %d\n",
  848. dev->name,__FUNCTION__,__LINE__);
  849. #endif
  850. CLAW_DBF_TEXT(4,trace,"RdIRQXit");
  851. return;
  852. case CLAW_START_WRITE:
  853. if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
  854. printk(KERN_INFO "%s: Unit Check Occured in "
  855. "write channel\n",dev->name);
  856. clear_bit(0, (void *)&p_ch->IO_active);
  857. if (p_ch->irb->ecw[0] & 0x80 ) {
  858. printk(KERN_INFO "%s: Resetting Event "
  859. "occurred:\n",dev->name);
  860. init_timer(&p_ch->timer);
  861. p_ch->timer.function =
  862. (void *)claw_write_retry;
  863. p_ch->timer.data = (unsigned long)p_ch;
  864. p_ch->timer.expires = jiffies + 10*HZ;
  865. add_timer(&p_ch->timer);
  866. printk(KERN_INFO "%s: write connection "
  867. "restarting\n",dev->name);
  868. }
  869. #ifdef FUNCTRACE
  870. printk(KERN_INFO "%s:%s Exit on line %d\n",
  871. dev->name,__FUNCTION__,__LINE__);
  872. #endif
  873. CLAW_DBF_TEXT(4,trace,"rstrtwrt");
  874. return;
  875. }
  876. if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
  877. clear_bit(0, (void *)&p_ch->IO_active);
  878. printk(KERN_INFO "%s: Unit Exception "
  879. "Occured in write channel\n",
  880. dev->name);
  881. }
  882. if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
  883. (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
  884. (p_ch->irb->scsw.stctl ==
  885. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  886. #ifdef FUNCTRACE
  887. printk(KERN_INFO "%s:%s Exit on line %d\n",
  888. dev->name,__FUNCTION__,__LINE__);
  889. #endif
  890. CLAW_DBF_TEXT(4,trace,"writeUE");
  891. return;
  892. }
  893. clear_bit(0, (void *)&p_ch->IO_active);
  894. if (claw_test_and_setbit_busy(TB_TX,dev)==0) {
  895. claw_write_next(p_ch);
  896. claw_clearbit_busy(TB_TX,dev);
  897. claw_clear_busy(dev);
  898. }
  899. p_ch_r=(struct chbk *)&privptr->channel[READ];
  900. if (test_and_set_bit(CLAW_BH_ACTIVE,
  901. (void *)&p_ch_r->flag_a) == 0) {
  902. tasklet_schedule(&p_ch_r->tasklet);
  903. }
  904. #ifdef DEBUGMSG
  905. printk(KERN_INFO "%s: process CLAW_START_WRITE exit\n",
  906. dev->name);
  907. #endif
  908. #ifdef FUNCTRACE
  909. printk(KERN_INFO "%s:%s Exit on line %d\n",
  910. dev->name,__FUNCTION__,__LINE__);
  911. #endif
  912. CLAW_DBF_TEXT(4,trace,"StWtExit");
  913. return;
  914. default:
  915. printk(KERN_WARNING "%s: wrong selection code - irq "
  916. "state=%d\n",dev->name,p_ch->claw_state);
  917. #ifdef FUNCTRACE
  918. printk(KERN_INFO "%s:%s Exit on line %d\n",
  919. dev->name,__FUNCTION__,__LINE__);
  920. #endif
  921. CLAW_DBF_TEXT(2,trace,"badIRQ");
  922. return;
  923. }
  924. } /* end of claw_irq_handler */
  925. /*-------------------------------------------------------------------*
  926. * claw_irq_tasklet *
  927. * *
  928. *--------------------------------------------------------------------*/
  929. static void
  930. claw_irq_tasklet ( unsigned long data )
  931. {
  932. struct chbk * p_ch;
  933. struct net_device *dev;
  934. struct claw_privbk * privptr;
  935. p_ch = (struct chbk *) data;
  936. dev = (struct net_device *)p_ch->ndev;
  937. #ifdef FUNCTRACE
  938. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  939. #endif
  940. #ifdef DEBUGMSG
  941. printk(KERN_INFO "%s: variable p_ch =\n",dev->name);
  942. dumpit((char *) p_ch, sizeof(struct chbk));
  943. #endif
  944. CLAW_DBF_TEXT(4,trace,"IRQtask");
  945. privptr = (struct claw_privbk *) dev->priv;
  946. #ifdef DEBUGMSG
  947. printk(KERN_INFO "%s: bh routine - state-%02x\n" ,
  948. dev->name, p_ch->claw_state);
  949. #endif
  950. unpack_read(dev);
  951. clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
  952. CLAW_DBF_TEXT(4,trace,"TskletXt");
  953. #ifdef FUNCTRACE
  954. printk(KERN_INFO "%s:%s Exit on line %d\n",
  955. dev->name,__FUNCTION__,__LINE__);
  956. #endif
  957. return;
  958. } /* end of claw_irq_bh */
  959. /*-------------------------------------------------------------------*
  960. * claw_release *
  961. * *
  962. *--------------------------------------------------------------------*/
  963. static int
  964. claw_release(struct net_device *dev)
  965. {
  966. int rc;
  967. int i;
  968. unsigned long saveflags;
  969. unsigned long parm;
  970. struct claw_privbk *privptr;
  971. DECLARE_WAITQUEUE(wait, current);
  972. struct ccwbk* p_this_ccw;
  973. struct ccwbk* p_buf;
  974. if (!dev)
  975. return 0;
  976. privptr = (struct claw_privbk *) dev->priv;
  977. if (!privptr)
  978. return 0;
  979. #ifdef FUNCTRACE
  980. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  981. #endif
  982. CLAW_DBF_TEXT(4,trace,"release");
  983. #ifdef DEBUGMSG
  984. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  985. dumpit((char *) dev, sizeof(struct net_device));
  986. printk(KERN_INFO "Priv Buffalloc %d\n",privptr->buffs_alloc);
  987. printk(KERN_INFO "Priv p_buff_ccw = %p\n",&privptr->p_buff_ccw);
  988. #endif
  989. privptr->release_pend=1;
  990. claw_setbit_busy(TB_STOP,dev);
  991. for ( i = 1; i >=0 ; i--) {
  992. spin_lock_irqsave(
  993. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  994. /* del_timer(&privptr->channel[READ].timer); */
  995. privptr->channel[i].claw_state = CLAW_STOP;
  996. privptr->channel[i].IO_active = 0;
  997. parm = (unsigned long) &privptr->channel[i];
  998. if (i == WRITE)
  999. claw_purge_skb_queue(
  1000. &privptr->channel[WRITE].collect_queue);
  1001. rc = ccw_device_halt (privptr->channel[i].cdev, parm);
  1002. if (privptr->system_validate_comp==0x00) /* never opened? */
  1003. init_waitqueue_head(&privptr->channel[i].wait);
  1004. add_wait_queue(&privptr->channel[i].wait, &wait);
  1005. set_current_state(TASK_INTERRUPTIBLE);
  1006. spin_unlock_irqrestore(
  1007. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  1008. schedule();
  1009. set_current_state(TASK_RUNNING);
  1010. remove_wait_queue(&privptr->channel[i].wait, &wait);
  1011. if (rc != 0) {
  1012. ccw_check_return_code(privptr->channel[i].cdev, rc);
  1013. }
  1014. }
  1015. if (privptr->pk_skb != NULL) {
  1016. dev_kfree_skb_any(privptr->pk_skb);
  1017. privptr->pk_skb = NULL;
  1018. }
  1019. if(privptr->buffs_alloc != 1) {
  1020. #ifdef FUNCTRACE
  1021. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1022. dev->name,__FUNCTION__,__LINE__);
  1023. #endif
  1024. CLAW_DBF_TEXT(4,trace,"none2fre");
  1025. return 0;
  1026. }
  1027. CLAW_DBF_TEXT(4,trace,"freebufs");
  1028. if (privptr->p_buff_ccw != NULL) {
  1029. free_pages((unsigned long)privptr->p_buff_ccw,
  1030. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  1031. }
  1032. CLAW_DBF_TEXT(4,trace,"freeread");
  1033. if (privptr->p_env->read_size < PAGE_SIZE) {
  1034. if (privptr->p_buff_read != NULL) {
  1035. free_pages((unsigned long)privptr->p_buff_read,
  1036. (int)pages_to_order_of_mag(privptr->p_buff_read_num));
  1037. }
  1038. }
  1039. else {
  1040. p_buf=privptr->p_read_active_first;
  1041. while (p_buf!=NULL) {
  1042. free_pages((unsigned long)p_buf->p_buffer,
  1043. (int)pages_to_order_of_mag(
  1044. privptr->p_buff_pages_perread ));
  1045. p_buf=p_buf->next;
  1046. }
  1047. }
  1048. CLAW_DBF_TEXT(4,trace,"freewrit");
  1049. if (privptr->p_env->write_size < PAGE_SIZE ) {
  1050. free_pages((unsigned long)privptr->p_buff_write,
  1051. (int)pages_to_order_of_mag(privptr->p_buff_write_num));
  1052. }
  1053. else {
  1054. p_buf=privptr->p_write_active_first;
  1055. while (p_buf!=NULL) {
  1056. free_pages((unsigned long)p_buf->p_buffer,
  1057. (int)pages_to_order_of_mag(
  1058. privptr->p_buff_pages_perwrite ));
  1059. p_buf=p_buf->next;
  1060. }
  1061. }
  1062. CLAW_DBF_TEXT(4,trace,"clearptr");
  1063. privptr->buffs_alloc = 0;
  1064. privptr->p_buff_ccw=NULL;
  1065. privptr->p_buff_read=NULL;
  1066. privptr->p_buff_write=NULL;
  1067. privptr->system_validate_comp=0;
  1068. privptr->release_pend=0;
  1069. /* Remove any writes that were pending and reset all reads */
  1070. p_this_ccw=privptr->p_read_active_first;
  1071. while (p_this_ccw!=NULL) {
  1072. p_this_ccw->header.length=0xffff;
  1073. p_this_ccw->header.opcode=0xff;
  1074. p_this_ccw->header.flag=0x00;
  1075. p_this_ccw=p_this_ccw->next;
  1076. }
  1077. while (privptr->p_write_active_first!=NULL) {
  1078. p_this_ccw=privptr->p_write_active_first;
  1079. p_this_ccw->header.flag=CLAW_PENDING;
  1080. privptr->p_write_active_first=p_this_ccw->next;
  1081. p_this_ccw->next=privptr->p_write_free_chain;
  1082. privptr->p_write_free_chain=p_this_ccw;
  1083. ++privptr->write_free_count;
  1084. }
  1085. privptr->p_write_active_last=NULL;
  1086. privptr->mtc_logical_link = -1;
  1087. privptr->mtc_skipping = 1;
  1088. privptr->mtc_offset=0;
  1089. if (((privptr->channel[READ].last_dstat |
  1090. privptr->channel[WRITE].last_dstat) &
  1091. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
  1092. printk(KERN_WARNING "%s: channel problems during close - "
  1093. "read: %02x - write: %02x\n",
  1094. dev->name,
  1095. privptr->channel[READ].last_dstat,
  1096. privptr->channel[WRITE].last_dstat);
  1097. CLAW_DBF_TEXT(2,trace,"badclose");
  1098. }
  1099. #ifdef FUNCTRACE
  1100. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1101. dev->name,__FUNCTION__,__LINE__);
  1102. #endif
  1103. CLAW_DBF_TEXT(4,trace,"rlsexit");
  1104. return 0;
  1105. } /* end of claw_release */
  1106. /*-------------------------------------------------------------------*
  1107. * claw_write_retry *
  1108. * *
  1109. *--------------------------------------------------------------------*/
  1110. static void
  1111. claw_write_retry ( struct chbk *p_ch )
  1112. {
  1113. struct net_device *dev=p_ch->ndev;
  1114. #ifdef FUNCTRACE
  1115. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  1116. printk(KERN_INFO "claw: variable p_ch =\n");
  1117. dumpit((char *) p_ch, sizeof(struct chbk));
  1118. #endif
  1119. CLAW_DBF_TEXT(4,trace,"w_retry");
  1120. if (p_ch->claw_state == CLAW_STOP) {
  1121. #ifdef FUNCTRACE
  1122. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1123. dev->name,__FUNCTION__,__LINE__);
  1124. #endif
  1125. return;
  1126. }
  1127. #ifdef DEBUGMSG
  1128. printk( KERN_INFO "%s:%s state-%02x\n" ,
  1129. dev->name,
  1130. __FUNCTION__,
  1131. p_ch->claw_state);
  1132. #endif
  1133. claw_strt_out_IO( dev );
  1134. #ifdef FUNCTRACE
  1135. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1136. dev->name,__FUNCTION__,__LINE__);
  1137. #endif
  1138. CLAW_DBF_TEXT(4,trace,"rtry_xit");
  1139. return;
  1140. } /* end of claw_write_retry */
  1141. /*-------------------------------------------------------------------*
  1142. * claw_write_next *
  1143. * *
  1144. *--------------------------------------------------------------------*/
  1145. static void
  1146. claw_write_next ( struct chbk * p_ch )
  1147. {
  1148. struct net_device *dev;
  1149. struct claw_privbk *privptr=NULL;
  1150. struct sk_buff *pk_skb;
  1151. int rc;
  1152. #ifdef FUNCTRACE
  1153. printk(KERN_INFO "%s:%s Enter \n",p_ch->ndev->name,__FUNCTION__);
  1154. printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
  1155. dumpit((char *) p_ch, sizeof(struct chbk));
  1156. #endif
  1157. CLAW_DBF_TEXT(4,trace,"claw_wrt");
  1158. if (p_ch->claw_state == CLAW_STOP)
  1159. return;
  1160. dev = (struct net_device *) p_ch->ndev;
  1161. privptr = (struct claw_privbk *) dev->priv;
  1162. claw_free_wrt_buf( dev );
  1163. if ((privptr->write_free_count > 0) &&
  1164. !skb_queue_empty(&p_ch->collect_queue)) {
  1165. pk_skb = claw_pack_skb(privptr);
  1166. while (pk_skb != NULL) {
  1167. rc = claw_hw_tx( pk_skb, dev,1);
  1168. if (privptr->write_free_count > 0) {
  1169. pk_skb = claw_pack_skb(privptr);
  1170. } else
  1171. pk_skb = NULL;
  1172. }
  1173. }
  1174. if (privptr->p_write_active_first!=NULL) {
  1175. claw_strt_out_IO(dev);
  1176. }
  1177. #ifdef FUNCTRACE
  1178. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1179. dev->name,__FUNCTION__,__LINE__);
  1180. #endif
  1181. return;
  1182. } /* end of claw_write_next */
  1183. /*-------------------------------------------------------------------*
  1184. * *
  1185. * claw_timer *
  1186. *--------------------------------------------------------------------*/
  1187. static void
  1188. claw_timer ( struct chbk * p_ch )
  1189. {
  1190. #ifdef FUNCTRACE
  1191. printk(KERN_INFO "%s:%s Entry\n",p_ch->ndev->name,__FUNCTION__);
  1192. printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
  1193. dumpit((char *) p_ch, sizeof(struct chbk));
  1194. #endif
  1195. CLAW_DBF_TEXT(4,trace,"timer");
  1196. p_ch->flag |= CLAW_TIMER;
  1197. wake_up(&p_ch->wait);
  1198. #ifdef FUNCTRACE
  1199. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1200. p_ch->ndev->name,__FUNCTION__,__LINE__);
  1201. #endif
  1202. return;
  1203. } /* end of claw_timer */
  1204. /*
  1205. *
  1206. * functions
  1207. */
  1208. /*-------------------------------------------------------------------*
  1209. * *
  1210. * pages_to_order_of_mag *
  1211. * *
  1212. * takes a number of pages from 1 to 512 and returns the *
  1213. * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
  1214. * of magnitude get_free_pages() has an upper order of 9 *
  1215. *--------------------------------------------------------------------*/
  1216. static int
  1217. pages_to_order_of_mag(int num_of_pages)
  1218. {
  1219. int order_of_mag=1; /* assume 2 pages */
  1220. int nump=2;
  1221. #ifdef FUNCTRACE
  1222. printk(KERN_INFO "%s Enter pages = %d \n",__FUNCTION__,num_of_pages);
  1223. #endif
  1224. CLAW_DBF_TEXT_(5,trace,"pages%d",num_of_pages);
  1225. if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
  1226. /* 512 pages = 2Meg on 4k page systems */
  1227. if (num_of_pages >= 512) {return 9; }
  1228. /* we have two or more pages order is at least 1 */
  1229. for (nump=2 ;nump <= 512;nump*=2) {
  1230. if (num_of_pages <= nump)
  1231. break;
  1232. order_of_mag +=1;
  1233. }
  1234. if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
  1235. #ifdef FUNCTRACE
  1236. printk(KERN_INFO "%s Exit on line %d, order = %d\n",
  1237. __FUNCTION__,__LINE__, order_of_mag);
  1238. #endif
  1239. CLAW_DBF_TEXT_(5,trace,"mag%d",order_of_mag);
  1240. return order_of_mag;
  1241. }
  1242. /*-------------------------------------------------------------------*
  1243. * *
  1244. * add_claw_reads *
  1245. * *
  1246. *--------------------------------------------------------------------*/
  1247. static int
  1248. add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
  1249. struct ccwbk* p_last)
  1250. {
  1251. struct claw_privbk *privptr;
  1252. struct ccw1 temp_ccw;
  1253. struct endccw * p_end;
  1254. #ifdef IOTRACE
  1255. struct ccwbk* p_buf;
  1256. #endif
  1257. #ifdef FUNCTRACE
  1258. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  1259. #endif
  1260. #ifdef DEBUGMSG
  1261. printk(KERN_INFO "dev\n");
  1262. dumpit((char *) dev, sizeof(struct net_device));
  1263. printk(KERN_INFO "p_first\n");
  1264. dumpit((char *) p_first, sizeof(struct ccwbk));
  1265. printk(KERN_INFO "p_last\n");
  1266. dumpit((char *) p_last, sizeof(struct ccwbk));
  1267. #endif
  1268. CLAW_DBF_TEXT(4,trace,"addreads");
  1269. privptr = dev->priv;
  1270. p_end = privptr->p_end_ccw;
  1271. /* first CCW and last CCW contains a new set of read channel programs
  1272. * to apend the running channel programs
  1273. */
  1274. if ( p_first==NULL) {
  1275. #ifdef FUNCTRACE
  1276. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1277. dev->name,__FUNCTION__,__LINE__);
  1278. #endif
  1279. CLAW_DBF_TEXT(4,trace,"addexit");
  1280. return 0;
  1281. }
  1282. /* set up ending CCW sequence for this segment */
  1283. if (p_end->read1) {
  1284. p_end->read1=0x00; /* second ending CCW is now active */
  1285. /* reset ending CCWs and setup TIC CCWs */
  1286. p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1287. p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1288. p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
  1289. p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
  1290. p_end->read2_nop2.cda=0;
  1291. p_end->read2_nop2.count=1;
  1292. }
  1293. else {
  1294. p_end->read1=0x01; /* first ending CCW is now active */
  1295. /* reset ending CCWs and setup TIC CCWs */
  1296. p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1297. p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1298. p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
  1299. p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
  1300. p_end->read1_nop2.cda=0;
  1301. p_end->read1_nop2.count=1;
  1302. }
  1303. if ( privptr-> p_read_active_first ==NULL ) {
  1304. #ifdef DEBUGMSG
  1305. printk(KERN_INFO "%s:%s p_read_active_first == NULL \n",
  1306. dev->name,__FUNCTION__);
  1307. printk(KERN_INFO "%s:%s Read active first/last changed \n",
  1308. dev->name,__FUNCTION__);
  1309. #endif
  1310. privptr-> p_read_active_first= p_first; /* set new first */
  1311. privptr-> p_read_active_last = p_last; /* set new last */
  1312. }
  1313. else {
  1314. #ifdef DEBUGMSG
  1315. printk(KERN_INFO "%s:%s Read in progress \n",
  1316. dev->name,__FUNCTION__);
  1317. #endif
  1318. /* set up TIC ccw */
  1319. temp_ccw.cda= (__u32)__pa(&p_first->read);
  1320. temp_ccw.count=0;
  1321. temp_ccw.flags=0;
  1322. temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
  1323. if (p_end->read1) {
  1324. /* first set of CCW's is chained to the new read */
  1325. /* chain, so the second set is chained to the active chain. */
  1326. /* Therefore modify the second set to point to the new */
  1327. /* read chain set up TIC CCWs */
  1328. /* make sure we update the CCW so channel doesn't fetch it */
  1329. /* when it's only half done */
  1330. memcpy( &p_end->read2_nop2, &temp_ccw ,
  1331. sizeof(struct ccw1));
  1332. privptr->p_read_active_last->r_TIC_1.cda=
  1333. (__u32)__pa(&p_first->read);
  1334. privptr->p_read_active_last->r_TIC_2.cda=
  1335. (__u32)__pa(&p_first->read);
  1336. }
  1337. else {
  1338. /* make sure we update the CCW so channel doesn't */
  1339. /* fetch it when it is only half done */
  1340. memcpy( &p_end->read1_nop2, &temp_ccw ,
  1341. sizeof(struct ccw1));
  1342. privptr->p_read_active_last->r_TIC_1.cda=
  1343. (__u32)__pa(&p_first->read);
  1344. privptr->p_read_active_last->r_TIC_2.cda=
  1345. (__u32)__pa(&p_first->read);
  1346. }
  1347. /* chain in new set of blocks */
  1348. privptr->p_read_active_last->next = p_first;
  1349. privptr->p_read_active_last=p_last;
  1350. } /* end of if ( privptr-> p_read_active_first ==NULL) */
  1351. #ifdef IOTRACE
  1352. printk(KERN_INFO "%s:%s dump p_last CCW BK \n",dev->name,__FUNCTION__);
  1353. dumpit((char *)p_last, sizeof(struct ccwbk));
  1354. printk(KERN_INFO "%s:%s dump p_end CCW BK \n",dev->name,__FUNCTION__);
  1355. dumpit((char *)p_end, sizeof(struct endccw));
  1356. printk(KERN_INFO "%s:%s dump p_first CCW BK \n",dev->name,__FUNCTION__);
  1357. dumpit((char *)p_first, sizeof(struct ccwbk));
  1358. printk(KERN_INFO "%s:%s Dump Active CCW chain \n",
  1359. dev->name,__FUNCTION__);
  1360. p_buf=privptr->p_read_active_first;
  1361. while (p_buf!=NULL) {
  1362. dumpit((char *)p_buf, sizeof(struct ccwbk));
  1363. p_buf=p_buf->next;
  1364. }
  1365. #endif
  1366. #ifdef FUNCTRACE
  1367. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1368. dev->name,__FUNCTION__,__LINE__);
  1369. #endif
  1370. CLAW_DBF_TEXT(4,trace,"addexit");
  1371. return 0;
  1372. } /* end of add_claw_reads */
  1373. /*-------------------------------------------------------------------*
  1374. * ccw_check_return_code *
  1375. * *
  1376. *-------------------------------------------------------------------*/
  1377. static void
  1378. ccw_check_return_code(struct ccw_device *cdev, int return_code)
  1379. {
  1380. #ifdef FUNCTRACE
  1381. printk(KERN_INFO "%s: %s() > enter \n",
  1382. cdev->dev.bus_id,__FUNCTION__);
  1383. #endif
  1384. CLAW_DBF_TEXT(4,trace,"ccwret");
  1385. #ifdef DEBUGMSG
  1386. printk(KERN_INFO "variable cdev =\n");
  1387. dumpit((char *) cdev, sizeof(struct ccw_device));
  1388. printk(KERN_INFO "variable return_code = %d\n",return_code);
  1389. #endif
  1390. if (return_code != 0) {
  1391. switch (return_code) {
  1392. case -EBUSY:
  1393. printk(KERN_INFO "%s: Busy !\n",
  1394. cdev->dev.bus_id);
  1395. break;
  1396. case -ENODEV:
  1397. printk(KERN_EMERG "%s: Missing device called "
  1398. "for IO ENODEV\n", cdev->dev.bus_id);
  1399. break;
  1400. case -EIO:
  1401. printk(KERN_EMERG "%s: Status pending... EIO \n",
  1402. cdev->dev.bus_id);
  1403. break;
  1404. case -EINVAL:
  1405. printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
  1406. cdev->dev.bus_id);
  1407. break;
  1408. default:
  1409. printk(KERN_EMERG "%s: Unknown error in "
  1410. "Do_IO %d\n",cdev->dev.bus_id, return_code);
  1411. }
  1412. }
  1413. #ifdef FUNCTRACE
  1414. printk(KERN_INFO "%s: %s() > exit on line %d\n",
  1415. cdev->dev.bus_id,__FUNCTION__,__LINE__);
  1416. #endif
  1417. CLAW_DBF_TEXT(4,trace,"ccwret");
  1418. } /* end of ccw_check_return_code */
  1419. /*-------------------------------------------------------------------*
  1420. * ccw_check_unit_check *
  1421. *--------------------------------------------------------------------*/
  1422. static void
  1423. ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
  1424. {
  1425. struct net_device *dev = p_ch->ndev;
  1426. #ifdef FUNCTRACE
  1427. printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
  1428. #endif
  1429. #ifdef DEBUGMSG
  1430. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  1431. dumpit((char *)dev, sizeof(struct net_device));
  1432. printk(KERN_INFO "%s: variable sense =\n",dev->name);
  1433. dumpit((char *)&sense, 2);
  1434. #endif
  1435. CLAW_DBF_TEXT(4,trace,"unitchek");
  1436. printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
  1437. dev->name, sense);
  1438. if (sense & 0x40) {
  1439. if (sense & 0x01) {
  1440. printk(KERN_WARNING "%s: Interface disconnect or "
  1441. "Selective reset "
  1442. "occurred (remote side)\n", dev->name);
  1443. }
  1444. else {
  1445. printk(KERN_WARNING "%s: System reset occured"
  1446. " (remote side)\n", dev->name);
  1447. }
  1448. }
  1449. else if (sense & 0x20) {
  1450. if (sense & 0x04) {
  1451. printk(KERN_WARNING "%s: Data-streaming "
  1452. "timeout)\n", dev->name);
  1453. }
  1454. else {
  1455. printk(KERN_WARNING "%s: Data-transfer parity"
  1456. " error\n", dev->name);
  1457. }
  1458. }
  1459. else if (sense & 0x10) {
  1460. if (sense & 0x20) {
  1461. printk(KERN_WARNING "%s: Hardware malfunction "
  1462. "(remote side)\n", dev->name);
  1463. }
  1464. else {
  1465. printk(KERN_WARNING "%s: read-data parity error "
  1466. "(remote side)\n", dev->name);
  1467. }
  1468. }
  1469. #ifdef FUNCTRACE
  1470. printk(KERN_INFO "%s: %s() exit on line %d\n",
  1471. dev->name,__FUNCTION__,__LINE__);
  1472. #endif
  1473. } /* end of ccw_check_unit_check */
  1474. /*-------------------------------------------------------------------*
  1475. * Dump buffer format *
  1476. * *
  1477. *--------------------------------------------------------------------*/
  1478. #ifdef DEBUG
  1479. static void
  1480. dumpit(char* buf, int len)
  1481. {
  1482. __u32 ct, sw, rm, dup;
  1483. char *ptr, *rptr;
  1484. char tbuf[82], tdup[82];
  1485. #if (CONFIG_64BIT)
  1486. char addr[22];
  1487. #else
  1488. char addr[12];
  1489. #endif
  1490. char boff[12];
  1491. char bhex[82], duphex[82];
  1492. char basc[40];
  1493. sw = 0;
  1494. rptr =ptr=buf;
  1495. rm = 16;
  1496. duphex[0] = 0x00;
  1497. dup = 0;
  1498. for ( ct=0; ct < len; ct++, ptr++, rptr++ ) {
  1499. if (sw == 0) {
  1500. #if (CONFIG_64BIT)
  1501. sprintf(addr, "%16.16lX",(unsigned long)rptr);
  1502. #else
  1503. sprintf(addr, "%8.8X",(__u32)rptr);
  1504. #endif
  1505. sprintf(boff, "%4.4X", (__u32)ct);
  1506. bhex[0] = '\0';
  1507. basc[0] = '\0';
  1508. }
  1509. if ((sw == 4) || (sw == 12)) {
  1510. strcat(bhex, " ");
  1511. }
  1512. if (sw == 8) {
  1513. strcat(bhex, " ");
  1514. }
  1515. #if (CONFIG_64BIT)
  1516. sprintf(tbuf,"%2.2lX", (unsigned long)*ptr);
  1517. #else
  1518. sprintf(tbuf,"%2.2X", (__u32)*ptr);
  1519. #endif
  1520. tbuf[2] = '\0';
  1521. strcat(bhex, tbuf);
  1522. if ((0!=isprint(*ptr)) && (*ptr >= 0x20)) {
  1523. basc[sw] = *ptr;
  1524. }
  1525. else {
  1526. basc[sw] = '.';
  1527. }
  1528. basc[sw+1] = '\0';
  1529. sw++;
  1530. rm--;
  1531. if (sw==16) {
  1532. if ((strcmp(duphex, bhex)) !=0) {
  1533. if (dup !=0) {
  1534. sprintf(tdup,"Duplicate as above to"
  1535. " %s", addr);
  1536. printk( KERN_INFO " "
  1537. " --- %s ---\n",tdup);
  1538. }
  1539. printk( KERN_INFO " %s (+%s) : %s [%s]\n",
  1540. addr, boff, bhex, basc);
  1541. dup = 0;
  1542. strcpy(duphex, bhex);
  1543. }
  1544. else {
  1545. dup++;
  1546. }
  1547. sw = 0;
  1548. rm = 16;
  1549. }
  1550. } /* endfor */
  1551. if (sw != 0) {
  1552. for ( ; rm > 0; rm--, sw++ ) {
  1553. if ((sw==4) || (sw==12)) strcat(bhex, " ");
  1554. if (sw==8) strcat(bhex, " ");
  1555. strcat(bhex, " ");
  1556. strcat(basc, " ");
  1557. }
  1558. if (dup !=0) {
  1559. sprintf(tdup,"Duplicate as above to %s", addr);
  1560. printk( KERN_INFO " --- %s ---\n",
  1561. tdup);
  1562. }
  1563. printk( KERN_INFO " %s (+%s) : %s [%s]\n",
  1564. addr, boff, bhex, basc);
  1565. }
  1566. else {
  1567. if (dup >=1) {
  1568. sprintf(tdup,"Duplicate as above to %s", addr);
  1569. printk( KERN_INFO " --- %s ---\n",
  1570. tdup);
  1571. }
  1572. if (dup !=0) {
  1573. printk( KERN_INFO " %s (+%s) : %s [%s]\n",
  1574. addr, boff, bhex, basc);
  1575. }
  1576. }
  1577. return;
  1578. } /* end of dumpit */
  1579. #endif
  1580. /*-------------------------------------------------------------------*
  1581. * find_link *
  1582. *--------------------------------------------------------------------*/
  1583. static int
  1584. find_link(struct net_device *dev, char *host_name, char *ws_name )
  1585. {
  1586. struct claw_privbk *privptr;
  1587. struct claw_env *p_env;
  1588. int rc=0;
  1589. #ifdef FUNCTRACE
  1590. printk(KERN_INFO "%s:%s > enter \n",dev->name,__FUNCTION__);
  1591. #endif
  1592. CLAW_DBF_TEXT(2,setup,"findlink");
  1593. #ifdef DEBUGMSG
  1594. printk(KERN_INFO "%s: variable dev = \n",dev->name);
  1595. dumpit((char *) dev, sizeof(struct net_device));
  1596. printk(KERN_INFO "%s: variable host_name = %s\n",dev->name, host_name);
  1597. printk(KERN_INFO "%s: variable ws_name = %s\n",dev->name, ws_name);
  1598. #endif
  1599. privptr=dev->priv;
  1600. p_env=privptr->p_env;
  1601. switch (p_env->packing)
  1602. {
  1603. case PACKING_ASK:
  1604. if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
  1605. (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
  1606. rc = EINVAL;
  1607. break;
  1608. case DO_PACKED:
  1609. case PACK_SEND:
  1610. if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
  1611. (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
  1612. rc = EINVAL;
  1613. break;
  1614. default:
  1615. if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
  1616. (memcmp(p_env->api_type , ws_name, 8)!=0))
  1617. rc = EINVAL;
  1618. break;
  1619. }
  1620. #ifdef FUNCTRACE
  1621. printk(KERN_INFO "%s:%s Exit on line %d\n",
  1622. dev->name,__FUNCTION__,__LINE__);
  1623. #endif
  1624. return 0;
  1625. } /* end of find_link */
  1626. /*-------------------------------------------------------------------*
  1627. * claw_hw_tx *
  1628. * *
  1629. * *
  1630. *-------------------------------------------------------------------*/
  1631. static int
  1632. claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
  1633. {
  1634. int rc=0;
  1635. struct claw_privbk *privptr;
  1636. struct ccwbk *p_this_ccw;
  1637. struct ccwbk *p_first_ccw;
  1638. struct ccwbk *p_last_ccw;
  1639. __u32 numBuffers;
  1640. signed long len_of_data;
  1641. unsigned long bytesInThisBuffer;
  1642. unsigned char *pDataAddress;
  1643. struct endccw *pEnd;
  1644. struct ccw1 tempCCW;
  1645. struct chbk *p_ch;
  1646. struct claw_env *p_env;
  1647. int lock;
  1648. struct clawph *pk_head;
  1649. struct chbk *ch;
  1650. #ifdef IOTRACE
  1651. struct ccwbk *p_buf;
  1652. #endif
  1653. #ifdef FUNCTRACE
  1654. printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
  1655. #endif
  1656. CLAW_DBF_TEXT(4,trace,"hw_tx");
  1657. #ifdef DEBUGMSG
  1658. printk(KERN_INFO "%s: variable dev skb =\n",dev->name);
  1659. dumpit((char *) skb, sizeof(struct sk_buff));
  1660. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  1661. dumpit((char *) dev, sizeof(struct net_device));
  1662. printk(KERN_INFO "%s: variable linkid = %ld\n",dev->name,linkid);
  1663. #endif
  1664. privptr = (struct claw_privbk *) (dev->priv);
  1665. p_ch=(struct chbk *)&privptr->channel[WRITE];
  1666. p_env =privptr->p_env;
  1667. #ifdef IOTRACE
  1668. printk(KERN_INFO "%s: %s() dump sk_buff \n",dev->name,__FUNCTION__);
  1669. dumpit((char *)skb ,sizeof(struct sk_buff));
  1670. #endif
  1671. claw_free_wrt_buf(dev); /* Clean up free chain if posible */
  1672. /* scan the write queue to free any completed write packets */
  1673. p_first_ccw=NULL;
  1674. p_last_ccw=NULL;
  1675. if ((p_env->packing >= PACK_SEND) &&
  1676. (skb->cb[1] != 'P')) {
  1677. skb_push(skb,sizeof(struct clawph));
  1678. pk_head=(struct clawph *)skb->data;
  1679. pk_head->len=skb->len-sizeof(struct clawph);
  1680. if (pk_head->len%4) {
  1681. pk_head->len+= 4-(pk_head->len%4);
  1682. skb_pad(skb,4-(pk_head->len%4));
  1683. skb_put(skb,4-(pk_head->len%4));
  1684. }
  1685. if (p_env->packing == DO_PACKED)
  1686. pk_head->link_num = linkid;
  1687. else
  1688. pk_head->link_num = 0;
  1689. pk_head->flag = 0x00;
  1690. skb_pad(skb,4);
  1691. skb->cb[1] = 'P';
  1692. }
  1693. if (linkid == 0) {
  1694. if (claw_check_busy(dev)) {
  1695. if (privptr->write_free_count!=0) {
  1696. claw_clear_busy(dev);
  1697. }
  1698. else {
  1699. claw_strt_out_IO(dev );
  1700. claw_free_wrt_buf( dev );
  1701. if (privptr->write_free_count==0) {
  1702. #ifdef IOTRACE
  1703. printk(KERN_INFO "%s: "
  1704. "(claw_check_busy) no free write "
  1705. "buffers\n", dev->name);
  1706. #endif
  1707. ch = &privptr->channel[WRITE];
  1708. atomic_inc(&skb->users);
  1709. skb_queue_tail(&ch->collect_queue, skb);
  1710. goto Done;
  1711. }
  1712. else {
  1713. claw_clear_busy(dev);
  1714. }
  1715. }
  1716. }
  1717. /* tx lock */
  1718. if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
  1719. #ifdef DEBUGMSG
  1720. printk(KERN_INFO "%s: busy (claw_test_and_setbit_"
  1721. "busy)\n", dev->name);
  1722. #endif
  1723. ch = &privptr->channel[WRITE];
  1724. atomic_inc(&skb->users);
  1725. skb_queue_tail(&ch->collect_queue, skb);
  1726. claw_strt_out_IO(dev );
  1727. rc=-EBUSY;
  1728. goto Done2;
  1729. }
  1730. }
  1731. /* See how many write buffers are required to hold this data */
  1732. numBuffers= ( skb->len + privptr->p_env->write_size - 1) /
  1733. ( privptr->p_env->write_size);
  1734. /* If that number of buffers isn't available, give up for now */
  1735. if (privptr->write_free_count < numBuffers ||
  1736. privptr->p_write_free_chain == NULL ) {
  1737. claw_setbit_busy(TB_NOBUFFER,dev);
  1738. #ifdef DEBUGMSG
  1739. printk(KERN_INFO "%s: busy (claw_setbit_busy"
  1740. "(TB_NOBUFFER))\n", dev->name);
  1741. printk(KERN_INFO " free_count: %d, numBuffers : %d\n",
  1742. (int)privptr->write_free_count,(int) numBuffers );
  1743. #endif
  1744. ch = &privptr->channel[WRITE];
  1745. atomic_inc(&skb->users);
  1746. skb_queue_tail(&ch->collect_queue, skb);
  1747. CLAW_DBF_TEXT(2,trace,"clawbusy");
  1748. goto Done2;
  1749. }
  1750. pDataAddress=skb->data;
  1751. len_of_data=skb->len;
  1752. while (len_of_data > 0) {
  1753. #ifdef DEBUGMSG
  1754. printk(KERN_INFO "%s: %s() length-of-data is %ld \n",
  1755. dev->name ,__FUNCTION__,len_of_data);
  1756. dumpit((char *)pDataAddress ,64);
  1757. #endif
  1758. p_this_ccw=privptr->p_write_free_chain; /* get a block */
  1759. if (p_this_ccw == NULL) { /* lost the race */
  1760. ch = &privptr->channel[WRITE];
  1761. atomic_inc(&skb->users);
  1762. skb_queue_tail(&ch->collect_queue, skb);
  1763. goto Done2;
  1764. }
  1765. privptr->p_write_free_chain=p_this_ccw->next;
  1766. p_this_ccw->next=NULL;
  1767. --privptr->write_free_count; /* -1 */
  1768. bytesInThisBuffer=len_of_data;
  1769. memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
  1770. len_of_data-=bytesInThisBuffer;
  1771. pDataAddress+=(unsigned long)bytesInThisBuffer;
  1772. /* setup write CCW */
  1773. p_this_ccw->write.cmd_code = (linkid * 8) +1;
  1774. if (len_of_data>0) {
  1775. p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
  1776. }
  1777. p_this_ccw->write.count=bytesInThisBuffer;
  1778. /* now add to end of this chain */
  1779. if (p_first_ccw==NULL) {
  1780. p_first_ccw=p_this_ccw;
  1781. }
  1782. if (p_last_ccw!=NULL) {
  1783. p_last_ccw->next=p_this_ccw;
  1784. /* set up TIC ccws */
  1785. p_last_ccw->w_TIC_1.cda=
  1786. (__u32)__pa(&p_this_ccw->write);
  1787. }
  1788. p_last_ccw=p_this_ccw; /* save new last block */
  1789. #ifdef IOTRACE
  1790. printk(KERN_INFO "%s: %s() > CCW and Buffer %ld bytes long \n",
  1791. dev->name,__FUNCTION__,bytesInThisBuffer);
  1792. dumpit((char *)p_this_ccw, sizeof(struct ccwbk));
  1793. dumpit((char *)p_this_ccw->p_buffer, 64);
  1794. #endif
  1795. }
  1796. /* FirstCCW and LastCCW now contain a new set of write channel
  1797. * programs to append to the running channel program
  1798. */
  1799. if (p_first_ccw!=NULL) {
  1800. /* setup ending ccw sequence for this segment */
  1801. pEnd=privptr->p_end_ccw;
  1802. if (pEnd->write1) {
  1803. pEnd->write1=0x00; /* second end ccw is now active */
  1804. /* set up Tic CCWs */
  1805. p_last_ccw->w_TIC_1.cda=
  1806. (__u32)__pa(&pEnd->write2_nop1);
  1807. pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1808. pEnd->write2_nop2.flags =
  1809. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1810. pEnd->write2_nop2.cda=0;
  1811. pEnd->write2_nop2.count=1;
  1812. }
  1813. else { /* end of if (pEnd->write1)*/
  1814. pEnd->write1=0x01; /* first end ccw is now active */
  1815. /* set up Tic CCWs */
  1816. p_last_ccw->w_TIC_1.cda=
  1817. (__u32)__pa(&pEnd->write1_nop1);
  1818. pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1819. pEnd->write1_nop2.flags =
  1820. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1821. pEnd->write1_nop2.cda=0;
  1822. pEnd->write1_nop2.count=1;
  1823. } /* end if if (pEnd->write1) */
  1824. if (privptr->p_write_active_first==NULL ) {
  1825. privptr->p_write_active_first=p_first_ccw;
  1826. privptr->p_write_active_last=p_last_ccw;
  1827. }
  1828. else {
  1829. /* set up Tic CCWs */
  1830. tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
  1831. tempCCW.count=0;
  1832. tempCCW.flags=0;
  1833. tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
  1834. if (pEnd->write1) {
  1835. /*
  1836. * first set of ending CCW's is chained to the new write
  1837. * chain, so the second set is chained to the active chain
  1838. * Therefore modify the second set to point the new write chain.
  1839. * make sure we update the CCW atomically
  1840. * so channel does not fetch it when it's only half done
  1841. */
  1842. memcpy( &pEnd->write2_nop2, &tempCCW ,
  1843. sizeof(struct ccw1));
  1844. privptr->p_write_active_last->w_TIC_1.cda=
  1845. (__u32)__pa(&p_first_ccw->write);
  1846. }
  1847. else {
  1848. /*make sure we update the CCW atomically
  1849. *so channel does not fetch it when it's only half done
  1850. */
  1851. memcpy(&pEnd->write1_nop2, &tempCCW ,
  1852. sizeof(struct ccw1));
  1853. privptr->p_write_active_last->w_TIC_1.cda=
  1854. (__u32)__pa(&p_first_ccw->write);
  1855. } /* end if if (pEnd->write1) */
  1856. privptr->p_write_active_last->next=p_first_ccw;
  1857. privptr->p_write_active_last=p_last_ccw;
  1858. }
  1859. } /* endif (p_first_ccw!=NULL) */
  1860. #ifdef IOTRACE
  1861. printk(KERN_INFO "%s: %s() > Dump Active CCW chain \n",
  1862. dev->name,__FUNCTION__);
  1863. p_buf=privptr->p_write_active_first;
  1864. while (p_buf!=NULL) {
  1865. dumpit((char *)p_buf, sizeof(struct ccwbk));
  1866. p_buf=p_buf->next;
  1867. }
  1868. p_buf=(struct ccwbk*)privptr->p_end_ccw;
  1869. dumpit((char *)p_buf, sizeof(struct endccw));
  1870. #endif
  1871. dev_kfree_skb_any(skb);
  1872. if (linkid==0) {
  1873. lock=LOCK_NO;
  1874. }
  1875. else {
  1876. lock=LOCK_YES;
  1877. }
  1878. claw_strt_out_IO(dev );
  1879. /* if write free count is zero , set NOBUFFER */
  1880. #ifdef DEBUGMSG
  1881. printk(KERN_INFO "%s: %s() > free_count is %d\n",
  1882. dev->name,__FUNCTION__,
  1883. (int) privptr->write_free_count );
  1884. #endif
  1885. if (privptr->write_free_count==0) {
  1886. claw_setbit_busy(TB_NOBUFFER,dev);
  1887. }
  1888. Done2:
  1889. claw_clearbit_busy(TB_TX,dev);
  1890. Done:
  1891. #ifdef FUNCTRACE
  1892. printk(KERN_INFO "%s: %s() > exit on line %d, rc = %d \n",
  1893. dev->name,__FUNCTION__,__LINE__, rc);
  1894. #endif
  1895. return(rc);
  1896. } /* end of claw_hw_tx */
  1897. /*-------------------------------------------------------------------*
  1898. * *
  1899. * init_ccw_bk *
  1900. * *
  1901. *--------------------------------------------------------------------*/
  1902. static int
  1903. init_ccw_bk(struct net_device *dev)
  1904. {
  1905. __u32 ccw_blocks_required;
  1906. __u32 ccw_blocks_perpage;
  1907. __u32 ccw_pages_required;
  1908. __u32 claw_reads_perpage=1;
  1909. __u32 claw_read_pages;
  1910. __u32 claw_writes_perpage=1;
  1911. __u32 claw_write_pages;
  1912. void *p_buff=NULL;
  1913. struct ccwbk*p_free_chain;
  1914. struct ccwbk*p_buf;
  1915. struct ccwbk*p_last_CCWB;
  1916. struct ccwbk*p_first_CCWB;
  1917. struct endccw *p_endccw=NULL;
  1918. addr_t real_address;
  1919. struct claw_privbk *privptr=dev->priv;
  1920. struct clawh *pClawH=NULL;
  1921. addr_t real_TIC_address;
  1922. int i,j;
  1923. #ifdef FUNCTRACE
  1924. printk(KERN_INFO "%s: %s() enter \n",dev->name,__FUNCTION__);
  1925. #endif
  1926. CLAW_DBF_TEXT(4,trace,"init_ccw");
  1927. #ifdef DEBUGMSG
  1928. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  1929. dumpit((char *) dev, sizeof(struct net_device));
  1930. #endif
  1931. /* initialize statistics field */
  1932. privptr->active_link_ID=0;
  1933. /* initialize ccwbk pointers */
  1934. privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
  1935. privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
  1936. privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
  1937. privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
  1938. privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
  1939. privptr->p_end_ccw=NULL; /* pointer to ending ccw */
  1940. privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
  1941. privptr->buffs_alloc = 0;
  1942. memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
  1943. memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
  1944. /* initialize free write ccwbk counter */
  1945. privptr->write_free_count=0; /* number of free bufs on write chain */
  1946. p_last_CCWB = NULL;
  1947. p_first_CCWB= NULL;
  1948. /*
  1949. * We need 1 CCW block for each read buffer, 1 for each
  1950. * write buffer, plus 1 for ClawSignalBlock
  1951. */
  1952. ccw_blocks_required =
  1953. privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
  1954. #ifdef DEBUGMSG
  1955. printk(KERN_INFO "%s: %s() "
  1956. "ccw_blocks_required=%d\n",
  1957. dev->name,__FUNCTION__,
  1958. ccw_blocks_required);
  1959. printk(KERN_INFO "%s: %s() "
  1960. "PAGE_SIZE=0x%x\n",
  1961. dev->name,__FUNCTION__,
  1962. (unsigned int)PAGE_SIZE);
  1963. printk(KERN_INFO "%s: %s() > "
  1964. "PAGE_MASK=0x%x\n",
  1965. dev->name,__FUNCTION__,
  1966. (unsigned int)PAGE_MASK);
  1967. #endif
  1968. /*
  1969. * compute number of CCW blocks that will fit in a page
  1970. */
  1971. ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
  1972. ccw_pages_required=
  1973. (ccw_blocks_required+ccw_blocks_perpage -1) /
  1974. ccw_blocks_perpage;
  1975. #ifdef DEBUGMSG
  1976. printk(KERN_INFO "%s: %s() > ccw_blocks_perpage=%d\n",
  1977. dev->name,__FUNCTION__,
  1978. ccw_blocks_perpage);
  1979. printk(KERN_INFO "%s: %s() > ccw_pages_required=%d\n",
  1980. dev->name,__FUNCTION__,
  1981. ccw_pages_required);
  1982. #endif
  1983. /*
  1984. * read and write sizes are set by 2 constants in claw.h
  1985. * 4k and 32k. Unpacked values other than 4k are not going to
  1986. * provide good performance. With packing buffers support 32k
  1987. * buffers are used.
  1988. */
  1989. if (privptr->p_env->read_size < PAGE_SIZE) {
  1990. claw_reads_perpage= PAGE_SIZE / privptr->p_env->read_size;
  1991. claw_read_pages= (privptr->p_env->read_buffers +
  1992. claw_reads_perpage -1) / claw_reads_perpage;
  1993. }
  1994. else { /* > or equal */
  1995. privptr->p_buff_pages_perread=
  1996. (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
  1997. claw_read_pages=
  1998. privptr->p_env->read_buffers * privptr->p_buff_pages_perread;
  1999. }
  2000. if (privptr->p_env->write_size < PAGE_SIZE) {
  2001. claw_writes_perpage=
  2002. PAGE_SIZE / privptr->p_env->write_size;
  2003. claw_write_pages=
  2004. (privptr->p_env->write_buffers + claw_writes_perpage -1) /
  2005. claw_writes_perpage;
  2006. }
  2007. else { /* > or equal */
  2008. privptr->p_buff_pages_perwrite=
  2009. (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
  2010. claw_write_pages=
  2011. privptr->p_env->write_buffers * privptr->p_buff_pages_perwrite;
  2012. }
  2013. #ifdef DEBUGMSG
  2014. if (privptr->p_env->read_size < PAGE_SIZE) {
  2015. printk(KERN_INFO "%s: %s() reads_perpage=%d\n",
  2016. dev->name,__FUNCTION__,
  2017. claw_reads_perpage);
  2018. }
  2019. else {
  2020. printk(KERN_INFO "%s: %s() pages_perread=%d\n",
  2021. dev->name,__FUNCTION__,
  2022. privptr->p_buff_pages_perread);
  2023. }
  2024. printk(KERN_INFO "%s: %s() read_pages=%d\n",
  2025. dev->name,__FUNCTION__,
  2026. claw_read_pages);
  2027. if (privptr->p_env->write_size < PAGE_SIZE) {
  2028. printk(KERN_INFO "%s: %s() writes_perpage=%d\n",
  2029. dev->name,__FUNCTION__,
  2030. claw_writes_perpage);
  2031. }
  2032. else {
  2033. printk(KERN_INFO "%s: %s() pages_perwrite=%d\n",
  2034. dev->name,__FUNCTION__,
  2035. privptr->p_buff_pages_perwrite);
  2036. }
  2037. printk(KERN_INFO "%s: %s() write_pages=%d\n",
  2038. dev->name,__FUNCTION__,
  2039. claw_write_pages);
  2040. #endif
  2041. /*
  2042. * allocate ccw_pages_required
  2043. */
  2044. if (privptr->p_buff_ccw==NULL) {
  2045. privptr->p_buff_ccw=
  2046. (void *)__get_free_pages(__GFP_DMA,
  2047. (int)pages_to_order_of_mag(ccw_pages_required ));
  2048. if (privptr->p_buff_ccw==NULL) {
  2049. printk(KERN_INFO "%s: %s() "
  2050. "__get_free_pages for CCWs failed : "
  2051. "pages is %d\n",
  2052. dev->name,__FUNCTION__,
  2053. ccw_pages_required );
  2054. #ifdef FUNCTRACE
  2055. printk(KERN_INFO "%s: %s() > "
  2056. "exit on line %d, rc = ENOMEM\n",
  2057. dev->name,__FUNCTION__,
  2058. __LINE__);
  2059. #endif
  2060. return -ENOMEM;
  2061. }
  2062. privptr->p_buff_ccw_num=ccw_pages_required;
  2063. }
  2064. memset(privptr->p_buff_ccw, 0x00,
  2065. privptr->p_buff_ccw_num * PAGE_SIZE);
  2066. /*
  2067. * obtain ending ccw block address
  2068. *
  2069. */
  2070. privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
  2071. real_address = (__u32)__pa(privptr->p_end_ccw);
  2072. /* Initialize ending CCW block */
  2073. #ifdef DEBUGMSG
  2074. printk(KERN_INFO "%s: %s() begin initialize ending CCW blocks\n",
  2075. dev->name,__FUNCTION__);
  2076. #endif
  2077. p_endccw=privptr->p_end_ccw;
  2078. p_endccw->real=real_address;
  2079. p_endccw->write1=0x00;
  2080. p_endccw->read1=0x00;
  2081. /* write1_nop1 */
  2082. p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  2083. p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2084. p_endccw->write1_nop1.count = 1;
  2085. p_endccw->write1_nop1.cda = 0;
  2086. /* write1_nop2 */
  2087. p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  2088. p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  2089. p_endccw->write1_nop2.count = 1;
  2090. p_endccw->write1_nop2.cda = 0;
  2091. /* write2_nop1 */
  2092. p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  2093. p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2094. p_endccw->write2_nop1.count = 1;
  2095. p_endccw->write2_nop1.cda = 0;
  2096. /* write2_nop2 */
  2097. p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  2098. p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  2099. p_endccw->write2_nop2.count = 1;
  2100. p_endccw->write2_nop2.cda = 0;
  2101. /* read1_nop1 */
  2102. p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  2103. p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2104. p_endccw->read1_nop1.count = 1;
  2105. p_endccw->read1_nop1.cda = 0;
  2106. /* read1_nop2 */
  2107. p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  2108. p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  2109. p_endccw->read1_nop2.count = 1;
  2110. p_endccw->read1_nop2.cda = 0;
  2111. /* read2_nop1 */
  2112. p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  2113. p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2114. p_endccw->read2_nop1.count = 1;
  2115. p_endccw->read2_nop1.cda = 0;
  2116. /* read2_nop2 */
  2117. p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  2118. p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  2119. p_endccw->read2_nop2.count = 1;
  2120. p_endccw->read2_nop2.cda = 0;
  2121. #ifdef IOTRACE
  2122. printk(KERN_INFO "%s: %s() dump claw ending CCW BK \n",
  2123. dev->name,__FUNCTION__);
  2124. dumpit((char *)p_endccw, sizeof(struct endccw));
  2125. #endif
  2126. /*
  2127. * Build a chain of CCWs
  2128. *
  2129. */
  2130. #ifdef DEBUGMSG
  2131. printk(KERN_INFO "%s: %s() Begin build a chain of CCW buffer \n",
  2132. dev->name,__FUNCTION__);
  2133. #endif
  2134. p_buff=privptr->p_buff_ccw;
  2135. p_free_chain=NULL;
  2136. for (i=0 ; i < ccw_pages_required; i++ ) {
  2137. real_address = (__u32)__pa(p_buff);
  2138. p_buf=p_buff;
  2139. for (j=0 ; j < ccw_blocks_perpage ; j++) {
  2140. p_buf->next = p_free_chain;
  2141. p_free_chain = p_buf;
  2142. p_buf->real=(__u32)__pa(p_buf);
  2143. ++p_buf;
  2144. }
  2145. p_buff+=PAGE_SIZE;
  2146. }
  2147. #ifdef DEBUGMSG
  2148. printk(KERN_INFO "%s: %s() "
  2149. "End build a chain of CCW buffer \n",
  2150. dev->name,__FUNCTION__);
  2151. p_buf=p_free_chain;
  2152. while (p_buf!=NULL) {
  2153. dumpit((char *)p_buf, sizeof(struct ccwbk));
  2154. p_buf=p_buf->next;
  2155. }
  2156. #endif
  2157. /*
  2158. * Initialize ClawSignalBlock
  2159. *
  2160. */
  2161. #ifdef DEBUGMSG
  2162. printk(KERN_INFO "%s: %s() "
  2163. "Begin initialize ClawSignalBlock \n",
  2164. dev->name,__FUNCTION__);
  2165. #endif
  2166. if (privptr->p_claw_signal_blk==NULL) {
  2167. privptr->p_claw_signal_blk=p_free_chain;
  2168. p_free_chain=p_free_chain->next;
  2169. pClawH=(struct clawh *)privptr->p_claw_signal_blk;
  2170. pClawH->length=0xffff;
  2171. pClawH->opcode=0xff;
  2172. pClawH->flag=CLAW_BUSY;
  2173. }
  2174. #ifdef DEBUGMSG
  2175. printk(KERN_INFO "%s: %s() > End initialize "
  2176. "ClawSignalBlock\n",
  2177. dev->name,__FUNCTION__);
  2178. dumpit((char *)privptr->p_claw_signal_blk, sizeof(struct ccwbk));
  2179. #endif
  2180. /*
  2181. * allocate write_pages_required and add to free chain
  2182. */
  2183. if (privptr->p_buff_write==NULL) {
  2184. if (privptr->p_env->write_size < PAGE_SIZE) {
  2185. privptr->p_buff_write=
  2186. (void *)__get_free_pages(__GFP_DMA,
  2187. (int)pages_to_order_of_mag(claw_write_pages ));
  2188. if (privptr->p_buff_write==NULL) {
  2189. printk(KERN_INFO "%s: %s() __get_free_pages for write"
  2190. " bufs failed : get is for %d pages\n",
  2191. dev->name,__FUNCTION__,claw_write_pages );
  2192. free_pages((unsigned long)privptr->p_buff_ccw,
  2193. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  2194. privptr->p_buff_ccw=NULL;
  2195. #ifdef FUNCTRACE
  2196. printk(KERN_INFO "%s: %s() > exit on line %d,"
  2197. "rc = ENOMEM\n",
  2198. dev->name,__FUNCTION__,__LINE__);
  2199. #endif
  2200. return -ENOMEM;
  2201. }
  2202. /*
  2203. * Build CLAW write free chain
  2204. *
  2205. */
  2206. memset(privptr->p_buff_write, 0x00,
  2207. ccw_pages_required * PAGE_SIZE);
  2208. #ifdef DEBUGMSG
  2209. printk(KERN_INFO "%s: %s() Begin build claw write free "
  2210. "chain \n",dev->name,__FUNCTION__);
  2211. #endif
  2212. privptr->p_write_free_chain=NULL;
  2213. p_buff=privptr->p_buff_write;
  2214. for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
  2215. p_buf = p_free_chain; /* get a CCW */
  2216. p_free_chain = p_buf->next;
  2217. p_buf->next =privptr->p_write_free_chain;
  2218. privptr->p_write_free_chain = p_buf;
  2219. p_buf-> p_buffer = (struct clawbuf *)p_buff;
  2220. p_buf-> write.cda = (__u32)__pa(p_buff);
  2221. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2222. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  2223. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2224. p_buf-> w_read_FF.count = 1;
  2225. p_buf-> w_read_FF.cda =
  2226. (__u32)__pa(&p_buf-> header.flag);
  2227. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  2228. p_buf-> w_TIC_1.flags = 0;
  2229. p_buf-> w_TIC_1.count = 0;
  2230. if (((unsigned long)p_buff+privptr->p_env->write_size) >=
  2231. ((unsigned long)(p_buff+2*
  2232. (privptr->p_env->write_size) -1) & PAGE_MASK)) {
  2233. p_buff= p_buff+privptr->p_env->write_size;
  2234. }
  2235. }
  2236. }
  2237. else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
  2238. {
  2239. privptr->p_write_free_chain=NULL;
  2240. for (i = 0; i< privptr->p_env->write_buffers ; i++) {
  2241. p_buff=(void *)__get_free_pages(__GFP_DMA,
  2242. (int)pages_to_order_of_mag(
  2243. privptr->p_buff_pages_perwrite) );
  2244. #ifdef IOTRACE
  2245. printk(KERN_INFO "%s:%s __get_free_pages "
  2246. "for writes buf: get for %d pages\n",
  2247. dev->name,__FUNCTION__,
  2248. privptr->p_buff_pages_perwrite);
  2249. #endif
  2250. if (p_buff==NULL) {
  2251. printk(KERN_INFO "%s:%s __get_free_pages"
  2252. "for writes buf failed : get is for %d pages\n",
  2253. dev->name,
  2254. __FUNCTION__,
  2255. privptr->p_buff_pages_perwrite );
  2256. free_pages((unsigned long)privptr->p_buff_ccw,
  2257. (int)pages_to_order_of_mag(
  2258. privptr->p_buff_ccw_num));
  2259. privptr->p_buff_ccw=NULL;
  2260. p_buf=privptr->p_buff_write;
  2261. while (p_buf!=NULL) {
  2262. free_pages((unsigned long)
  2263. p_buf->p_buffer,
  2264. (int)pages_to_order_of_mag(
  2265. privptr->p_buff_pages_perwrite));
  2266. p_buf=p_buf->next;
  2267. }
  2268. #ifdef FUNCTRACE
  2269. printk(KERN_INFO "%s: %s exit on line %d, rc = ENOMEM\n",
  2270. dev->name,
  2271. __FUNCTION__,
  2272. __LINE__);
  2273. #endif
  2274. return -ENOMEM;
  2275. } /* Error on get_pages */
  2276. memset(p_buff, 0x00, privptr->p_env->write_size );
  2277. p_buf = p_free_chain;
  2278. p_free_chain = p_buf->next;
  2279. p_buf->next = privptr->p_write_free_chain;
  2280. privptr->p_write_free_chain = p_buf;
  2281. privptr->p_buff_write = p_buf;
  2282. p_buf->p_buffer=(struct clawbuf *)p_buff;
  2283. p_buf-> write.cda = (__u32)__pa(p_buff);
  2284. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2285. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  2286. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2287. p_buf-> w_read_FF.count = 1;
  2288. p_buf-> w_read_FF.cda =
  2289. (__u32)__pa(&p_buf-> header.flag);
  2290. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  2291. p_buf-> w_TIC_1.flags = 0;
  2292. p_buf-> w_TIC_1.count = 0;
  2293. } /* for all write_buffers */
  2294. } /* else buffers are PAGE_SIZE or bigger */
  2295. }
  2296. privptr->p_buff_write_num=claw_write_pages;
  2297. privptr->write_free_count=privptr->p_env->write_buffers;
  2298. #ifdef DEBUGMSG
  2299. printk(KERN_INFO "%s:%s End build claw write free chain \n",
  2300. dev->name,__FUNCTION__);
  2301. p_buf=privptr->p_write_free_chain;
  2302. while (p_buf!=NULL) {
  2303. dumpit((char *)p_buf, sizeof(struct ccwbk));
  2304. p_buf=p_buf->next;
  2305. }
  2306. #endif
  2307. /*
  2308. * allocate read_pages_required and chain to free chain
  2309. */
  2310. if (privptr->p_buff_read==NULL) {
  2311. if (privptr->p_env->read_size < PAGE_SIZE) {
  2312. privptr->p_buff_read=
  2313. (void *)__get_free_pages(__GFP_DMA,
  2314. (int)pages_to_order_of_mag(claw_read_pages) );
  2315. if (privptr->p_buff_read==NULL) {
  2316. printk(KERN_INFO "%s: %s() "
  2317. "__get_free_pages for read buf failed : "
  2318. "get is for %d pages\n",
  2319. dev->name,__FUNCTION__,claw_read_pages );
  2320. free_pages((unsigned long)privptr->p_buff_ccw,
  2321. (int)pages_to_order_of_mag(
  2322. privptr->p_buff_ccw_num));
  2323. /* free the write pages size is < page size */
  2324. free_pages((unsigned long)privptr->p_buff_write,
  2325. (int)pages_to_order_of_mag(
  2326. privptr->p_buff_write_num));
  2327. privptr->p_buff_ccw=NULL;
  2328. privptr->p_buff_write=NULL;
  2329. #ifdef FUNCTRACE
  2330. printk(KERN_INFO "%s: %s() > exit on line %d, rc ="
  2331. " ENOMEM\n",dev->name,__FUNCTION__,__LINE__);
  2332. #endif
  2333. return -ENOMEM;
  2334. }
  2335. memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
  2336. privptr->p_buff_read_num=claw_read_pages;
  2337. /*
  2338. * Build CLAW read free chain
  2339. *
  2340. */
  2341. #ifdef DEBUGMSG
  2342. printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
  2343. dev->name,__FUNCTION__);
  2344. #endif
  2345. p_buff=privptr->p_buff_read;
  2346. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  2347. p_buf = p_free_chain;
  2348. p_free_chain = p_buf->next;
  2349. if (p_last_CCWB==NULL) {
  2350. p_buf->next=NULL;
  2351. real_TIC_address=0;
  2352. p_last_CCWB=p_buf;
  2353. }
  2354. else {
  2355. p_buf->next=p_first_CCWB;
  2356. real_TIC_address=
  2357. (__u32)__pa(&p_first_CCWB -> read );
  2358. }
  2359. p_first_CCWB=p_buf;
  2360. p_buf->p_buffer=(struct clawbuf *)p_buff;
  2361. /* initialize read command */
  2362. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  2363. p_buf-> read.cda = (__u32)__pa(p_buff);
  2364. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2365. p_buf-> read.count = privptr->p_env->read_size;
  2366. /* initialize read_h command */
  2367. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  2368. p_buf-> read_h.cda =
  2369. (__u32)__pa(&(p_buf->header));
  2370. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2371. p_buf-> read_h.count = sizeof(struct clawh);
  2372. /* initialize Signal command */
  2373. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  2374. p_buf-> signal.cda =
  2375. (__u32)__pa(&(pClawH->flag));
  2376. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2377. p_buf-> signal.count = 1;
  2378. /* initialize r_TIC_1 command */
  2379. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  2380. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  2381. p_buf-> r_TIC_1.flags = 0;
  2382. p_buf-> r_TIC_1.count = 0;
  2383. /* initialize r_read_FF command */
  2384. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  2385. p_buf-> r_read_FF.cda =
  2386. (__u32)__pa(&(pClawH->flag));
  2387. p_buf-> r_read_FF.flags =
  2388. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  2389. p_buf-> r_read_FF.count = 1;
  2390. /* initialize r_TIC_2 */
  2391. memcpy(&p_buf->r_TIC_2,
  2392. &p_buf->r_TIC_1, sizeof(struct ccw1));
  2393. /* initialize Header */
  2394. p_buf->header.length=0xffff;
  2395. p_buf->header.opcode=0xff;
  2396. p_buf->header.flag=CLAW_PENDING;
  2397. if (((unsigned long)p_buff+privptr->p_env->read_size) >=
  2398. ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
  2399. & PAGE_MASK) ) {
  2400. p_buff= p_buff+privptr->p_env->read_size;
  2401. }
  2402. else {
  2403. p_buff=
  2404. (void *)((unsigned long)
  2405. (p_buff+2*(privptr->p_env->read_size) -1)
  2406. & PAGE_MASK) ;
  2407. }
  2408. } /* for read_buffers */
  2409. } /* read_size < PAGE_SIZE */
  2410. else { /* read Size >= PAGE_SIZE */
  2411. #ifdef DEBUGMSG
  2412. printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
  2413. dev->name,__FUNCTION__);
  2414. #endif
  2415. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  2416. p_buff = (void *)__get_free_pages(__GFP_DMA,
  2417. (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
  2418. if (p_buff==NULL) {
  2419. printk(KERN_INFO "%s: %s() __get_free_pages for read "
  2420. "buf failed : get is for %d pages\n",
  2421. dev->name,__FUNCTION__,
  2422. privptr->p_buff_pages_perread );
  2423. free_pages((unsigned long)privptr->p_buff_ccw,
  2424. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  2425. /* free the write pages */
  2426. p_buf=privptr->p_buff_write;
  2427. while (p_buf!=NULL) {
  2428. free_pages((unsigned long)p_buf->p_buffer,
  2429. (int)pages_to_order_of_mag(
  2430. privptr->p_buff_pages_perwrite ));
  2431. p_buf=p_buf->next;
  2432. }
  2433. /* free any read pages already alloc */
  2434. p_buf=privptr->p_buff_read;
  2435. while (p_buf!=NULL) {
  2436. free_pages((unsigned long)p_buf->p_buffer,
  2437. (int)pages_to_order_of_mag(
  2438. privptr->p_buff_pages_perread ));
  2439. p_buf=p_buf->next;
  2440. }
  2441. privptr->p_buff_ccw=NULL;
  2442. privptr->p_buff_write=NULL;
  2443. #ifdef FUNCTRACE
  2444. printk(KERN_INFO "%s: %s() exit on line %d, rc = ENOMEM\n",
  2445. dev->name,__FUNCTION__,
  2446. __LINE__);
  2447. #endif
  2448. return -ENOMEM;
  2449. }
  2450. memset(p_buff, 0x00, privptr->p_env->read_size);
  2451. p_buf = p_free_chain;
  2452. privptr->p_buff_read = p_buf;
  2453. p_free_chain = p_buf->next;
  2454. if (p_last_CCWB==NULL) {
  2455. p_buf->next=NULL;
  2456. real_TIC_address=0;
  2457. p_last_CCWB=p_buf;
  2458. }
  2459. else {
  2460. p_buf->next=p_first_CCWB;
  2461. real_TIC_address=
  2462. (addr_t)__pa(
  2463. &p_first_CCWB -> read );
  2464. }
  2465. p_first_CCWB=p_buf;
  2466. /* save buff address */
  2467. p_buf->p_buffer=(struct clawbuf *)p_buff;
  2468. /* initialize read command */
  2469. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  2470. p_buf-> read.cda = (__u32)__pa(p_buff);
  2471. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2472. p_buf-> read.count = privptr->p_env->read_size;
  2473. /* initialize read_h command */
  2474. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  2475. p_buf-> read_h.cda =
  2476. (__u32)__pa(&(p_buf->header));
  2477. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2478. p_buf-> read_h.count = sizeof(struct clawh);
  2479. /* initialize Signal command */
  2480. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  2481. p_buf-> signal.cda =
  2482. (__u32)__pa(&(pClawH->flag));
  2483. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  2484. p_buf-> signal.count = 1;
  2485. /* initialize r_TIC_1 command */
  2486. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  2487. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  2488. p_buf-> r_TIC_1.flags = 0;
  2489. p_buf-> r_TIC_1.count = 0;
  2490. /* initialize r_read_FF command */
  2491. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  2492. p_buf-> r_read_FF.cda =
  2493. (__u32)__pa(&(pClawH->flag));
  2494. p_buf-> r_read_FF.flags =
  2495. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  2496. p_buf-> r_read_FF.count = 1;
  2497. /* initialize r_TIC_2 */
  2498. memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
  2499. sizeof(struct ccw1));
  2500. /* initialize Header */
  2501. p_buf->header.length=0xffff;
  2502. p_buf->header.opcode=0xff;
  2503. p_buf->header.flag=CLAW_PENDING;
  2504. } /* For read_buffers */
  2505. } /* read_size >= PAGE_SIZE */
  2506. } /* pBuffread = NULL */
  2507. #ifdef DEBUGMSG
  2508. printk(KERN_INFO "%s: %s() > End build claw read free chain \n",
  2509. dev->name,__FUNCTION__);
  2510. p_buf=p_first_CCWB;
  2511. while (p_buf!=NULL) {
  2512. dumpit((char *)p_buf, sizeof(struct ccwbk));
  2513. p_buf=p_buf->next;
  2514. }
  2515. #endif
  2516. add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
  2517. privptr->buffs_alloc = 1;
  2518. #ifdef FUNCTRACE
  2519. printk(KERN_INFO "%s: %s() exit on line %d\n",
  2520. dev->name,__FUNCTION__,__LINE__);
  2521. #endif
  2522. return 0;
  2523. } /* end of init_ccw_bk */
  2524. /*-------------------------------------------------------------------*
  2525. * *
  2526. * probe_error *
  2527. * *
  2528. *--------------------------------------------------------------------*/
  2529. static void
  2530. probe_error( struct ccwgroup_device *cgdev)
  2531. {
  2532. struct claw_privbk *privptr;
  2533. #ifdef FUNCTRACE
  2534. printk(KERN_INFO "%s enter \n",__FUNCTION__);
  2535. #endif
  2536. CLAW_DBF_TEXT(4,trace,"proberr");
  2537. #ifdef DEBUGMSG
  2538. printk(KERN_INFO "%s variable cgdev =\n",__FUNCTION__);
  2539. dumpit((char *) cgdev, sizeof(struct ccwgroup_device));
  2540. #endif
  2541. privptr=(struct claw_privbk *)cgdev->dev.driver_data;
  2542. if (privptr!=NULL) {
  2543. kfree(privptr->p_env);
  2544. privptr->p_env=NULL;
  2545. kfree(privptr->p_mtc_envelope);
  2546. privptr->p_mtc_envelope=NULL;
  2547. kfree(privptr);
  2548. privptr=NULL;
  2549. }
  2550. #ifdef FUNCTRACE
  2551. printk(KERN_INFO "%s > exit on line %d\n",
  2552. __FUNCTION__,__LINE__);
  2553. #endif
  2554. return;
  2555. } /* probe_error */
  2556. /*-------------------------------------------------------------------*
  2557. * claw_process_control *
  2558. * *
  2559. * *
  2560. *--------------------------------------------------------------------*/
  2561. static int
  2562. claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
  2563. {
  2564. struct clawbuf *p_buf;
  2565. struct clawctl ctlbk;
  2566. struct clawctl *p_ctlbk;
  2567. char temp_host_name[8];
  2568. char temp_ws_name[8];
  2569. struct claw_privbk *privptr;
  2570. struct claw_env *p_env;
  2571. struct sysval *p_sysval;
  2572. struct conncmd *p_connect=NULL;
  2573. int rc;
  2574. struct chbk *p_ch = NULL;
  2575. #ifdef FUNCTRACE
  2576. printk(KERN_INFO "%s: %s() > enter \n",
  2577. dev->name,__FUNCTION__);
  2578. #endif
  2579. CLAW_DBF_TEXT(2,setup,"clw_cntl");
  2580. #ifdef DEBUGMSG
  2581. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  2582. dumpit((char *) dev, sizeof(struct net_device));
  2583. printk(KERN_INFO "%s: variable p_ccw =\n",dev->name);
  2584. dumpit((char *) p_ccw, sizeof(struct ccwbk *));
  2585. #endif
  2586. udelay(1000); /* Wait a ms for the control packets to
  2587. *catch up to each other */
  2588. privptr=dev->priv;
  2589. p_env=privptr->p_env;
  2590. memcpy( &temp_host_name, p_env->host_name, 8);
  2591. memcpy( &temp_ws_name, p_env->adapter_name , 8);
  2592. printk(KERN_INFO "%s: CLAW device %.8s: "
  2593. "Received Control Packet\n",
  2594. dev->name, temp_ws_name);
  2595. if (privptr->release_pend==1) {
  2596. #ifdef FUNCTRACE
  2597. printk(KERN_INFO "%s: %s() > "
  2598. "exit on line %d, rc=0\n",
  2599. dev->name,__FUNCTION__,__LINE__);
  2600. #endif
  2601. return 0;
  2602. }
  2603. p_buf=p_ccw->p_buffer;
  2604. p_ctlbk=&ctlbk;
  2605. if (p_env->packing == DO_PACKED) { /* packing in progress?*/
  2606. memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
  2607. } else {
  2608. memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
  2609. }
  2610. #ifdef IOTRACE
  2611. printk(KERN_INFO "%s: dump claw control data inbound\n",dev->name);
  2612. dumpit((char *)p_ctlbk, sizeof(struct clawctl));
  2613. #endif
  2614. switch (p_ctlbk->command)
  2615. {
  2616. case SYSTEM_VALIDATE_REQUEST:
  2617. if (p_ctlbk->version!=CLAW_VERSION_ID) {
  2618. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  2619. CLAW_RC_WRONG_VERSION );
  2620. printk("%s: %d is wrong version id. "
  2621. "Expected %d\n",
  2622. dev->name, p_ctlbk->version,
  2623. CLAW_VERSION_ID);
  2624. }
  2625. p_sysval=(struct sysval *)&(p_ctlbk->data);
  2626. printk( "%s: Recv Sys Validate Request: "
  2627. "Vers=%d,link_id=%d,Corr=%d,WS name=%."
  2628. "8s,Host name=%.8s\n",
  2629. dev->name, p_ctlbk->version,
  2630. p_ctlbk->linkid,
  2631. p_ctlbk->correlator,
  2632. p_sysval->WS_name,
  2633. p_sysval->host_name);
  2634. if (0!=memcmp(temp_host_name,p_sysval->host_name,8)) {
  2635. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  2636. CLAW_RC_NAME_MISMATCH );
  2637. CLAW_DBF_TEXT(2,setup,"HSTBAD");
  2638. CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->host_name);
  2639. CLAW_DBF_TEXT_(2,setup,"%s",temp_host_name);
  2640. printk(KERN_INFO "%s: Host name mismatch\n",
  2641. dev->name);
  2642. printk(KERN_INFO "%s: Received :%s: "
  2643. "expected :%s: \n",
  2644. dev->name,
  2645. p_sysval->host_name,
  2646. temp_host_name);
  2647. }
  2648. if (0!=memcmp(temp_ws_name,p_sysval->WS_name,8)) {
  2649. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  2650. CLAW_RC_NAME_MISMATCH );
  2651. CLAW_DBF_TEXT(2,setup,"WSNBAD");
  2652. CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->WS_name);
  2653. CLAW_DBF_TEXT_(2,setup,"%s",temp_ws_name);
  2654. printk(KERN_INFO "%s: WS name mismatch\n",
  2655. dev->name);
  2656. printk(KERN_INFO "%s: Received :%s: "
  2657. "expected :%s: \n",
  2658. dev->name,
  2659. p_sysval->WS_name,
  2660. temp_ws_name);
  2661. }
  2662. if (( p_sysval->write_frame_size < p_env->write_size) &&
  2663. ( p_env->packing == 0)) {
  2664. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  2665. CLAW_RC_HOST_RCV_TOO_SMALL );
  2666. printk(KERN_INFO "%s: host write size is too "
  2667. "small\n", dev->name);
  2668. CLAW_DBF_TEXT(2,setup,"wrtszbad");
  2669. }
  2670. if (( p_sysval->read_frame_size < p_env->read_size) &&
  2671. ( p_env->packing == 0)) {
  2672. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  2673. CLAW_RC_HOST_RCV_TOO_SMALL );
  2674. printk(KERN_INFO "%s: host read size is too "
  2675. "small\n", dev->name);
  2676. CLAW_DBF_TEXT(2,setup,"rdsizbad");
  2677. }
  2678. claw_snd_sys_validate_rsp(dev, p_ctlbk, 0 );
  2679. printk("%s: CLAW device %.8s: System validate"
  2680. " completed.\n",dev->name, temp_ws_name);
  2681. printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev->name,
  2682. p_sysval->read_frame_size,p_sysval->write_frame_size);
  2683. privptr->system_validate_comp=1;
  2684. if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  2685. p_env->packing = PACKING_ASK;
  2686. }
  2687. claw_strt_conn_req(dev);
  2688. break;
  2689. case SYSTEM_VALIDATE_RESPONSE:
  2690. p_sysval=(struct sysval *)&(p_ctlbk->data);
  2691. printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
  2692. "WS name=%.8s,Host name=%.8s\n",
  2693. dev->name,
  2694. p_ctlbk->version,
  2695. p_ctlbk->correlator,
  2696. p_ctlbk->rc,
  2697. p_sysval->WS_name,
  2698. p_sysval->host_name);
  2699. switch (p_ctlbk->rc)
  2700. {
  2701. case 0:
  2702. printk(KERN_INFO "%s: CLAW device "
  2703. "%.8s: System validate "
  2704. "completed.\n",
  2705. dev->name, temp_ws_name);
  2706. if (privptr->system_validate_comp == 0)
  2707. claw_strt_conn_req(dev);
  2708. privptr->system_validate_comp=1;
  2709. break;
  2710. case CLAW_RC_NAME_MISMATCH:
  2711. printk(KERN_INFO "%s: Sys Validate "
  2712. "Resp : Host, WS name is "
  2713. "mismatch\n",
  2714. dev->name);
  2715. break;
  2716. case CLAW_RC_WRONG_VERSION:
  2717. printk(KERN_INFO "%s: Sys Validate "
  2718. "Resp : Wrong version\n",
  2719. dev->name);
  2720. break;
  2721. case CLAW_RC_HOST_RCV_TOO_SMALL:
  2722. printk(KERN_INFO "%s: Sys Validate "
  2723. "Resp : bad frame size\n",
  2724. dev->name);
  2725. break;
  2726. default:
  2727. printk(KERN_INFO "%s: Sys Validate "
  2728. "error code=%d \n",
  2729. dev->name, p_ctlbk->rc );
  2730. break;
  2731. }
  2732. break;
  2733. case CONNECTION_REQUEST:
  2734. p_connect=(struct conncmd *)&(p_ctlbk->data);
  2735. printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
  2736. "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
  2737. dev->name,
  2738. p_ctlbk->version,
  2739. p_ctlbk->linkid,
  2740. p_ctlbk->correlator,
  2741. p_connect->host_name,
  2742. p_connect->WS_name);
  2743. if (privptr->active_link_ID!=0 ) {
  2744. claw_snd_disc(dev, p_ctlbk);
  2745. printk(KERN_INFO "%s: Conn Req error : "
  2746. "already logical link is active \n",
  2747. dev->name);
  2748. }
  2749. if (p_ctlbk->linkid!=1 ) {
  2750. claw_snd_disc(dev, p_ctlbk);
  2751. printk(KERN_INFO "%s: Conn Req error : "
  2752. "req logical link id is not 1\n",
  2753. dev->name);
  2754. }
  2755. rc=find_link(dev,
  2756. p_connect->host_name, p_connect->WS_name);
  2757. if (rc!=0) {
  2758. claw_snd_disc(dev, p_ctlbk);
  2759. printk(KERN_INFO "%s: Conn Req error : "
  2760. "req appl name does not match\n",
  2761. dev->name);
  2762. }
  2763. claw_send_control(dev,
  2764. CONNECTION_CONFIRM, p_ctlbk->linkid,
  2765. p_ctlbk->correlator,
  2766. 0, p_connect->host_name,
  2767. p_connect->WS_name);
  2768. if (p_env->packing == PACKING_ASK) {
  2769. printk("%s: Now Pack ask\n",dev->name);
  2770. p_env->packing = PACK_SEND;
  2771. claw_snd_conn_req(dev,0);
  2772. }
  2773. printk(KERN_INFO "%s: CLAW device %.8s: Connection "
  2774. "completed link_id=%d.\n",
  2775. dev->name, temp_ws_name,
  2776. p_ctlbk->linkid);
  2777. privptr->active_link_ID=p_ctlbk->linkid;
  2778. p_ch=&privptr->channel[WRITE];
  2779. wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
  2780. break;
  2781. case CONNECTION_RESPONSE:
  2782. p_connect=(struct conncmd *)&(p_ctlbk->data);
  2783. printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
  2784. "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
  2785. dev->name,
  2786. p_ctlbk->version,
  2787. p_ctlbk->linkid,
  2788. p_ctlbk->correlator,
  2789. p_ctlbk->rc,
  2790. p_connect->host_name,
  2791. p_connect->WS_name);
  2792. if (p_ctlbk->rc !=0 ) {
  2793. printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
  2794. dev->name, p_ctlbk->rc);
  2795. return 1;
  2796. }
  2797. rc=find_link(dev,
  2798. p_connect->host_name, p_connect->WS_name);
  2799. if (rc!=0) {
  2800. claw_snd_disc(dev, p_ctlbk);
  2801. printk(KERN_INFO "%s: Conn Resp error: "
  2802. "req appl name does not match\n",
  2803. dev->name);
  2804. }
  2805. /* should be until CONNECTION_CONFIRM */
  2806. privptr->active_link_ID = - (p_ctlbk->linkid);
  2807. break;
  2808. case CONNECTION_CONFIRM:
  2809. p_connect=(struct conncmd *)&(p_ctlbk->data);
  2810. printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
  2811. "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
  2812. dev->name,
  2813. p_ctlbk->version,
  2814. p_ctlbk->linkid,
  2815. p_ctlbk->correlator,
  2816. p_connect->host_name,
  2817. p_connect->WS_name);
  2818. if (p_ctlbk->linkid== -(privptr->active_link_ID)) {
  2819. privptr->active_link_ID=p_ctlbk->linkid;
  2820. if (p_env->packing > PACKING_ASK) {
  2821. printk(KERN_INFO "%s: Confirmed Now packing\n",dev->name);
  2822. p_env->packing = DO_PACKED;
  2823. }
  2824. p_ch=&privptr->channel[WRITE];
  2825. wake_up(&p_ch->wait);
  2826. }
  2827. else {
  2828. printk(KERN_INFO "%s: Conn confirm: "
  2829. "unexpected linkid=%d \n",
  2830. dev->name, p_ctlbk->linkid);
  2831. claw_snd_disc(dev, p_ctlbk);
  2832. }
  2833. break;
  2834. case DISCONNECT:
  2835. printk(KERN_INFO "%s: Disconnect: "
  2836. "Vers=%d,link_id=%d,Corr=%d\n",
  2837. dev->name, p_ctlbk->version,
  2838. p_ctlbk->linkid, p_ctlbk->correlator);
  2839. if ((p_ctlbk->linkid == 2) &&
  2840. (p_env->packing == PACK_SEND)) {
  2841. privptr->active_link_ID = 1;
  2842. p_env->packing = DO_PACKED;
  2843. }
  2844. else
  2845. privptr->active_link_ID=0;
  2846. break;
  2847. case CLAW_ERROR:
  2848. printk(KERN_INFO "%s: CLAW ERROR detected\n",
  2849. dev->name);
  2850. break;
  2851. default:
  2852. printk(KERN_INFO "%s: Unexpected command code=%d \n",
  2853. dev->name, p_ctlbk->command);
  2854. break;
  2855. }
  2856. #ifdef FUNCTRACE
  2857. printk(KERN_INFO "%s: %s() exit on line %d, rc = 0\n",
  2858. dev->name,__FUNCTION__,__LINE__);
  2859. #endif
  2860. return 0;
  2861. } /* end of claw_process_control */
  2862. /*-------------------------------------------------------------------*
  2863. * claw_send_control *
  2864. * *
  2865. *--------------------------------------------------------------------*/
  2866. static int
  2867. claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  2868. __u8 correlator, __u8 rc, char *local_name, char *remote_name)
  2869. {
  2870. struct claw_privbk *privptr;
  2871. struct clawctl *p_ctl;
  2872. struct sysval *p_sysval;
  2873. struct conncmd *p_connect;
  2874. struct sk_buff *skb;
  2875. #ifdef FUNCTRACE
  2876. printk(KERN_INFO "%s:%s > enter \n",dev->name,__FUNCTION__);
  2877. #endif
  2878. CLAW_DBF_TEXT(2,setup,"sndcntl");
  2879. #ifdef DEBUGMSG
  2880. printk(KERN_INFO "%s: Sending Control Packet \n",dev->name);
  2881. printk(KERN_INFO "%s: variable type = 0x%X, link = "
  2882. "%d, correlator = %d, rc = %d\n",
  2883. dev->name,type, link, correlator, rc);
  2884. printk(KERN_INFO "%s: variable local_name = %s, "
  2885. "remote_name = %s\n",dev->name, local_name, remote_name);
  2886. #endif
  2887. privptr=dev->priv;
  2888. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2889. p_ctl->command=type;
  2890. p_ctl->version=CLAW_VERSION_ID;
  2891. p_ctl->linkid=link;
  2892. p_ctl->correlator=correlator;
  2893. p_ctl->rc=rc;
  2894. p_sysval=(struct sysval *)&p_ctl->data;
  2895. p_connect=(struct conncmd *)&p_ctl->data;
  2896. switch (p_ctl->command) {
  2897. case SYSTEM_VALIDATE_REQUEST:
  2898. case SYSTEM_VALIDATE_RESPONSE:
  2899. memcpy(&p_sysval->host_name, local_name, 8);
  2900. memcpy(&p_sysval->WS_name, remote_name, 8);
  2901. if (privptr->p_env->packing > 0) {
  2902. p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
  2903. p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
  2904. } else {
  2905. /* how big is the piggest group of packets */
  2906. p_sysval->read_frame_size=privptr->p_env->read_size;
  2907. p_sysval->write_frame_size=privptr->p_env->write_size;
  2908. }
  2909. memset(&p_sysval->reserved, 0x00, 4);
  2910. break;
  2911. case CONNECTION_REQUEST:
  2912. case CONNECTION_RESPONSE:
  2913. case CONNECTION_CONFIRM:
  2914. case DISCONNECT:
  2915. memcpy(&p_sysval->host_name, local_name, 8);
  2916. memcpy(&p_sysval->WS_name, remote_name, 8);
  2917. if (privptr->p_env->packing > 0) {
  2918. /* How big is the biggest packet */
  2919. p_connect->reserved1[0]=CLAW_FRAME_SIZE;
  2920. p_connect->reserved1[1]=CLAW_FRAME_SIZE;
  2921. } else {
  2922. memset(&p_connect->reserved1, 0x00, 4);
  2923. memset(&p_connect->reserved2, 0x00, 4);
  2924. }
  2925. break;
  2926. default:
  2927. break;
  2928. }
  2929. /* write Control Record to the device */
  2930. skb = dev_alloc_skb(sizeof(struct clawctl));
  2931. if (!skb) {
  2932. printk( "%s:%s low on mem, returning...\n",
  2933. dev->name,__FUNCTION__);
  2934. #ifdef DEBUG
  2935. printk(KERN_INFO "%s:%s Exit, rc = ENOMEM\n",
  2936. dev->name,__FUNCTION__);
  2937. #endif
  2938. return -ENOMEM;
  2939. }
  2940. memcpy(skb_put(skb, sizeof(struct clawctl)),
  2941. p_ctl, sizeof(struct clawctl));
  2942. #ifdef IOTRACE
  2943. printk(KERN_INFO "%s: outbnd claw cntl data \n",dev->name);
  2944. dumpit((char *)p_ctl,sizeof(struct clawctl));
  2945. #endif
  2946. if (privptr->p_env->packing >= PACK_SEND)
  2947. claw_hw_tx(skb, dev, 1);
  2948. else
  2949. claw_hw_tx(skb, dev, 0);
  2950. #ifdef FUNCTRACE
  2951. printk(KERN_INFO "%s:%s Exit on line %d\n",
  2952. dev->name,__FUNCTION__,__LINE__);
  2953. #endif
  2954. return 0;
  2955. } /* end of claw_send_control */
  2956. /*-------------------------------------------------------------------*
  2957. * claw_snd_conn_req *
  2958. * *
  2959. *--------------------------------------------------------------------*/
  2960. static int
  2961. claw_snd_conn_req(struct net_device *dev, __u8 link)
  2962. {
  2963. int rc;
  2964. struct claw_privbk *privptr=dev->priv;
  2965. struct clawctl *p_ctl;
  2966. #ifdef FUNCTRACE
  2967. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  2968. #endif
  2969. CLAW_DBF_TEXT(2,setup,"snd_conn");
  2970. #ifdef DEBUGMSG
  2971. printk(KERN_INFO "%s: variable link = %X, dev =\n",dev->name, link);
  2972. dumpit((char *) dev, sizeof(struct net_device));
  2973. #endif
  2974. rc = 1;
  2975. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2976. p_ctl->linkid = link;
  2977. if ( privptr->system_validate_comp==0x00 ) {
  2978. #ifdef FUNCTRACE
  2979. printk(KERN_INFO "%s:%s Exit on line %d, rc = 1\n",
  2980. dev->name,__FUNCTION__,__LINE__);
  2981. #endif
  2982. return rc;
  2983. }
  2984. if (privptr->p_env->packing == PACKING_ASK )
  2985. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2986. WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
  2987. if (privptr->p_env->packing == PACK_SEND) {
  2988. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2989. WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
  2990. }
  2991. if (privptr->p_env->packing == 0)
  2992. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2993. HOST_APPL_NAME, privptr->p_env->api_type);
  2994. #ifdef FUNCTRACE
  2995. printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
  2996. dev->name,__FUNCTION__,__LINE__, rc);
  2997. #endif
  2998. return rc;
  2999. } /* end of claw_snd_conn_req */
  3000. /*-------------------------------------------------------------------*
  3001. * claw_snd_disc *
  3002. * *
  3003. *--------------------------------------------------------------------*/
  3004. static int
  3005. claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
  3006. {
  3007. int rc;
  3008. struct conncmd * p_connect;
  3009. #ifdef FUNCTRACE
  3010. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3011. #endif
  3012. CLAW_DBF_TEXT(2,setup,"snd_dsc");
  3013. #ifdef DEBUGMSG
  3014. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  3015. dumpit((char *) dev, sizeof(struct net_device));
  3016. printk(KERN_INFO "%s: variable p_ctl",dev->name);
  3017. dumpit((char *) p_ctl, sizeof(struct clawctl));
  3018. #endif
  3019. p_connect=(struct conncmd *)&p_ctl->data;
  3020. rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
  3021. p_ctl->correlator, 0,
  3022. p_connect->host_name, p_connect->WS_name);
  3023. #ifdef FUNCTRACE
  3024. printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
  3025. dev->name,__FUNCTION__, __LINE__, rc);
  3026. #endif
  3027. return rc;
  3028. } /* end of claw_snd_disc */
  3029. /*-------------------------------------------------------------------*
  3030. * claw_snd_sys_validate_rsp *
  3031. * *
  3032. *--------------------------------------------------------------------*/
  3033. static int
  3034. claw_snd_sys_validate_rsp(struct net_device *dev,
  3035. struct clawctl *p_ctl, __u32 return_code)
  3036. {
  3037. struct claw_env * p_env;
  3038. struct claw_privbk *privptr;
  3039. int rc;
  3040. #ifdef FUNCTRACE
  3041. printk(KERN_INFO "%s:%s Enter\n",
  3042. dev->name,__FUNCTION__);
  3043. #endif
  3044. CLAW_DBF_TEXT(2,setup,"chkresp");
  3045. #ifdef DEBUGMSG
  3046. printk(KERN_INFO "%s: variable return_code = %d, dev =\n",
  3047. dev->name, return_code);
  3048. dumpit((char *) dev, sizeof(struct net_device));
  3049. printk(KERN_INFO "%s: variable p_ctl =\n",dev->name);
  3050. dumpit((char *) p_ctl, sizeof(struct clawctl));
  3051. #endif
  3052. privptr = dev->priv;
  3053. p_env=privptr->p_env;
  3054. rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
  3055. p_ctl->linkid,
  3056. p_ctl->correlator,
  3057. return_code,
  3058. p_env->host_name,
  3059. p_env->adapter_name );
  3060. #ifdef FUNCTRACE
  3061. printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
  3062. dev->name,__FUNCTION__,__LINE__, rc);
  3063. #endif
  3064. return rc;
  3065. } /* end of claw_snd_sys_validate_rsp */
  3066. /*-------------------------------------------------------------------*
  3067. * claw_strt_conn_req *
  3068. * *
  3069. *--------------------------------------------------------------------*/
  3070. static int
  3071. claw_strt_conn_req(struct net_device *dev )
  3072. {
  3073. int rc;
  3074. #ifdef FUNCTRACE
  3075. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3076. #endif
  3077. CLAW_DBF_TEXT(2,setup,"conn_req");
  3078. #ifdef DEBUGMSG
  3079. printk(KERN_INFO "%s: variable dev =\n",dev->name);
  3080. dumpit((char *) dev, sizeof(struct net_device));
  3081. #endif
  3082. rc=claw_snd_conn_req(dev, 1);
  3083. #ifdef FUNCTRACE
  3084. printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
  3085. dev->name,__FUNCTION__,__LINE__, rc);
  3086. #endif
  3087. return rc;
  3088. } /* end of claw_strt_conn_req */
  3089. /*-------------------------------------------------------------------*
  3090. * claw_stats *
  3091. *-------------------------------------------------------------------*/
  3092. static struct
  3093. net_device_stats *claw_stats(struct net_device *dev)
  3094. {
  3095. struct claw_privbk *privptr;
  3096. #ifdef FUNCTRACE
  3097. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3098. #endif
  3099. CLAW_DBF_TEXT(4,trace,"stats");
  3100. privptr = dev->priv;
  3101. #ifdef FUNCTRACE
  3102. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3103. dev->name,__FUNCTION__,__LINE__);
  3104. #endif
  3105. return &privptr->stats;
  3106. } /* end of claw_stats */
  3107. /*-------------------------------------------------------------------*
  3108. * unpack_read *
  3109. * *
  3110. *--------------------------------------------------------------------*/
  3111. static void
  3112. unpack_read(struct net_device *dev )
  3113. {
  3114. struct sk_buff *skb;
  3115. struct claw_privbk *privptr;
  3116. struct claw_env *p_env;
  3117. struct ccwbk *p_this_ccw;
  3118. struct ccwbk *p_first_ccw;
  3119. struct ccwbk *p_last_ccw;
  3120. struct clawph *p_packh;
  3121. void *p_packd;
  3122. struct clawctl *p_ctlrec=NULL;
  3123. __u32 len_of_data;
  3124. __u32 pack_off;
  3125. __u8 link_num;
  3126. __u8 mtc_this_frm=0;
  3127. __u32 bytes_to_mov;
  3128. struct chbk *p_ch = NULL;
  3129. int i=0;
  3130. int p=0;
  3131. #ifdef FUNCTRACE
  3132. printk(KERN_INFO "%s:%s enter \n",dev->name,__FUNCTION__);
  3133. #endif
  3134. CLAW_DBF_TEXT(4,trace,"unpkread");
  3135. p_first_ccw=NULL;
  3136. p_last_ccw=NULL;
  3137. p_packh=NULL;
  3138. p_packd=NULL;
  3139. privptr=dev->priv;
  3140. p_env = privptr->p_env;
  3141. p_this_ccw=privptr->p_read_active_first;
  3142. i=0;
  3143. while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
  3144. #ifdef IOTRACE
  3145. printk(KERN_INFO "%s p_this_ccw \n",dev->name);
  3146. dumpit((char*)p_this_ccw, sizeof(struct ccwbk));
  3147. printk(KERN_INFO "%s Inbound p_this_ccw->p_buffer(64)"
  3148. " pk=%d \n",dev->name,p_env->packing);
  3149. dumpit((char *)p_this_ccw->p_buffer, 64 );
  3150. #endif
  3151. pack_off = 0;
  3152. p = 0;
  3153. p_this_ccw->header.flag=CLAW_PENDING;
  3154. privptr->p_read_active_first=p_this_ccw->next;
  3155. p_this_ccw->next=NULL;
  3156. p_packh = (struct clawph *)p_this_ccw->p_buffer;
  3157. if ((p_env->packing == PACK_SEND) &&
  3158. (p_packh->len == 32) &&
  3159. (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
  3160. p_packh++; /* peek past pack header */
  3161. p_ctlrec = (struct clawctl *)p_packh;
  3162. p_packh--; /* un peek */
  3163. if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
  3164. (p_ctlrec->command == CONNECTION_CONFIRM))
  3165. p_env->packing = DO_PACKED;
  3166. }
  3167. if (p_env->packing == DO_PACKED)
  3168. link_num=p_packh->link_num;
  3169. else
  3170. link_num=p_this_ccw->header.opcode / 8;
  3171. if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
  3172. #ifdef DEBUGMSG
  3173. printk(KERN_INFO "%s: %s > More_to_come is ON\n",
  3174. dev->name,__FUNCTION__);
  3175. #endif
  3176. mtc_this_frm=1;
  3177. if (p_this_ccw->header.length!=
  3178. privptr->p_env->read_size ) {
  3179. printk(KERN_INFO " %s: Invalid frame detected "
  3180. "length is %02x\n" ,
  3181. dev->name, p_this_ccw->header.length);
  3182. }
  3183. }
  3184. if (privptr->mtc_skipping) {
  3185. /*
  3186. * We're in the mode of skipping past a
  3187. * multi-frame message
  3188. * that we can't process for some reason or other.
  3189. * The first frame without the More-To-Come flag is
  3190. * the last frame of the skipped message.
  3191. */
  3192. /* in case of More-To-Come not set in this frame */
  3193. if (mtc_this_frm==0) {
  3194. privptr->mtc_skipping=0; /* Ok, the end */
  3195. privptr->mtc_logical_link=-1;
  3196. }
  3197. #ifdef DEBUGMSG
  3198. printk(KERN_INFO "%s:%s goto next "
  3199. "frame from MoretoComeSkip \n",
  3200. dev->name,__FUNCTION__);
  3201. #endif
  3202. goto NextFrame;
  3203. }
  3204. if (link_num==0) {
  3205. claw_process_control(dev, p_this_ccw);
  3206. #ifdef DEBUGMSG
  3207. printk(KERN_INFO "%s:%s goto next "
  3208. "frame from claw_process_control \n",
  3209. dev->name,__FUNCTION__);
  3210. #endif
  3211. CLAW_DBF_TEXT(4,trace,"UnpkCntl");
  3212. goto NextFrame;
  3213. }
  3214. unpack_next:
  3215. if (p_env->packing == DO_PACKED) {
  3216. if (pack_off > p_env->read_size)
  3217. goto NextFrame;
  3218. p_packd = p_this_ccw->p_buffer+pack_off;
  3219. p_packh = (struct clawph *) p_packd;
  3220. if ((p_packh->len == 0) || /* all done with this frame? */
  3221. (p_packh->flag != 0))
  3222. goto NextFrame;
  3223. bytes_to_mov = p_packh->len;
  3224. pack_off += bytes_to_mov+sizeof(struct clawph);
  3225. p++;
  3226. } else {
  3227. bytes_to_mov=p_this_ccw->header.length;
  3228. }
  3229. if (privptr->mtc_logical_link<0) {
  3230. #ifdef DEBUGMSG
  3231. printk(KERN_INFO "%s: %s mtc_logical_link < 0 \n",
  3232. dev->name,__FUNCTION__);
  3233. #endif
  3234. /*
  3235. * if More-To-Come is set in this frame then we don't know
  3236. * length of entire message, and hence have to allocate
  3237. * large buffer */
  3238. /* We are starting a new envelope */
  3239. privptr->mtc_offset=0;
  3240. privptr->mtc_logical_link=link_num;
  3241. }
  3242. if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
  3243. /* error */
  3244. #ifdef DEBUGMSG
  3245. printk(KERN_INFO "%s: %s > goto next "
  3246. "frame from MoretoComeSkip \n",
  3247. dev->name,
  3248. __FUNCTION__);
  3249. printk(KERN_INFO " bytes_to_mov %d > (MAX_ENVELOPE_"
  3250. "SIZE-privptr->mtc_offset %d)\n",
  3251. bytes_to_mov,(MAX_ENVELOPE_SIZE- privptr->mtc_offset));
  3252. #endif
  3253. privptr->stats.rx_frame_errors++;
  3254. goto NextFrame;
  3255. }
  3256. if (p_env->packing == DO_PACKED) {
  3257. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  3258. p_packd+sizeof(struct clawph), bytes_to_mov);
  3259. } else {
  3260. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  3261. p_this_ccw->p_buffer, bytes_to_mov);
  3262. }
  3263. #ifdef DEBUGMSG
  3264. printk(KERN_INFO "%s: %s() received data \n",
  3265. dev->name,__FUNCTION__);
  3266. if (p_env->packing == DO_PACKED)
  3267. dumpit((char *)p_packd+sizeof(struct clawph),32);
  3268. else
  3269. dumpit((char *)p_this_ccw->p_buffer, 32);
  3270. printk(KERN_INFO "%s: %s() bytelength %d \n",
  3271. dev->name,__FUNCTION__,bytes_to_mov);
  3272. #endif
  3273. if (mtc_this_frm==0) {
  3274. len_of_data=privptr->mtc_offset+bytes_to_mov;
  3275. skb=dev_alloc_skb(len_of_data);
  3276. if (skb) {
  3277. memcpy(skb_put(skb,len_of_data),
  3278. privptr->p_mtc_envelope,
  3279. len_of_data);
  3280. skb->dev=dev;
  3281. skb_reset_mac_header(skb);
  3282. skb->protocol=htons(ETH_P_IP);
  3283. skb->ip_summed=CHECKSUM_UNNECESSARY;
  3284. privptr->stats.rx_packets++;
  3285. privptr->stats.rx_bytes+=len_of_data;
  3286. netif_rx(skb);
  3287. #ifdef DEBUGMSG
  3288. printk(KERN_INFO "%s: %s() netif_"
  3289. "rx(skb) completed \n",
  3290. dev->name,__FUNCTION__);
  3291. #endif
  3292. }
  3293. else {
  3294. privptr->stats.rx_dropped++;
  3295. printk(KERN_WARNING "%s: %s() low on memory\n",
  3296. dev->name,__FUNCTION__);
  3297. }
  3298. privptr->mtc_offset=0;
  3299. privptr->mtc_logical_link=-1;
  3300. }
  3301. else {
  3302. privptr->mtc_offset+=bytes_to_mov;
  3303. }
  3304. if (p_env->packing == DO_PACKED)
  3305. goto unpack_next;
  3306. NextFrame:
  3307. /*
  3308. * Remove ThisCCWblock from active read queue, and add it
  3309. * to queue of free blocks to be reused.
  3310. */
  3311. i++;
  3312. p_this_ccw->header.length=0xffff;
  3313. p_this_ccw->header.opcode=0xff;
  3314. /*
  3315. * add this one to the free queue for later reuse
  3316. */
  3317. if (p_first_ccw==NULL) {
  3318. p_first_ccw = p_this_ccw;
  3319. }
  3320. else {
  3321. p_last_ccw->next = p_this_ccw;
  3322. }
  3323. p_last_ccw = p_this_ccw;
  3324. /*
  3325. * chain to next block on active read queue
  3326. */
  3327. p_this_ccw = privptr->p_read_active_first;
  3328. CLAW_DBF_TEXT_(4,trace,"rxpkt %d",p);
  3329. } /* end of while */
  3330. /* check validity */
  3331. #ifdef IOTRACE
  3332. printk(KERN_INFO "%s:%s processed frame is %d \n",
  3333. dev->name,__FUNCTION__,i);
  3334. printk(KERN_INFO "%s:%s F:%lx L:%lx\n",
  3335. dev->name,
  3336. __FUNCTION__,
  3337. (unsigned long)p_first_ccw,
  3338. (unsigned long)p_last_ccw);
  3339. #endif
  3340. CLAW_DBF_TEXT_(4,trace,"rxfrm %d",i);
  3341. add_claw_reads(dev, p_first_ccw, p_last_ccw);
  3342. p_ch=&privptr->channel[READ];
  3343. claw_strt_read(dev, LOCK_YES);
  3344. #ifdef FUNCTRACE
  3345. printk(KERN_INFO "%s: %s exit on line %d\n",
  3346. dev->name, __FUNCTION__, __LINE__);
  3347. #endif
  3348. return;
  3349. } /* end of unpack_read */
  3350. /*-------------------------------------------------------------------*
  3351. * claw_strt_read *
  3352. * *
  3353. *--------------------------------------------------------------------*/
  3354. static void
  3355. claw_strt_read (struct net_device *dev, int lock )
  3356. {
  3357. int rc = 0;
  3358. __u32 parm;
  3359. unsigned long saveflags = 0;
  3360. struct claw_privbk *privptr=dev->priv;
  3361. struct ccwbk*p_ccwbk;
  3362. struct chbk *p_ch;
  3363. struct clawh *p_clawh;
  3364. p_ch=&privptr->channel[READ];
  3365. #ifdef FUNCTRACE
  3366. printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
  3367. printk(KERN_INFO "%s: variable lock = %d, dev =\n",dev->name, lock);
  3368. dumpit((char *) dev, sizeof(struct net_device));
  3369. #endif
  3370. CLAW_DBF_TEXT(4,trace,"StRdNter");
  3371. p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
  3372. p_clawh->flag=CLAW_IDLE; /* 0x00 */
  3373. if ((privptr->p_write_active_first!=NULL &&
  3374. privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
  3375. (privptr->p_read_active_first!=NULL &&
  3376. privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
  3377. p_clawh->flag=CLAW_BUSY; /* 0xff */
  3378. }
  3379. #ifdef DEBUGMSG
  3380. printk(KERN_INFO "%s:%s state-%02x\n" ,
  3381. dev->name,__FUNCTION__, p_ch->claw_state);
  3382. #endif
  3383. if (lock==LOCK_YES) {
  3384. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  3385. }
  3386. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  3387. #ifdef DEBUGMSG
  3388. printk(KERN_INFO "%s: HOT READ started in %s\n" ,
  3389. dev->name,__FUNCTION__);
  3390. p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
  3391. dumpit((char *)&p_clawh->flag , 1);
  3392. #endif
  3393. CLAW_DBF_TEXT(4,trace,"HotRead");
  3394. p_ccwbk=privptr->p_read_active_first;
  3395. parm = (unsigned long) p_ch;
  3396. rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
  3397. 0xff, 0);
  3398. if (rc != 0) {
  3399. ccw_check_return_code(p_ch->cdev, rc);
  3400. }
  3401. }
  3402. else {
  3403. #ifdef DEBUGMSG
  3404. printk(KERN_INFO "%s: No READ started by %s() In progress\n" ,
  3405. dev->name,__FUNCTION__);
  3406. #endif
  3407. CLAW_DBF_TEXT(2,trace,"ReadAct");
  3408. }
  3409. if (lock==LOCK_YES) {
  3410. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  3411. }
  3412. #ifdef FUNCTRACE
  3413. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3414. dev->name,__FUNCTION__,__LINE__);
  3415. #endif
  3416. CLAW_DBF_TEXT(4,trace,"StRdExit");
  3417. return;
  3418. } /* end of claw_strt_read */
  3419. /*-------------------------------------------------------------------*
  3420. * claw_strt_out_IO *
  3421. * *
  3422. *--------------------------------------------------------------------*/
  3423. static void
  3424. claw_strt_out_IO( struct net_device *dev )
  3425. {
  3426. int rc = 0;
  3427. unsigned long parm;
  3428. struct claw_privbk *privptr;
  3429. struct chbk *p_ch;
  3430. struct ccwbk *p_first_ccw;
  3431. #ifdef FUNCTRACE
  3432. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3433. #endif
  3434. if (!dev) {
  3435. return;
  3436. }
  3437. privptr=(struct claw_privbk *)dev->priv;
  3438. p_ch=&privptr->channel[WRITE];
  3439. #ifdef DEBUGMSG
  3440. printk(KERN_INFO "%s:%s state-%02x\n" ,
  3441. dev->name,__FUNCTION__,p_ch->claw_state);
  3442. #endif
  3443. CLAW_DBF_TEXT(4,trace,"strt_io");
  3444. p_first_ccw=privptr->p_write_active_first;
  3445. if (p_ch->claw_state == CLAW_STOP)
  3446. return;
  3447. if (p_first_ccw == NULL) {
  3448. #ifdef FUNCTRACE
  3449. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3450. dev->name,__FUNCTION__,__LINE__);
  3451. #endif
  3452. return;
  3453. }
  3454. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  3455. parm = (unsigned long) p_ch;
  3456. #ifdef DEBUGMSG
  3457. printk(KERN_INFO "%s:%s do_io \n" ,dev->name,__FUNCTION__);
  3458. dumpit((char *)p_first_ccw, sizeof(struct ccwbk));
  3459. #endif
  3460. CLAW_DBF_TEXT(2,trace,"StWrtIO");
  3461. rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
  3462. 0xff, 0);
  3463. if (rc != 0) {
  3464. ccw_check_return_code(p_ch->cdev, rc);
  3465. }
  3466. }
  3467. dev->trans_start = jiffies;
  3468. #ifdef FUNCTRACE
  3469. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3470. dev->name,__FUNCTION__,__LINE__);
  3471. #endif
  3472. return;
  3473. } /* end of claw_strt_out_IO */
  3474. /*-------------------------------------------------------------------*
  3475. * Free write buffers *
  3476. * *
  3477. *--------------------------------------------------------------------*/
  3478. static void
  3479. claw_free_wrt_buf( struct net_device *dev )
  3480. {
  3481. struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
  3482. struct ccwbk*p_first_ccw;
  3483. struct ccwbk*p_last_ccw;
  3484. struct ccwbk*p_this_ccw;
  3485. struct ccwbk*p_next_ccw;
  3486. #ifdef IOTRACE
  3487. struct ccwbk*p_buf;
  3488. #endif
  3489. #ifdef FUNCTRACE
  3490. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3491. printk(KERN_INFO "%s: free count = %d variable dev =\n",
  3492. dev->name,privptr->write_free_count);
  3493. #endif
  3494. CLAW_DBF_TEXT(4,trace,"freewrtb");
  3495. /* scan the write queue to free any completed write packets */
  3496. p_first_ccw=NULL;
  3497. p_last_ccw=NULL;
  3498. #ifdef IOTRACE
  3499. printk(KERN_INFO "%s: Dump current CCW chain \n",dev->name );
  3500. p_buf=privptr->p_write_active_first;
  3501. while (p_buf!=NULL) {
  3502. dumpit((char *)p_buf, sizeof(struct ccwbk));
  3503. p_buf=p_buf->next;
  3504. }
  3505. if (p_buf==NULL) {
  3506. printk(KERN_INFO "%s: privptr->p_write_"
  3507. "active_first==NULL\n",dev->name );
  3508. }
  3509. p_buf=(struct ccwbk*)privptr->p_end_ccw;
  3510. dumpit((char *)p_buf, sizeof(struct endccw));
  3511. #endif
  3512. p_this_ccw=privptr->p_write_active_first;
  3513. while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
  3514. {
  3515. p_next_ccw = p_this_ccw->next;
  3516. if (((p_next_ccw!=NULL) &&
  3517. (p_next_ccw->header.flag!=CLAW_PENDING)) ||
  3518. ((p_this_ccw == privptr->p_write_active_last) &&
  3519. (p_this_ccw->header.flag!=CLAW_PENDING))) {
  3520. /* The next CCW is OK or this is */
  3521. /* the last CCW...free it @A1A */
  3522. privptr->p_write_active_first=p_this_ccw->next;
  3523. p_this_ccw->header.flag=CLAW_PENDING;
  3524. p_this_ccw->next=privptr->p_write_free_chain;
  3525. privptr->p_write_free_chain=p_this_ccw;
  3526. ++privptr->write_free_count;
  3527. privptr->stats.tx_bytes+= p_this_ccw->write.count;
  3528. p_this_ccw=privptr->p_write_active_first;
  3529. privptr->stats.tx_packets++;
  3530. }
  3531. else {
  3532. break;
  3533. }
  3534. }
  3535. if (privptr->write_free_count!=0) {
  3536. claw_clearbit_busy(TB_NOBUFFER,dev);
  3537. }
  3538. /* whole chain removed? */
  3539. if (privptr->p_write_active_first==NULL) {
  3540. privptr->p_write_active_last=NULL;
  3541. #ifdef DEBUGMSG
  3542. printk(KERN_INFO "%s:%s p_write_"
  3543. "active_first==NULL\n",dev->name,__FUNCTION__);
  3544. #endif
  3545. }
  3546. #ifdef IOTRACE
  3547. printk(KERN_INFO "%s: Dump arranged CCW chain \n",dev->name );
  3548. p_buf=privptr->p_write_active_first;
  3549. while (p_buf!=NULL) {
  3550. dumpit((char *)p_buf, sizeof(struct ccwbk));
  3551. p_buf=p_buf->next;
  3552. }
  3553. if (p_buf==NULL) {
  3554. printk(KERN_INFO "%s: privptr->p_write_active_"
  3555. "first==NULL\n",dev->name );
  3556. }
  3557. p_buf=(struct ccwbk*)privptr->p_end_ccw;
  3558. dumpit((char *)p_buf, sizeof(struct endccw));
  3559. #endif
  3560. CLAW_DBF_TEXT_(4,trace,"FWC=%d",privptr->write_free_count);
  3561. #ifdef FUNCTRACE
  3562. printk(KERN_INFO "%s:%s Exit on line %d free_count =%d\n",
  3563. dev->name,__FUNCTION__, __LINE__,privptr->write_free_count);
  3564. #endif
  3565. return;
  3566. }
  3567. /*-------------------------------------------------------------------*
  3568. * claw free netdevice *
  3569. * *
  3570. *--------------------------------------------------------------------*/
  3571. static void
  3572. claw_free_netdevice(struct net_device * dev, int free_dev)
  3573. {
  3574. struct claw_privbk *privptr;
  3575. #ifdef FUNCTRACE
  3576. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3577. #endif
  3578. CLAW_DBF_TEXT(2,setup,"free_dev");
  3579. if (!dev)
  3580. return;
  3581. CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
  3582. privptr = dev->priv;
  3583. if (dev->flags & IFF_RUNNING)
  3584. claw_release(dev);
  3585. if (privptr) {
  3586. privptr->channel[READ].ndev = NULL; /* say it's free */
  3587. }
  3588. dev->priv=NULL;
  3589. #ifdef MODULE
  3590. if (free_dev) {
  3591. free_netdev(dev);
  3592. }
  3593. #endif
  3594. CLAW_DBF_TEXT(2,setup,"feee_ok");
  3595. #ifdef FUNCTRACE
  3596. printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
  3597. #endif
  3598. }
  3599. /**
  3600. * Claw init netdevice
  3601. * Initialize everything of the net device except the name and the
  3602. * channel structs.
  3603. */
  3604. static void
  3605. claw_init_netdevice(struct net_device * dev)
  3606. {
  3607. #ifdef FUNCTRACE
  3608. printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
  3609. #endif
  3610. CLAW_DBF_TEXT(2,setup,"init_dev");
  3611. CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
  3612. if (!dev) {
  3613. printk(KERN_WARNING "claw:%s BAD Device exit line %d\n",
  3614. __FUNCTION__,__LINE__);
  3615. CLAW_DBF_TEXT(2,setup,"baddev");
  3616. return;
  3617. }
  3618. dev->mtu = CLAW_DEFAULT_MTU_SIZE;
  3619. dev->hard_start_xmit = claw_tx;
  3620. dev->open = claw_open;
  3621. dev->stop = claw_release;
  3622. dev->get_stats = claw_stats;
  3623. dev->change_mtu = claw_change_mtu;
  3624. dev->hard_header_len = 0;
  3625. dev->addr_len = 0;
  3626. dev->type = ARPHRD_SLIP;
  3627. dev->tx_queue_len = 1300;
  3628. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  3629. #ifdef FUNCTRACE
  3630. printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
  3631. #endif
  3632. CLAW_DBF_TEXT(2,setup,"initok");
  3633. return;
  3634. }
  3635. /**
  3636. * Init a new channel in the privptr->channel[i].
  3637. *
  3638. * @param cdev The ccw_device to be added.
  3639. *
  3640. * @return 0 on success, !0 on error.
  3641. */
  3642. static int
  3643. add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
  3644. {
  3645. struct chbk *p_ch;
  3646. struct ccw_dev_id dev_id;
  3647. #ifdef FUNCTRACE
  3648. printk(KERN_INFO "%s:%s Enter\n",cdev->dev.bus_id,__FUNCTION__);
  3649. #endif
  3650. CLAW_DBF_TEXT_(2,setup,"%s",cdev->dev.bus_id);
  3651. privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
  3652. p_ch = &privptr->channel[i];
  3653. p_ch->cdev = cdev;
  3654. snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
  3655. ccw_device_get_id(cdev, &dev_id);
  3656. p_ch->devno = dev_id.devno;
  3657. if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
  3658. printk(KERN_WARNING "%s Out of memory in %s for irb\n",
  3659. p_ch->id,__FUNCTION__);
  3660. #ifdef FUNCTRACE
  3661. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3662. p_ch->id,__FUNCTION__,__LINE__);
  3663. #endif
  3664. return -ENOMEM;
  3665. }
  3666. #ifdef FUNCTRACE
  3667. printk(KERN_INFO "%s:%s Exit on line %d\n",
  3668. cdev->dev.bus_id,__FUNCTION__,__LINE__);
  3669. #endif
  3670. return 0;
  3671. }
  3672. /**
  3673. *
  3674. * Setup an interface.
  3675. *
  3676. * @param cgdev Device to be setup.
  3677. *
  3678. * @returns 0 on success, !0 on failure.
  3679. */
  3680. static int
  3681. claw_new_device(struct ccwgroup_device *cgdev)
  3682. {
  3683. struct claw_privbk *privptr;
  3684. struct claw_env *p_env;
  3685. struct net_device *dev;
  3686. int ret;
  3687. struct ccw_dev_id dev_id;
  3688. pr_debug("%s() called\n", __FUNCTION__);
  3689. printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
  3690. CLAW_DBF_TEXT(2,setup,"new_dev");
  3691. privptr = cgdev->dev.driver_data;
  3692. cgdev->cdev[READ]->dev.driver_data = privptr;
  3693. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  3694. if (!privptr)
  3695. return -ENODEV;
  3696. p_env = privptr->p_env;
  3697. ccw_device_get_id(cgdev->cdev[READ], &dev_id);
  3698. p_env->devno[READ] = dev_id.devno;
  3699. ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
  3700. p_env->devno[WRITE] = dev_id.devno;
  3701. ret = add_channel(cgdev->cdev[0],0,privptr);
  3702. if (ret == 0)
  3703. ret = add_channel(cgdev->cdev[1],1,privptr);
  3704. if (ret != 0) {
  3705. printk(KERN_WARNING
  3706. "add channel failed "
  3707. "with ret = %d\n", ret);
  3708. goto out;
  3709. }
  3710. ret = ccw_device_set_online(cgdev->cdev[READ]);
  3711. if (ret != 0) {
  3712. printk(KERN_WARNING
  3713. "claw: ccw_device_set_online %s READ failed "
  3714. "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
  3715. goto out;
  3716. }
  3717. ret = ccw_device_set_online(cgdev->cdev[WRITE]);
  3718. if (ret != 0) {
  3719. printk(KERN_WARNING
  3720. "claw: ccw_device_set_online %s WRITE failed "
  3721. "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
  3722. goto out;
  3723. }
  3724. dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
  3725. if (!dev) {
  3726. printk(KERN_WARNING "%s:alloc_netdev failed\n",__FUNCTION__);
  3727. goto out;
  3728. }
  3729. dev->priv = privptr;
  3730. cgdev->dev.driver_data = privptr;
  3731. cgdev->cdev[READ]->dev.driver_data = privptr;
  3732. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  3733. /* sysfs magic */
  3734. SET_NETDEV_DEV(dev, &cgdev->dev);
  3735. if (register_netdev(dev) != 0) {
  3736. claw_free_netdevice(dev, 1);
  3737. CLAW_DBF_TEXT(2,trace,"regfail");
  3738. goto out;
  3739. }
  3740. dev->flags &=~IFF_RUNNING;
  3741. if (privptr->buffs_alloc == 0) {
  3742. ret=init_ccw_bk(dev);
  3743. if (ret !=0) {
  3744. printk(KERN_WARNING
  3745. "claw: init_ccw_bk failed with ret=%d\n", ret);
  3746. unregister_netdev(dev);
  3747. claw_free_netdevice(dev,1);
  3748. CLAW_DBF_TEXT(2,trace,"ccwmem");
  3749. goto out;
  3750. }
  3751. }
  3752. privptr->channel[READ].ndev = dev;
  3753. privptr->channel[WRITE].ndev = dev;
  3754. privptr->p_env->ndev = dev;
  3755. printk(KERN_INFO "%s:readsize=%d writesize=%d "
  3756. "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
  3757. dev->name, p_env->read_size,
  3758. p_env->write_size, p_env->read_buffers,
  3759. p_env->write_buffers, p_env->devno[READ],
  3760. p_env->devno[WRITE]);
  3761. printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
  3762. ":%.8s api_type: %.8s\n",
  3763. dev->name, p_env->host_name,
  3764. p_env->adapter_name , p_env->api_type);
  3765. return 0;
  3766. out:
  3767. ccw_device_set_offline(cgdev->cdev[1]);
  3768. ccw_device_set_offline(cgdev->cdev[0]);
  3769. return -ENODEV;
  3770. }
  3771. static void
  3772. claw_purge_skb_queue(struct sk_buff_head *q)
  3773. {
  3774. struct sk_buff *skb;
  3775. CLAW_DBF_TEXT(4,trace,"purgque");
  3776. while ((skb = skb_dequeue(q))) {
  3777. atomic_dec(&skb->users);
  3778. dev_kfree_skb_any(skb);
  3779. }
  3780. }
  3781. /**
  3782. * Shutdown an interface.
  3783. *
  3784. * @param cgdev Device to be shut down.
  3785. *
  3786. * @returns 0 on success, !0 on failure.
  3787. */
  3788. static int
  3789. claw_shutdown_device(struct ccwgroup_device *cgdev)
  3790. {
  3791. struct claw_privbk *priv;
  3792. struct net_device *ndev;
  3793. int ret;
  3794. pr_debug("%s() called\n", __FUNCTION__);
  3795. CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
  3796. priv = cgdev->dev.driver_data;
  3797. if (!priv)
  3798. return -ENODEV;
  3799. ndev = priv->channel[READ].ndev;
  3800. if (ndev) {
  3801. /* Close the device */
  3802. printk(KERN_INFO
  3803. "%s: shuting down \n",ndev->name);
  3804. if (ndev->flags & IFF_RUNNING)
  3805. ret = claw_release(ndev);
  3806. ndev->flags &=~IFF_RUNNING;
  3807. unregister_netdev(ndev);
  3808. ndev->priv = NULL; /* cgdev data, not ndev's to free */
  3809. claw_free_netdevice(ndev, 1);
  3810. priv->channel[READ].ndev = NULL;
  3811. priv->channel[WRITE].ndev = NULL;
  3812. priv->p_env->ndev = NULL;
  3813. }
  3814. ccw_device_set_offline(cgdev->cdev[1]);
  3815. ccw_device_set_offline(cgdev->cdev[0]);
  3816. return 0;
  3817. }
  3818. static void
  3819. claw_remove_device(struct ccwgroup_device *cgdev)
  3820. {
  3821. struct claw_privbk *priv;
  3822. pr_debug("%s() called\n", __FUNCTION__);
  3823. CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
  3824. priv = cgdev->dev.driver_data;
  3825. if (!priv) {
  3826. printk(KERN_WARNING "claw: %s() no Priv exiting\n",__FUNCTION__);
  3827. return;
  3828. }
  3829. printk(KERN_INFO "claw: %s() called %s will be removed.\n",
  3830. __FUNCTION__,cgdev->cdev[0]->dev.bus_id);
  3831. if (cgdev->state == CCWGROUP_ONLINE)
  3832. claw_shutdown_device(cgdev);
  3833. claw_remove_files(&cgdev->dev);
  3834. kfree(priv->p_mtc_envelope);
  3835. priv->p_mtc_envelope=NULL;
  3836. kfree(priv->p_env);
  3837. priv->p_env=NULL;
  3838. kfree(priv->channel[0].irb);
  3839. priv->channel[0].irb=NULL;
  3840. kfree(priv->channel[1].irb);
  3841. priv->channel[1].irb=NULL;
  3842. kfree(priv);
  3843. cgdev->dev.driver_data=NULL;
  3844. cgdev->cdev[READ]->dev.driver_data = NULL;
  3845. cgdev->cdev[WRITE]->dev.driver_data = NULL;
  3846. put_device(&cgdev->dev);
  3847. }
  3848. /*
  3849. * sysfs attributes
  3850. */
  3851. static ssize_t
  3852. claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
  3853. {
  3854. struct claw_privbk *priv;
  3855. struct claw_env * p_env;
  3856. priv = dev->driver_data;
  3857. if (!priv)
  3858. return -ENODEV;
  3859. p_env = priv->p_env;
  3860. return sprintf(buf, "%s\n",p_env->host_name);
  3861. }
  3862. static ssize_t
  3863. claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  3864. {
  3865. struct claw_privbk *priv;
  3866. struct claw_env * p_env;
  3867. priv = dev->driver_data;
  3868. if (!priv)
  3869. return -ENODEV;
  3870. p_env = priv->p_env;
  3871. if (count > MAX_NAME_LEN+1)
  3872. return -EINVAL;
  3873. memset(p_env->host_name, 0x20, MAX_NAME_LEN);
  3874. strncpy(p_env->host_name,buf, count);
  3875. p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
  3876. p_env->host_name[MAX_NAME_LEN] = 0x00;
  3877. CLAW_DBF_TEXT(2,setup,"HstnSet");
  3878. CLAW_DBF_TEXT_(2,setup,"%s",p_env->host_name);
  3879. return count;
  3880. }
  3881. static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
  3882. static ssize_t
  3883. claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
  3884. {
  3885. struct claw_privbk *priv;
  3886. struct claw_env * p_env;
  3887. priv = dev->driver_data;
  3888. if (!priv)
  3889. return -ENODEV;
  3890. p_env = priv->p_env;
  3891. return sprintf(buf, "%s\n",p_env->adapter_name);
  3892. }
  3893. static ssize_t
  3894. claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  3895. {
  3896. struct claw_privbk *priv;
  3897. struct claw_env * p_env;
  3898. priv = dev->driver_data;
  3899. if (!priv)
  3900. return -ENODEV;
  3901. p_env = priv->p_env;
  3902. if (count > MAX_NAME_LEN+1)
  3903. return -EINVAL;
  3904. memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
  3905. strncpy(p_env->adapter_name,buf, count);
  3906. p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
  3907. p_env->adapter_name[MAX_NAME_LEN] = 0x00;
  3908. CLAW_DBF_TEXT(2,setup,"AdnSet");
  3909. CLAW_DBF_TEXT_(2,setup,"%s",p_env->adapter_name);
  3910. return count;
  3911. }
  3912. static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
  3913. static ssize_t
  3914. claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
  3915. {
  3916. struct claw_privbk *priv;
  3917. struct claw_env * p_env;
  3918. priv = dev->driver_data;
  3919. if (!priv)
  3920. return -ENODEV;
  3921. p_env = priv->p_env;
  3922. return sprintf(buf, "%s\n",
  3923. p_env->api_type);
  3924. }
  3925. static ssize_t
  3926. claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  3927. {
  3928. struct claw_privbk *priv;
  3929. struct claw_env * p_env;
  3930. priv = dev->driver_data;
  3931. if (!priv)
  3932. return -ENODEV;
  3933. p_env = priv->p_env;
  3934. if (count > MAX_NAME_LEN+1)
  3935. return -EINVAL;
  3936. memset(p_env->api_type, 0x20, MAX_NAME_LEN);
  3937. strncpy(p_env->api_type,buf, count);
  3938. p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
  3939. p_env->api_type[MAX_NAME_LEN] = 0x00;
  3940. if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  3941. p_env->read_size=DEF_PACK_BUFSIZE;
  3942. p_env->write_size=DEF_PACK_BUFSIZE;
  3943. p_env->packing=PACKING_ASK;
  3944. CLAW_DBF_TEXT(2,setup,"PACKING");
  3945. }
  3946. else {
  3947. p_env->packing=0;
  3948. p_env->read_size=CLAW_FRAME_SIZE;
  3949. p_env->write_size=CLAW_FRAME_SIZE;
  3950. CLAW_DBF_TEXT(2,setup,"ApiSet");
  3951. }
  3952. CLAW_DBF_TEXT_(2,setup,"%s",p_env->api_type);
  3953. return count;
  3954. }
  3955. static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
  3956. static ssize_t
  3957. claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  3958. {
  3959. struct claw_privbk *priv;
  3960. struct claw_env * p_env;
  3961. priv = dev->driver_data;
  3962. if (!priv)
  3963. return -ENODEV;
  3964. p_env = priv->p_env;
  3965. return sprintf(buf, "%d\n", p_env->write_buffers);
  3966. }
  3967. static ssize_t
  3968. claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  3969. {
  3970. struct claw_privbk *priv;
  3971. struct claw_env * p_env;
  3972. int nnn,max;
  3973. priv = dev->driver_data;
  3974. if (!priv)
  3975. return -ENODEV;
  3976. p_env = priv->p_env;
  3977. sscanf(buf, "%i", &nnn);
  3978. if (p_env->packing) {
  3979. max = 64;
  3980. }
  3981. else {
  3982. max = 512;
  3983. }
  3984. if ((nnn > max ) || (nnn < 2))
  3985. return -EINVAL;
  3986. p_env->write_buffers = nnn;
  3987. CLAW_DBF_TEXT(2,setup,"Wbufset");
  3988. CLAW_DBF_TEXT_(2,setup,"WB=%d",p_env->write_buffers);
  3989. return count;
  3990. }
  3991. static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
  3992. static ssize_t
  3993. claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  3994. {
  3995. struct claw_privbk *priv;
  3996. struct claw_env * p_env;
  3997. priv = dev->driver_data;
  3998. if (!priv)
  3999. return -ENODEV;
  4000. p_env = priv->p_env;
  4001. return sprintf(buf, "%d\n", p_env->read_buffers);
  4002. }
  4003. static ssize_t
  4004. claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  4005. {
  4006. struct claw_privbk *priv;
  4007. struct claw_env *p_env;
  4008. int nnn,max;
  4009. priv = dev->driver_data;
  4010. if (!priv)
  4011. return -ENODEV;
  4012. p_env = priv->p_env;
  4013. sscanf(buf, "%i", &nnn);
  4014. if (p_env->packing) {
  4015. max = 64;
  4016. }
  4017. else {
  4018. max = 512;
  4019. }
  4020. if ((nnn > max ) || (nnn < 2))
  4021. return -EINVAL;
  4022. p_env->read_buffers = nnn;
  4023. CLAW_DBF_TEXT(2,setup,"Rbufset");
  4024. CLAW_DBF_TEXT_(2,setup,"RB=%d",p_env->read_buffers);
  4025. return count;
  4026. }
  4027. static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
  4028. static struct attribute *claw_attr[] = {
  4029. &dev_attr_read_buffer.attr,
  4030. &dev_attr_write_buffer.attr,
  4031. &dev_attr_adapter_name.attr,
  4032. &dev_attr_api_type.attr,
  4033. &dev_attr_host_name.attr,
  4034. NULL,
  4035. };
  4036. static struct attribute_group claw_attr_group = {
  4037. .attrs = claw_attr,
  4038. };
  4039. static int
  4040. claw_add_files(struct device *dev)
  4041. {
  4042. pr_debug("%s() called\n", __FUNCTION__);
  4043. CLAW_DBF_TEXT(2,setup,"add_file");
  4044. return sysfs_create_group(&dev->kobj, &claw_attr_group);
  4045. }
  4046. static void
  4047. claw_remove_files(struct device *dev)
  4048. {
  4049. pr_debug("%s() called\n", __FUNCTION__);
  4050. CLAW_DBF_TEXT(2,setup,"rem_file");
  4051. sysfs_remove_group(&dev->kobj, &claw_attr_group);
  4052. }
  4053. /*--------------------------------------------------------------------*
  4054. * claw_init and cleanup *
  4055. *---------------------------------------------------------------------*/
  4056. static void __exit
  4057. claw_cleanup(void)
  4058. {
  4059. unregister_cu3088_discipline(&claw_group_driver);
  4060. claw_unregister_debug_facility();
  4061. printk(KERN_INFO "claw: Driver unloaded\n");
  4062. }
  4063. /**
  4064. * Initialize module.
  4065. * This is called just after the module is loaded.
  4066. *
  4067. * @return 0 on success, !0 on error.
  4068. */
  4069. static int __init
  4070. claw_init(void)
  4071. {
  4072. int ret = 0;
  4073. printk(KERN_INFO "claw: starting driver\n");
  4074. #ifdef FUNCTRACE
  4075. printk(KERN_INFO "claw: %s() enter \n",__FUNCTION__);
  4076. #endif
  4077. ret = claw_register_debug_facility();
  4078. if (ret) {
  4079. printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
  4080. __FUNCTION__,ret);
  4081. return ret;
  4082. }
  4083. CLAW_DBF_TEXT(2,setup,"init_mod");
  4084. ret = register_cu3088_discipline(&claw_group_driver);
  4085. if (ret) {
  4086. claw_unregister_debug_facility();
  4087. printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
  4088. __FUNCTION__,ret);
  4089. }
  4090. #ifdef FUNCTRACE
  4091. printk(KERN_INFO "claw: %s() exit \n",__FUNCTION__);
  4092. #endif
  4093. return ret;
  4094. }
  4095. module_init(claw_init);
  4096. module_exit(claw_cleanup);
  4097. /*--------------------------------------------------------------------*
  4098. * End of File *
  4099. *---------------------------------------------------------------------*/