claw.c 113 KB

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