claw.c 115 KB

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