claw.c 115 KB

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