claw.c 113 KB

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