claw.c 153 KB

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