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