claw.c 115 KB

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