claw.c 154 KB

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