claw.c 154 KB

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