claw.c 154 KB

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