claw.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330
  1. /*
  2. * drivers/s390/net/claw.c
  3. * ESCON CLAW network driver
  4. *
  5. * Linux for zSeries version
  6. * Copyright (C) 2002,2005 IBM Corporation
  7. * Author(s) Original code written by:
  8. * Kazuo Iimura (iimura@jp.ibm.com)
  9. * Rewritten by
  10. * Andy Richter (richtera@us.ibm.com)
  11. * Marc Price (mwprice@us.ibm.com)
  12. *
  13. * sysfs parms:
  14. * group x.x.rrrr,x.x.wwww
  15. * read_buffer nnnnnnn
  16. * write_buffer nnnnnn
  17. * host_name aaaaaaaa
  18. * adapter_name aaaaaaaa
  19. * api_type aaaaaaaa
  20. *
  21. * eg.
  22. * group 0.0.0200 0.0.0201
  23. * read_buffer 25
  24. * write_buffer 20
  25. * host_name LINUX390
  26. * adapter_name RS6K
  27. * api_type TCPIP
  28. *
  29. * where
  30. *
  31. * The device id is decided by the order entries
  32. * are added to the group the first is claw0 the second claw1
  33. * up to CLAW_MAX_DEV
  34. *
  35. * rrrr - the first of 2 consecutive device addresses used for the
  36. * CLAW protocol.
  37. * The specified address is always used as the input (Read)
  38. * channel and the next address is used as the output channel.
  39. *
  40. * wwww - the second of 2 consecutive device addresses used for
  41. * the CLAW protocol.
  42. * The specified address is always used as the output
  43. * channel and the previous address is used as the input channel.
  44. *
  45. * read_buffer - specifies number of input buffers to allocate.
  46. * write_buffer - specifies number of output buffers to allocate.
  47. * host_name - host name
  48. * adaptor_name - adaptor name
  49. * api_type - API type TCPIP or API will be sent and expected
  50. * as ws_name
  51. *
  52. * Note the following requirements:
  53. * 1) host_name must match the configured adapter_name on the remote side
  54. * 2) adaptor_name must match the configured host name on the remote side
  55. *
  56. * Change History
  57. * 1.00 Initial release shipped
  58. * 1.10 Changes for Buffer allocation
  59. * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
  60. * 1.25 Added Packing support
  61. * 1.5
  62. */
  63. #include <asm/ccwdev.h>
  64. #include <asm/ccwgroup.h>
  65. #include <asm/debug.h>
  66. #include <asm/idals.h>
  67. #include <asm/io.h>
  68. #include <linux/bitops.h>
  69. #include <linux/ctype.h>
  70. #include <linux/delay.h>
  71. #include <linux/errno.h>
  72. #include <linux/if_arp.h>
  73. #include <linux/init.h>
  74. #include <linux/interrupt.h>
  75. #include <linux/ip.h>
  76. #include <linux/kernel.h>
  77. #include <linux/module.h>
  78. #include <linux/netdevice.h>
  79. #include <linux/etherdevice.h>
  80. #include <linux/proc_fs.h>
  81. #include <linux/sched.h>
  82. #include <linux/signal.h>
  83. #include <linux/skbuff.h>
  84. #include <linux/slab.h>
  85. #include <linux/string.h>
  86. #include <linux/tcp.h>
  87. #include <linux/timer.h>
  88. #include <linux/types.h>
  89. #include "cu3088.h"
  90. #include "claw.h"
  91. /*
  92. CLAW uses the s390dbf file system see claw_trace and claw_setup
  93. */
  94. static char debug_buffer[255];
  95. /**
  96. * Debug Facility Stuff
  97. */
  98. static debug_info_t *claw_dbf_setup;
  99. static debug_info_t *claw_dbf_trace;
  100. /**
  101. * CLAW Debug Facility functions
  102. */
  103. static void
  104. claw_unregister_debug_facility(void)
  105. {
  106. if (claw_dbf_setup)
  107. debug_unregister(claw_dbf_setup);
  108. if (claw_dbf_trace)
  109. debug_unregister(claw_dbf_trace);
  110. }
  111. static int
  112. claw_register_debug_facility(void)
  113. {
  114. claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
  115. claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
  116. if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
  117. claw_unregister_debug_facility();
  118. return -ENOMEM;
  119. }
  120. debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
  121. debug_set_level(claw_dbf_setup, 2);
  122. debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
  123. debug_set_level(claw_dbf_trace, 2);
  124. return 0;
  125. }
  126. static inline void
  127. claw_set_busy(struct net_device *dev)
  128. {
  129. ((struct claw_privbk *) dev->priv)->tbusy=1;
  130. eieio();
  131. }
  132. static inline void
  133. claw_clear_busy(struct net_device *dev)
  134. {
  135. clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
  136. netif_wake_queue(dev);
  137. eieio();
  138. }
  139. static inline int
  140. claw_check_busy(struct net_device *dev)
  141. {
  142. eieio();
  143. return ((struct claw_privbk *) dev->priv)->tbusy;
  144. }
  145. static inline void
  146. claw_setbit_busy(int nr,struct net_device *dev)
  147. {
  148. netif_stop_queue(dev);
  149. set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
  150. }
  151. static inline void
  152. claw_clearbit_busy(int nr,struct net_device *dev)
  153. {
  154. clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
  155. netif_wake_queue(dev);
  156. }
  157. static inline int
  158. claw_test_and_setbit_busy(int nr,struct net_device *dev)
  159. {
  160. netif_stop_queue(dev);
  161. return test_and_set_bit(nr,
  162. (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
  163. }
  164. /* Functions for the DEV methods */
  165. static int claw_probe(struct ccwgroup_device *cgdev);
  166. static void claw_remove_device(struct ccwgroup_device *cgdev);
  167. static void claw_purge_skb_queue(struct sk_buff_head *q);
  168. static int claw_new_device(struct ccwgroup_device *cgdev);
  169. static int claw_shutdown_device(struct ccwgroup_device *cgdev);
  170. static int claw_tx(struct sk_buff *skb, struct net_device *dev);
  171. static int claw_change_mtu( struct net_device *dev, int new_mtu);
  172. static int claw_open(struct net_device *dev);
  173. static void claw_irq_handler(struct ccw_device *cdev,
  174. unsigned long intparm, struct irb *irb);
  175. static void claw_irq_tasklet ( unsigned long data );
  176. static int claw_release(struct net_device *dev);
  177. static void claw_write_retry ( struct chbk * p_ch );
  178. static void claw_write_next ( struct chbk * p_ch );
  179. static void claw_timer ( struct chbk * p_ch );
  180. /* Functions */
  181. static int add_claw_reads(struct net_device *dev,
  182. struct ccwbk* p_first, struct ccwbk* p_last);
  183. static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
  184. static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
  185. static int find_link(struct net_device *dev, char *host_name, char *ws_name );
  186. static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
  187. static int init_ccw_bk(struct net_device *dev);
  188. static void probe_error( struct ccwgroup_device *cgdev);
  189. static struct net_device_stats *claw_stats(struct net_device *dev);
  190. static int pages_to_order_of_mag(int num_of_pages);
  191. static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
  192. /* sysfs Functions */
  193. static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
  194. static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
  195. const char *buf, size_t count);
  196. static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
  197. static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
  198. const char *buf, size_t count);
  199. static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
  200. static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
  201. const char *buf, size_t count);
  202. static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  203. static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
  204. const char *buf, size_t count);
  205. static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  206. static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
  207. const char *buf, size_t count);
  208. static int claw_add_files(struct device *dev);
  209. static void claw_remove_files(struct device *dev);
  210. /* Functions for System Validate */
  211. static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
  212. static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  213. __u8 correlator, __u8 rc , char *local_name, char *remote_name);
  214. static int claw_snd_conn_req(struct net_device *dev, __u8 link);
  215. static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
  216. static int claw_snd_sys_validate_rsp(struct net_device *dev,
  217. struct clawctl * p_ctl, __u32 return_code);
  218. static int claw_strt_conn_req(struct net_device *dev );
  219. static void claw_strt_read(struct net_device *dev, int lock);
  220. static void claw_strt_out_IO(struct net_device *dev);
  221. static void claw_free_wrt_buf(struct net_device *dev);
  222. /* Functions for unpack reads */
  223. static void unpack_read(struct net_device *dev);
  224. /* ccwgroup table */
  225. static struct ccwgroup_driver claw_group_driver = {
  226. .owner = THIS_MODULE,
  227. .name = "claw",
  228. .max_slaves = 2,
  229. .driver_id = 0xC3D3C1E6,
  230. .probe = claw_probe,
  231. .remove = claw_remove_device,
  232. .set_online = claw_new_device,
  233. .set_offline = claw_shutdown_device,
  234. };
  235. /*
  236. * Key functions
  237. */
  238. /*----------------------------------------------------------------*
  239. * claw_probe *
  240. * this function is called for each CLAW device. *
  241. *----------------------------------------------------------------*/
  242. static int
  243. claw_probe(struct ccwgroup_device *cgdev)
  244. {
  245. int rc;
  246. struct claw_privbk *privptr=NULL;
  247. CLAW_DBF_TEXT(2, setup, "probe");
  248. if (!get_device(&cgdev->dev))
  249. return -ENODEV;
  250. privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
  251. if (privptr == NULL) {
  252. probe_error(cgdev);
  253. put_device(&cgdev->dev);
  254. CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
  255. return -ENOMEM;
  256. }
  257. privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
  258. privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
  259. if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
  260. probe_error(cgdev);
  261. put_device(&cgdev->dev);
  262. CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
  263. return -ENOMEM;
  264. }
  265. memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
  266. memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
  267. memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
  268. privptr->p_env->packing = 0;
  269. privptr->p_env->write_buffers = 5;
  270. privptr->p_env->read_buffers = 5;
  271. privptr->p_env->read_size = CLAW_FRAME_SIZE;
  272. privptr->p_env->write_size = CLAW_FRAME_SIZE;
  273. rc = claw_add_files(&cgdev->dev);
  274. if (rc) {
  275. probe_error(cgdev);
  276. put_device(&cgdev->dev);
  277. printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
  278. cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
  279. CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
  280. return rc;
  281. }
  282. privptr->p_env->p_priv = privptr;
  283. cgdev->cdev[0]->handler = claw_irq_handler;
  284. cgdev->cdev[1]->handler = claw_irq_handler;
  285. cgdev->dev.driver_data = privptr;
  286. CLAW_DBF_TEXT(2, setup, "prbext 0");
  287. return 0;
  288. } /* end of claw_probe */
  289. /*-------------------------------------------------------------------*
  290. * claw_tx *
  291. *-------------------------------------------------------------------*/
  292. static int
  293. claw_tx(struct sk_buff *skb, struct net_device *dev)
  294. {
  295. int rc;
  296. struct claw_privbk *privptr=dev->priv;
  297. unsigned long saveflags;
  298. struct chbk *p_ch;
  299. CLAW_DBF_TEXT(4, trace, "claw_tx");
  300. p_ch=&privptr->channel[WRITE];
  301. if (skb == NULL) {
  302. privptr->stats.tx_dropped++;
  303. privptr->stats.tx_errors++;
  304. CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO);
  305. return -EIO;
  306. }
  307. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  308. rc=claw_hw_tx( skb, dev, 1 );
  309. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  310. CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
  311. return rc;
  312. } /* end of claw_tx */
  313. /*------------------------------------------------------------------*
  314. * pack the collect queue into an skb and return it *
  315. * If not packing just return the top skb from the queue *
  316. *------------------------------------------------------------------*/
  317. static struct sk_buff *
  318. claw_pack_skb(struct claw_privbk *privptr)
  319. {
  320. struct sk_buff *new_skb,*held_skb;
  321. struct chbk *p_ch = &privptr->channel[WRITE];
  322. struct claw_env *p_env = privptr->p_env;
  323. int pkt_cnt,pk_ind,so_far;
  324. new_skb = NULL; /* assume no dice */
  325. pkt_cnt = 0;
  326. CLAW_DBF_TEXT(4, trace, "PackSKBe");
  327. if (!skb_queue_empty(&p_ch->collect_queue)) {
  328. /* some data */
  329. held_skb = skb_dequeue(&p_ch->collect_queue);
  330. if (held_skb)
  331. dev_kfree_skb_any(held_skb);
  332. else
  333. return NULL;
  334. if (p_env->packing != DO_PACKED)
  335. return held_skb;
  336. /* get a new SKB we will pack at least one */
  337. new_skb = dev_alloc_skb(p_env->write_size);
  338. if (new_skb == NULL) {
  339. atomic_inc(&held_skb->users);
  340. skb_queue_head(&p_ch->collect_queue,held_skb);
  341. return NULL;
  342. }
  343. /* we have packed packet and a place to put it */
  344. pk_ind = 1;
  345. so_far = 0;
  346. new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
  347. while ((pk_ind) && (held_skb != NULL)) {
  348. if (held_skb->len+so_far <= p_env->write_size-8) {
  349. memcpy(skb_put(new_skb,held_skb->len),
  350. held_skb->data,held_skb->len);
  351. privptr->stats.tx_packets++;
  352. so_far += held_skb->len;
  353. pkt_cnt++;
  354. dev_kfree_skb_any(held_skb);
  355. held_skb = skb_dequeue(&p_ch->collect_queue);
  356. if (held_skb)
  357. atomic_dec(&held_skb->users);
  358. } else {
  359. pk_ind = 0;
  360. atomic_inc(&held_skb->users);
  361. skb_queue_head(&p_ch->collect_queue,held_skb);
  362. }
  363. }
  364. }
  365. CLAW_DBF_TEXT(4, trace, "PackSKBx");
  366. return new_skb;
  367. }
  368. /*-------------------------------------------------------------------*
  369. * claw_change_mtu *
  370. * *
  371. *-------------------------------------------------------------------*/
  372. static int
  373. claw_change_mtu(struct net_device *dev, int new_mtu)
  374. {
  375. struct claw_privbk *privptr=dev->priv;
  376. int buff_size;
  377. CLAW_DBF_TEXT(4, trace, "setmtu");
  378. buff_size = privptr->p_env->write_size;
  379. if ((new_mtu < 60) || (new_mtu > buff_size)) {
  380. return -EINVAL;
  381. }
  382. dev->mtu = new_mtu;
  383. return 0;
  384. } /* end of claw_change_mtu */
  385. /*-------------------------------------------------------------------*
  386. * claw_open *
  387. * *
  388. *-------------------------------------------------------------------*/
  389. static int
  390. claw_open(struct net_device *dev)
  391. {
  392. int rc;
  393. int i;
  394. unsigned long saveflags=0;
  395. unsigned long parm;
  396. struct claw_privbk *privptr;
  397. DECLARE_WAITQUEUE(wait, current);
  398. struct timer_list timer;
  399. struct ccwbk *p_buf;
  400. CLAW_DBF_TEXT(4, trace, "open");
  401. privptr = (struct claw_privbk *)dev->priv;
  402. /* allocate and initialize CCW blocks */
  403. if (privptr->buffs_alloc == 0) {
  404. rc=init_ccw_bk(dev);
  405. if (rc) {
  406. CLAW_DBF_TEXT(2, trace, "openmem");
  407. return -ENOMEM;
  408. }
  409. }
  410. privptr->system_validate_comp=0;
  411. privptr->release_pend=0;
  412. if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  413. privptr->p_env->read_size=DEF_PACK_BUFSIZE;
  414. privptr->p_env->write_size=DEF_PACK_BUFSIZE;
  415. privptr->p_env->packing=PACKING_ASK;
  416. } else {
  417. privptr->p_env->packing=0;
  418. privptr->p_env->read_size=CLAW_FRAME_SIZE;
  419. privptr->p_env->write_size=CLAW_FRAME_SIZE;
  420. }
  421. claw_set_busy(dev);
  422. tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
  423. (unsigned long) &privptr->channel[READ]);
  424. for ( i = 0; i < 2; i++) {
  425. CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
  426. init_waitqueue_head(&privptr->channel[i].wait);
  427. /* skb_queue_head_init(&p_ch->io_queue); */
  428. if (i == WRITE)
  429. skb_queue_head_init(
  430. &privptr->channel[WRITE].collect_queue);
  431. privptr->channel[i].flag_a = 0;
  432. privptr->channel[i].IO_active = 0;
  433. privptr->channel[i].flag &= ~CLAW_TIMER;
  434. init_timer(&timer);
  435. timer.function = (void *)claw_timer;
  436. timer.data = (unsigned long)(&privptr->channel[i]);
  437. timer.expires = jiffies + 15*HZ;
  438. add_timer(&timer);
  439. spin_lock_irqsave(get_ccwdev_lock(
  440. privptr->channel[i].cdev), saveflags);
  441. parm = (unsigned long) &privptr->channel[i];
  442. privptr->channel[i].claw_state = CLAW_START_HALT_IO;
  443. rc = 0;
  444. add_wait_queue(&privptr->channel[i].wait, &wait);
  445. rc = ccw_device_halt(
  446. (struct ccw_device *)privptr->channel[i].cdev,parm);
  447. set_current_state(TASK_INTERRUPTIBLE);
  448. spin_unlock_irqrestore(
  449. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  450. schedule();
  451. set_current_state(TASK_RUNNING);
  452. remove_wait_queue(&privptr->channel[i].wait, &wait);
  453. if(rc != 0)
  454. ccw_check_return_code(privptr->channel[i].cdev, rc);
  455. if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
  456. del_timer(&timer);
  457. }
  458. if ((((privptr->channel[READ].last_dstat |
  459. privptr->channel[WRITE].last_dstat) &
  460. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
  461. (((privptr->channel[READ].flag |
  462. privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
  463. printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
  464. CLAW_DBF_TEXT(2, trace, "notrdy");
  465. for ( i = 0; i < 2; i++) {
  466. spin_lock_irqsave(
  467. get_ccwdev_lock(privptr->channel[i].cdev),
  468. saveflags);
  469. parm = (unsigned long) &privptr->channel[i];
  470. privptr->channel[i].claw_state = CLAW_STOP;
  471. rc = ccw_device_halt(
  472. (struct ccw_device *)&privptr->channel[i].cdev,
  473. parm);
  474. spin_unlock_irqrestore(
  475. get_ccwdev_lock(privptr->channel[i].cdev),
  476. saveflags);
  477. if (rc != 0) {
  478. ccw_check_return_code(
  479. privptr->channel[i].cdev, rc);
  480. }
  481. }
  482. free_pages((unsigned long)privptr->p_buff_ccw,
  483. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  484. if (privptr->p_env->read_size < PAGE_SIZE) {
  485. free_pages((unsigned long)privptr->p_buff_read,
  486. (int)pages_to_order_of_mag(
  487. privptr->p_buff_read_num));
  488. }
  489. else {
  490. p_buf=privptr->p_read_active_first;
  491. while (p_buf!=NULL) {
  492. free_pages((unsigned long)p_buf->p_buffer,
  493. (int)pages_to_order_of_mag(
  494. privptr->p_buff_pages_perread ));
  495. p_buf=p_buf->next;
  496. }
  497. }
  498. if (privptr->p_env->write_size < PAGE_SIZE ) {
  499. free_pages((unsigned long)privptr->p_buff_write,
  500. (int)pages_to_order_of_mag(
  501. privptr->p_buff_write_num));
  502. }
  503. else {
  504. p_buf=privptr->p_write_active_first;
  505. while (p_buf!=NULL) {
  506. free_pages((unsigned long)p_buf->p_buffer,
  507. (int)pages_to_order_of_mag(
  508. privptr->p_buff_pages_perwrite ));
  509. p_buf=p_buf->next;
  510. }
  511. }
  512. privptr->buffs_alloc = 0;
  513. privptr->channel[READ].flag= 0x00;
  514. privptr->channel[WRITE].flag = 0x00;
  515. privptr->p_buff_ccw=NULL;
  516. privptr->p_buff_read=NULL;
  517. privptr->p_buff_write=NULL;
  518. claw_clear_busy(dev);
  519. CLAW_DBF_TEXT(2, trace, "open EIO");
  520. return -EIO;
  521. }
  522. /* Send SystemValidate command */
  523. claw_clear_busy(dev);
  524. CLAW_DBF_TEXT(4, trace, "openok");
  525. return 0;
  526. } /* end of claw_open */
  527. /*-------------------------------------------------------------------*
  528. * *
  529. * claw_irq_handler *
  530. * *
  531. *--------------------------------------------------------------------*/
  532. static void
  533. claw_irq_handler(struct ccw_device *cdev,
  534. unsigned long intparm, struct irb *irb)
  535. {
  536. struct chbk *p_ch = NULL;
  537. struct claw_privbk *privptr = NULL;
  538. struct net_device *dev = NULL;
  539. struct claw_env *p_env;
  540. struct chbk *p_ch_r=NULL;
  541. CLAW_DBF_TEXT(4, trace, "clawirq");
  542. /* Bypass all 'unsolicited interrupts' */
  543. if (!cdev->dev.driver_data) {
  544. printk(KERN_WARNING "claw: unsolicited interrupt for device:"
  545. "%s received c-%02x d-%02x\n",
  546. cdev->dev.bus_id, irb->scsw.cmd.cstat,
  547. irb->scsw.cmd.dstat);
  548. CLAW_DBF_TEXT(2, trace, "badirq");
  549. return;
  550. }
  551. privptr = (struct claw_privbk *)cdev->dev.driver_data;
  552. /* Try to extract channel from driver data. */
  553. if (privptr->channel[READ].cdev == cdev)
  554. p_ch = &privptr->channel[READ];
  555. else if (privptr->channel[WRITE].cdev == cdev)
  556. p_ch = &privptr->channel[WRITE];
  557. else {
  558. printk(KERN_WARNING "claw: Can't determine channel for "
  559. "interrupt, device %s\n", cdev->dev.bus_id);
  560. CLAW_DBF_TEXT(2, trace, "badchan");
  561. return;
  562. }
  563. CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
  564. dev = (struct net_device *) (p_ch->ndev);
  565. p_env=privptr->p_env;
  566. /* Copy interruption response block. */
  567. memcpy(p_ch->irb, irb, sizeof(struct irb));
  568. /* Check for good subchannel return code, otherwise info message */
  569. if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
  570. printk(KERN_INFO "%s: subchannel check for device: %04x -"
  571. " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
  572. dev->name, p_ch->devno,
  573. irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
  574. irb->scsw.cmd.cpa);
  575. CLAW_DBF_TEXT(2, trace, "chanchk");
  576. /* return; */
  577. }
  578. /* Check the reason-code of a unit check */
  579. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
  580. ccw_check_unit_check(p_ch, irb->ecw[0]);
  581. /* State machine to bring the connection up, down and to restart */
  582. p_ch->last_dstat = irb->scsw.cmd.dstat;
  583. switch (p_ch->claw_state) {
  584. case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
  585. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  586. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  587. (p_ch->irb->scsw.cmd.stctl ==
  588. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
  589. return;
  590. wake_up(&p_ch->wait); /* wake up claw_release */
  591. CLAW_DBF_TEXT(4, trace, "stop");
  592. return;
  593. case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
  594. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  595. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  596. (p_ch->irb->scsw.cmd.stctl ==
  597. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  598. CLAW_DBF_TEXT(4, trace, "haltio");
  599. return;
  600. }
  601. if (p_ch->flag == CLAW_READ) {
  602. p_ch->claw_state = CLAW_START_READ;
  603. wake_up(&p_ch->wait); /* wake claw_open (READ)*/
  604. } else if (p_ch->flag == CLAW_WRITE) {
  605. p_ch->claw_state = CLAW_START_WRITE;
  606. /* send SYSTEM_VALIDATE */
  607. claw_strt_read(dev, LOCK_NO);
  608. claw_send_control(dev,
  609. SYSTEM_VALIDATE_REQUEST,
  610. 0, 0, 0,
  611. p_env->host_name,
  612. p_env->adapter_name);
  613. } else {
  614. printk(KERN_WARNING "claw: unsolicited "
  615. "interrupt for device:"
  616. "%s received c-%02x d-%02x\n",
  617. cdev->dev.bus_id,
  618. irb->scsw.cmd.cstat,
  619. irb->scsw.cmd.dstat);
  620. return;
  621. }
  622. CLAW_DBF_TEXT(4, trace, "haltio");
  623. return;
  624. case CLAW_START_READ:
  625. CLAW_DBF_TEXT(4, trace, "ReadIRQ");
  626. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  627. clear_bit(0, (void *)&p_ch->IO_active);
  628. if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
  629. (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
  630. (p_ch->irb->ecw[0]) == 0) {
  631. privptr->stats.rx_errors++;
  632. printk(KERN_INFO "%s: Restart is "
  633. "required after remote "
  634. "side recovers \n",
  635. dev->name);
  636. }
  637. CLAW_DBF_TEXT(4, trace, "notrdy");
  638. return;
  639. }
  640. if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
  641. (p_ch->irb->scsw.cmd.dstat == 0)) {
  642. if (test_and_set_bit(CLAW_BH_ACTIVE,
  643. (void *)&p_ch->flag_a) == 0)
  644. tasklet_schedule(&p_ch->tasklet);
  645. else
  646. CLAW_DBF_TEXT(4, trace, "PCINoBH");
  647. CLAW_DBF_TEXT(4, trace, "PCI_read");
  648. return;
  649. }
  650. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  651. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  652. (p_ch->irb->scsw.cmd.stctl ==
  653. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  654. CLAW_DBF_TEXT(4, trace, "SPend_rd");
  655. return;
  656. }
  657. clear_bit(0, (void *)&p_ch->IO_active);
  658. claw_clearbit_busy(TB_RETRY, dev);
  659. if (test_and_set_bit(CLAW_BH_ACTIVE,
  660. (void *)&p_ch->flag_a) == 0)
  661. tasklet_schedule(&p_ch->tasklet);
  662. else
  663. CLAW_DBF_TEXT(4, trace, "RdBHAct");
  664. CLAW_DBF_TEXT(4, trace, "RdIRQXit");
  665. return;
  666. case CLAW_START_WRITE:
  667. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  668. printk(KERN_INFO "%s: Unit Check Occured in "
  669. "write channel\n", dev->name);
  670. clear_bit(0, (void *)&p_ch->IO_active);
  671. if (p_ch->irb->ecw[0] & 0x80) {
  672. printk(KERN_INFO "%s: Resetting Event "
  673. "occurred:\n", dev->name);
  674. init_timer(&p_ch->timer);
  675. p_ch->timer.function =
  676. (void *)claw_write_retry;
  677. p_ch->timer.data = (unsigned long)p_ch;
  678. p_ch->timer.expires = jiffies + 10*HZ;
  679. add_timer(&p_ch->timer);
  680. printk(KERN_INFO "%s: write connection "
  681. "restarting\n", dev->name);
  682. }
  683. CLAW_DBF_TEXT(4, trace, "rstrtwrt");
  684. return;
  685. }
  686. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
  687. clear_bit(0, (void *)&p_ch->IO_active);
  688. printk(KERN_INFO "%s: Unit Exception "
  689. "Occured in write channel\n",
  690. dev->name);
  691. }
  692. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  693. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  694. (p_ch->irb->scsw.cmd.stctl ==
  695. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  696. CLAW_DBF_TEXT(4, trace, "writeUE");
  697. return;
  698. }
  699. clear_bit(0, (void *)&p_ch->IO_active);
  700. if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
  701. claw_write_next(p_ch);
  702. claw_clearbit_busy(TB_TX, dev);
  703. claw_clear_busy(dev);
  704. }
  705. p_ch_r = (struct chbk *)&privptr->channel[READ];
  706. if (test_and_set_bit(CLAW_BH_ACTIVE,
  707. (void *)&p_ch_r->flag_a) == 0)
  708. tasklet_schedule(&p_ch_r->tasklet);
  709. CLAW_DBF_TEXT(4, trace, "StWtExit");
  710. return;
  711. default:
  712. printk(KERN_WARNING "%s: wrong selection code - irq "
  713. "state=%d\n", dev->name, p_ch->claw_state);
  714. CLAW_DBF_TEXT(2, trace, "badIRQ");
  715. return;
  716. }
  717. } /* end of claw_irq_handler */
  718. /*-------------------------------------------------------------------*
  719. * claw_irq_tasklet *
  720. * *
  721. *--------------------------------------------------------------------*/
  722. static void
  723. claw_irq_tasklet ( unsigned long data )
  724. {
  725. struct chbk * p_ch;
  726. struct net_device *dev;
  727. struct claw_privbk * privptr;
  728. p_ch = (struct chbk *) data;
  729. dev = (struct net_device *)p_ch->ndev;
  730. CLAW_DBF_TEXT(4, trace, "IRQtask");
  731. privptr = (struct claw_privbk *) dev->priv;
  732. unpack_read(dev);
  733. clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
  734. CLAW_DBF_TEXT(4, trace, "TskletXt");
  735. return;
  736. } /* end of claw_irq_bh */
  737. /*-------------------------------------------------------------------*
  738. * claw_release *
  739. * *
  740. *--------------------------------------------------------------------*/
  741. static int
  742. claw_release(struct net_device *dev)
  743. {
  744. int rc;
  745. int i;
  746. unsigned long saveflags;
  747. unsigned long parm;
  748. struct claw_privbk *privptr;
  749. DECLARE_WAITQUEUE(wait, current);
  750. struct ccwbk* p_this_ccw;
  751. struct ccwbk* p_buf;
  752. if (!dev)
  753. return 0;
  754. privptr = (struct claw_privbk *) dev->priv;
  755. if (!privptr)
  756. return 0;
  757. CLAW_DBF_TEXT(4, trace, "release");
  758. privptr->release_pend=1;
  759. claw_setbit_busy(TB_STOP,dev);
  760. for ( i = 1; i >=0 ; i--) {
  761. spin_lock_irqsave(
  762. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  763. /* del_timer(&privptr->channel[READ].timer); */
  764. privptr->channel[i].claw_state = CLAW_STOP;
  765. privptr->channel[i].IO_active = 0;
  766. parm = (unsigned long) &privptr->channel[i];
  767. if (i == WRITE)
  768. claw_purge_skb_queue(
  769. &privptr->channel[WRITE].collect_queue);
  770. rc = ccw_device_halt (privptr->channel[i].cdev, parm);
  771. if (privptr->system_validate_comp==0x00) /* never opened? */
  772. init_waitqueue_head(&privptr->channel[i].wait);
  773. add_wait_queue(&privptr->channel[i].wait, &wait);
  774. set_current_state(TASK_INTERRUPTIBLE);
  775. spin_unlock_irqrestore(
  776. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  777. schedule();
  778. set_current_state(TASK_RUNNING);
  779. remove_wait_queue(&privptr->channel[i].wait, &wait);
  780. if (rc != 0) {
  781. ccw_check_return_code(privptr->channel[i].cdev, rc);
  782. }
  783. }
  784. if (privptr->pk_skb != NULL) {
  785. dev_kfree_skb_any(privptr->pk_skb);
  786. privptr->pk_skb = NULL;
  787. }
  788. if(privptr->buffs_alloc != 1) {
  789. CLAW_DBF_TEXT(4, trace, "none2fre");
  790. return 0;
  791. }
  792. CLAW_DBF_TEXT(4, trace, "freebufs");
  793. if (privptr->p_buff_ccw != NULL) {
  794. free_pages((unsigned long)privptr->p_buff_ccw,
  795. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  796. }
  797. CLAW_DBF_TEXT(4, trace, "freeread");
  798. if (privptr->p_env->read_size < PAGE_SIZE) {
  799. if (privptr->p_buff_read != NULL) {
  800. free_pages((unsigned long)privptr->p_buff_read,
  801. (int)pages_to_order_of_mag(privptr->p_buff_read_num));
  802. }
  803. }
  804. else {
  805. p_buf=privptr->p_read_active_first;
  806. while (p_buf!=NULL) {
  807. free_pages((unsigned long)p_buf->p_buffer,
  808. (int)pages_to_order_of_mag(
  809. privptr->p_buff_pages_perread ));
  810. p_buf=p_buf->next;
  811. }
  812. }
  813. CLAW_DBF_TEXT(4, trace, "freewrit");
  814. if (privptr->p_env->write_size < PAGE_SIZE ) {
  815. free_pages((unsigned long)privptr->p_buff_write,
  816. (int)pages_to_order_of_mag(privptr->p_buff_write_num));
  817. }
  818. else {
  819. p_buf=privptr->p_write_active_first;
  820. while (p_buf!=NULL) {
  821. free_pages((unsigned long)p_buf->p_buffer,
  822. (int)pages_to_order_of_mag(
  823. privptr->p_buff_pages_perwrite ));
  824. p_buf=p_buf->next;
  825. }
  826. }
  827. CLAW_DBF_TEXT(4, trace, "clearptr");
  828. privptr->buffs_alloc = 0;
  829. privptr->p_buff_ccw=NULL;
  830. privptr->p_buff_read=NULL;
  831. privptr->p_buff_write=NULL;
  832. privptr->system_validate_comp=0;
  833. privptr->release_pend=0;
  834. /* Remove any writes that were pending and reset all reads */
  835. p_this_ccw=privptr->p_read_active_first;
  836. while (p_this_ccw!=NULL) {
  837. p_this_ccw->header.length=0xffff;
  838. p_this_ccw->header.opcode=0xff;
  839. p_this_ccw->header.flag=0x00;
  840. p_this_ccw=p_this_ccw->next;
  841. }
  842. while (privptr->p_write_active_first!=NULL) {
  843. p_this_ccw=privptr->p_write_active_first;
  844. p_this_ccw->header.flag=CLAW_PENDING;
  845. privptr->p_write_active_first=p_this_ccw->next;
  846. p_this_ccw->next=privptr->p_write_free_chain;
  847. privptr->p_write_free_chain=p_this_ccw;
  848. ++privptr->write_free_count;
  849. }
  850. privptr->p_write_active_last=NULL;
  851. privptr->mtc_logical_link = -1;
  852. privptr->mtc_skipping = 1;
  853. privptr->mtc_offset=0;
  854. if (((privptr->channel[READ].last_dstat |
  855. privptr->channel[WRITE].last_dstat) &
  856. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
  857. printk(KERN_WARNING "%s: channel problems during close - "
  858. "read: %02x - write: %02x\n",
  859. dev->name,
  860. privptr->channel[READ].last_dstat,
  861. privptr->channel[WRITE].last_dstat);
  862. CLAW_DBF_TEXT(2, trace, "badclose");
  863. }
  864. CLAW_DBF_TEXT(4, trace, "rlsexit");
  865. return 0;
  866. } /* end of claw_release */
  867. /*-------------------------------------------------------------------*
  868. * claw_write_retry *
  869. * *
  870. *--------------------------------------------------------------------*/
  871. static void
  872. claw_write_retry ( struct chbk *p_ch )
  873. {
  874. struct net_device *dev=p_ch->ndev;
  875. CLAW_DBF_TEXT(4, trace, "w_retry");
  876. if (p_ch->claw_state == CLAW_STOP) {
  877. return;
  878. }
  879. claw_strt_out_IO( dev );
  880. CLAW_DBF_TEXT(4, trace, "rtry_xit");
  881. return;
  882. } /* end of claw_write_retry */
  883. /*-------------------------------------------------------------------*
  884. * claw_write_next *
  885. * *
  886. *--------------------------------------------------------------------*/
  887. static void
  888. claw_write_next ( struct chbk * p_ch )
  889. {
  890. struct net_device *dev;
  891. struct claw_privbk *privptr=NULL;
  892. struct sk_buff *pk_skb;
  893. int rc;
  894. CLAW_DBF_TEXT(4, trace, "claw_wrt");
  895. if (p_ch->claw_state == CLAW_STOP)
  896. return;
  897. dev = (struct net_device *) p_ch->ndev;
  898. privptr = (struct claw_privbk *) dev->priv;
  899. claw_free_wrt_buf( dev );
  900. if ((privptr->write_free_count > 0) &&
  901. !skb_queue_empty(&p_ch->collect_queue)) {
  902. pk_skb = claw_pack_skb(privptr);
  903. while (pk_skb != NULL) {
  904. rc = claw_hw_tx( pk_skb, dev,1);
  905. if (privptr->write_free_count > 0) {
  906. pk_skb = claw_pack_skb(privptr);
  907. } else
  908. pk_skb = NULL;
  909. }
  910. }
  911. if (privptr->p_write_active_first!=NULL) {
  912. claw_strt_out_IO(dev);
  913. }
  914. return;
  915. } /* end of claw_write_next */
  916. /*-------------------------------------------------------------------*
  917. * *
  918. * claw_timer *
  919. *--------------------------------------------------------------------*/
  920. static void
  921. claw_timer ( struct chbk * p_ch )
  922. {
  923. CLAW_DBF_TEXT(4, trace, "timer");
  924. p_ch->flag |= CLAW_TIMER;
  925. wake_up(&p_ch->wait);
  926. return;
  927. } /* end of claw_timer */
  928. /*
  929. *
  930. * functions
  931. */
  932. /*-------------------------------------------------------------------*
  933. * *
  934. * pages_to_order_of_mag *
  935. * *
  936. * takes a number of pages from 1 to 512 and returns the *
  937. * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
  938. * of magnitude get_free_pages() has an upper order of 9 *
  939. *--------------------------------------------------------------------*/
  940. static int
  941. pages_to_order_of_mag(int num_of_pages)
  942. {
  943. int order_of_mag=1; /* assume 2 pages */
  944. int nump=2;
  945. CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
  946. if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
  947. /* 512 pages = 2Meg on 4k page systems */
  948. if (num_of_pages >= 512) {return 9; }
  949. /* we have two or more pages order is at least 1 */
  950. for (nump=2 ;nump <= 512;nump*=2) {
  951. if (num_of_pages <= nump)
  952. break;
  953. order_of_mag +=1;
  954. }
  955. if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
  956. CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
  957. return order_of_mag;
  958. }
  959. /*-------------------------------------------------------------------*
  960. * *
  961. * add_claw_reads *
  962. * *
  963. *--------------------------------------------------------------------*/
  964. static int
  965. add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
  966. struct ccwbk* p_last)
  967. {
  968. struct claw_privbk *privptr;
  969. struct ccw1 temp_ccw;
  970. struct endccw * p_end;
  971. CLAW_DBF_TEXT(4, trace, "addreads");
  972. privptr = dev->priv;
  973. p_end = privptr->p_end_ccw;
  974. /* first CCW and last CCW contains a new set of read channel programs
  975. * to apend the running channel programs
  976. */
  977. if ( p_first==NULL) {
  978. CLAW_DBF_TEXT(4, trace, "addexit");
  979. return 0;
  980. }
  981. /* set up ending CCW sequence for this segment */
  982. if (p_end->read1) {
  983. p_end->read1=0x00; /* second ending CCW is now active */
  984. /* reset ending CCWs and setup TIC CCWs */
  985. p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  986. p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  987. p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
  988. p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
  989. p_end->read2_nop2.cda=0;
  990. p_end->read2_nop2.count=1;
  991. }
  992. else {
  993. p_end->read1=0x01; /* first ending CCW is now active */
  994. /* reset ending CCWs and setup TIC CCWs */
  995. p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  996. p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  997. p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
  998. p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
  999. p_end->read1_nop2.cda=0;
  1000. p_end->read1_nop2.count=1;
  1001. }
  1002. if ( privptr-> p_read_active_first ==NULL ) {
  1003. privptr-> p_read_active_first= p_first; /* set new first */
  1004. privptr-> p_read_active_last = p_last; /* set new last */
  1005. }
  1006. else {
  1007. /* set up TIC ccw */
  1008. temp_ccw.cda= (__u32)__pa(&p_first->read);
  1009. temp_ccw.count=0;
  1010. temp_ccw.flags=0;
  1011. temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
  1012. if (p_end->read1) {
  1013. /* first set of CCW's is chained to the new read */
  1014. /* chain, so the second set is chained to the active chain. */
  1015. /* Therefore modify the second set to point to the new */
  1016. /* read chain set up TIC CCWs */
  1017. /* make sure we update the CCW so channel doesn't fetch it */
  1018. /* when it's only half done */
  1019. memcpy( &p_end->read2_nop2, &temp_ccw ,
  1020. sizeof(struct ccw1));
  1021. privptr->p_read_active_last->r_TIC_1.cda=
  1022. (__u32)__pa(&p_first->read);
  1023. privptr->p_read_active_last->r_TIC_2.cda=
  1024. (__u32)__pa(&p_first->read);
  1025. }
  1026. else {
  1027. /* make sure we update the CCW so channel doesn't */
  1028. /* fetch it when it is only half done */
  1029. memcpy( &p_end->read1_nop2, &temp_ccw ,
  1030. sizeof(struct ccw1));
  1031. privptr->p_read_active_last->r_TIC_1.cda=
  1032. (__u32)__pa(&p_first->read);
  1033. privptr->p_read_active_last->r_TIC_2.cda=
  1034. (__u32)__pa(&p_first->read);
  1035. }
  1036. /* chain in new set of blocks */
  1037. privptr->p_read_active_last->next = p_first;
  1038. privptr->p_read_active_last=p_last;
  1039. } /* end of if ( privptr-> p_read_active_first ==NULL) */
  1040. CLAW_DBF_TEXT(4, trace, "addexit");
  1041. return 0;
  1042. } /* end of add_claw_reads */
  1043. /*-------------------------------------------------------------------*
  1044. * ccw_check_return_code *
  1045. * *
  1046. *-------------------------------------------------------------------*/
  1047. static void
  1048. ccw_check_return_code(struct ccw_device *cdev, int return_code)
  1049. {
  1050. CLAW_DBF_TEXT(4, trace, "ccwret");
  1051. if (return_code != 0) {
  1052. switch (return_code) {
  1053. case -EBUSY: /* BUSY is a transient state no action needed */
  1054. break;
  1055. case -ENODEV:
  1056. printk(KERN_EMERG "%s: Missing device called "
  1057. "for IO ENODEV\n", cdev->dev.bus_id);
  1058. break;
  1059. case -EIO:
  1060. printk(KERN_EMERG "%s: Status pending... EIO \n",
  1061. cdev->dev.bus_id);
  1062. break;
  1063. case -EINVAL:
  1064. printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
  1065. cdev->dev.bus_id);
  1066. break;
  1067. default:
  1068. printk(KERN_EMERG "%s: Unknown error in "
  1069. "Do_IO %d\n",cdev->dev.bus_id, return_code);
  1070. }
  1071. }
  1072. CLAW_DBF_TEXT(4, trace, "ccwret");
  1073. } /* end of ccw_check_return_code */
  1074. /*-------------------------------------------------------------------*
  1075. * ccw_check_unit_check *
  1076. *--------------------------------------------------------------------*/
  1077. static void
  1078. ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
  1079. {
  1080. struct net_device *ndev = p_ch->ndev;
  1081. CLAW_DBF_TEXT(4, trace, "unitchek");
  1082. printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
  1083. ndev->name, sense);
  1084. if (sense & 0x40) {
  1085. if (sense & 0x01) {
  1086. printk(KERN_WARNING "%s: Interface disconnect or "
  1087. "Selective reset "
  1088. "occurred (remote side)\n", ndev->name);
  1089. }
  1090. else {
  1091. printk(KERN_WARNING "%s: System reset occured"
  1092. " (remote side)\n", ndev->name);
  1093. }
  1094. }
  1095. else if (sense & 0x20) {
  1096. if (sense & 0x04) {
  1097. printk(KERN_WARNING "%s: Data-streaming "
  1098. "timeout)\n", ndev->name);
  1099. }
  1100. else {
  1101. printk(KERN_WARNING "%s: Data-transfer parity"
  1102. " error\n", ndev->name);
  1103. }
  1104. }
  1105. else if (sense & 0x10) {
  1106. if (sense & 0x20) {
  1107. printk(KERN_WARNING "%s: Hardware malfunction "
  1108. "(remote side)\n", ndev->name);
  1109. }
  1110. else {
  1111. printk(KERN_WARNING "%s: read-data parity error "
  1112. "(remote side)\n", ndev->name);
  1113. }
  1114. }
  1115. } /* end of ccw_check_unit_check */
  1116. /*-------------------------------------------------------------------*
  1117. * find_link *
  1118. *--------------------------------------------------------------------*/
  1119. static int
  1120. find_link(struct net_device *dev, char *host_name, char *ws_name )
  1121. {
  1122. struct claw_privbk *privptr;
  1123. struct claw_env *p_env;
  1124. int rc=0;
  1125. CLAW_DBF_TEXT(2, setup, "findlink");
  1126. privptr=dev->priv;
  1127. p_env=privptr->p_env;
  1128. switch (p_env->packing)
  1129. {
  1130. case PACKING_ASK:
  1131. if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
  1132. (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
  1133. rc = EINVAL;
  1134. break;
  1135. case DO_PACKED:
  1136. case PACK_SEND:
  1137. if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
  1138. (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
  1139. rc = EINVAL;
  1140. break;
  1141. default:
  1142. if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
  1143. (memcmp(p_env->api_type , ws_name, 8)!=0))
  1144. rc = EINVAL;
  1145. break;
  1146. }
  1147. return 0;
  1148. } /* end of find_link */
  1149. /*-------------------------------------------------------------------*
  1150. * claw_hw_tx *
  1151. * *
  1152. * *
  1153. *-------------------------------------------------------------------*/
  1154. static int
  1155. claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
  1156. {
  1157. int rc=0;
  1158. struct claw_privbk *privptr;
  1159. struct ccwbk *p_this_ccw;
  1160. struct ccwbk *p_first_ccw;
  1161. struct ccwbk *p_last_ccw;
  1162. __u32 numBuffers;
  1163. signed long len_of_data;
  1164. unsigned long bytesInThisBuffer;
  1165. unsigned char *pDataAddress;
  1166. struct endccw *pEnd;
  1167. struct ccw1 tempCCW;
  1168. struct chbk *p_ch;
  1169. struct claw_env *p_env;
  1170. int lock;
  1171. struct clawph *pk_head;
  1172. struct chbk *ch;
  1173. CLAW_DBF_TEXT(4, trace, "hw_tx");
  1174. privptr = (struct claw_privbk *) (dev->priv);
  1175. p_ch=(struct chbk *)&privptr->channel[WRITE];
  1176. p_env =privptr->p_env;
  1177. claw_free_wrt_buf(dev); /* Clean up free chain if posible */
  1178. /* scan the write queue to free any completed write packets */
  1179. p_first_ccw=NULL;
  1180. p_last_ccw=NULL;
  1181. if ((p_env->packing >= PACK_SEND) &&
  1182. (skb->cb[1] != 'P')) {
  1183. skb_push(skb,sizeof(struct clawph));
  1184. pk_head=(struct clawph *)skb->data;
  1185. pk_head->len=skb->len-sizeof(struct clawph);
  1186. if (pk_head->len%4) {
  1187. pk_head->len+= 4-(pk_head->len%4);
  1188. skb_pad(skb,4-(pk_head->len%4));
  1189. skb_put(skb,4-(pk_head->len%4));
  1190. }
  1191. if (p_env->packing == DO_PACKED)
  1192. pk_head->link_num = linkid;
  1193. else
  1194. pk_head->link_num = 0;
  1195. pk_head->flag = 0x00;
  1196. skb_pad(skb,4);
  1197. skb->cb[1] = 'P';
  1198. }
  1199. if (linkid == 0) {
  1200. if (claw_check_busy(dev)) {
  1201. if (privptr->write_free_count!=0) {
  1202. claw_clear_busy(dev);
  1203. }
  1204. else {
  1205. claw_strt_out_IO(dev );
  1206. claw_free_wrt_buf( dev );
  1207. if (privptr->write_free_count==0) {
  1208. ch = &privptr->channel[WRITE];
  1209. atomic_inc(&skb->users);
  1210. skb_queue_tail(&ch->collect_queue, skb);
  1211. goto Done;
  1212. }
  1213. else {
  1214. claw_clear_busy(dev);
  1215. }
  1216. }
  1217. }
  1218. /* tx lock */
  1219. if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
  1220. ch = &privptr->channel[WRITE];
  1221. atomic_inc(&skb->users);
  1222. skb_queue_tail(&ch->collect_queue, skb);
  1223. claw_strt_out_IO(dev );
  1224. rc=-EBUSY;
  1225. goto Done2;
  1226. }
  1227. }
  1228. /* See how many write buffers are required to hold this data */
  1229. numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
  1230. /* If that number of buffers isn't available, give up for now */
  1231. if (privptr->write_free_count < numBuffers ||
  1232. privptr->p_write_free_chain == NULL ) {
  1233. claw_setbit_busy(TB_NOBUFFER,dev);
  1234. ch = &privptr->channel[WRITE];
  1235. atomic_inc(&skb->users);
  1236. skb_queue_tail(&ch->collect_queue, skb);
  1237. CLAW_DBF_TEXT(2, trace, "clawbusy");
  1238. goto Done2;
  1239. }
  1240. pDataAddress=skb->data;
  1241. len_of_data=skb->len;
  1242. while (len_of_data > 0) {
  1243. p_this_ccw=privptr->p_write_free_chain; /* get a block */
  1244. if (p_this_ccw == NULL) { /* lost the race */
  1245. ch = &privptr->channel[WRITE];
  1246. atomic_inc(&skb->users);
  1247. skb_queue_tail(&ch->collect_queue, skb);
  1248. goto Done2;
  1249. }
  1250. privptr->p_write_free_chain=p_this_ccw->next;
  1251. p_this_ccw->next=NULL;
  1252. --privptr->write_free_count; /* -1 */
  1253. bytesInThisBuffer=len_of_data;
  1254. memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
  1255. len_of_data-=bytesInThisBuffer;
  1256. pDataAddress+=(unsigned long)bytesInThisBuffer;
  1257. /* setup write CCW */
  1258. p_this_ccw->write.cmd_code = (linkid * 8) +1;
  1259. if (len_of_data>0) {
  1260. p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
  1261. }
  1262. p_this_ccw->write.count=bytesInThisBuffer;
  1263. /* now add to end of this chain */
  1264. if (p_first_ccw==NULL) {
  1265. p_first_ccw=p_this_ccw;
  1266. }
  1267. if (p_last_ccw!=NULL) {
  1268. p_last_ccw->next=p_this_ccw;
  1269. /* set up TIC ccws */
  1270. p_last_ccw->w_TIC_1.cda=
  1271. (__u32)__pa(&p_this_ccw->write);
  1272. }
  1273. p_last_ccw=p_this_ccw; /* save new last block */
  1274. }
  1275. /* FirstCCW and LastCCW now contain a new set of write channel
  1276. * programs to append to the running channel program
  1277. */
  1278. if (p_first_ccw!=NULL) {
  1279. /* setup ending ccw sequence for this segment */
  1280. pEnd=privptr->p_end_ccw;
  1281. if (pEnd->write1) {
  1282. pEnd->write1=0x00; /* second end ccw is now active */
  1283. /* set up Tic CCWs */
  1284. p_last_ccw->w_TIC_1.cda=
  1285. (__u32)__pa(&pEnd->write2_nop1);
  1286. pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1287. pEnd->write2_nop2.flags =
  1288. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1289. pEnd->write2_nop2.cda=0;
  1290. pEnd->write2_nop2.count=1;
  1291. }
  1292. else { /* end of if (pEnd->write1)*/
  1293. pEnd->write1=0x01; /* first end ccw is now active */
  1294. /* set up Tic CCWs */
  1295. p_last_ccw->w_TIC_1.cda=
  1296. (__u32)__pa(&pEnd->write1_nop1);
  1297. pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1298. pEnd->write1_nop2.flags =
  1299. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1300. pEnd->write1_nop2.cda=0;
  1301. pEnd->write1_nop2.count=1;
  1302. } /* end if if (pEnd->write1) */
  1303. if (privptr->p_write_active_first==NULL ) {
  1304. privptr->p_write_active_first=p_first_ccw;
  1305. privptr->p_write_active_last=p_last_ccw;
  1306. }
  1307. else {
  1308. /* set up Tic CCWs */
  1309. tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
  1310. tempCCW.count=0;
  1311. tempCCW.flags=0;
  1312. tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
  1313. if (pEnd->write1) {
  1314. /*
  1315. * first set of ending CCW's is chained to the new write
  1316. * chain, so the second set is chained to the active chain
  1317. * Therefore modify the second set to point the new write chain.
  1318. * make sure we update the CCW atomically
  1319. * so channel does not fetch it when it's only half done
  1320. */
  1321. memcpy( &pEnd->write2_nop2, &tempCCW ,
  1322. sizeof(struct ccw1));
  1323. privptr->p_write_active_last->w_TIC_1.cda=
  1324. (__u32)__pa(&p_first_ccw->write);
  1325. }
  1326. else {
  1327. /*make sure we update the CCW atomically
  1328. *so channel does not fetch it when it's only half done
  1329. */
  1330. memcpy(&pEnd->write1_nop2, &tempCCW ,
  1331. sizeof(struct ccw1));
  1332. privptr->p_write_active_last->w_TIC_1.cda=
  1333. (__u32)__pa(&p_first_ccw->write);
  1334. } /* end if if (pEnd->write1) */
  1335. privptr->p_write_active_last->next=p_first_ccw;
  1336. privptr->p_write_active_last=p_last_ccw;
  1337. }
  1338. } /* endif (p_first_ccw!=NULL) */
  1339. dev_kfree_skb_any(skb);
  1340. if (linkid==0) {
  1341. lock=LOCK_NO;
  1342. }
  1343. else {
  1344. lock=LOCK_YES;
  1345. }
  1346. claw_strt_out_IO(dev );
  1347. /* if write free count is zero , set NOBUFFER */
  1348. if (privptr->write_free_count==0) {
  1349. claw_setbit_busy(TB_NOBUFFER,dev);
  1350. }
  1351. Done2:
  1352. claw_clearbit_busy(TB_TX,dev);
  1353. Done:
  1354. return(rc);
  1355. } /* end of claw_hw_tx */
  1356. /*-------------------------------------------------------------------*
  1357. * *
  1358. * init_ccw_bk *
  1359. * *
  1360. *--------------------------------------------------------------------*/
  1361. static int
  1362. init_ccw_bk(struct net_device *dev)
  1363. {
  1364. __u32 ccw_blocks_required;
  1365. __u32 ccw_blocks_perpage;
  1366. __u32 ccw_pages_required;
  1367. __u32 claw_reads_perpage=1;
  1368. __u32 claw_read_pages;
  1369. __u32 claw_writes_perpage=1;
  1370. __u32 claw_write_pages;
  1371. void *p_buff=NULL;
  1372. struct ccwbk*p_free_chain;
  1373. struct ccwbk*p_buf;
  1374. struct ccwbk*p_last_CCWB;
  1375. struct ccwbk*p_first_CCWB;
  1376. struct endccw *p_endccw=NULL;
  1377. addr_t real_address;
  1378. struct claw_privbk *privptr=dev->priv;
  1379. struct clawh *pClawH=NULL;
  1380. addr_t real_TIC_address;
  1381. int i,j;
  1382. CLAW_DBF_TEXT(4, trace, "init_ccw");
  1383. /* initialize statistics field */
  1384. privptr->active_link_ID=0;
  1385. /* initialize ccwbk pointers */
  1386. privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
  1387. privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
  1388. privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
  1389. privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
  1390. privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
  1391. privptr->p_end_ccw=NULL; /* pointer to ending ccw */
  1392. privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
  1393. privptr->buffs_alloc = 0;
  1394. memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
  1395. memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
  1396. /* initialize free write ccwbk counter */
  1397. privptr->write_free_count=0; /* number of free bufs on write chain */
  1398. p_last_CCWB = NULL;
  1399. p_first_CCWB= NULL;
  1400. /*
  1401. * We need 1 CCW block for each read buffer, 1 for each
  1402. * write buffer, plus 1 for ClawSignalBlock
  1403. */
  1404. ccw_blocks_required =
  1405. privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
  1406. /*
  1407. * compute number of CCW blocks that will fit in a page
  1408. */
  1409. ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
  1410. ccw_pages_required=
  1411. DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
  1412. /*
  1413. * read and write sizes are set by 2 constants in claw.h
  1414. * 4k and 32k. Unpacked values other than 4k are not going to
  1415. * provide good performance. With packing buffers support 32k
  1416. * buffers are used.
  1417. */
  1418. if (privptr->p_env->read_size < PAGE_SIZE) {
  1419. claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
  1420. claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
  1421. claw_reads_perpage);
  1422. }
  1423. else { /* > or equal */
  1424. privptr->p_buff_pages_perread =
  1425. DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
  1426. claw_read_pages = privptr->p_env->read_buffers *
  1427. privptr->p_buff_pages_perread;
  1428. }
  1429. if (privptr->p_env->write_size < PAGE_SIZE) {
  1430. claw_writes_perpage =
  1431. PAGE_SIZE / privptr->p_env->write_size;
  1432. claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
  1433. claw_writes_perpage);
  1434. }
  1435. else { /* > or equal */
  1436. privptr->p_buff_pages_perwrite =
  1437. DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
  1438. claw_write_pages = privptr->p_env->write_buffers *
  1439. privptr->p_buff_pages_perwrite;
  1440. }
  1441. /*
  1442. * allocate ccw_pages_required
  1443. */
  1444. if (privptr->p_buff_ccw==NULL) {
  1445. privptr->p_buff_ccw=
  1446. (void *)__get_free_pages(__GFP_DMA,
  1447. (int)pages_to_order_of_mag(ccw_pages_required ));
  1448. if (privptr->p_buff_ccw==NULL) {
  1449. return -ENOMEM;
  1450. }
  1451. privptr->p_buff_ccw_num=ccw_pages_required;
  1452. }
  1453. memset(privptr->p_buff_ccw, 0x00,
  1454. privptr->p_buff_ccw_num * PAGE_SIZE);
  1455. /*
  1456. * obtain ending ccw block address
  1457. *
  1458. */
  1459. privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
  1460. real_address = (__u32)__pa(privptr->p_end_ccw);
  1461. /* Initialize ending CCW block */
  1462. p_endccw=privptr->p_end_ccw;
  1463. p_endccw->real=real_address;
  1464. p_endccw->write1=0x00;
  1465. p_endccw->read1=0x00;
  1466. /* write1_nop1 */
  1467. p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1468. p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1469. p_endccw->write1_nop1.count = 1;
  1470. p_endccw->write1_nop1.cda = 0;
  1471. /* write1_nop2 */
  1472. p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1473. p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1474. p_endccw->write1_nop2.count = 1;
  1475. p_endccw->write1_nop2.cda = 0;
  1476. /* write2_nop1 */
  1477. p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1478. p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1479. p_endccw->write2_nop1.count = 1;
  1480. p_endccw->write2_nop1.cda = 0;
  1481. /* write2_nop2 */
  1482. p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1483. p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1484. p_endccw->write2_nop2.count = 1;
  1485. p_endccw->write2_nop2.cda = 0;
  1486. /* read1_nop1 */
  1487. p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1488. p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1489. p_endccw->read1_nop1.count = 1;
  1490. p_endccw->read1_nop1.cda = 0;
  1491. /* read1_nop2 */
  1492. p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1493. p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1494. p_endccw->read1_nop2.count = 1;
  1495. p_endccw->read1_nop2.cda = 0;
  1496. /* read2_nop1 */
  1497. p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1498. p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1499. p_endccw->read2_nop1.count = 1;
  1500. p_endccw->read2_nop1.cda = 0;
  1501. /* read2_nop2 */
  1502. p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1503. p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1504. p_endccw->read2_nop2.count = 1;
  1505. p_endccw->read2_nop2.cda = 0;
  1506. /*
  1507. * Build a chain of CCWs
  1508. *
  1509. */
  1510. p_buff=privptr->p_buff_ccw;
  1511. p_free_chain=NULL;
  1512. for (i=0 ; i < ccw_pages_required; i++ ) {
  1513. real_address = (__u32)__pa(p_buff);
  1514. p_buf=p_buff;
  1515. for (j=0 ; j < ccw_blocks_perpage ; j++) {
  1516. p_buf->next = p_free_chain;
  1517. p_free_chain = p_buf;
  1518. p_buf->real=(__u32)__pa(p_buf);
  1519. ++p_buf;
  1520. }
  1521. p_buff+=PAGE_SIZE;
  1522. }
  1523. /*
  1524. * Initialize ClawSignalBlock
  1525. *
  1526. */
  1527. if (privptr->p_claw_signal_blk==NULL) {
  1528. privptr->p_claw_signal_blk=p_free_chain;
  1529. p_free_chain=p_free_chain->next;
  1530. pClawH=(struct clawh *)privptr->p_claw_signal_blk;
  1531. pClawH->length=0xffff;
  1532. pClawH->opcode=0xff;
  1533. pClawH->flag=CLAW_BUSY;
  1534. }
  1535. /*
  1536. * allocate write_pages_required and add to free chain
  1537. */
  1538. if (privptr->p_buff_write==NULL) {
  1539. if (privptr->p_env->write_size < PAGE_SIZE) {
  1540. privptr->p_buff_write=
  1541. (void *)__get_free_pages(__GFP_DMA,
  1542. (int)pages_to_order_of_mag(claw_write_pages ));
  1543. if (privptr->p_buff_write==NULL) {
  1544. privptr->p_buff_ccw=NULL;
  1545. return -ENOMEM;
  1546. }
  1547. /*
  1548. * Build CLAW write free chain
  1549. *
  1550. */
  1551. memset(privptr->p_buff_write, 0x00,
  1552. ccw_pages_required * PAGE_SIZE);
  1553. privptr->p_write_free_chain=NULL;
  1554. p_buff=privptr->p_buff_write;
  1555. for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
  1556. p_buf = p_free_chain; /* get a CCW */
  1557. p_free_chain = p_buf->next;
  1558. p_buf->next =privptr->p_write_free_chain;
  1559. privptr->p_write_free_chain = p_buf;
  1560. p_buf-> p_buffer = (struct clawbuf *)p_buff;
  1561. p_buf-> write.cda = (__u32)__pa(p_buff);
  1562. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1563. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1564. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1565. p_buf-> w_read_FF.count = 1;
  1566. p_buf-> w_read_FF.cda =
  1567. (__u32)__pa(&p_buf-> header.flag);
  1568. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1569. p_buf-> w_TIC_1.flags = 0;
  1570. p_buf-> w_TIC_1.count = 0;
  1571. if (((unsigned long)p_buff+privptr->p_env->write_size) >=
  1572. ((unsigned long)(p_buff+2*
  1573. (privptr->p_env->write_size) -1) & PAGE_MASK)) {
  1574. p_buff= p_buff+privptr->p_env->write_size;
  1575. }
  1576. }
  1577. }
  1578. else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
  1579. {
  1580. privptr->p_write_free_chain=NULL;
  1581. for (i = 0; i< privptr->p_env->write_buffers ; i++) {
  1582. p_buff=(void *)__get_free_pages(__GFP_DMA,
  1583. (int)pages_to_order_of_mag(
  1584. privptr->p_buff_pages_perwrite) );
  1585. if (p_buff==NULL) {
  1586. free_pages((unsigned long)privptr->p_buff_ccw,
  1587. (int)pages_to_order_of_mag(
  1588. privptr->p_buff_ccw_num));
  1589. privptr->p_buff_ccw=NULL;
  1590. p_buf=privptr->p_buff_write;
  1591. while (p_buf!=NULL) {
  1592. free_pages((unsigned long)
  1593. p_buf->p_buffer,
  1594. (int)pages_to_order_of_mag(
  1595. privptr->p_buff_pages_perwrite));
  1596. p_buf=p_buf->next;
  1597. }
  1598. return -ENOMEM;
  1599. } /* Error on get_pages */
  1600. memset(p_buff, 0x00, privptr->p_env->write_size );
  1601. p_buf = p_free_chain;
  1602. p_free_chain = p_buf->next;
  1603. p_buf->next = privptr->p_write_free_chain;
  1604. privptr->p_write_free_chain = p_buf;
  1605. privptr->p_buff_write = p_buf;
  1606. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1607. p_buf-> write.cda = (__u32)__pa(p_buff);
  1608. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1609. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1610. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1611. p_buf-> w_read_FF.count = 1;
  1612. p_buf-> w_read_FF.cda =
  1613. (__u32)__pa(&p_buf-> header.flag);
  1614. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1615. p_buf-> w_TIC_1.flags = 0;
  1616. p_buf-> w_TIC_1.count = 0;
  1617. } /* for all write_buffers */
  1618. } /* else buffers are PAGE_SIZE or bigger */
  1619. }
  1620. privptr->p_buff_write_num=claw_write_pages;
  1621. privptr->write_free_count=privptr->p_env->write_buffers;
  1622. /*
  1623. * allocate read_pages_required and chain to free chain
  1624. */
  1625. if (privptr->p_buff_read==NULL) {
  1626. if (privptr->p_env->read_size < PAGE_SIZE) {
  1627. privptr->p_buff_read=
  1628. (void *)__get_free_pages(__GFP_DMA,
  1629. (int)pages_to_order_of_mag(claw_read_pages) );
  1630. if (privptr->p_buff_read==NULL) {
  1631. free_pages((unsigned long)privptr->p_buff_ccw,
  1632. (int)pages_to_order_of_mag(
  1633. privptr->p_buff_ccw_num));
  1634. /* free the write pages size is < page size */
  1635. free_pages((unsigned long)privptr->p_buff_write,
  1636. (int)pages_to_order_of_mag(
  1637. privptr->p_buff_write_num));
  1638. privptr->p_buff_ccw=NULL;
  1639. privptr->p_buff_write=NULL;
  1640. return -ENOMEM;
  1641. }
  1642. memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
  1643. privptr->p_buff_read_num=claw_read_pages;
  1644. /*
  1645. * Build CLAW read free chain
  1646. *
  1647. */
  1648. p_buff=privptr->p_buff_read;
  1649. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  1650. p_buf = p_free_chain;
  1651. p_free_chain = p_buf->next;
  1652. if (p_last_CCWB==NULL) {
  1653. p_buf->next=NULL;
  1654. real_TIC_address=0;
  1655. p_last_CCWB=p_buf;
  1656. }
  1657. else {
  1658. p_buf->next=p_first_CCWB;
  1659. real_TIC_address=
  1660. (__u32)__pa(&p_first_CCWB -> read );
  1661. }
  1662. p_first_CCWB=p_buf;
  1663. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1664. /* initialize read command */
  1665. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  1666. p_buf-> read.cda = (__u32)__pa(p_buff);
  1667. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1668. p_buf-> read.count = privptr->p_env->read_size;
  1669. /* initialize read_h command */
  1670. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  1671. p_buf-> read_h.cda =
  1672. (__u32)__pa(&(p_buf->header));
  1673. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1674. p_buf-> read_h.count = sizeof(struct clawh);
  1675. /* initialize Signal command */
  1676. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  1677. p_buf-> signal.cda =
  1678. (__u32)__pa(&(pClawH->flag));
  1679. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1680. p_buf-> signal.count = 1;
  1681. /* initialize r_TIC_1 command */
  1682. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1683. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  1684. p_buf-> r_TIC_1.flags = 0;
  1685. p_buf-> r_TIC_1.count = 0;
  1686. /* initialize r_read_FF command */
  1687. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1688. p_buf-> r_read_FF.cda =
  1689. (__u32)__pa(&(pClawH->flag));
  1690. p_buf-> r_read_FF.flags =
  1691. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  1692. p_buf-> r_read_FF.count = 1;
  1693. /* initialize r_TIC_2 */
  1694. memcpy(&p_buf->r_TIC_2,
  1695. &p_buf->r_TIC_1, sizeof(struct ccw1));
  1696. /* initialize Header */
  1697. p_buf->header.length=0xffff;
  1698. p_buf->header.opcode=0xff;
  1699. p_buf->header.flag=CLAW_PENDING;
  1700. if (((unsigned long)p_buff+privptr->p_env->read_size) >=
  1701. ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
  1702. & PAGE_MASK) ) {
  1703. p_buff= p_buff+privptr->p_env->read_size;
  1704. }
  1705. else {
  1706. p_buff=
  1707. (void *)((unsigned long)
  1708. (p_buff+2*(privptr->p_env->read_size) -1)
  1709. & PAGE_MASK) ;
  1710. }
  1711. } /* for read_buffers */
  1712. } /* read_size < PAGE_SIZE */
  1713. else { /* read Size >= PAGE_SIZE */
  1714. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  1715. p_buff = (void *)__get_free_pages(__GFP_DMA,
  1716. (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
  1717. if (p_buff==NULL) {
  1718. free_pages((unsigned long)privptr->p_buff_ccw,
  1719. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  1720. /* free the write pages */
  1721. p_buf=privptr->p_buff_write;
  1722. while (p_buf!=NULL) {
  1723. free_pages((unsigned long)p_buf->p_buffer,
  1724. (int)pages_to_order_of_mag(
  1725. privptr->p_buff_pages_perwrite ));
  1726. p_buf=p_buf->next;
  1727. }
  1728. /* free any read pages already alloc */
  1729. p_buf=privptr->p_buff_read;
  1730. while (p_buf!=NULL) {
  1731. free_pages((unsigned long)p_buf->p_buffer,
  1732. (int)pages_to_order_of_mag(
  1733. privptr->p_buff_pages_perread ));
  1734. p_buf=p_buf->next;
  1735. }
  1736. privptr->p_buff_ccw=NULL;
  1737. privptr->p_buff_write=NULL;
  1738. return -ENOMEM;
  1739. }
  1740. memset(p_buff, 0x00, privptr->p_env->read_size);
  1741. p_buf = p_free_chain;
  1742. privptr->p_buff_read = p_buf;
  1743. p_free_chain = p_buf->next;
  1744. if (p_last_CCWB==NULL) {
  1745. p_buf->next=NULL;
  1746. real_TIC_address=0;
  1747. p_last_CCWB=p_buf;
  1748. }
  1749. else {
  1750. p_buf->next=p_first_CCWB;
  1751. real_TIC_address=
  1752. (addr_t)__pa(
  1753. &p_first_CCWB -> read );
  1754. }
  1755. p_first_CCWB=p_buf;
  1756. /* save buff address */
  1757. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1758. /* initialize read command */
  1759. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  1760. p_buf-> read.cda = (__u32)__pa(p_buff);
  1761. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1762. p_buf-> read.count = privptr->p_env->read_size;
  1763. /* initialize read_h command */
  1764. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  1765. p_buf-> read_h.cda =
  1766. (__u32)__pa(&(p_buf->header));
  1767. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1768. p_buf-> read_h.count = sizeof(struct clawh);
  1769. /* initialize Signal command */
  1770. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  1771. p_buf-> signal.cda =
  1772. (__u32)__pa(&(pClawH->flag));
  1773. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1774. p_buf-> signal.count = 1;
  1775. /* initialize r_TIC_1 command */
  1776. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1777. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  1778. p_buf-> r_TIC_1.flags = 0;
  1779. p_buf-> r_TIC_1.count = 0;
  1780. /* initialize r_read_FF command */
  1781. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1782. p_buf-> r_read_FF.cda =
  1783. (__u32)__pa(&(pClawH->flag));
  1784. p_buf-> r_read_FF.flags =
  1785. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  1786. p_buf-> r_read_FF.count = 1;
  1787. /* initialize r_TIC_2 */
  1788. memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
  1789. sizeof(struct ccw1));
  1790. /* initialize Header */
  1791. p_buf->header.length=0xffff;
  1792. p_buf->header.opcode=0xff;
  1793. p_buf->header.flag=CLAW_PENDING;
  1794. } /* For read_buffers */
  1795. } /* read_size >= PAGE_SIZE */
  1796. } /* pBuffread = NULL */
  1797. add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
  1798. privptr->buffs_alloc = 1;
  1799. return 0;
  1800. } /* end of init_ccw_bk */
  1801. /*-------------------------------------------------------------------*
  1802. * *
  1803. * probe_error *
  1804. * *
  1805. *--------------------------------------------------------------------*/
  1806. static void
  1807. probe_error( struct ccwgroup_device *cgdev)
  1808. {
  1809. struct claw_privbk *privptr;
  1810. CLAW_DBF_TEXT(4, trace, "proberr");
  1811. privptr=(struct claw_privbk *)cgdev->dev.driver_data;
  1812. if (privptr!=NULL) {
  1813. kfree(privptr->p_env);
  1814. privptr->p_env=NULL;
  1815. kfree(privptr->p_mtc_envelope);
  1816. privptr->p_mtc_envelope=NULL;
  1817. kfree(privptr);
  1818. privptr=NULL;
  1819. }
  1820. return;
  1821. } /* probe_error */
  1822. /*-------------------------------------------------------------------*
  1823. * claw_process_control *
  1824. * *
  1825. * *
  1826. *--------------------------------------------------------------------*/
  1827. static int
  1828. claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
  1829. {
  1830. struct clawbuf *p_buf;
  1831. struct clawctl ctlbk;
  1832. struct clawctl *p_ctlbk;
  1833. char temp_host_name[8];
  1834. char temp_ws_name[8];
  1835. struct claw_privbk *privptr;
  1836. struct claw_env *p_env;
  1837. struct sysval *p_sysval;
  1838. struct conncmd *p_connect=NULL;
  1839. int rc;
  1840. struct chbk *p_ch = NULL;
  1841. struct device *tdev;
  1842. CLAW_DBF_TEXT(2, setup, "clw_cntl");
  1843. udelay(1000); /* Wait a ms for the control packets to
  1844. *catch up to each other */
  1845. privptr=dev->priv;
  1846. p_env=privptr->p_env;
  1847. tdev = &privptr->channel[READ].cdev->dev;
  1848. memcpy( &temp_host_name, p_env->host_name, 8);
  1849. memcpy( &temp_ws_name, p_env->adapter_name , 8);
  1850. printk(KERN_INFO "%s: CLAW device %.8s: "
  1851. "Received Control Packet\n",
  1852. dev->name, temp_ws_name);
  1853. if (privptr->release_pend==1) {
  1854. return 0;
  1855. }
  1856. p_buf=p_ccw->p_buffer;
  1857. p_ctlbk=&ctlbk;
  1858. if (p_env->packing == DO_PACKED) { /* packing in progress?*/
  1859. memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
  1860. } else {
  1861. memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
  1862. }
  1863. switch (p_ctlbk->command)
  1864. {
  1865. case SYSTEM_VALIDATE_REQUEST:
  1866. if (p_ctlbk->version != CLAW_VERSION_ID) {
  1867. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1868. CLAW_RC_WRONG_VERSION);
  1869. printk("%s: %d is wrong version id. "
  1870. "Expected %d\n",
  1871. dev->name, p_ctlbk->version,
  1872. CLAW_VERSION_ID);
  1873. }
  1874. p_sysval = (struct sysval *)&(p_ctlbk->data);
  1875. printk("%s: Recv Sys Validate Request: "
  1876. "Vers=%d,link_id=%d,Corr=%d,WS name=%."
  1877. "8s,Host name=%.8s\n",
  1878. dev->name, p_ctlbk->version,
  1879. p_ctlbk->linkid,
  1880. p_ctlbk->correlator,
  1881. p_sysval->WS_name,
  1882. p_sysval->host_name);
  1883. if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
  1884. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1885. CLAW_RC_NAME_MISMATCH);
  1886. CLAW_DBF_TEXT(2, setup, "HSTBAD");
  1887. CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
  1888. CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
  1889. printk(KERN_INFO "%s: Host name mismatch\n",
  1890. dev->name);
  1891. printk(KERN_INFO "%s: Received :%s: "
  1892. "expected :%s: \n",
  1893. dev->name,
  1894. p_sysval->host_name,
  1895. temp_host_name);
  1896. }
  1897. if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
  1898. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1899. CLAW_RC_NAME_MISMATCH);
  1900. CLAW_DBF_TEXT(2, setup, "WSNBAD");
  1901. CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
  1902. CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
  1903. printk(KERN_INFO "%s: WS name mismatch\n",
  1904. dev->name);
  1905. printk(KERN_INFO "%s: Received :%s: "
  1906. "expected :%s: \n",
  1907. dev->name,
  1908. p_sysval->WS_name,
  1909. temp_ws_name);
  1910. }
  1911. if ((p_sysval->write_frame_size < p_env->write_size) &&
  1912. (p_env->packing == 0)) {
  1913. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1914. CLAW_RC_HOST_RCV_TOO_SMALL);
  1915. printk(KERN_INFO "%s: host write size is too "
  1916. "small\n", dev->name);
  1917. CLAW_DBF_TEXT(2, setup, "wrtszbad");
  1918. }
  1919. if ((p_sysval->read_frame_size < p_env->read_size) &&
  1920. (p_env->packing == 0)) {
  1921. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1922. CLAW_RC_HOST_RCV_TOO_SMALL);
  1923. printk(KERN_INFO "%s: host read size is too "
  1924. "small\n", dev->name);
  1925. CLAW_DBF_TEXT(2, setup, "rdsizbad");
  1926. }
  1927. claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
  1928. printk(KERN_INFO "%s: CLAW device %.8s: System validate "
  1929. "completed.\n", dev->name, temp_ws_name);
  1930. printk("%s: sys Validate Rsize:%d Wsize:%d\n", dev->name,
  1931. p_sysval->read_frame_size, p_sysval->write_frame_size);
  1932. privptr->system_validate_comp = 1;
  1933. if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
  1934. p_env->packing = PACKING_ASK;
  1935. claw_strt_conn_req(dev);
  1936. break;
  1937. case SYSTEM_VALIDATE_RESPONSE:
  1938. p_sysval = (struct sysval *)&(p_ctlbk->data);
  1939. printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
  1940. "WS name=%.8s,Host name=%.8s\n",
  1941. dev->name,
  1942. p_ctlbk->version,
  1943. p_ctlbk->correlator,
  1944. p_ctlbk->rc,
  1945. p_sysval->WS_name,
  1946. p_sysval->host_name);
  1947. switch (p_ctlbk->rc) {
  1948. case 0:
  1949. printk(KERN_INFO "%s: CLAW device "
  1950. "%.8s: System validate "
  1951. "completed.\n",
  1952. dev->name, temp_ws_name);
  1953. if (privptr->system_validate_comp == 0)
  1954. claw_strt_conn_req(dev);
  1955. privptr->system_validate_comp = 1;
  1956. break;
  1957. case CLAW_RC_NAME_MISMATCH:
  1958. printk(KERN_INFO "%s: Sys Validate "
  1959. "Resp : Host, WS name is "
  1960. "mismatch\n",
  1961. dev->name);
  1962. break;
  1963. case CLAW_RC_WRONG_VERSION:
  1964. printk(KERN_INFO "%s: Sys Validate "
  1965. "Resp : Wrong version\n",
  1966. dev->name);
  1967. break;
  1968. case CLAW_RC_HOST_RCV_TOO_SMALL:
  1969. printk(KERN_INFO "%s: Sys Validate "
  1970. "Resp : bad frame size\n",
  1971. dev->name);
  1972. break;
  1973. default:
  1974. printk(KERN_INFO "%s: Sys Validate "
  1975. "error code=%d \n",
  1976. dev->name, p_ctlbk->rc);
  1977. break;
  1978. }
  1979. break;
  1980. case CONNECTION_REQUEST:
  1981. p_connect = (struct conncmd *)&(p_ctlbk->data);
  1982. printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
  1983. "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
  1984. dev->name,
  1985. p_ctlbk->version,
  1986. p_ctlbk->linkid,
  1987. p_ctlbk->correlator,
  1988. p_connect->host_name,
  1989. p_connect->WS_name);
  1990. if (privptr->active_link_ID != 0) {
  1991. claw_snd_disc(dev, p_ctlbk);
  1992. printk(KERN_INFO "%s: Conn Req error : "
  1993. "already logical link is active \n",
  1994. dev->name);
  1995. }
  1996. if (p_ctlbk->linkid != 1) {
  1997. claw_snd_disc(dev, p_ctlbk);
  1998. printk(KERN_INFO "%s: Conn Req error : "
  1999. "req logical link id is not 1\n",
  2000. dev->name);
  2001. }
  2002. rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
  2003. if (rc != 0) {
  2004. claw_snd_disc(dev, p_ctlbk);
  2005. printk(KERN_INFO "%s: Conn Resp error: "
  2006. "req appl name does not match\n",
  2007. dev->name);
  2008. }
  2009. claw_send_control(dev,
  2010. CONNECTION_CONFIRM, p_ctlbk->linkid,
  2011. p_ctlbk->correlator,
  2012. 0, p_connect->host_name,
  2013. p_connect->WS_name);
  2014. if (p_env->packing == PACKING_ASK) {
  2015. p_env->packing = PACK_SEND;
  2016. claw_snd_conn_req(dev, 0);
  2017. }
  2018. printk(KERN_INFO "%s: CLAW device %.8s: Connection "
  2019. "completed link_id=%d.\n",
  2020. dev->name, temp_ws_name,
  2021. p_ctlbk->linkid);
  2022. privptr->active_link_ID = p_ctlbk->linkid;
  2023. p_ch = &privptr->channel[WRITE];
  2024. wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
  2025. break;
  2026. case CONNECTION_RESPONSE:
  2027. p_connect = (struct conncmd *)&(p_ctlbk->data);
  2028. printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
  2029. "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
  2030. dev->name,
  2031. p_ctlbk->version,
  2032. p_ctlbk->linkid,
  2033. p_ctlbk->correlator,
  2034. p_ctlbk->rc,
  2035. p_connect->host_name,
  2036. p_connect->WS_name);
  2037. if (p_ctlbk->rc != 0) {
  2038. printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
  2039. dev->name, p_ctlbk->rc);
  2040. return 1;
  2041. }
  2042. rc = find_link(dev,
  2043. p_connect->host_name, p_connect->WS_name);
  2044. if (rc != 0) {
  2045. claw_snd_disc(dev, p_ctlbk);
  2046. printk(KERN_INFO "%s: Conn Resp error: "
  2047. "req appl name does not match\n",
  2048. dev->name);
  2049. }
  2050. /* should be until CONNECTION_CONFIRM */
  2051. privptr->active_link_ID = -(p_ctlbk->linkid);
  2052. break;
  2053. case CONNECTION_CONFIRM:
  2054. p_connect = (struct conncmd *)&(p_ctlbk->data);
  2055. printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
  2056. "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
  2057. dev->name,
  2058. p_ctlbk->version,
  2059. p_ctlbk->linkid,
  2060. p_ctlbk->correlator,
  2061. p_connect->host_name,
  2062. p_connect->WS_name);
  2063. if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
  2064. privptr->active_link_ID = p_ctlbk->linkid;
  2065. if (p_env->packing > PACKING_ASK) {
  2066. printk(KERN_INFO "%s: Confirmed Now packing\n",
  2067. dev->name);
  2068. p_env->packing = DO_PACKED;
  2069. }
  2070. p_ch = &privptr->channel[WRITE];
  2071. wake_up(&p_ch->wait);
  2072. } else {
  2073. printk(KERN_INFO "%s: Conn confirm: "
  2074. "unexpected linkid=%d \n",
  2075. dev->name, p_ctlbk->linkid);
  2076. claw_snd_disc(dev, p_ctlbk);
  2077. }
  2078. break;
  2079. case DISCONNECT:
  2080. printk(KERN_INFO "%s: Disconnect: "
  2081. "Vers=%d,link_id=%d,Corr=%d\n",
  2082. dev->name, p_ctlbk->version,
  2083. p_ctlbk->linkid, p_ctlbk->correlator);
  2084. if ((p_ctlbk->linkid == 2) &&
  2085. (p_env->packing == PACK_SEND)) {
  2086. privptr->active_link_ID = 1;
  2087. p_env->packing = DO_PACKED;
  2088. } else
  2089. privptr->active_link_ID = 0;
  2090. break;
  2091. case CLAW_ERROR:
  2092. printk(KERN_INFO "%s: CLAW ERROR detected\n",
  2093. dev->name);
  2094. break;
  2095. default:
  2096. printk(KERN_INFO "%s: Unexpected command code=%d \n",
  2097. dev->name, p_ctlbk->command);
  2098. break;
  2099. }
  2100. return 0;
  2101. } /* end of claw_process_control */
  2102. /*-------------------------------------------------------------------*
  2103. * claw_send_control *
  2104. * *
  2105. *--------------------------------------------------------------------*/
  2106. static int
  2107. claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  2108. __u8 correlator, __u8 rc, char *local_name, char *remote_name)
  2109. {
  2110. struct claw_privbk *privptr;
  2111. struct clawctl *p_ctl;
  2112. struct sysval *p_sysval;
  2113. struct conncmd *p_connect;
  2114. struct sk_buff *skb;
  2115. CLAW_DBF_TEXT(2, setup, "sndcntl");
  2116. privptr=dev->priv;
  2117. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2118. p_ctl->command=type;
  2119. p_ctl->version=CLAW_VERSION_ID;
  2120. p_ctl->linkid=link;
  2121. p_ctl->correlator=correlator;
  2122. p_ctl->rc=rc;
  2123. p_sysval=(struct sysval *)&p_ctl->data;
  2124. p_connect=(struct conncmd *)&p_ctl->data;
  2125. switch (p_ctl->command) {
  2126. case SYSTEM_VALIDATE_REQUEST:
  2127. case SYSTEM_VALIDATE_RESPONSE:
  2128. memcpy(&p_sysval->host_name, local_name, 8);
  2129. memcpy(&p_sysval->WS_name, remote_name, 8);
  2130. if (privptr->p_env->packing > 0) {
  2131. p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
  2132. p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
  2133. } else {
  2134. /* how big is the biggest group of packets */
  2135. p_sysval->read_frame_size=privptr->p_env->read_size;
  2136. p_sysval->write_frame_size=privptr->p_env->write_size;
  2137. }
  2138. memset(&p_sysval->reserved, 0x00, 4);
  2139. break;
  2140. case CONNECTION_REQUEST:
  2141. case CONNECTION_RESPONSE:
  2142. case CONNECTION_CONFIRM:
  2143. case DISCONNECT:
  2144. memcpy(&p_sysval->host_name, local_name, 8);
  2145. memcpy(&p_sysval->WS_name, remote_name, 8);
  2146. if (privptr->p_env->packing > 0) {
  2147. /* How big is the biggest packet */
  2148. p_connect->reserved1[0]=CLAW_FRAME_SIZE;
  2149. p_connect->reserved1[1]=CLAW_FRAME_SIZE;
  2150. } else {
  2151. memset(&p_connect->reserved1, 0x00, 4);
  2152. memset(&p_connect->reserved2, 0x00, 4);
  2153. }
  2154. break;
  2155. default:
  2156. break;
  2157. }
  2158. /* write Control Record to the device */
  2159. skb = dev_alloc_skb(sizeof(struct clawctl));
  2160. if (!skb) {
  2161. return -ENOMEM;
  2162. }
  2163. memcpy(skb_put(skb, sizeof(struct clawctl)),
  2164. p_ctl, sizeof(struct clawctl));
  2165. if (privptr->p_env->packing >= PACK_SEND)
  2166. claw_hw_tx(skb, dev, 1);
  2167. else
  2168. claw_hw_tx(skb, dev, 0);
  2169. return 0;
  2170. } /* end of claw_send_control */
  2171. /*-------------------------------------------------------------------*
  2172. * claw_snd_conn_req *
  2173. * *
  2174. *--------------------------------------------------------------------*/
  2175. static int
  2176. claw_snd_conn_req(struct net_device *dev, __u8 link)
  2177. {
  2178. int rc;
  2179. struct claw_privbk *privptr=dev->priv;
  2180. struct clawctl *p_ctl;
  2181. CLAW_DBF_TEXT(2, setup, "snd_conn");
  2182. rc = 1;
  2183. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2184. p_ctl->linkid = link;
  2185. if ( privptr->system_validate_comp==0x00 ) {
  2186. return rc;
  2187. }
  2188. if (privptr->p_env->packing == PACKING_ASK )
  2189. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2190. WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
  2191. if (privptr->p_env->packing == PACK_SEND) {
  2192. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2193. WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
  2194. }
  2195. if (privptr->p_env->packing == 0)
  2196. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2197. HOST_APPL_NAME, privptr->p_env->api_type);
  2198. return rc;
  2199. } /* end of claw_snd_conn_req */
  2200. /*-------------------------------------------------------------------*
  2201. * claw_snd_disc *
  2202. * *
  2203. *--------------------------------------------------------------------*/
  2204. static int
  2205. claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
  2206. {
  2207. int rc;
  2208. struct conncmd * p_connect;
  2209. CLAW_DBF_TEXT(2, setup, "snd_dsc");
  2210. p_connect=(struct conncmd *)&p_ctl->data;
  2211. rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
  2212. p_ctl->correlator, 0,
  2213. p_connect->host_name, p_connect->WS_name);
  2214. return rc;
  2215. } /* end of claw_snd_disc */
  2216. /*-------------------------------------------------------------------*
  2217. * claw_snd_sys_validate_rsp *
  2218. * *
  2219. *--------------------------------------------------------------------*/
  2220. static int
  2221. claw_snd_sys_validate_rsp(struct net_device *dev,
  2222. struct clawctl *p_ctl, __u32 return_code)
  2223. {
  2224. struct claw_env * p_env;
  2225. struct claw_privbk *privptr;
  2226. int rc;
  2227. CLAW_DBF_TEXT(2, setup, "chkresp");
  2228. privptr = dev->priv;
  2229. p_env=privptr->p_env;
  2230. rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
  2231. p_ctl->linkid,
  2232. p_ctl->correlator,
  2233. return_code,
  2234. p_env->host_name,
  2235. p_env->adapter_name );
  2236. return rc;
  2237. } /* end of claw_snd_sys_validate_rsp */
  2238. /*-------------------------------------------------------------------*
  2239. * claw_strt_conn_req *
  2240. * *
  2241. *--------------------------------------------------------------------*/
  2242. static int
  2243. claw_strt_conn_req(struct net_device *dev )
  2244. {
  2245. int rc;
  2246. CLAW_DBF_TEXT(2, setup, "conn_req");
  2247. rc=claw_snd_conn_req(dev, 1);
  2248. return rc;
  2249. } /* end of claw_strt_conn_req */
  2250. /*-------------------------------------------------------------------*
  2251. * claw_stats *
  2252. *-------------------------------------------------------------------*/
  2253. static struct
  2254. net_device_stats *claw_stats(struct net_device *dev)
  2255. {
  2256. struct claw_privbk *privptr;
  2257. CLAW_DBF_TEXT(4, trace, "stats");
  2258. privptr = dev->priv;
  2259. return &privptr->stats;
  2260. } /* end of claw_stats */
  2261. /*-------------------------------------------------------------------*
  2262. * unpack_read *
  2263. * *
  2264. *--------------------------------------------------------------------*/
  2265. static void
  2266. unpack_read(struct net_device *dev )
  2267. {
  2268. struct sk_buff *skb;
  2269. struct claw_privbk *privptr;
  2270. struct claw_env *p_env;
  2271. struct ccwbk *p_this_ccw;
  2272. struct ccwbk *p_first_ccw;
  2273. struct ccwbk *p_last_ccw;
  2274. struct clawph *p_packh;
  2275. void *p_packd;
  2276. struct clawctl *p_ctlrec=NULL;
  2277. struct device *p_dev;
  2278. __u32 len_of_data;
  2279. __u32 pack_off;
  2280. __u8 link_num;
  2281. __u8 mtc_this_frm=0;
  2282. __u32 bytes_to_mov;
  2283. int i=0;
  2284. int p=0;
  2285. CLAW_DBF_TEXT(4, trace, "unpkread");
  2286. p_first_ccw=NULL;
  2287. p_last_ccw=NULL;
  2288. p_packh=NULL;
  2289. p_packd=NULL;
  2290. privptr=dev->priv;
  2291. p_dev = &privptr->channel[READ].cdev->dev;
  2292. p_env = privptr->p_env;
  2293. p_this_ccw=privptr->p_read_active_first;
  2294. i=0;
  2295. while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
  2296. pack_off = 0;
  2297. p = 0;
  2298. p_this_ccw->header.flag=CLAW_PENDING;
  2299. privptr->p_read_active_first=p_this_ccw->next;
  2300. p_this_ccw->next=NULL;
  2301. p_packh = (struct clawph *)p_this_ccw->p_buffer;
  2302. if ((p_env->packing == PACK_SEND) &&
  2303. (p_packh->len == 32) &&
  2304. (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
  2305. p_packh++; /* peek past pack header */
  2306. p_ctlrec = (struct clawctl *)p_packh;
  2307. p_packh--; /* un peek */
  2308. if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
  2309. (p_ctlrec->command == CONNECTION_CONFIRM))
  2310. p_env->packing = DO_PACKED;
  2311. }
  2312. if (p_env->packing == DO_PACKED)
  2313. link_num=p_packh->link_num;
  2314. else
  2315. link_num=p_this_ccw->header.opcode / 8;
  2316. if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
  2317. mtc_this_frm=1;
  2318. if (p_this_ccw->header.length!=
  2319. privptr->p_env->read_size ) {
  2320. printk(KERN_INFO " %s: Invalid frame detected "
  2321. "length is %02x\n" ,
  2322. dev->name, p_this_ccw->header.length);
  2323. }
  2324. }
  2325. if (privptr->mtc_skipping) {
  2326. /*
  2327. * We're in the mode of skipping past a
  2328. * multi-frame message
  2329. * that we can't process for some reason or other.
  2330. * The first frame without the More-To-Come flag is
  2331. * the last frame of the skipped message.
  2332. */
  2333. /* in case of More-To-Come not set in this frame */
  2334. if (mtc_this_frm==0) {
  2335. privptr->mtc_skipping=0; /* Ok, the end */
  2336. privptr->mtc_logical_link=-1;
  2337. }
  2338. goto NextFrame;
  2339. }
  2340. if (link_num==0) {
  2341. claw_process_control(dev, p_this_ccw);
  2342. CLAW_DBF_TEXT(4, trace, "UnpkCntl");
  2343. goto NextFrame;
  2344. }
  2345. unpack_next:
  2346. if (p_env->packing == DO_PACKED) {
  2347. if (pack_off > p_env->read_size)
  2348. goto NextFrame;
  2349. p_packd = p_this_ccw->p_buffer+pack_off;
  2350. p_packh = (struct clawph *) p_packd;
  2351. if ((p_packh->len == 0) || /* all done with this frame? */
  2352. (p_packh->flag != 0))
  2353. goto NextFrame;
  2354. bytes_to_mov = p_packh->len;
  2355. pack_off += bytes_to_mov+sizeof(struct clawph);
  2356. p++;
  2357. } else {
  2358. bytes_to_mov=p_this_ccw->header.length;
  2359. }
  2360. if (privptr->mtc_logical_link<0) {
  2361. /*
  2362. * if More-To-Come is set in this frame then we don't know
  2363. * length of entire message, and hence have to allocate
  2364. * large buffer */
  2365. /* We are starting a new envelope */
  2366. privptr->mtc_offset=0;
  2367. privptr->mtc_logical_link=link_num;
  2368. }
  2369. if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
  2370. /* error */
  2371. privptr->stats.rx_frame_errors++;
  2372. goto NextFrame;
  2373. }
  2374. if (p_env->packing == DO_PACKED) {
  2375. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  2376. p_packd+sizeof(struct clawph), bytes_to_mov);
  2377. } else {
  2378. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  2379. p_this_ccw->p_buffer, bytes_to_mov);
  2380. }
  2381. if (mtc_this_frm==0) {
  2382. len_of_data=privptr->mtc_offset+bytes_to_mov;
  2383. skb=dev_alloc_skb(len_of_data);
  2384. if (skb) {
  2385. memcpy(skb_put(skb,len_of_data),
  2386. privptr->p_mtc_envelope,
  2387. len_of_data);
  2388. skb->dev=dev;
  2389. skb_reset_mac_header(skb);
  2390. skb->protocol=htons(ETH_P_IP);
  2391. skb->ip_summed=CHECKSUM_UNNECESSARY;
  2392. privptr->stats.rx_packets++;
  2393. privptr->stats.rx_bytes+=len_of_data;
  2394. netif_rx(skb);
  2395. }
  2396. else {
  2397. privptr->stats.rx_dropped++;
  2398. printk(KERN_WARNING "%s: %s() low on memory\n",
  2399. dev->name,__func__);
  2400. }
  2401. privptr->mtc_offset=0;
  2402. privptr->mtc_logical_link=-1;
  2403. }
  2404. else {
  2405. privptr->mtc_offset+=bytes_to_mov;
  2406. }
  2407. if (p_env->packing == DO_PACKED)
  2408. goto unpack_next;
  2409. NextFrame:
  2410. /*
  2411. * Remove ThisCCWblock from active read queue, and add it
  2412. * to queue of free blocks to be reused.
  2413. */
  2414. i++;
  2415. p_this_ccw->header.length=0xffff;
  2416. p_this_ccw->header.opcode=0xff;
  2417. /*
  2418. * add this one to the free queue for later reuse
  2419. */
  2420. if (p_first_ccw==NULL) {
  2421. p_first_ccw = p_this_ccw;
  2422. }
  2423. else {
  2424. p_last_ccw->next = p_this_ccw;
  2425. }
  2426. p_last_ccw = p_this_ccw;
  2427. /*
  2428. * chain to next block on active read queue
  2429. */
  2430. p_this_ccw = privptr->p_read_active_first;
  2431. CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
  2432. } /* end of while */
  2433. /* check validity */
  2434. CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
  2435. add_claw_reads(dev, p_first_ccw, p_last_ccw);
  2436. claw_strt_read(dev, LOCK_YES);
  2437. return;
  2438. } /* end of unpack_read */
  2439. /*-------------------------------------------------------------------*
  2440. * claw_strt_read *
  2441. * *
  2442. *--------------------------------------------------------------------*/
  2443. static void
  2444. claw_strt_read (struct net_device *dev, int lock )
  2445. {
  2446. int rc = 0;
  2447. __u32 parm;
  2448. unsigned long saveflags = 0;
  2449. struct claw_privbk *privptr=dev->priv;
  2450. struct ccwbk*p_ccwbk;
  2451. struct chbk *p_ch;
  2452. struct clawh *p_clawh;
  2453. p_ch=&privptr->channel[READ];
  2454. CLAW_DBF_TEXT(4, trace, "StRdNter");
  2455. p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
  2456. p_clawh->flag=CLAW_IDLE; /* 0x00 */
  2457. if ((privptr->p_write_active_first!=NULL &&
  2458. privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
  2459. (privptr->p_read_active_first!=NULL &&
  2460. privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
  2461. p_clawh->flag=CLAW_BUSY; /* 0xff */
  2462. }
  2463. if (lock==LOCK_YES) {
  2464. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  2465. }
  2466. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  2467. CLAW_DBF_TEXT(4, trace, "HotRead");
  2468. p_ccwbk=privptr->p_read_active_first;
  2469. parm = (unsigned long) p_ch;
  2470. rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
  2471. 0xff, 0);
  2472. if (rc != 0) {
  2473. ccw_check_return_code(p_ch->cdev, rc);
  2474. }
  2475. }
  2476. else {
  2477. CLAW_DBF_TEXT(2, trace, "ReadAct");
  2478. }
  2479. if (lock==LOCK_YES) {
  2480. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  2481. }
  2482. CLAW_DBF_TEXT(4, trace, "StRdExit");
  2483. return;
  2484. } /* end of claw_strt_read */
  2485. /*-------------------------------------------------------------------*
  2486. * claw_strt_out_IO *
  2487. * *
  2488. *--------------------------------------------------------------------*/
  2489. static void
  2490. claw_strt_out_IO( struct net_device *dev )
  2491. {
  2492. int rc = 0;
  2493. unsigned long parm;
  2494. struct claw_privbk *privptr;
  2495. struct chbk *p_ch;
  2496. struct ccwbk *p_first_ccw;
  2497. if (!dev) {
  2498. return;
  2499. }
  2500. privptr=(struct claw_privbk *)dev->priv;
  2501. p_ch=&privptr->channel[WRITE];
  2502. CLAW_DBF_TEXT(4, trace, "strt_io");
  2503. p_first_ccw=privptr->p_write_active_first;
  2504. if (p_ch->claw_state == CLAW_STOP)
  2505. return;
  2506. if (p_first_ccw == NULL) {
  2507. return;
  2508. }
  2509. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  2510. parm = (unsigned long) p_ch;
  2511. CLAW_DBF_TEXT(2, trace, "StWrtIO");
  2512. rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
  2513. 0xff, 0);
  2514. if (rc != 0) {
  2515. ccw_check_return_code(p_ch->cdev, rc);
  2516. }
  2517. }
  2518. dev->trans_start = jiffies;
  2519. return;
  2520. } /* end of claw_strt_out_IO */
  2521. /*-------------------------------------------------------------------*
  2522. * Free write buffers *
  2523. * *
  2524. *--------------------------------------------------------------------*/
  2525. static void
  2526. claw_free_wrt_buf( struct net_device *dev )
  2527. {
  2528. struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
  2529. struct ccwbk*p_first_ccw;
  2530. struct ccwbk*p_last_ccw;
  2531. struct ccwbk*p_this_ccw;
  2532. struct ccwbk*p_next_ccw;
  2533. CLAW_DBF_TEXT(4, trace, "freewrtb");
  2534. /* scan the write queue to free any completed write packets */
  2535. p_first_ccw=NULL;
  2536. p_last_ccw=NULL;
  2537. p_this_ccw=privptr->p_write_active_first;
  2538. while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
  2539. {
  2540. p_next_ccw = p_this_ccw->next;
  2541. if (((p_next_ccw!=NULL) &&
  2542. (p_next_ccw->header.flag!=CLAW_PENDING)) ||
  2543. ((p_this_ccw == privptr->p_write_active_last) &&
  2544. (p_this_ccw->header.flag!=CLAW_PENDING))) {
  2545. /* The next CCW is OK or this is */
  2546. /* the last CCW...free it @A1A */
  2547. privptr->p_write_active_first=p_this_ccw->next;
  2548. p_this_ccw->header.flag=CLAW_PENDING;
  2549. p_this_ccw->next=privptr->p_write_free_chain;
  2550. privptr->p_write_free_chain=p_this_ccw;
  2551. ++privptr->write_free_count;
  2552. privptr->stats.tx_bytes+= p_this_ccw->write.count;
  2553. p_this_ccw=privptr->p_write_active_first;
  2554. privptr->stats.tx_packets++;
  2555. }
  2556. else {
  2557. break;
  2558. }
  2559. }
  2560. if (privptr->write_free_count!=0) {
  2561. claw_clearbit_busy(TB_NOBUFFER,dev);
  2562. }
  2563. /* whole chain removed? */
  2564. if (privptr->p_write_active_first==NULL) {
  2565. privptr->p_write_active_last=NULL;
  2566. }
  2567. CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
  2568. return;
  2569. }
  2570. /*-------------------------------------------------------------------*
  2571. * claw free netdevice *
  2572. * *
  2573. *--------------------------------------------------------------------*/
  2574. static void
  2575. claw_free_netdevice(struct net_device * dev, int free_dev)
  2576. {
  2577. struct claw_privbk *privptr;
  2578. CLAW_DBF_TEXT(2, setup, "free_dev");
  2579. if (!dev)
  2580. return;
  2581. CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
  2582. privptr = dev->priv;
  2583. if (dev->flags & IFF_RUNNING)
  2584. claw_release(dev);
  2585. if (privptr) {
  2586. privptr->channel[READ].ndev = NULL; /* say it's free */
  2587. }
  2588. dev->priv=NULL;
  2589. #ifdef MODULE
  2590. if (free_dev) {
  2591. free_netdev(dev);
  2592. }
  2593. #endif
  2594. CLAW_DBF_TEXT(2, setup, "free_ok");
  2595. }
  2596. /**
  2597. * Claw init netdevice
  2598. * Initialize everything of the net device except the name and the
  2599. * channel structs.
  2600. */
  2601. static void
  2602. claw_init_netdevice(struct net_device * dev)
  2603. {
  2604. CLAW_DBF_TEXT(2, setup, "init_dev");
  2605. CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
  2606. dev->mtu = CLAW_DEFAULT_MTU_SIZE;
  2607. dev->hard_start_xmit = claw_tx;
  2608. dev->open = claw_open;
  2609. dev->stop = claw_release;
  2610. dev->get_stats = claw_stats;
  2611. dev->change_mtu = claw_change_mtu;
  2612. dev->hard_header_len = 0;
  2613. dev->addr_len = 0;
  2614. dev->type = ARPHRD_SLIP;
  2615. dev->tx_queue_len = 1300;
  2616. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  2617. CLAW_DBF_TEXT(2, setup, "initok");
  2618. return;
  2619. }
  2620. /**
  2621. * Init a new channel in the privptr->channel[i].
  2622. *
  2623. * @param cdev The ccw_device to be added.
  2624. *
  2625. * @return 0 on success, !0 on error.
  2626. */
  2627. static int
  2628. add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
  2629. {
  2630. struct chbk *p_ch;
  2631. struct ccw_dev_id dev_id;
  2632. CLAW_DBF_TEXT_(2, setup, "%s", cdev->dev.bus_id);
  2633. privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
  2634. p_ch = &privptr->channel[i];
  2635. p_ch->cdev = cdev;
  2636. snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
  2637. ccw_device_get_id(cdev, &dev_id);
  2638. p_ch->devno = dev_id.devno;
  2639. if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
  2640. return -ENOMEM;
  2641. }
  2642. return 0;
  2643. }
  2644. /**
  2645. *
  2646. * Setup an interface.
  2647. *
  2648. * @param cgdev Device to be setup.
  2649. *
  2650. * @returns 0 on success, !0 on failure.
  2651. */
  2652. static int
  2653. claw_new_device(struct ccwgroup_device *cgdev)
  2654. {
  2655. struct claw_privbk *privptr;
  2656. struct claw_env *p_env;
  2657. struct net_device *dev;
  2658. int ret;
  2659. struct ccw_dev_id dev_id;
  2660. printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
  2661. CLAW_DBF_TEXT(2, setup, "new_dev");
  2662. privptr = cgdev->dev.driver_data;
  2663. cgdev->cdev[READ]->dev.driver_data = privptr;
  2664. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  2665. if (!privptr)
  2666. return -ENODEV;
  2667. p_env = privptr->p_env;
  2668. ccw_device_get_id(cgdev->cdev[READ], &dev_id);
  2669. p_env->devno[READ] = dev_id.devno;
  2670. ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
  2671. p_env->devno[WRITE] = dev_id.devno;
  2672. ret = add_channel(cgdev->cdev[0],0,privptr);
  2673. if (ret == 0)
  2674. ret = add_channel(cgdev->cdev[1],1,privptr);
  2675. if (ret != 0) {
  2676. printk(KERN_WARNING
  2677. "add channel failed with ret = %d\n", ret);
  2678. goto out;
  2679. }
  2680. ret = ccw_device_set_online(cgdev->cdev[READ]);
  2681. if (ret != 0) {
  2682. printk(KERN_WARNING
  2683. "claw: ccw_device_set_online %s READ failed "
  2684. "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
  2685. goto out;
  2686. }
  2687. ret = ccw_device_set_online(cgdev->cdev[WRITE]);
  2688. if (ret != 0) {
  2689. printk(KERN_WARNING
  2690. "claw: ccw_device_set_online %s WRITE failed "
  2691. "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
  2692. goto out;
  2693. }
  2694. dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
  2695. if (!dev) {
  2696. printk(KERN_WARNING "%s:alloc_netdev failed\n",__func__);
  2697. goto out;
  2698. }
  2699. dev->priv = privptr;
  2700. cgdev->dev.driver_data = privptr;
  2701. cgdev->cdev[READ]->dev.driver_data = privptr;
  2702. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  2703. /* sysfs magic */
  2704. SET_NETDEV_DEV(dev, &cgdev->dev);
  2705. if (register_netdev(dev) != 0) {
  2706. claw_free_netdevice(dev, 1);
  2707. CLAW_DBF_TEXT(2, trace, "regfail");
  2708. goto out;
  2709. }
  2710. dev->flags &=~IFF_RUNNING;
  2711. if (privptr->buffs_alloc == 0) {
  2712. ret=init_ccw_bk(dev);
  2713. if (ret !=0) {
  2714. unregister_netdev(dev);
  2715. claw_free_netdevice(dev,1);
  2716. CLAW_DBF_TEXT(2, trace, "ccwmem");
  2717. goto out;
  2718. }
  2719. }
  2720. privptr->channel[READ].ndev = dev;
  2721. privptr->channel[WRITE].ndev = dev;
  2722. privptr->p_env->ndev = dev;
  2723. printk(KERN_INFO "%s:readsize=%d writesize=%d "
  2724. "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
  2725. dev->name, p_env->read_size,
  2726. p_env->write_size, p_env->read_buffers,
  2727. p_env->write_buffers, p_env->devno[READ],
  2728. p_env->devno[WRITE]);
  2729. printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
  2730. ":%.8s api_type: %.8s\n",
  2731. dev->name, p_env->host_name,
  2732. p_env->adapter_name , p_env->api_type);
  2733. return 0;
  2734. out:
  2735. ccw_device_set_offline(cgdev->cdev[1]);
  2736. ccw_device_set_offline(cgdev->cdev[0]);
  2737. return -ENODEV;
  2738. }
  2739. static void
  2740. claw_purge_skb_queue(struct sk_buff_head *q)
  2741. {
  2742. struct sk_buff *skb;
  2743. CLAW_DBF_TEXT(4, trace, "purgque");
  2744. while ((skb = skb_dequeue(q))) {
  2745. atomic_dec(&skb->users);
  2746. dev_kfree_skb_any(skb);
  2747. }
  2748. }
  2749. /**
  2750. * Shutdown an interface.
  2751. *
  2752. * @param cgdev Device to be shut down.
  2753. *
  2754. * @returns 0 on success, !0 on failure.
  2755. */
  2756. static int
  2757. claw_shutdown_device(struct ccwgroup_device *cgdev)
  2758. {
  2759. struct claw_privbk *priv;
  2760. struct net_device *ndev;
  2761. int ret;
  2762. CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
  2763. priv = cgdev->dev.driver_data;
  2764. if (!priv)
  2765. return -ENODEV;
  2766. ndev = priv->channel[READ].ndev;
  2767. if (ndev) {
  2768. /* Close the device */
  2769. printk(KERN_INFO
  2770. "%s: shuting down \n",ndev->name);
  2771. if (ndev->flags & IFF_RUNNING)
  2772. ret = claw_release(ndev);
  2773. ndev->flags &=~IFF_RUNNING;
  2774. unregister_netdev(ndev);
  2775. ndev->priv = NULL; /* cgdev data, not ndev's to free */
  2776. claw_free_netdevice(ndev, 1);
  2777. priv->channel[READ].ndev = NULL;
  2778. priv->channel[WRITE].ndev = NULL;
  2779. priv->p_env->ndev = NULL;
  2780. }
  2781. ccw_device_set_offline(cgdev->cdev[1]);
  2782. ccw_device_set_offline(cgdev->cdev[0]);
  2783. return 0;
  2784. }
  2785. static void
  2786. claw_remove_device(struct ccwgroup_device *cgdev)
  2787. {
  2788. struct claw_privbk *priv;
  2789. BUG_ON(!cgdev);
  2790. CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
  2791. priv = cgdev->dev.driver_data;
  2792. BUG_ON(!priv);
  2793. printk(KERN_INFO "claw: %s() called %s will be removed.\n",
  2794. __func__,cgdev->cdev[0]->dev.bus_id);
  2795. if (cgdev->state == CCWGROUP_ONLINE)
  2796. claw_shutdown_device(cgdev);
  2797. claw_remove_files(&cgdev->dev);
  2798. kfree(priv->p_mtc_envelope);
  2799. priv->p_mtc_envelope=NULL;
  2800. kfree(priv->p_env);
  2801. priv->p_env=NULL;
  2802. kfree(priv->channel[0].irb);
  2803. priv->channel[0].irb=NULL;
  2804. kfree(priv->channel[1].irb);
  2805. priv->channel[1].irb=NULL;
  2806. kfree(priv);
  2807. cgdev->dev.driver_data=NULL;
  2808. cgdev->cdev[READ]->dev.driver_data = NULL;
  2809. cgdev->cdev[WRITE]->dev.driver_data = NULL;
  2810. put_device(&cgdev->dev);
  2811. return;
  2812. }
  2813. /*
  2814. * sysfs attributes
  2815. */
  2816. static ssize_t
  2817. claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2818. {
  2819. struct claw_privbk *priv;
  2820. struct claw_env * p_env;
  2821. priv = dev->driver_data;
  2822. if (!priv)
  2823. return -ENODEV;
  2824. p_env = priv->p_env;
  2825. return sprintf(buf, "%s\n",p_env->host_name);
  2826. }
  2827. static ssize_t
  2828. claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2829. {
  2830. struct claw_privbk *priv;
  2831. struct claw_env * p_env;
  2832. priv = dev->driver_data;
  2833. if (!priv)
  2834. return -ENODEV;
  2835. p_env = priv->p_env;
  2836. if (count > MAX_NAME_LEN+1)
  2837. return -EINVAL;
  2838. memset(p_env->host_name, 0x20, MAX_NAME_LEN);
  2839. strncpy(p_env->host_name,buf, count);
  2840. p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
  2841. p_env->host_name[MAX_NAME_LEN] = 0x00;
  2842. CLAW_DBF_TEXT(2, setup, "HstnSet");
  2843. CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
  2844. return count;
  2845. }
  2846. static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
  2847. static ssize_t
  2848. claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2849. {
  2850. struct claw_privbk *priv;
  2851. struct claw_env * p_env;
  2852. priv = dev->driver_data;
  2853. if (!priv)
  2854. return -ENODEV;
  2855. p_env = priv->p_env;
  2856. return sprintf(buf, "%s\n", p_env->adapter_name);
  2857. }
  2858. static ssize_t
  2859. claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2860. {
  2861. struct claw_privbk *priv;
  2862. struct claw_env * p_env;
  2863. priv = dev->driver_data;
  2864. if (!priv)
  2865. return -ENODEV;
  2866. p_env = priv->p_env;
  2867. if (count > MAX_NAME_LEN+1)
  2868. return -EINVAL;
  2869. memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
  2870. strncpy(p_env->adapter_name,buf, count);
  2871. p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
  2872. p_env->adapter_name[MAX_NAME_LEN] = 0x00;
  2873. CLAW_DBF_TEXT(2, setup, "AdnSet");
  2874. CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
  2875. return count;
  2876. }
  2877. static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
  2878. static ssize_t
  2879. claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2880. {
  2881. struct claw_privbk *priv;
  2882. struct claw_env * p_env;
  2883. priv = dev->driver_data;
  2884. if (!priv)
  2885. return -ENODEV;
  2886. p_env = priv->p_env;
  2887. return sprintf(buf, "%s\n",
  2888. p_env->api_type);
  2889. }
  2890. static ssize_t
  2891. claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2892. {
  2893. struct claw_privbk *priv;
  2894. struct claw_env * p_env;
  2895. priv = dev->driver_data;
  2896. if (!priv)
  2897. return -ENODEV;
  2898. p_env = priv->p_env;
  2899. if (count > MAX_NAME_LEN+1)
  2900. return -EINVAL;
  2901. memset(p_env->api_type, 0x20, MAX_NAME_LEN);
  2902. strncpy(p_env->api_type,buf, count);
  2903. p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
  2904. p_env->api_type[MAX_NAME_LEN] = 0x00;
  2905. if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  2906. p_env->read_size=DEF_PACK_BUFSIZE;
  2907. p_env->write_size=DEF_PACK_BUFSIZE;
  2908. p_env->packing=PACKING_ASK;
  2909. CLAW_DBF_TEXT(2, setup, "PACKING");
  2910. }
  2911. else {
  2912. p_env->packing=0;
  2913. p_env->read_size=CLAW_FRAME_SIZE;
  2914. p_env->write_size=CLAW_FRAME_SIZE;
  2915. CLAW_DBF_TEXT(2, setup, "ApiSet");
  2916. }
  2917. CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
  2918. return count;
  2919. }
  2920. static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
  2921. static ssize_t
  2922. claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  2923. {
  2924. struct claw_privbk *priv;
  2925. struct claw_env * p_env;
  2926. priv = dev->driver_data;
  2927. if (!priv)
  2928. return -ENODEV;
  2929. p_env = priv->p_env;
  2930. return sprintf(buf, "%d\n", p_env->write_buffers);
  2931. }
  2932. static ssize_t
  2933. claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2934. {
  2935. struct claw_privbk *priv;
  2936. struct claw_env * p_env;
  2937. int nnn,max;
  2938. priv = dev->driver_data;
  2939. if (!priv)
  2940. return -ENODEV;
  2941. p_env = priv->p_env;
  2942. sscanf(buf, "%i", &nnn);
  2943. if (p_env->packing) {
  2944. max = 64;
  2945. }
  2946. else {
  2947. max = 512;
  2948. }
  2949. if ((nnn > max ) || (nnn < 2))
  2950. return -EINVAL;
  2951. p_env->write_buffers = nnn;
  2952. CLAW_DBF_TEXT(2, setup, "Wbufset");
  2953. CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
  2954. return count;
  2955. }
  2956. static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
  2957. static ssize_t
  2958. claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  2959. {
  2960. struct claw_privbk *priv;
  2961. struct claw_env * p_env;
  2962. priv = dev->driver_data;
  2963. if (!priv)
  2964. return -ENODEV;
  2965. p_env = priv->p_env;
  2966. return sprintf(buf, "%d\n", p_env->read_buffers);
  2967. }
  2968. static ssize_t
  2969. claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2970. {
  2971. struct claw_privbk *priv;
  2972. struct claw_env *p_env;
  2973. int nnn,max;
  2974. priv = dev->driver_data;
  2975. if (!priv)
  2976. return -ENODEV;
  2977. p_env = priv->p_env;
  2978. sscanf(buf, "%i", &nnn);
  2979. if (p_env->packing) {
  2980. max = 64;
  2981. }
  2982. else {
  2983. max = 512;
  2984. }
  2985. if ((nnn > max ) || (nnn < 2))
  2986. return -EINVAL;
  2987. p_env->read_buffers = nnn;
  2988. CLAW_DBF_TEXT(2, setup, "Rbufset");
  2989. CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
  2990. return count;
  2991. }
  2992. static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
  2993. static struct attribute *claw_attr[] = {
  2994. &dev_attr_read_buffer.attr,
  2995. &dev_attr_write_buffer.attr,
  2996. &dev_attr_adapter_name.attr,
  2997. &dev_attr_api_type.attr,
  2998. &dev_attr_host_name.attr,
  2999. NULL,
  3000. };
  3001. static struct attribute_group claw_attr_group = {
  3002. .attrs = claw_attr,
  3003. };
  3004. static int
  3005. claw_add_files(struct device *dev)
  3006. {
  3007. CLAW_DBF_TEXT(2, setup, "add_file");
  3008. return sysfs_create_group(&dev->kobj, &claw_attr_group);
  3009. }
  3010. static void
  3011. claw_remove_files(struct device *dev)
  3012. {
  3013. CLAW_DBF_TEXT(2, setup, "rem_file");
  3014. sysfs_remove_group(&dev->kobj, &claw_attr_group);
  3015. }
  3016. /*--------------------------------------------------------------------*
  3017. * claw_init and cleanup *
  3018. *---------------------------------------------------------------------*/
  3019. static void __exit
  3020. claw_cleanup(void)
  3021. {
  3022. unregister_cu3088_discipline(&claw_group_driver);
  3023. claw_unregister_debug_facility();
  3024. printk(KERN_INFO "claw: Driver unloaded\n");
  3025. }
  3026. /**
  3027. * Initialize module.
  3028. * This is called just after the module is loaded.
  3029. *
  3030. * @return 0 on success, !0 on error.
  3031. */
  3032. static int __init
  3033. claw_init(void)
  3034. {
  3035. int ret = 0;
  3036. printk(KERN_INFO "claw: starting driver\n");
  3037. ret = claw_register_debug_facility();
  3038. if (ret) {
  3039. printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
  3040. __func__,ret);
  3041. return ret;
  3042. }
  3043. CLAW_DBF_TEXT(2, setup, "init_mod");
  3044. ret = register_cu3088_discipline(&claw_group_driver);
  3045. if (ret) {
  3046. CLAW_DBF_TEXT(2, setup, "init_bad");
  3047. claw_unregister_debug_facility();
  3048. printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
  3049. __func__,ret);
  3050. }
  3051. return ret;
  3052. }
  3053. module_init(claw_init);
  3054. module_exit(claw_cleanup);
  3055. MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
  3056. MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
  3057. "Copyright 2000,2008 IBM Corporation\n");
  3058. MODULE_LICENSE("GPL");