claw.c 115 KB

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