claw.c 114 KB

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