claw.c 114 KB

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