claw.c 114 KB

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