claw.c 154 KB

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