claw.c 114 KB

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