claw.c 113 KB

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