claw.c 152 KB

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