qeth_core_main.c 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774
  1. /*
  2. * drivers/s390/net/qeth_core_main.c
  3. *
  4. * Copyright IBM Corp. 2007, 2009
  5. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  6. * Frank Pavlic <fpavlic@de.ibm.com>,
  7. * Thomas Spatzier <tspat@de.ibm.com>,
  8. * Frank Blaschka <frank.blaschka@de.ibm.com>
  9. */
  10. #define KMSG_COMPONENT "qeth"
  11. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel.h>
  17. #include <linux/ip.h>
  18. #include <linux/tcp.h>
  19. #include <linux/mii.h>
  20. #include <linux/kthread.h>
  21. #include <linux/slab.h>
  22. #include <asm/ebcdic.h>
  23. #include <asm/io.h>
  24. #include "qeth_core.h"
  25. struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
  26. /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
  27. /* N P A M L V H */
  28. [QETH_DBF_SETUP] = {"qeth_setup",
  29. 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
  30. [QETH_DBF_MSG] = {"qeth_msg",
  31. 8, 1, 128, 3, &debug_sprintf_view, NULL},
  32. [QETH_DBF_CTRL] = {"qeth_control",
  33. 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
  34. };
  35. EXPORT_SYMBOL_GPL(qeth_dbf);
  36. struct qeth_card_list_struct qeth_core_card_list;
  37. EXPORT_SYMBOL_GPL(qeth_core_card_list);
  38. struct kmem_cache *qeth_core_header_cache;
  39. EXPORT_SYMBOL_GPL(qeth_core_header_cache);
  40. static struct device *qeth_core_root_dev;
  41. static unsigned int known_devices[][6] = QETH_MODELLIST_ARRAY;
  42. static struct lock_class_key qdio_out_skb_queue_key;
  43. static void qeth_send_control_data_cb(struct qeth_channel *,
  44. struct qeth_cmd_buffer *);
  45. static int qeth_issue_next_read(struct qeth_card *);
  46. static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *);
  47. static void qeth_setup_ccw(struct qeth_channel *, unsigned char *, __u32);
  48. static void qeth_free_buffer_pool(struct qeth_card *);
  49. static int qeth_qdio_establish(struct qeth_card *);
  50. static inline const char *qeth_get_cardname(struct qeth_card *card)
  51. {
  52. if (card->info.guestlan) {
  53. switch (card->info.type) {
  54. case QETH_CARD_TYPE_OSD:
  55. return " Guest LAN QDIO";
  56. case QETH_CARD_TYPE_IQD:
  57. return " Guest LAN Hiper";
  58. case QETH_CARD_TYPE_OSM:
  59. return " Guest LAN QDIO - OSM";
  60. case QETH_CARD_TYPE_OSX:
  61. return " Guest LAN QDIO - OSX";
  62. default:
  63. return " unknown";
  64. }
  65. } else {
  66. switch (card->info.type) {
  67. case QETH_CARD_TYPE_OSD:
  68. return " OSD Express";
  69. case QETH_CARD_TYPE_IQD:
  70. return " HiperSockets";
  71. case QETH_CARD_TYPE_OSN:
  72. return " OSN QDIO";
  73. case QETH_CARD_TYPE_OSM:
  74. return " OSM QDIO";
  75. case QETH_CARD_TYPE_OSX:
  76. return " OSX QDIO";
  77. default:
  78. return " unknown";
  79. }
  80. }
  81. return " n/a";
  82. }
  83. /* max length to be returned: 14 */
  84. const char *qeth_get_cardname_short(struct qeth_card *card)
  85. {
  86. if (card->info.guestlan) {
  87. switch (card->info.type) {
  88. case QETH_CARD_TYPE_OSD:
  89. return "GuestLAN QDIO";
  90. case QETH_CARD_TYPE_IQD:
  91. return "GuestLAN Hiper";
  92. case QETH_CARD_TYPE_OSM:
  93. return "GuestLAN OSM";
  94. case QETH_CARD_TYPE_OSX:
  95. return "GuestLAN OSX";
  96. default:
  97. return "unknown";
  98. }
  99. } else {
  100. switch (card->info.type) {
  101. case QETH_CARD_TYPE_OSD:
  102. switch (card->info.link_type) {
  103. case QETH_LINK_TYPE_FAST_ETH:
  104. return "OSD_100";
  105. case QETH_LINK_TYPE_HSTR:
  106. return "HSTR";
  107. case QETH_LINK_TYPE_GBIT_ETH:
  108. return "OSD_1000";
  109. case QETH_LINK_TYPE_10GBIT_ETH:
  110. return "OSD_10GIG";
  111. case QETH_LINK_TYPE_LANE_ETH100:
  112. return "OSD_FE_LANE";
  113. case QETH_LINK_TYPE_LANE_TR:
  114. return "OSD_TR_LANE";
  115. case QETH_LINK_TYPE_LANE_ETH1000:
  116. return "OSD_GbE_LANE";
  117. case QETH_LINK_TYPE_LANE:
  118. return "OSD_ATM_LANE";
  119. default:
  120. return "OSD_Express";
  121. }
  122. case QETH_CARD_TYPE_IQD:
  123. return "HiperSockets";
  124. case QETH_CARD_TYPE_OSN:
  125. return "OSN";
  126. case QETH_CARD_TYPE_OSM:
  127. return "OSM_1000";
  128. case QETH_CARD_TYPE_OSX:
  129. return "OSX_10GIG";
  130. default:
  131. return "unknown";
  132. }
  133. }
  134. return "n/a";
  135. }
  136. void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
  137. int clear_start_mask)
  138. {
  139. unsigned long flags;
  140. spin_lock_irqsave(&card->thread_mask_lock, flags);
  141. card->thread_allowed_mask = threads;
  142. if (clear_start_mask)
  143. card->thread_start_mask &= threads;
  144. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  145. wake_up(&card->wait_q);
  146. }
  147. EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
  148. int qeth_threads_running(struct qeth_card *card, unsigned long threads)
  149. {
  150. unsigned long flags;
  151. int rc = 0;
  152. spin_lock_irqsave(&card->thread_mask_lock, flags);
  153. rc = (card->thread_running_mask & threads);
  154. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  155. return rc;
  156. }
  157. EXPORT_SYMBOL_GPL(qeth_threads_running);
  158. int qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
  159. {
  160. return wait_event_interruptible(card->wait_q,
  161. qeth_threads_running(card, threads) == 0);
  162. }
  163. EXPORT_SYMBOL_GPL(qeth_wait_for_threads);
  164. void qeth_clear_working_pool_list(struct qeth_card *card)
  165. {
  166. struct qeth_buffer_pool_entry *pool_entry, *tmp;
  167. QETH_CARD_TEXT(card, 5, "clwrklst");
  168. list_for_each_entry_safe(pool_entry, tmp,
  169. &card->qdio.in_buf_pool.entry_list, list){
  170. list_del(&pool_entry->list);
  171. }
  172. }
  173. EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list);
  174. static int qeth_alloc_buffer_pool(struct qeth_card *card)
  175. {
  176. struct qeth_buffer_pool_entry *pool_entry;
  177. void *ptr;
  178. int i, j;
  179. QETH_CARD_TEXT(card, 5, "alocpool");
  180. for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
  181. pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
  182. if (!pool_entry) {
  183. qeth_free_buffer_pool(card);
  184. return -ENOMEM;
  185. }
  186. for (j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j) {
  187. ptr = (void *) __get_free_page(GFP_KERNEL);
  188. if (!ptr) {
  189. while (j > 0)
  190. free_page((unsigned long)
  191. pool_entry->elements[--j]);
  192. kfree(pool_entry);
  193. qeth_free_buffer_pool(card);
  194. return -ENOMEM;
  195. }
  196. pool_entry->elements[j] = ptr;
  197. }
  198. list_add(&pool_entry->init_list,
  199. &card->qdio.init_pool.entry_list);
  200. }
  201. return 0;
  202. }
  203. int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
  204. {
  205. QETH_CARD_TEXT(card, 2, "realcbp");
  206. if ((card->state != CARD_STATE_DOWN) &&
  207. (card->state != CARD_STATE_RECOVER))
  208. return -EPERM;
  209. /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
  210. qeth_clear_working_pool_list(card);
  211. qeth_free_buffer_pool(card);
  212. card->qdio.in_buf_pool.buf_count = bufcnt;
  213. card->qdio.init_pool.buf_count = bufcnt;
  214. return qeth_alloc_buffer_pool(card);
  215. }
  216. EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool);
  217. static int qeth_issue_next_read(struct qeth_card *card)
  218. {
  219. int rc;
  220. struct qeth_cmd_buffer *iob;
  221. QETH_CARD_TEXT(card, 5, "issnxrd");
  222. if (card->read.state != CH_STATE_UP)
  223. return -EIO;
  224. iob = qeth_get_buffer(&card->read);
  225. if (!iob) {
  226. dev_warn(&card->gdev->dev, "The qeth device driver "
  227. "failed to recover an error on the device\n");
  228. QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
  229. "available\n", dev_name(&card->gdev->dev));
  230. return -ENOMEM;
  231. }
  232. qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
  233. QETH_CARD_TEXT(card, 6, "noirqpnd");
  234. rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
  235. (addr_t) iob, 0, 0);
  236. if (rc) {
  237. QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
  238. "rc=%i\n", dev_name(&card->gdev->dev), rc);
  239. atomic_set(&card->read.irq_pending, 0);
  240. qeth_schedule_recovery(card);
  241. wake_up(&card->wait_q);
  242. }
  243. return rc;
  244. }
  245. static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
  246. {
  247. struct qeth_reply *reply;
  248. reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
  249. if (reply) {
  250. atomic_set(&reply->refcnt, 1);
  251. atomic_set(&reply->received, 0);
  252. reply->card = card;
  253. };
  254. return reply;
  255. }
  256. static void qeth_get_reply(struct qeth_reply *reply)
  257. {
  258. WARN_ON(atomic_read(&reply->refcnt) <= 0);
  259. atomic_inc(&reply->refcnt);
  260. }
  261. static void qeth_put_reply(struct qeth_reply *reply)
  262. {
  263. WARN_ON(atomic_read(&reply->refcnt) <= 0);
  264. if (atomic_dec_and_test(&reply->refcnt))
  265. kfree(reply);
  266. }
  267. static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
  268. struct qeth_card *card)
  269. {
  270. char *ipa_name;
  271. int com = cmd->hdr.command;
  272. ipa_name = qeth_get_ipa_cmd_name(com);
  273. if (rc)
  274. QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s returned x%X \"%s\"\n",
  275. ipa_name, com, QETH_CARD_IFNAME(card),
  276. rc, qeth_get_ipa_msg(rc));
  277. else
  278. QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s succeeded\n",
  279. ipa_name, com, QETH_CARD_IFNAME(card));
  280. }
  281. static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
  282. struct qeth_cmd_buffer *iob)
  283. {
  284. struct qeth_ipa_cmd *cmd = NULL;
  285. QETH_CARD_TEXT(card, 5, "chkipad");
  286. if (IS_IPA(iob->data)) {
  287. cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
  288. if (IS_IPA_REPLY(cmd)) {
  289. if (cmd->hdr.command != IPA_CMD_SETCCID &&
  290. cmd->hdr.command != IPA_CMD_DELCCID &&
  291. cmd->hdr.command != IPA_CMD_MODCCID &&
  292. cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
  293. qeth_issue_ipa_msg(cmd,
  294. cmd->hdr.return_code, card);
  295. return cmd;
  296. } else {
  297. switch (cmd->hdr.command) {
  298. case IPA_CMD_STOPLAN:
  299. dev_warn(&card->gdev->dev,
  300. "The link for interface %s on CHPID"
  301. " 0x%X failed\n",
  302. QETH_CARD_IFNAME(card),
  303. card->info.chpid);
  304. card->lan_online = 0;
  305. if (card->dev && netif_carrier_ok(card->dev))
  306. netif_carrier_off(card->dev);
  307. return NULL;
  308. case IPA_CMD_STARTLAN:
  309. dev_info(&card->gdev->dev,
  310. "The link for %s on CHPID 0x%X has"
  311. " been restored\n",
  312. QETH_CARD_IFNAME(card),
  313. card->info.chpid);
  314. netif_carrier_on(card->dev);
  315. card->lan_online = 1;
  316. qeth_schedule_recovery(card);
  317. return NULL;
  318. case IPA_CMD_MODCCID:
  319. return cmd;
  320. case IPA_CMD_REGISTER_LOCAL_ADDR:
  321. QETH_CARD_TEXT(card, 3, "irla");
  322. break;
  323. case IPA_CMD_UNREGISTER_LOCAL_ADDR:
  324. QETH_CARD_TEXT(card, 3, "urla");
  325. break;
  326. default:
  327. QETH_DBF_MESSAGE(2, "Received data is IPA "
  328. "but not a reply!\n");
  329. break;
  330. }
  331. }
  332. }
  333. return cmd;
  334. }
  335. void qeth_clear_ipacmd_list(struct qeth_card *card)
  336. {
  337. struct qeth_reply *reply, *r;
  338. unsigned long flags;
  339. QETH_CARD_TEXT(card, 4, "clipalst");
  340. spin_lock_irqsave(&card->lock, flags);
  341. list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
  342. qeth_get_reply(reply);
  343. reply->rc = -EIO;
  344. atomic_inc(&reply->received);
  345. list_del_init(&reply->list);
  346. wake_up(&reply->wait_q);
  347. qeth_put_reply(reply);
  348. }
  349. spin_unlock_irqrestore(&card->lock, flags);
  350. }
  351. EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list);
  352. static int qeth_check_idx_response(struct qeth_card *card,
  353. unsigned char *buffer)
  354. {
  355. if (!buffer)
  356. return 0;
  357. QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
  358. if ((buffer[2] & 0xc0) == 0xc0) {
  359. QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
  360. "with cause code 0x%02x%s\n",
  361. buffer[4],
  362. ((buffer[4] == 0x22) ?
  363. " -- try another portname" : ""));
  364. QETH_CARD_TEXT(card, 2, "ckidxres");
  365. QETH_CARD_TEXT(card, 2, " idxterm");
  366. QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
  367. if (buffer[4] == 0xf6) {
  368. dev_err(&card->gdev->dev,
  369. "The qeth device is not configured "
  370. "for the OSI layer required by z/VM\n");
  371. return -EPERM;
  372. }
  373. return -EIO;
  374. }
  375. return 0;
  376. }
  377. static void qeth_setup_ccw(struct qeth_channel *channel, unsigned char *iob,
  378. __u32 len)
  379. {
  380. struct qeth_card *card;
  381. card = CARD_FROM_CDEV(channel->ccwdev);
  382. QETH_CARD_TEXT(card, 4, "setupccw");
  383. if (channel == &card->read)
  384. memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
  385. else
  386. memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
  387. channel->ccw.count = len;
  388. channel->ccw.cda = (__u32) __pa(iob);
  389. }
  390. static struct qeth_cmd_buffer *__qeth_get_buffer(struct qeth_channel *channel)
  391. {
  392. __u8 index;
  393. QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "getbuff");
  394. index = channel->io_buf_no;
  395. do {
  396. if (channel->iob[index].state == BUF_STATE_FREE) {
  397. channel->iob[index].state = BUF_STATE_LOCKED;
  398. channel->io_buf_no = (channel->io_buf_no + 1) %
  399. QETH_CMD_BUFFER_NO;
  400. memset(channel->iob[index].data, 0, QETH_BUFSIZE);
  401. return channel->iob + index;
  402. }
  403. index = (index + 1) % QETH_CMD_BUFFER_NO;
  404. } while (index != channel->io_buf_no);
  405. return NULL;
  406. }
  407. void qeth_release_buffer(struct qeth_channel *channel,
  408. struct qeth_cmd_buffer *iob)
  409. {
  410. unsigned long flags;
  411. QETH_CARD_TEXT(CARD_FROM_CDEV(channel->ccwdev), 6, "relbuff");
  412. spin_lock_irqsave(&channel->iob_lock, flags);
  413. memset(iob->data, 0, QETH_BUFSIZE);
  414. iob->state = BUF_STATE_FREE;
  415. iob->callback = qeth_send_control_data_cb;
  416. iob->rc = 0;
  417. spin_unlock_irqrestore(&channel->iob_lock, flags);
  418. }
  419. EXPORT_SYMBOL_GPL(qeth_release_buffer);
  420. static struct qeth_cmd_buffer *qeth_get_buffer(struct qeth_channel *channel)
  421. {
  422. struct qeth_cmd_buffer *buffer = NULL;
  423. unsigned long flags;
  424. spin_lock_irqsave(&channel->iob_lock, flags);
  425. buffer = __qeth_get_buffer(channel);
  426. spin_unlock_irqrestore(&channel->iob_lock, flags);
  427. return buffer;
  428. }
  429. struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *channel)
  430. {
  431. struct qeth_cmd_buffer *buffer;
  432. wait_event(channel->wait_q,
  433. ((buffer = qeth_get_buffer(channel)) != NULL));
  434. return buffer;
  435. }
  436. EXPORT_SYMBOL_GPL(qeth_wait_for_buffer);
  437. void qeth_clear_cmd_buffers(struct qeth_channel *channel)
  438. {
  439. int cnt;
  440. for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
  441. qeth_release_buffer(channel, &channel->iob[cnt]);
  442. channel->buf_no = 0;
  443. channel->io_buf_no = 0;
  444. }
  445. EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers);
  446. static void qeth_send_control_data_cb(struct qeth_channel *channel,
  447. struct qeth_cmd_buffer *iob)
  448. {
  449. struct qeth_card *card;
  450. struct qeth_reply *reply, *r;
  451. struct qeth_ipa_cmd *cmd;
  452. unsigned long flags;
  453. int keep_reply;
  454. int rc = 0;
  455. card = CARD_FROM_CDEV(channel->ccwdev);
  456. QETH_CARD_TEXT(card, 4, "sndctlcb");
  457. rc = qeth_check_idx_response(card, iob->data);
  458. switch (rc) {
  459. case 0:
  460. break;
  461. case -EIO:
  462. qeth_clear_ipacmd_list(card);
  463. qeth_schedule_recovery(card);
  464. /* fall through */
  465. default:
  466. goto out;
  467. }
  468. cmd = qeth_check_ipa_data(card, iob);
  469. if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
  470. goto out;
  471. /*in case of OSN : check if cmd is set */
  472. if (card->info.type == QETH_CARD_TYPE_OSN &&
  473. cmd &&
  474. cmd->hdr.command != IPA_CMD_STARTLAN &&
  475. card->osn_info.assist_cb != NULL) {
  476. card->osn_info.assist_cb(card->dev, cmd);
  477. goto out;
  478. }
  479. spin_lock_irqsave(&card->lock, flags);
  480. list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
  481. if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
  482. ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
  483. qeth_get_reply(reply);
  484. list_del_init(&reply->list);
  485. spin_unlock_irqrestore(&card->lock, flags);
  486. keep_reply = 0;
  487. if (reply->callback != NULL) {
  488. if (cmd) {
  489. reply->offset = (__u16)((char *)cmd -
  490. (char *)iob->data);
  491. keep_reply = reply->callback(card,
  492. reply,
  493. (unsigned long)cmd);
  494. } else
  495. keep_reply = reply->callback(card,
  496. reply,
  497. (unsigned long)iob);
  498. }
  499. if (cmd)
  500. reply->rc = (u16) cmd->hdr.return_code;
  501. else if (iob->rc)
  502. reply->rc = iob->rc;
  503. if (keep_reply) {
  504. spin_lock_irqsave(&card->lock, flags);
  505. list_add_tail(&reply->list,
  506. &card->cmd_waiter_list);
  507. spin_unlock_irqrestore(&card->lock, flags);
  508. } else {
  509. atomic_inc(&reply->received);
  510. wake_up(&reply->wait_q);
  511. }
  512. qeth_put_reply(reply);
  513. goto out;
  514. }
  515. }
  516. spin_unlock_irqrestore(&card->lock, flags);
  517. out:
  518. memcpy(&card->seqno.pdu_hdr_ack,
  519. QETH_PDU_HEADER_SEQ_NO(iob->data),
  520. QETH_SEQ_NO_LENGTH);
  521. qeth_release_buffer(channel, iob);
  522. }
  523. static int qeth_setup_channel(struct qeth_channel *channel)
  524. {
  525. int cnt;
  526. QETH_DBF_TEXT(SETUP, 2, "setupch");
  527. for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
  528. channel->iob[cnt].data =
  529. kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
  530. if (channel->iob[cnt].data == NULL)
  531. break;
  532. channel->iob[cnt].state = BUF_STATE_FREE;
  533. channel->iob[cnt].channel = channel;
  534. channel->iob[cnt].callback = qeth_send_control_data_cb;
  535. channel->iob[cnt].rc = 0;
  536. }
  537. if (cnt < QETH_CMD_BUFFER_NO) {
  538. while (cnt-- > 0)
  539. kfree(channel->iob[cnt].data);
  540. return -ENOMEM;
  541. }
  542. channel->buf_no = 0;
  543. channel->io_buf_no = 0;
  544. atomic_set(&channel->irq_pending, 0);
  545. spin_lock_init(&channel->iob_lock);
  546. init_waitqueue_head(&channel->wait_q);
  547. return 0;
  548. }
  549. static int qeth_set_thread_start_bit(struct qeth_card *card,
  550. unsigned long thread)
  551. {
  552. unsigned long flags;
  553. spin_lock_irqsave(&card->thread_mask_lock, flags);
  554. if (!(card->thread_allowed_mask & thread) ||
  555. (card->thread_start_mask & thread)) {
  556. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  557. return -EPERM;
  558. }
  559. card->thread_start_mask |= thread;
  560. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  561. return 0;
  562. }
  563. void qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
  564. {
  565. unsigned long flags;
  566. spin_lock_irqsave(&card->thread_mask_lock, flags);
  567. card->thread_start_mask &= ~thread;
  568. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  569. wake_up(&card->wait_q);
  570. }
  571. EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit);
  572. void qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
  573. {
  574. unsigned long flags;
  575. spin_lock_irqsave(&card->thread_mask_lock, flags);
  576. card->thread_running_mask &= ~thread;
  577. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  578. wake_up(&card->wait_q);
  579. }
  580. EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit);
  581. static int __qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
  582. {
  583. unsigned long flags;
  584. int rc = 0;
  585. spin_lock_irqsave(&card->thread_mask_lock, flags);
  586. if (card->thread_start_mask & thread) {
  587. if ((card->thread_allowed_mask & thread) &&
  588. !(card->thread_running_mask & thread)) {
  589. rc = 1;
  590. card->thread_start_mask &= ~thread;
  591. card->thread_running_mask |= thread;
  592. } else
  593. rc = -EPERM;
  594. }
  595. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  596. return rc;
  597. }
  598. int qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
  599. {
  600. int rc = 0;
  601. wait_event(card->wait_q,
  602. (rc = __qeth_do_run_thread(card, thread)) >= 0);
  603. return rc;
  604. }
  605. EXPORT_SYMBOL_GPL(qeth_do_run_thread);
  606. void qeth_schedule_recovery(struct qeth_card *card)
  607. {
  608. QETH_CARD_TEXT(card, 2, "startrec");
  609. if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
  610. schedule_work(&card->kernel_thread_starter);
  611. }
  612. EXPORT_SYMBOL_GPL(qeth_schedule_recovery);
  613. static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
  614. {
  615. int dstat, cstat;
  616. char *sense;
  617. struct qeth_card *card;
  618. sense = (char *) irb->ecw;
  619. cstat = irb->scsw.cmd.cstat;
  620. dstat = irb->scsw.cmd.dstat;
  621. card = CARD_FROM_CDEV(cdev);
  622. if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
  623. SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
  624. SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
  625. QETH_CARD_TEXT(card, 2, "CGENCHK");
  626. dev_warn(&cdev->dev, "The qeth device driver "
  627. "failed to recover an error on the device\n");
  628. QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
  629. dev_name(&cdev->dev), dstat, cstat);
  630. print_hex_dump(KERN_WARNING, "qeth: irb ", DUMP_PREFIX_OFFSET,
  631. 16, 1, irb, 64, 1);
  632. return 1;
  633. }
  634. if (dstat & DEV_STAT_UNIT_CHECK) {
  635. if (sense[SENSE_RESETTING_EVENT_BYTE] &
  636. SENSE_RESETTING_EVENT_FLAG) {
  637. QETH_CARD_TEXT(card, 2, "REVIND");
  638. return 1;
  639. }
  640. if (sense[SENSE_COMMAND_REJECT_BYTE] &
  641. SENSE_COMMAND_REJECT_FLAG) {
  642. QETH_CARD_TEXT(card, 2, "CMDREJi");
  643. return 1;
  644. }
  645. if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
  646. QETH_CARD_TEXT(card, 2, "AFFE");
  647. return 1;
  648. }
  649. if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
  650. QETH_CARD_TEXT(card, 2, "ZEROSEN");
  651. return 0;
  652. }
  653. QETH_CARD_TEXT(card, 2, "DGENCHK");
  654. return 1;
  655. }
  656. return 0;
  657. }
  658. static long __qeth_check_irb_error(struct ccw_device *cdev,
  659. unsigned long intparm, struct irb *irb)
  660. {
  661. struct qeth_card *card;
  662. card = CARD_FROM_CDEV(cdev);
  663. if (!IS_ERR(irb))
  664. return 0;
  665. switch (PTR_ERR(irb)) {
  666. case -EIO:
  667. QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
  668. dev_name(&cdev->dev));
  669. QETH_CARD_TEXT(card, 2, "ckirberr");
  670. QETH_CARD_TEXT_(card, 2, " rc%d", -EIO);
  671. break;
  672. case -ETIMEDOUT:
  673. dev_warn(&cdev->dev, "A hardware operation timed out"
  674. " on the device\n");
  675. QETH_CARD_TEXT(card, 2, "ckirberr");
  676. QETH_CARD_TEXT_(card, 2, " rc%d", -ETIMEDOUT);
  677. if (intparm == QETH_RCD_PARM) {
  678. if (card && (card->data.ccwdev == cdev)) {
  679. card->data.state = CH_STATE_DOWN;
  680. wake_up(&card->wait_q);
  681. }
  682. }
  683. break;
  684. default:
  685. QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
  686. dev_name(&cdev->dev), PTR_ERR(irb));
  687. QETH_CARD_TEXT(card, 2, "ckirberr");
  688. QETH_CARD_TEXT(card, 2, " rc???");
  689. }
  690. return PTR_ERR(irb);
  691. }
  692. static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
  693. struct irb *irb)
  694. {
  695. int rc;
  696. int cstat, dstat;
  697. struct qeth_cmd_buffer *buffer;
  698. struct qeth_channel *channel;
  699. struct qeth_card *card;
  700. struct qeth_cmd_buffer *iob;
  701. __u8 index;
  702. if (__qeth_check_irb_error(cdev, intparm, irb))
  703. return;
  704. cstat = irb->scsw.cmd.cstat;
  705. dstat = irb->scsw.cmd.dstat;
  706. card = CARD_FROM_CDEV(cdev);
  707. if (!card)
  708. return;
  709. QETH_CARD_TEXT(card, 5, "irq");
  710. if (card->read.ccwdev == cdev) {
  711. channel = &card->read;
  712. QETH_CARD_TEXT(card, 5, "read");
  713. } else if (card->write.ccwdev == cdev) {
  714. channel = &card->write;
  715. QETH_CARD_TEXT(card, 5, "write");
  716. } else {
  717. channel = &card->data;
  718. QETH_CARD_TEXT(card, 5, "data");
  719. }
  720. atomic_set(&channel->irq_pending, 0);
  721. if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
  722. channel->state = CH_STATE_STOPPED;
  723. if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
  724. channel->state = CH_STATE_HALTED;
  725. /*let's wake up immediately on data channel*/
  726. if ((channel == &card->data) && (intparm != 0) &&
  727. (intparm != QETH_RCD_PARM))
  728. goto out;
  729. if (intparm == QETH_CLEAR_CHANNEL_PARM) {
  730. QETH_CARD_TEXT(card, 6, "clrchpar");
  731. /* we don't have to handle this further */
  732. intparm = 0;
  733. }
  734. if (intparm == QETH_HALT_CHANNEL_PARM) {
  735. QETH_CARD_TEXT(card, 6, "hltchpar");
  736. /* we don't have to handle this further */
  737. intparm = 0;
  738. }
  739. if ((dstat & DEV_STAT_UNIT_EXCEP) ||
  740. (dstat & DEV_STAT_UNIT_CHECK) ||
  741. (cstat)) {
  742. if (irb->esw.esw0.erw.cons) {
  743. dev_warn(&channel->ccwdev->dev,
  744. "The qeth device driver failed to recover "
  745. "an error on the device\n");
  746. QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
  747. "0x%X dstat 0x%X\n",
  748. dev_name(&channel->ccwdev->dev), cstat, dstat);
  749. print_hex_dump(KERN_WARNING, "qeth: irb ",
  750. DUMP_PREFIX_OFFSET, 16, 1, irb, 32, 1);
  751. print_hex_dump(KERN_WARNING, "qeth: sense data ",
  752. DUMP_PREFIX_OFFSET, 16, 1, irb->ecw, 32, 1);
  753. }
  754. if (intparm == QETH_RCD_PARM) {
  755. channel->state = CH_STATE_DOWN;
  756. goto out;
  757. }
  758. rc = qeth_get_problem(cdev, irb);
  759. if (rc) {
  760. qeth_clear_ipacmd_list(card);
  761. qeth_schedule_recovery(card);
  762. goto out;
  763. }
  764. }
  765. if (intparm == QETH_RCD_PARM) {
  766. channel->state = CH_STATE_RCD_DONE;
  767. goto out;
  768. }
  769. if (intparm) {
  770. buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
  771. buffer->state = BUF_STATE_PROCESSED;
  772. }
  773. if (channel == &card->data)
  774. return;
  775. if (channel == &card->read &&
  776. channel->state == CH_STATE_UP)
  777. qeth_issue_next_read(card);
  778. iob = channel->iob;
  779. index = channel->buf_no;
  780. while (iob[index].state == BUF_STATE_PROCESSED) {
  781. if (iob[index].callback != NULL)
  782. iob[index].callback(channel, iob + index);
  783. index = (index + 1) % QETH_CMD_BUFFER_NO;
  784. }
  785. channel->buf_no = index;
  786. out:
  787. wake_up(&card->wait_q);
  788. return;
  789. }
  790. static void __qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
  791. struct qeth_qdio_out_buffer *buf, unsigned int qeth_skip_skb)
  792. {
  793. int i;
  794. struct sk_buff *skb;
  795. /* is PCI flag set on buffer? */
  796. if (buf->buffer->element[0].flags & 0x40)
  797. atomic_dec(&queue->set_pci_flags_count);
  798. if (!qeth_skip_skb) {
  799. skb = skb_dequeue(&buf->skb_list);
  800. while (skb) {
  801. atomic_dec(&skb->users);
  802. dev_kfree_skb_any(skb);
  803. skb = skb_dequeue(&buf->skb_list);
  804. }
  805. }
  806. for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i) {
  807. if (buf->buffer->element[i].addr && buf->is_header[i])
  808. kmem_cache_free(qeth_core_header_cache,
  809. buf->buffer->element[i].addr);
  810. buf->is_header[i] = 0;
  811. buf->buffer->element[i].length = 0;
  812. buf->buffer->element[i].addr = NULL;
  813. buf->buffer->element[i].flags = 0;
  814. }
  815. buf->buffer->element[15].flags = 0;
  816. buf->next_element_to_fill = 0;
  817. atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
  818. }
  819. static void qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
  820. struct qeth_qdio_out_buffer *buf)
  821. {
  822. __qeth_clear_output_buffer(queue, buf, 0);
  823. }
  824. void qeth_clear_qdio_buffers(struct qeth_card *card)
  825. {
  826. int i, j;
  827. QETH_CARD_TEXT(card, 2, "clearqdbf");
  828. /* clear outbound buffers to free skbs */
  829. for (i = 0; i < card->qdio.no_out_queues; ++i)
  830. if (card->qdio.out_qs[i]) {
  831. for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
  832. qeth_clear_output_buffer(card->qdio.out_qs[i],
  833. &card->qdio.out_qs[i]->bufs[j]);
  834. }
  835. }
  836. EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers);
  837. static void qeth_free_buffer_pool(struct qeth_card *card)
  838. {
  839. struct qeth_buffer_pool_entry *pool_entry, *tmp;
  840. int i = 0;
  841. list_for_each_entry_safe(pool_entry, tmp,
  842. &card->qdio.init_pool.entry_list, init_list){
  843. for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
  844. free_page((unsigned long)pool_entry->elements[i]);
  845. list_del(&pool_entry->init_list);
  846. kfree(pool_entry);
  847. }
  848. }
  849. static void qeth_free_qdio_buffers(struct qeth_card *card)
  850. {
  851. int i, j;
  852. if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
  853. QETH_QDIO_UNINITIALIZED)
  854. return;
  855. kfree(card->qdio.in_q);
  856. card->qdio.in_q = NULL;
  857. /* inbound buffer pool */
  858. qeth_free_buffer_pool(card);
  859. /* free outbound qdio_qs */
  860. if (card->qdio.out_qs) {
  861. for (i = 0; i < card->qdio.no_out_queues; ++i) {
  862. for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
  863. qeth_clear_output_buffer(card->qdio.out_qs[i],
  864. &card->qdio.out_qs[i]->bufs[j]);
  865. kfree(card->qdio.out_qs[i]);
  866. }
  867. kfree(card->qdio.out_qs);
  868. card->qdio.out_qs = NULL;
  869. }
  870. }
  871. static void qeth_clean_channel(struct qeth_channel *channel)
  872. {
  873. int cnt;
  874. QETH_DBF_TEXT(SETUP, 2, "freech");
  875. for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
  876. kfree(channel->iob[cnt].data);
  877. }
  878. static void qeth_get_channel_path_desc(struct qeth_card *card)
  879. {
  880. struct ccw_device *ccwdev;
  881. struct channelPath_dsc {
  882. u8 flags;
  883. u8 lsn;
  884. u8 desc;
  885. u8 chpid;
  886. u8 swla;
  887. u8 zeroes;
  888. u8 chla;
  889. u8 chpp;
  890. } *chp_dsc;
  891. QETH_DBF_TEXT(SETUP, 2, "chp_desc");
  892. ccwdev = card->data.ccwdev;
  893. chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
  894. if (chp_dsc != NULL) {
  895. /* CHPP field bit 6 == 1 -> single queue */
  896. if ((chp_dsc->chpp & 0x02) == 0x02)
  897. card->qdio.no_out_queues = 1;
  898. card->info.func_level = 0x4100 + chp_dsc->desc;
  899. kfree(chp_dsc);
  900. }
  901. if (card->qdio.no_out_queues == 1) {
  902. card->qdio.default_out_queue = 0;
  903. dev_info(&card->gdev->dev,
  904. "Priority Queueing not supported\n");
  905. }
  906. QETH_DBF_TEXT_(SETUP, 2, "nr:%x", card->qdio.no_out_queues);
  907. QETH_DBF_TEXT_(SETUP, 2, "lvl:%02x", card->info.func_level);
  908. return;
  909. }
  910. static void qeth_init_qdio_info(struct qeth_card *card)
  911. {
  912. QETH_DBF_TEXT(SETUP, 4, "intqdinf");
  913. atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
  914. /* inbound */
  915. card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
  916. card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
  917. card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
  918. INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
  919. INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
  920. }
  921. static void qeth_set_intial_options(struct qeth_card *card)
  922. {
  923. card->options.route4.type = NO_ROUTER;
  924. card->options.route6.type = NO_ROUTER;
  925. card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
  926. card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
  927. card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
  928. card->options.fake_broadcast = 0;
  929. card->options.add_hhlen = DEFAULT_ADD_HHLEN;
  930. card->options.performance_stats = 0;
  931. card->options.rx_sg_cb = QETH_RX_SG_CB;
  932. card->options.isolation = ISOLATION_MODE_NONE;
  933. }
  934. static int qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
  935. {
  936. unsigned long flags;
  937. int rc = 0;
  938. spin_lock_irqsave(&card->thread_mask_lock, flags);
  939. QETH_CARD_TEXT_(card, 4, " %02x%02x%02x",
  940. (u8) card->thread_start_mask,
  941. (u8) card->thread_allowed_mask,
  942. (u8) card->thread_running_mask);
  943. rc = (card->thread_start_mask & thread);
  944. spin_unlock_irqrestore(&card->thread_mask_lock, flags);
  945. return rc;
  946. }
  947. static void qeth_start_kernel_thread(struct work_struct *work)
  948. {
  949. struct qeth_card *card = container_of(work, struct qeth_card,
  950. kernel_thread_starter);
  951. QETH_CARD_TEXT(card , 2, "strthrd");
  952. if (card->read.state != CH_STATE_UP &&
  953. card->write.state != CH_STATE_UP)
  954. return;
  955. if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
  956. kthread_run(card->discipline.recover, (void *) card,
  957. "qeth_recover");
  958. }
  959. static int qeth_setup_card(struct qeth_card *card)
  960. {
  961. QETH_DBF_TEXT(SETUP, 2, "setupcrd");
  962. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  963. card->read.state = CH_STATE_DOWN;
  964. card->write.state = CH_STATE_DOWN;
  965. card->data.state = CH_STATE_DOWN;
  966. card->state = CARD_STATE_DOWN;
  967. card->lan_online = 0;
  968. card->use_hard_stop = 0;
  969. card->dev = NULL;
  970. spin_lock_init(&card->vlanlock);
  971. spin_lock_init(&card->mclock);
  972. card->vlangrp = NULL;
  973. spin_lock_init(&card->lock);
  974. spin_lock_init(&card->ip_lock);
  975. spin_lock_init(&card->thread_mask_lock);
  976. mutex_init(&card->conf_mutex);
  977. mutex_init(&card->discipline_mutex);
  978. card->thread_start_mask = 0;
  979. card->thread_allowed_mask = 0;
  980. card->thread_running_mask = 0;
  981. INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
  982. INIT_LIST_HEAD(&card->ip_list);
  983. INIT_LIST_HEAD(card->ip_tbd_list);
  984. INIT_LIST_HEAD(&card->cmd_waiter_list);
  985. init_waitqueue_head(&card->wait_q);
  986. /* intial options */
  987. qeth_set_intial_options(card);
  988. /* IP address takeover */
  989. INIT_LIST_HEAD(&card->ipato.entries);
  990. card->ipato.enabled = 0;
  991. card->ipato.invert4 = 0;
  992. card->ipato.invert6 = 0;
  993. /* init QDIO stuff */
  994. qeth_init_qdio_info(card);
  995. return 0;
  996. }
  997. static void qeth_core_sl_print(struct seq_file *m, struct service_level *slr)
  998. {
  999. struct qeth_card *card = container_of(slr, struct qeth_card,
  1000. qeth_service_level);
  1001. if (card->info.mcl_level[0])
  1002. seq_printf(m, "qeth: %s firmware level %s\n",
  1003. CARD_BUS_ID(card), card->info.mcl_level);
  1004. }
  1005. static struct qeth_card *qeth_alloc_card(void)
  1006. {
  1007. struct qeth_card *card;
  1008. QETH_DBF_TEXT(SETUP, 2, "alloccrd");
  1009. card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
  1010. if (!card)
  1011. goto out;
  1012. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  1013. card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
  1014. if (!card->ip_tbd_list) {
  1015. QETH_DBF_TEXT(SETUP, 0, "iptbdnom");
  1016. goto out_card;
  1017. }
  1018. if (qeth_setup_channel(&card->read))
  1019. goto out_ip;
  1020. if (qeth_setup_channel(&card->write))
  1021. goto out_channel;
  1022. card->options.layer2 = -1;
  1023. card->qeth_service_level.seq_print = qeth_core_sl_print;
  1024. register_service_level(&card->qeth_service_level);
  1025. return card;
  1026. out_channel:
  1027. qeth_clean_channel(&card->read);
  1028. out_ip:
  1029. kfree(card->ip_tbd_list);
  1030. out_card:
  1031. kfree(card);
  1032. out:
  1033. return NULL;
  1034. }
  1035. static int qeth_determine_card_type(struct qeth_card *card)
  1036. {
  1037. int i = 0;
  1038. QETH_DBF_TEXT(SETUP, 2, "detcdtyp");
  1039. card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
  1040. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  1041. while (known_devices[i][QETH_DEV_MODEL_IND]) {
  1042. if ((CARD_RDEV(card)->id.dev_type ==
  1043. known_devices[i][QETH_DEV_TYPE_IND]) &&
  1044. (CARD_RDEV(card)->id.dev_model ==
  1045. known_devices[i][QETH_DEV_MODEL_IND])) {
  1046. card->info.type = known_devices[i][QETH_DEV_MODEL_IND];
  1047. card->qdio.no_out_queues =
  1048. known_devices[i][QETH_QUEUE_NO_IND];
  1049. card->info.is_multicast_different =
  1050. known_devices[i][QETH_MULTICAST_IND];
  1051. qeth_get_channel_path_desc(card);
  1052. return 0;
  1053. }
  1054. i++;
  1055. }
  1056. card->info.type = QETH_CARD_TYPE_UNKNOWN;
  1057. dev_err(&card->gdev->dev, "The adapter hardware is of an "
  1058. "unknown type\n");
  1059. return -ENOENT;
  1060. }
  1061. static int qeth_clear_channel(struct qeth_channel *channel)
  1062. {
  1063. unsigned long flags;
  1064. struct qeth_card *card;
  1065. int rc;
  1066. card = CARD_FROM_CDEV(channel->ccwdev);
  1067. QETH_CARD_TEXT(card, 3, "clearch");
  1068. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1069. rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
  1070. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1071. if (rc)
  1072. return rc;
  1073. rc = wait_event_interruptible_timeout(card->wait_q,
  1074. channel->state == CH_STATE_STOPPED, QETH_TIMEOUT);
  1075. if (rc == -ERESTARTSYS)
  1076. return rc;
  1077. if (channel->state != CH_STATE_STOPPED)
  1078. return -ETIME;
  1079. channel->state = CH_STATE_DOWN;
  1080. return 0;
  1081. }
  1082. static int qeth_halt_channel(struct qeth_channel *channel)
  1083. {
  1084. unsigned long flags;
  1085. struct qeth_card *card;
  1086. int rc;
  1087. card = CARD_FROM_CDEV(channel->ccwdev);
  1088. QETH_CARD_TEXT(card, 3, "haltch");
  1089. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1090. rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
  1091. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1092. if (rc)
  1093. return rc;
  1094. rc = wait_event_interruptible_timeout(card->wait_q,
  1095. channel->state == CH_STATE_HALTED, QETH_TIMEOUT);
  1096. if (rc == -ERESTARTSYS)
  1097. return rc;
  1098. if (channel->state != CH_STATE_HALTED)
  1099. return -ETIME;
  1100. return 0;
  1101. }
  1102. static int qeth_halt_channels(struct qeth_card *card)
  1103. {
  1104. int rc1 = 0, rc2 = 0, rc3 = 0;
  1105. QETH_CARD_TEXT(card, 3, "haltchs");
  1106. rc1 = qeth_halt_channel(&card->read);
  1107. rc2 = qeth_halt_channel(&card->write);
  1108. rc3 = qeth_halt_channel(&card->data);
  1109. if (rc1)
  1110. return rc1;
  1111. if (rc2)
  1112. return rc2;
  1113. return rc3;
  1114. }
  1115. static int qeth_clear_channels(struct qeth_card *card)
  1116. {
  1117. int rc1 = 0, rc2 = 0, rc3 = 0;
  1118. QETH_CARD_TEXT(card, 3, "clearchs");
  1119. rc1 = qeth_clear_channel(&card->read);
  1120. rc2 = qeth_clear_channel(&card->write);
  1121. rc3 = qeth_clear_channel(&card->data);
  1122. if (rc1)
  1123. return rc1;
  1124. if (rc2)
  1125. return rc2;
  1126. return rc3;
  1127. }
  1128. static int qeth_clear_halt_card(struct qeth_card *card, int halt)
  1129. {
  1130. int rc = 0;
  1131. QETH_CARD_TEXT(card, 3, "clhacrd");
  1132. if (halt)
  1133. rc = qeth_halt_channels(card);
  1134. if (rc)
  1135. return rc;
  1136. return qeth_clear_channels(card);
  1137. }
  1138. int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
  1139. {
  1140. int rc = 0;
  1141. QETH_CARD_TEXT(card, 3, "qdioclr");
  1142. switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
  1143. QETH_QDIO_CLEANING)) {
  1144. case QETH_QDIO_ESTABLISHED:
  1145. if (card->info.type == QETH_CARD_TYPE_IQD)
  1146. rc = qdio_shutdown(CARD_DDEV(card),
  1147. QDIO_FLAG_CLEANUP_USING_HALT);
  1148. else
  1149. rc = qdio_shutdown(CARD_DDEV(card),
  1150. QDIO_FLAG_CLEANUP_USING_CLEAR);
  1151. if (rc)
  1152. QETH_CARD_TEXT_(card, 3, "1err%d", rc);
  1153. qdio_free(CARD_DDEV(card));
  1154. atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
  1155. break;
  1156. case QETH_QDIO_CLEANING:
  1157. return rc;
  1158. default:
  1159. break;
  1160. }
  1161. rc = qeth_clear_halt_card(card, use_halt);
  1162. if (rc)
  1163. QETH_CARD_TEXT_(card, 3, "2err%d", rc);
  1164. card->state = CARD_STATE_DOWN;
  1165. return rc;
  1166. }
  1167. EXPORT_SYMBOL_GPL(qeth_qdio_clear_card);
  1168. static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
  1169. int *length)
  1170. {
  1171. struct ciw *ciw;
  1172. char *rcd_buf;
  1173. int ret;
  1174. struct qeth_channel *channel = &card->data;
  1175. unsigned long flags;
  1176. /*
  1177. * scan for RCD command in extended SenseID data
  1178. */
  1179. ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
  1180. if (!ciw || ciw->cmd == 0)
  1181. return -EOPNOTSUPP;
  1182. rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
  1183. if (!rcd_buf)
  1184. return -ENOMEM;
  1185. channel->ccw.cmd_code = ciw->cmd;
  1186. channel->ccw.cda = (__u32) __pa(rcd_buf);
  1187. channel->ccw.count = ciw->count;
  1188. channel->ccw.flags = CCW_FLAG_SLI;
  1189. channel->state = CH_STATE_RCD;
  1190. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1191. ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
  1192. QETH_RCD_PARM, LPM_ANYPATH, 0,
  1193. QETH_RCD_TIMEOUT);
  1194. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1195. if (!ret)
  1196. wait_event(card->wait_q,
  1197. (channel->state == CH_STATE_RCD_DONE ||
  1198. channel->state == CH_STATE_DOWN));
  1199. if (channel->state == CH_STATE_DOWN)
  1200. ret = -EIO;
  1201. else
  1202. channel->state = CH_STATE_DOWN;
  1203. if (ret) {
  1204. kfree(rcd_buf);
  1205. *buffer = NULL;
  1206. *length = 0;
  1207. } else {
  1208. *length = ciw->count;
  1209. *buffer = rcd_buf;
  1210. }
  1211. return ret;
  1212. }
  1213. static void qeth_configure_unitaddr(struct qeth_card *card, char *prcd)
  1214. {
  1215. QETH_DBF_TEXT(SETUP, 2, "cfgunit");
  1216. card->info.chpid = prcd[30];
  1217. card->info.unit_addr2 = prcd[31];
  1218. card->info.cula = prcd[63];
  1219. card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
  1220. (prcd[0x11] == _ascebc['M']));
  1221. }
  1222. static void qeth_configure_blkt_default(struct qeth_card *card, char *prcd)
  1223. {
  1224. QETH_DBF_TEXT(SETUP, 2, "cfgblkt");
  1225. if (prcd[74] == 0xF0 && prcd[75] == 0xF0 && prcd[76] == 0xF5) {
  1226. card->info.blkt.time_total = 250;
  1227. card->info.blkt.inter_packet = 5;
  1228. card->info.blkt.inter_packet_jumbo = 15;
  1229. } else {
  1230. card->info.blkt.time_total = 0;
  1231. card->info.blkt.inter_packet = 0;
  1232. card->info.blkt.inter_packet_jumbo = 0;
  1233. }
  1234. }
  1235. static void qeth_init_tokens(struct qeth_card *card)
  1236. {
  1237. card->token.issuer_rm_w = 0x00010103UL;
  1238. card->token.cm_filter_w = 0x00010108UL;
  1239. card->token.cm_connection_w = 0x0001010aUL;
  1240. card->token.ulp_filter_w = 0x0001010bUL;
  1241. card->token.ulp_connection_w = 0x0001010dUL;
  1242. }
  1243. static void qeth_init_func_level(struct qeth_card *card)
  1244. {
  1245. switch (card->info.type) {
  1246. case QETH_CARD_TYPE_IQD:
  1247. card->info.func_level = QETH_IDX_FUNC_LEVEL_IQD;
  1248. break;
  1249. case QETH_CARD_TYPE_OSD:
  1250. case QETH_CARD_TYPE_OSN:
  1251. card->info.func_level = QETH_IDX_FUNC_LEVEL_OSD;
  1252. break;
  1253. default:
  1254. break;
  1255. }
  1256. }
  1257. static int qeth_idx_activate_get_answer(struct qeth_channel *channel,
  1258. void (*idx_reply_cb)(struct qeth_channel *,
  1259. struct qeth_cmd_buffer *))
  1260. {
  1261. struct qeth_cmd_buffer *iob;
  1262. unsigned long flags;
  1263. int rc;
  1264. struct qeth_card *card;
  1265. QETH_DBF_TEXT(SETUP, 2, "idxanswr");
  1266. card = CARD_FROM_CDEV(channel->ccwdev);
  1267. iob = qeth_get_buffer(channel);
  1268. iob->callback = idx_reply_cb;
  1269. memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
  1270. channel->ccw.count = QETH_BUFSIZE;
  1271. channel->ccw.cda = (__u32) __pa(iob->data);
  1272. wait_event(card->wait_q,
  1273. atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
  1274. QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
  1275. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1276. rc = ccw_device_start(channel->ccwdev,
  1277. &channel->ccw, (addr_t) iob, 0, 0);
  1278. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1279. if (rc) {
  1280. QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc);
  1281. QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
  1282. atomic_set(&channel->irq_pending, 0);
  1283. wake_up(&card->wait_q);
  1284. return rc;
  1285. }
  1286. rc = wait_event_interruptible_timeout(card->wait_q,
  1287. channel->state == CH_STATE_UP, QETH_TIMEOUT);
  1288. if (rc == -ERESTARTSYS)
  1289. return rc;
  1290. if (channel->state != CH_STATE_UP) {
  1291. rc = -ETIME;
  1292. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  1293. qeth_clear_cmd_buffers(channel);
  1294. } else
  1295. rc = 0;
  1296. return rc;
  1297. }
  1298. static int qeth_idx_activate_channel(struct qeth_channel *channel,
  1299. void (*idx_reply_cb)(struct qeth_channel *,
  1300. struct qeth_cmd_buffer *))
  1301. {
  1302. struct qeth_card *card;
  1303. struct qeth_cmd_buffer *iob;
  1304. unsigned long flags;
  1305. __u16 temp;
  1306. __u8 tmp;
  1307. int rc;
  1308. struct ccw_dev_id temp_devid;
  1309. card = CARD_FROM_CDEV(channel->ccwdev);
  1310. QETH_DBF_TEXT(SETUP, 2, "idxactch");
  1311. iob = qeth_get_buffer(channel);
  1312. iob->callback = idx_reply_cb;
  1313. memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
  1314. channel->ccw.count = IDX_ACTIVATE_SIZE;
  1315. channel->ccw.cda = (__u32) __pa(iob->data);
  1316. if (channel == &card->write) {
  1317. memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
  1318. memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
  1319. &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
  1320. card->seqno.trans_hdr++;
  1321. } else {
  1322. memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
  1323. memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
  1324. &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
  1325. }
  1326. tmp = ((__u8)card->info.portno) | 0x80;
  1327. memcpy(QETH_IDX_ACT_PNO(iob->data), &tmp, 1);
  1328. memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
  1329. &card->token.issuer_rm_w, QETH_MPC_TOKEN_LENGTH);
  1330. memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
  1331. &card->info.func_level, sizeof(__u16));
  1332. ccw_device_get_id(CARD_DDEV(card), &temp_devid);
  1333. memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp_devid.devno, 2);
  1334. temp = (card->info.cula << 8) + card->info.unit_addr2;
  1335. memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
  1336. wait_event(card->wait_q,
  1337. atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
  1338. QETH_DBF_TEXT(SETUP, 6, "noirqpnd");
  1339. spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
  1340. rc = ccw_device_start(channel->ccwdev,
  1341. &channel->ccw, (addr_t) iob, 0, 0);
  1342. spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
  1343. if (rc) {
  1344. QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
  1345. rc);
  1346. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  1347. atomic_set(&channel->irq_pending, 0);
  1348. wake_up(&card->wait_q);
  1349. return rc;
  1350. }
  1351. rc = wait_event_interruptible_timeout(card->wait_q,
  1352. channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
  1353. if (rc == -ERESTARTSYS)
  1354. return rc;
  1355. if (channel->state != CH_STATE_ACTIVATING) {
  1356. dev_warn(&channel->ccwdev->dev, "The qeth device driver"
  1357. " failed to recover an error on the device\n");
  1358. QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
  1359. dev_name(&channel->ccwdev->dev));
  1360. QETH_DBF_TEXT_(SETUP, 2, "2err%d", -ETIME);
  1361. qeth_clear_cmd_buffers(channel);
  1362. return -ETIME;
  1363. }
  1364. return qeth_idx_activate_get_answer(channel, idx_reply_cb);
  1365. }
  1366. static int qeth_peer_func_level(int level)
  1367. {
  1368. if ((level & 0xff) == 8)
  1369. return (level & 0xff) + 0x400;
  1370. if (((level >> 8) & 3) == 1)
  1371. return (level & 0xff) + 0x200;
  1372. return level;
  1373. }
  1374. static void qeth_idx_write_cb(struct qeth_channel *channel,
  1375. struct qeth_cmd_buffer *iob)
  1376. {
  1377. struct qeth_card *card;
  1378. __u16 temp;
  1379. QETH_DBF_TEXT(SETUP , 2, "idxwrcb");
  1380. if (channel->state == CH_STATE_DOWN) {
  1381. channel->state = CH_STATE_ACTIVATING;
  1382. goto out;
  1383. }
  1384. card = CARD_FROM_CDEV(channel->ccwdev);
  1385. if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
  1386. if (QETH_IDX_ACT_CAUSE_CODE(iob->data) == QETH_IDX_ACT_ERR_EXCL)
  1387. dev_err(&card->write.ccwdev->dev,
  1388. "The adapter is used exclusively by another "
  1389. "host\n");
  1390. else
  1391. QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
  1392. " negative reply\n",
  1393. dev_name(&card->write.ccwdev->dev));
  1394. goto out;
  1395. }
  1396. memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
  1397. if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
  1398. QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
  1399. "function level mismatch (sent: 0x%x, received: "
  1400. "0x%x)\n", dev_name(&card->write.ccwdev->dev),
  1401. card->info.func_level, temp);
  1402. goto out;
  1403. }
  1404. channel->state = CH_STATE_UP;
  1405. out:
  1406. qeth_release_buffer(channel, iob);
  1407. }
  1408. static void qeth_idx_read_cb(struct qeth_channel *channel,
  1409. struct qeth_cmd_buffer *iob)
  1410. {
  1411. struct qeth_card *card;
  1412. __u16 temp;
  1413. QETH_DBF_TEXT(SETUP , 2, "idxrdcb");
  1414. if (channel->state == CH_STATE_DOWN) {
  1415. channel->state = CH_STATE_ACTIVATING;
  1416. goto out;
  1417. }
  1418. card = CARD_FROM_CDEV(channel->ccwdev);
  1419. if (qeth_check_idx_response(card, iob->data))
  1420. goto out;
  1421. if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
  1422. switch (QETH_IDX_ACT_CAUSE_CODE(iob->data)) {
  1423. case QETH_IDX_ACT_ERR_EXCL:
  1424. dev_err(&card->write.ccwdev->dev,
  1425. "The adapter is used exclusively by another "
  1426. "host\n");
  1427. break;
  1428. case QETH_IDX_ACT_ERR_AUTH:
  1429. case QETH_IDX_ACT_ERR_AUTH_USER:
  1430. dev_err(&card->read.ccwdev->dev,
  1431. "Setting the device online failed because of "
  1432. "insufficient authorization\n");
  1433. break;
  1434. default:
  1435. QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
  1436. " negative reply\n",
  1437. dev_name(&card->read.ccwdev->dev));
  1438. }
  1439. QETH_CARD_TEXT_(card, 2, "idxread%c",
  1440. QETH_IDX_ACT_CAUSE_CODE(iob->data));
  1441. goto out;
  1442. }
  1443. /**
  1444. * * temporary fix for microcode bug
  1445. * * to revert it,replace OR by AND
  1446. * */
  1447. if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
  1448. (card->info.type == QETH_CARD_TYPE_OSD))
  1449. card->info.portname_required = 1;
  1450. memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
  1451. if (temp != qeth_peer_func_level(card->info.func_level)) {
  1452. QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
  1453. "level mismatch (sent: 0x%x, received: 0x%x)\n",
  1454. dev_name(&card->read.ccwdev->dev),
  1455. card->info.func_level, temp);
  1456. goto out;
  1457. }
  1458. memcpy(&card->token.issuer_rm_r,
  1459. QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
  1460. QETH_MPC_TOKEN_LENGTH);
  1461. memcpy(&card->info.mcl_level[0],
  1462. QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
  1463. channel->state = CH_STATE_UP;
  1464. out:
  1465. qeth_release_buffer(channel, iob);
  1466. }
  1467. void qeth_prepare_control_data(struct qeth_card *card, int len,
  1468. struct qeth_cmd_buffer *iob)
  1469. {
  1470. qeth_setup_ccw(&card->write, iob->data, len);
  1471. iob->callback = qeth_release_buffer;
  1472. memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
  1473. &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
  1474. card->seqno.trans_hdr++;
  1475. memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
  1476. &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
  1477. card->seqno.pdu_hdr++;
  1478. memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
  1479. &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
  1480. QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
  1481. }
  1482. EXPORT_SYMBOL_GPL(qeth_prepare_control_data);
  1483. int qeth_send_control_data(struct qeth_card *card, int len,
  1484. struct qeth_cmd_buffer *iob,
  1485. int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
  1486. unsigned long),
  1487. void *reply_param)
  1488. {
  1489. int rc;
  1490. unsigned long flags;
  1491. struct qeth_reply *reply = NULL;
  1492. unsigned long timeout, event_timeout;
  1493. struct qeth_ipa_cmd *cmd;
  1494. QETH_CARD_TEXT(card, 2, "sendctl");
  1495. reply = qeth_alloc_reply(card);
  1496. if (!reply) {
  1497. return -ENOMEM;
  1498. }
  1499. reply->callback = reply_cb;
  1500. reply->param = reply_param;
  1501. if (card->state == CARD_STATE_DOWN)
  1502. reply->seqno = QETH_IDX_COMMAND_SEQNO;
  1503. else
  1504. reply->seqno = card->seqno.ipa++;
  1505. init_waitqueue_head(&reply->wait_q);
  1506. spin_lock_irqsave(&card->lock, flags);
  1507. list_add_tail(&reply->list, &card->cmd_waiter_list);
  1508. spin_unlock_irqrestore(&card->lock, flags);
  1509. QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN);
  1510. while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
  1511. qeth_prepare_control_data(card, len, iob);
  1512. if (IS_IPA(iob->data))
  1513. event_timeout = QETH_IPA_TIMEOUT;
  1514. else
  1515. event_timeout = QETH_TIMEOUT;
  1516. timeout = jiffies + event_timeout;
  1517. QETH_CARD_TEXT(card, 6, "noirqpnd");
  1518. spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
  1519. rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
  1520. (addr_t) iob, 0, 0);
  1521. spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
  1522. if (rc) {
  1523. QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
  1524. "ccw_device_start rc = %i\n",
  1525. dev_name(&card->write.ccwdev->dev), rc);
  1526. QETH_CARD_TEXT_(card, 2, " err%d", rc);
  1527. spin_lock_irqsave(&card->lock, flags);
  1528. list_del_init(&reply->list);
  1529. qeth_put_reply(reply);
  1530. spin_unlock_irqrestore(&card->lock, flags);
  1531. qeth_release_buffer(iob->channel, iob);
  1532. atomic_set(&card->write.irq_pending, 0);
  1533. wake_up(&card->wait_q);
  1534. return rc;
  1535. }
  1536. /* we have only one long running ipassist, since we can ensure
  1537. process context of this command we can sleep */
  1538. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1539. if ((cmd->hdr.command == IPA_CMD_SETIP) &&
  1540. (cmd->hdr.prot_version == QETH_PROT_IPV4)) {
  1541. if (!wait_event_timeout(reply->wait_q,
  1542. atomic_read(&reply->received), event_timeout))
  1543. goto time_err;
  1544. } else {
  1545. while (!atomic_read(&reply->received)) {
  1546. if (time_after(jiffies, timeout))
  1547. goto time_err;
  1548. cpu_relax();
  1549. };
  1550. }
  1551. rc = reply->rc;
  1552. qeth_put_reply(reply);
  1553. return rc;
  1554. time_err:
  1555. spin_lock_irqsave(&reply->card->lock, flags);
  1556. list_del_init(&reply->list);
  1557. spin_unlock_irqrestore(&reply->card->lock, flags);
  1558. reply->rc = -ETIME;
  1559. atomic_inc(&reply->received);
  1560. wake_up(&reply->wait_q);
  1561. rc = reply->rc;
  1562. qeth_put_reply(reply);
  1563. return rc;
  1564. }
  1565. EXPORT_SYMBOL_GPL(qeth_send_control_data);
  1566. static int qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
  1567. unsigned long data)
  1568. {
  1569. struct qeth_cmd_buffer *iob;
  1570. QETH_DBF_TEXT(SETUP, 2, "cmenblcb");
  1571. iob = (struct qeth_cmd_buffer *) data;
  1572. memcpy(&card->token.cm_filter_r,
  1573. QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
  1574. QETH_MPC_TOKEN_LENGTH);
  1575. QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
  1576. return 0;
  1577. }
  1578. static int qeth_cm_enable(struct qeth_card *card)
  1579. {
  1580. int rc;
  1581. struct qeth_cmd_buffer *iob;
  1582. QETH_DBF_TEXT(SETUP, 2, "cmenable");
  1583. iob = qeth_wait_for_buffer(&card->write);
  1584. memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
  1585. memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
  1586. &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
  1587. memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
  1588. &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
  1589. rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
  1590. qeth_cm_enable_cb, NULL);
  1591. return rc;
  1592. }
  1593. static int qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
  1594. unsigned long data)
  1595. {
  1596. struct qeth_cmd_buffer *iob;
  1597. QETH_DBF_TEXT(SETUP, 2, "cmsetpcb");
  1598. iob = (struct qeth_cmd_buffer *) data;
  1599. memcpy(&card->token.cm_connection_r,
  1600. QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
  1601. QETH_MPC_TOKEN_LENGTH);
  1602. QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
  1603. return 0;
  1604. }
  1605. static int qeth_cm_setup(struct qeth_card *card)
  1606. {
  1607. int rc;
  1608. struct qeth_cmd_buffer *iob;
  1609. QETH_DBF_TEXT(SETUP, 2, "cmsetup");
  1610. iob = qeth_wait_for_buffer(&card->write);
  1611. memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
  1612. memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
  1613. &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
  1614. memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
  1615. &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
  1616. memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
  1617. &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
  1618. rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
  1619. qeth_cm_setup_cb, NULL);
  1620. return rc;
  1621. }
  1622. static inline int qeth_get_initial_mtu_for_card(struct qeth_card *card)
  1623. {
  1624. switch (card->info.type) {
  1625. case QETH_CARD_TYPE_UNKNOWN:
  1626. return 1500;
  1627. case QETH_CARD_TYPE_IQD:
  1628. return card->info.max_mtu;
  1629. case QETH_CARD_TYPE_OSD:
  1630. switch (card->info.link_type) {
  1631. case QETH_LINK_TYPE_HSTR:
  1632. case QETH_LINK_TYPE_LANE_TR:
  1633. return 2000;
  1634. default:
  1635. return 1492;
  1636. }
  1637. case QETH_CARD_TYPE_OSM:
  1638. case QETH_CARD_TYPE_OSX:
  1639. return 1492;
  1640. default:
  1641. return 1500;
  1642. }
  1643. }
  1644. static inline int qeth_get_max_mtu_for_card(int cardtype)
  1645. {
  1646. switch (cardtype) {
  1647. case QETH_CARD_TYPE_UNKNOWN:
  1648. case QETH_CARD_TYPE_OSD:
  1649. case QETH_CARD_TYPE_OSN:
  1650. case QETH_CARD_TYPE_OSM:
  1651. case QETH_CARD_TYPE_OSX:
  1652. return 61440;
  1653. case QETH_CARD_TYPE_IQD:
  1654. return 57344;
  1655. default:
  1656. return 1500;
  1657. }
  1658. }
  1659. static inline int qeth_get_mtu_out_of_mpc(int cardtype)
  1660. {
  1661. switch (cardtype) {
  1662. case QETH_CARD_TYPE_IQD:
  1663. return 1;
  1664. default:
  1665. return 0;
  1666. }
  1667. }
  1668. static inline int qeth_get_mtu_outof_framesize(int framesize)
  1669. {
  1670. switch (framesize) {
  1671. case 0x4000:
  1672. return 8192;
  1673. case 0x6000:
  1674. return 16384;
  1675. case 0xa000:
  1676. return 32768;
  1677. case 0xffff:
  1678. return 57344;
  1679. default:
  1680. return 0;
  1681. }
  1682. }
  1683. static inline int qeth_mtu_is_valid(struct qeth_card *card, int mtu)
  1684. {
  1685. switch (card->info.type) {
  1686. case QETH_CARD_TYPE_OSD:
  1687. case QETH_CARD_TYPE_OSM:
  1688. case QETH_CARD_TYPE_OSX:
  1689. return ((mtu >= 576) && (mtu <= 61440));
  1690. case QETH_CARD_TYPE_IQD:
  1691. return ((mtu >= 576) &&
  1692. (mtu <= card->info.max_mtu + 4096 - 32));
  1693. case QETH_CARD_TYPE_OSN:
  1694. case QETH_CARD_TYPE_UNKNOWN:
  1695. default:
  1696. return 1;
  1697. }
  1698. }
  1699. static int qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
  1700. unsigned long data)
  1701. {
  1702. __u16 mtu, framesize;
  1703. __u16 len;
  1704. __u8 link_type;
  1705. struct qeth_cmd_buffer *iob;
  1706. QETH_DBF_TEXT(SETUP, 2, "ulpenacb");
  1707. iob = (struct qeth_cmd_buffer *) data;
  1708. memcpy(&card->token.ulp_filter_r,
  1709. QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
  1710. QETH_MPC_TOKEN_LENGTH);
  1711. if (qeth_get_mtu_out_of_mpc(card->info.type)) {
  1712. memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
  1713. mtu = qeth_get_mtu_outof_framesize(framesize);
  1714. if (!mtu) {
  1715. iob->rc = -EINVAL;
  1716. QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
  1717. return 0;
  1718. }
  1719. card->info.max_mtu = mtu;
  1720. card->info.initial_mtu = mtu;
  1721. card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
  1722. } else {
  1723. card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
  1724. card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
  1725. card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
  1726. }
  1727. memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
  1728. if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
  1729. memcpy(&link_type,
  1730. QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
  1731. card->info.link_type = link_type;
  1732. } else
  1733. card->info.link_type = 0;
  1734. QETH_DBF_TEXT_(SETUP, 2, "link%d", card->info.link_type);
  1735. QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
  1736. return 0;
  1737. }
  1738. static int qeth_ulp_enable(struct qeth_card *card)
  1739. {
  1740. int rc;
  1741. char prot_type;
  1742. struct qeth_cmd_buffer *iob;
  1743. /*FIXME: trace view callbacks*/
  1744. QETH_DBF_TEXT(SETUP, 2, "ulpenabl");
  1745. iob = qeth_wait_for_buffer(&card->write);
  1746. memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
  1747. *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
  1748. (__u8) card->info.portno;
  1749. if (card->options.layer2)
  1750. if (card->info.type == QETH_CARD_TYPE_OSN)
  1751. prot_type = QETH_PROT_OSN2;
  1752. else
  1753. prot_type = QETH_PROT_LAYER2;
  1754. else
  1755. prot_type = QETH_PROT_TCPIP;
  1756. memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data), &prot_type, 1);
  1757. memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
  1758. &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
  1759. memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
  1760. &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
  1761. memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
  1762. card->info.portname, 9);
  1763. rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
  1764. qeth_ulp_enable_cb, NULL);
  1765. return rc;
  1766. }
  1767. static int qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
  1768. unsigned long data)
  1769. {
  1770. struct qeth_cmd_buffer *iob;
  1771. int rc = 0;
  1772. QETH_DBF_TEXT(SETUP, 2, "ulpstpcb");
  1773. iob = (struct qeth_cmd_buffer *) data;
  1774. memcpy(&card->token.ulp_connection_r,
  1775. QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
  1776. QETH_MPC_TOKEN_LENGTH);
  1777. if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
  1778. 3)) {
  1779. QETH_DBF_TEXT(SETUP, 2, "olmlimit");
  1780. dev_err(&card->gdev->dev, "A connection could not be "
  1781. "established because of an OLM limit\n");
  1782. rc = -EMLINK;
  1783. }
  1784. QETH_DBF_TEXT_(SETUP, 2, " rc%d", iob->rc);
  1785. return rc;
  1786. }
  1787. static int qeth_ulp_setup(struct qeth_card *card)
  1788. {
  1789. int rc;
  1790. __u16 temp;
  1791. struct qeth_cmd_buffer *iob;
  1792. struct ccw_dev_id dev_id;
  1793. QETH_DBF_TEXT(SETUP, 2, "ulpsetup");
  1794. iob = qeth_wait_for_buffer(&card->write);
  1795. memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
  1796. memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
  1797. &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
  1798. memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
  1799. &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
  1800. memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
  1801. &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
  1802. ccw_device_get_id(CARD_DDEV(card), &dev_id);
  1803. memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
  1804. temp = (card->info.cula << 8) + card->info.unit_addr2;
  1805. memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
  1806. rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
  1807. qeth_ulp_setup_cb, NULL);
  1808. return rc;
  1809. }
  1810. static int qeth_alloc_qdio_buffers(struct qeth_card *card)
  1811. {
  1812. int i, j;
  1813. QETH_DBF_TEXT(SETUP, 2, "allcqdbf");
  1814. if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
  1815. QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
  1816. return 0;
  1817. card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
  1818. GFP_KERNEL);
  1819. if (!card->qdio.in_q)
  1820. goto out_nomem;
  1821. QETH_DBF_TEXT(SETUP, 2, "inq");
  1822. QETH_DBF_HEX(SETUP, 2, &card->qdio.in_q, sizeof(void *));
  1823. memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
  1824. /* give inbound qeth_qdio_buffers their qdio_buffers */
  1825. for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
  1826. card->qdio.in_q->bufs[i].buffer =
  1827. &card->qdio.in_q->qdio_bufs[i];
  1828. /* inbound buffer pool */
  1829. if (qeth_alloc_buffer_pool(card))
  1830. goto out_freeinq;
  1831. /* outbound */
  1832. card->qdio.out_qs =
  1833. kmalloc(card->qdio.no_out_queues *
  1834. sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
  1835. if (!card->qdio.out_qs)
  1836. goto out_freepool;
  1837. for (i = 0; i < card->qdio.no_out_queues; ++i) {
  1838. card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
  1839. GFP_KERNEL);
  1840. if (!card->qdio.out_qs[i])
  1841. goto out_freeoutq;
  1842. QETH_DBF_TEXT_(SETUP, 2, "outq %i", i);
  1843. QETH_DBF_HEX(SETUP, 2, &card->qdio.out_qs[i], sizeof(void *));
  1844. memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
  1845. card->qdio.out_qs[i]->queue_no = i;
  1846. /* give outbound qeth_qdio_buffers their qdio_buffers */
  1847. for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
  1848. card->qdio.out_qs[i]->bufs[j].buffer =
  1849. &card->qdio.out_qs[i]->qdio_bufs[j];
  1850. skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
  1851. skb_list);
  1852. lockdep_set_class(
  1853. &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
  1854. &qdio_out_skb_queue_key);
  1855. INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
  1856. }
  1857. }
  1858. return 0;
  1859. out_freeoutq:
  1860. while (i > 0)
  1861. kfree(card->qdio.out_qs[--i]);
  1862. kfree(card->qdio.out_qs);
  1863. card->qdio.out_qs = NULL;
  1864. out_freepool:
  1865. qeth_free_buffer_pool(card);
  1866. out_freeinq:
  1867. kfree(card->qdio.in_q);
  1868. card->qdio.in_q = NULL;
  1869. out_nomem:
  1870. atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
  1871. return -ENOMEM;
  1872. }
  1873. static void qeth_create_qib_param_field(struct qeth_card *card,
  1874. char *param_field)
  1875. {
  1876. param_field[0] = _ascebc['P'];
  1877. param_field[1] = _ascebc['C'];
  1878. param_field[2] = _ascebc['I'];
  1879. param_field[3] = _ascebc['T'];
  1880. *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
  1881. *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
  1882. *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
  1883. }
  1884. static void qeth_create_qib_param_field_blkt(struct qeth_card *card,
  1885. char *param_field)
  1886. {
  1887. param_field[16] = _ascebc['B'];
  1888. param_field[17] = _ascebc['L'];
  1889. param_field[18] = _ascebc['K'];
  1890. param_field[19] = _ascebc['T'];
  1891. *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
  1892. *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
  1893. *((unsigned int *) (&param_field[28])) =
  1894. card->info.blkt.inter_packet_jumbo;
  1895. }
  1896. static int qeth_qdio_activate(struct qeth_card *card)
  1897. {
  1898. QETH_DBF_TEXT(SETUP, 3, "qdioact");
  1899. return qdio_activate(CARD_DDEV(card));
  1900. }
  1901. static int qeth_dm_act(struct qeth_card *card)
  1902. {
  1903. int rc;
  1904. struct qeth_cmd_buffer *iob;
  1905. QETH_DBF_TEXT(SETUP, 2, "dmact");
  1906. iob = qeth_wait_for_buffer(&card->write);
  1907. memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
  1908. memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
  1909. &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
  1910. memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
  1911. &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
  1912. rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
  1913. return rc;
  1914. }
  1915. static int qeth_mpc_initialize(struct qeth_card *card)
  1916. {
  1917. int rc;
  1918. QETH_DBF_TEXT(SETUP, 2, "mpcinit");
  1919. rc = qeth_issue_next_read(card);
  1920. if (rc) {
  1921. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  1922. return rc;
  1923. }
  1924. rc = qeth_cm_enable(card);
  1925. if (rc) {
  1926. QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
  1927. goto out_qdio;
  1928. }
  1929. rc = qeth_cm_setup(card);
  1930. if (rc) {
  1931. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  1932. goto out_qdio;
  1933. }
  1934. rc = qeth_ulp_enable(card);
  1935. if (rc) {
  1936. QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
  1937. goto out_qdio;
  1938. }
  1939. rc = qeth_ulp_setup(card);
  1940. if (rc) {
  1941. QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
  1942. goto out_qdio;
  1943. }
  1944. rc = qeth_alloc_qdio_buffers(card);
  1945. if (rc) {
  1946. QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
  1947. goto out_qdio;
  1948. }
  1949. rc = qeth_qdio_establish(card);
  1950. if (rc) {
  1951. QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
  1952. qeth_free_qdio_buffers(card);
  1953. goto out_qdio;
  1954. }
  1955. rc = qeth_qdio_activate(card);
  1956. if (rc) {
  1957. QETH_DBF_TEXT_(SETUP, 2, "7err%d", rc);
  1958. goto out_qdio;
  1959. }
  1960. rc = qeth_dm_act(card);
  1961. if (rc) {
  1962. QETH_DBF_TEXT_(SETUP, 2, "8err%d", rc);
  1963. goto out_qdio;
  1964. }
  1965. return 0;
  1966. out_qdio:
  1967. qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
  1968. return rc;
  1969. }
  1970. static void qeth_print_status_with_portname(struct qeth_card *card)
  1971. {
  1972. char dbf_text[15];
  1973. int i;
  1974. sprintf(dbf_text, "%s", card->info.portname + 1);
  1975. for (i = 0; i < 8; i++)
  1976. dbf_text[i] =
  1977. (char) _ebcasc[(__u8) dbf_text[i]];
  1978. dbf_text[8] = 0;
  1979. dev_info(&card->gdev->dev, "Device is a%s card%s%s%s\n"
  1980. "with link type %s (portname: %s)\n",
  1981. qeth_get_cardname(card),
  1982. (card->info.mcl_level[0]) ? " (level: " : "",
  1983. (card->info.mcl_level[0]) ? card->info.mcl_level : "",
  1984. (card->info.mcl_level[0]) ? ")" : "",
  1985. qeth_get_cardname_short(card),
  1986. dbf_text);
  1987. }
  1988. static void qeth_print_status_no_portname(struct qeth_card *card)
  1989. {
  1990. if (card->info.portname[0])
  1991. dev_info(&card->gdev->dev, "Device is a%s "
  1992. "card%s%s%s\nwith link type %s "
  1993. "(no portname needed by interface).\n",
  1994. qeth_get_cardname(card),
  1995. (card->info.mcl_level[0]) ? " (level: " : "",
  1996. (card->info.mcl_level[0]) ? card->info.mcl_level : "",
  1997. (card->info.mcl_level[0]) ? ")" : "",
  1998. qeth_get_cardname_short(card));
  1999. else
  2000. dev_info(&card->gdev->dev, "Device is a%s "
  2001. "card%s%s%s\nwith link type %s.\n",
  2002. qeth_get_cardname(card),
  2003. (card->info.mcl_level[0]) ? " (level: " : "",
  2004. (card->info.mcl_level[0]) ? card->info.mcl_level : "",
  2005. (card->info.mcl_level[0]) ? ")" : "",
  2006. qeth_get_cardname_short(card));
  2007. }
  2008. void qeth_print_status_message(struct qeth_card *card)
  2009. {
  2010. switch (card->info.type) {
  2011. case QETH_CARD_TYPE_OSD:
  2012. case QETH_CARD_TYPE_OSM:
  2013. case QETH_CARD_TYPE_OSX:
  2014. /* VM will use a non-zero first character
  2015. * to indicate a HiperSockets like reporting
  2016. * of the level OSA sets the first character to zero
  2017. * */
  2018. if (!card->info.mcl_level[0]) {
  2019. sprintf(card->info.mcl_level, "%02x%02x",
  2020. card->info.mcl_level[2],
  2021. card->info.mcl_level[3]);
  2022. card->info.mcl_level[QETH_MCL_LENGTH] = 0;
  2023. break;
  2024. }
  2025. /* fallthrough */
  2026. case QETH_CARD_TYPE_IQD:
  2027. if ((card->info.guestlan) ||
  2028. (card->info.mcl_level[0] & 0x80)) {
  2029. card->info.mcl_level[0] = (char) _ebcasc[(__u8)
  2030. card->info.mcl_level[0]];
  2031. card->info.mcl_level[1] = (char) _ebcasc[(__u8)
  2032. card->info.mcl_level[1]];
  2033. card->info.mcl_level[2] = (char) _ebcasc[(__u8)
  2034. card->info.mcl_level[2]];
  2035. card->info.mcl_level[3] = (char) _ebcasc[(__u8)
  2036. card->info.mcl_level[3]];
  2037. card->info.mcl_level[QETH_MCL_LENGTH] = 0;
  2038. }
  2039. break;
  2040. default:
  2041. memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
  2042. }
  2043. if (card->info.portname_required)
  2044. qeth_print_status_with_portname(card);
  2045. else
  2046. qeth_print_status_no_portname(card);
  2047. }
  2048. EXPORT_SYMBOL_GPL(qeth_print_status_message);
  2049. static void qeth_initialize_working_pool_list(struct qeth_card *card)
  2050. {
  2051. struct qeth_buffer_pool_entry *entry;
  2052. QETH_CARD_TEXT(card, 5, "inwrklst");
  2053. list_for_each_entry(entry,
  2054. &card->qdio.init_pool.entry_list, init_list) {
  2055. qeth_put_buffer_pool_entry(card, entry);
  2056. }
  2057. }
  2058. static inline struct qeth_buffer_pool_entry *qeth_find_free_buffer_pool_entry(
  2059. struct qeth_card *card)
  2060. {
  2061. struct list_head *plh;
  2062. struct qeth_buffer_pool_entry *entry;
  2063. int i, free;
  2064. struct page *page;
  2065. if (list_empty(&card->qdio.in_buf_pool.entry_list))
  2066. return NULL;
  2067. list_for_each(plh, &card->qdio.in_buf_pool.entry_list) {
  2068. entry = list_entry(plh, struct qeth_buffer_pool_entry, list);
  2069. free = 1;
  2070. for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
  2071. if (page_count(virt_to_page(entry->elements[i])) > 1) {
  2072. free = 0;
  2073. break;
  2074. }
  2075. }
  2076. if (free) {
  2077. list_del_init(&entry->list);
  2078. return entry;
  2079. }
  2080. }
  2081. /* no free buffer in pool so take first one and swap pages */
  2082. entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
  2083. struct qeth_buffer_pool_entry, list);
  2084. for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
  2085. if (page_count(virt_to_page(entry->elements[i])) > 1) {
  2086. page = alloc_page(GFP_ATOMIC);
  2087. if (!page) {
  2088. return NULL;
  2089. } else {
  2090. free_page((unsigned long)entry->elements[i]);
  2091. entry->elements[i] = page_address(page);
  2092. if (card->options.performance_stats)
  2093. card->perf_stats.sg_alloc_page_rx++;
  2094. }
  2095. }
  2096. }
  2097. list_del_init(&entry->list);
  2098. return entry;
  2099. }
  2100. static int qeth_init_input_buffer(struct qeth_card *card,
  2101. struct qeth_qdio_buffer *buf)
  2102. {
  2103. struct qeth_buffer_pool_entry *pool_entry;
  2104. int i;
  2105. pool_entry = qeth_find_free_buffer_pool_entry(card);
  2106. if (!pool_entry)
  2107. return 1;
  2108. /*
  2109. * since the buffer is accessed only from the input_tasklet
  2110. * there shouldn't be a need to synchronize; also, since we use
  2111. * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
  2112. * buffers
  2113. */
  2114. buf->pool_entry = pool_entry;
  2115. for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) {
  2116. buf->buffer->element[i].length = PAGE_SIZE;
  2117. buf->buffer->element[i].addr = pool_entry->elements[i];
  2118. if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
  2119. buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
  2120. else
  2121. buf->buffer->element[i].flags = 0;
  2122. }
  2123. return 0;
  2124. }
  2125. int qeth_init_qdio_queues(struct qeth_card *card)
  2126. {
  2127. int i, j;
  2128. int rc;
  2129. QETH_DBF_TEXT(SETUP, 2, "initqdqs");
  2130. /* inbound queue */
  2131. memset(card->qdio.in_q->qdio_bufs, 0,
  2132. QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
  2133. qeth_initialize_working_pool_list(card);
  2134. /*give only as many buffers to hardware as we have buffer pool entries*/
  2135. for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
  2136. qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
  2137. card->qdio.in_q->next_buf_to_init =
  2138. card->qdio.in_buf_pool.buf_count - 1;
  2139. rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
  2140. card->qdio.in_buf_pool.buf_count - 1);
  2141. if (rc) {
  2142. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  2143. return rc;
  2144. }
  2145. /* outbound queue */
  2146. for (i = 0; i < card->qdio.no_out_queues; ++i) {
  2147. memset(card->qdio.out_qs[i]->qdio_bufs, 0,
  2148. QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
  2149. for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) {
  2150. qeth_clear_output_buffer(card->qdio.out_qs[i],
  2151. &card->qdio.out_qs[i]->bufs[j]);
  2152. }
  2153. card->qdio.out_qs[i]->card = card;
  2154. card->qdio.out_qs[i]->next_buf_to_fill = 0;
  2155. card->qdio.out_qs[i]->do_pack = 0;
  2156. atomic_set(&card->qdio.out_qs[i]->used_buffers, 0);
  2157. atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
  2158. atomic_set(&card->qdio.out_qs[i]->state,
  2159. QETH_OUT_Q_UNLOCKED);
  2160. }
  2161. return 0;
  2162. }
  2163. EXPORT_SYMBOL_GPL(qeth_init_qdio_queues);
  2164. static inline __u8 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
  2165. {
  2166. switch (link_type) {
  2167. case QETH_LINK_TYPE_HSTR:
  2168. return 2;
  2169. default:
  2170. return 1;
  2171. }
  2172. }
  2173. static void qeth_fill_ipacmd_header(struct qeth_card *card,
  2174. struct qeth_ipa_cmd *cmd, __u8 command,
  2175. enum qeth_prot_versions prot)
  2176. {
  2177. memset(cmd, 0, sizeof(struct qeth_ipa_cmd));
  2178. cmd->hdr.command = command;
  2179. cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
  2180. cmd->hdr.seqno = card->seqno.ipa;
  2181. cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
  2182. cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
  2183. if (card->options.layer2)
  2184. cmd->hdr.prim_version_no = 2;
  2185. else
  2186. cmd->hdr.prim_version_no = 1;
  2187. cmd->hdr.param_count = 1;
  2188. cmd->hdr.prot_version = prot;
  2189. cmd->hdr.ipa_supported = 0;
  2190. cmd->hdr.ipa_enabled = 0;
  2191. }
  2192. struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *card,
  2193. enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
  2194. {
  2195. struct qeth_cmd_buffer *iob;
  2196. struct qeth_ipa_cmd *cmd;
  2197. iob = qeth_wait_for_buffer(&card->write);
  2198. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  2199. qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
  2200. return iob;
  2201. }
  2202. EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer);
  2203. void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
  2204. char prot_type)
  2205. {
  2206. memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
  2207. memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data), &prot_type, 1);
  2208. memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
  2209. &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
  2210. }
  2211. EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd);
  2212. int qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
  2213. int (*reply_cb)(struct qeth_card *, struct qeth_reply*,
  2214. unsigned long),
  2215. void *reply_param)
  2216. {
  2217. int rc;
  2218. char prot_type;
  2219. QETH_CARD_TEXT(card, 4, "sendipa");
  2220. if (card->options.layer2)
  2221. if (card->info.type == QETH_CARD_TYPE_OSN)
  2222. prot_type = QETH_PROT_OSN2;
  2223. else
  2224. prot_type = QETH_PROT_LAYER2;
  2225. else
  2226. prot_type = QETH_PROT_TCPIP;
  2227. qeth_prepare_ipa_cmd(card, iob, prot_type);
  2228. rc = qeth_send_control_data(card, IPA_CMD_LENGTH,
  2229. iob, reply_cb, reply_param);
  2230. return rc;
  2231. }
  2232. EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd);
  2233. static int qeth_send_startstoplan(struct qeth_card *card,
  2234. enum qeth_ipa_cmds ipacmd, enum qeth_prot_versions prot)
  2235. {
  2236. int rc;
  2237. struct qeth_cmd_buffer *iob;
  2238. iob = qeth_get_ipacmd_buffer(card, ipacmd, prot);
  2239. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  2240. return rc;
  2241. }
  2242. int qeth_send_startlan(struct qeth_card *card)
  2243. {
  2244. int rc;
  2245. QETH_DBF_TEXT(SETUP, 2, "strtlan");
  2246. rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, 0);
  2247. return rc;
  2248. }
  2249. EXPORT_SYMBOL_GPL(qeth_send_startlan);
  2250. int qeth_send_stoplan(struct qeth_card *card)
  2251. {
  2252. int rc = 0;
  2253. /*
  2254. * TODO: according to the IPA format document page 14,
  2255. * TCP/IP (we!) never issue a STOPLAN
  2256. * is this right ?!?
  2257. */
  2258. QETH_DBF_TEXT(SETUP, 2, "stoplan");
  2259. rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, 0);
  2260. return rc;
  2261. }
  2262. EXPORT_SYMBOL_GPL(qeth_send_stoplan);
  2263. int qeth_default_setadapterparms_cb(struct qeth_card *card,
  2264. struct qeth_reply *reply, unsigned long data)
  2265. {
  2266. struct qeth_ipa_cmd *cmd;
  2267. QETH_CARD_TEXT(card, 4, "defadpcb");
  2268. cmd = (struct qeth_ipa_cmd *) data;
  2269. if (cmd->hdr.return_code == 0)
  2270. cmd->hdr.return_code =
  2271. cmd->data.setadapterparms.hdr.return_code;
  2272. return 0;
  2273. }
  2274. EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb);
  2275. static int qeth_query_setadapterparms_cb(struct qeth_card *card,
  2276. struct qeth_reply *reply, unsigned long data)
  2277. {
  2278. struct qeth_ipa_cmd *cmd;
  2279. QETH_CARD_TEXT(card, 3, "quyadpcb");
  2280. cmd = (struct qeth_ipa_cmd *) data;
  2281. if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) {
  2282. card->info.link_type =
  2283. cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
  2284. QETH_DBF_TEXT_(SETUP, 2, "lnk %d", card->info.link_type);
  2285. }
  2286. card->options.adp.supported_funcs =
  2287. cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
  2288. return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
  2289. }
  2290. struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *card,
  2291. __u32 command, __u32 cmdlen)
  2292. {
  2293. struct qeth_cmd_buffer *iob;
  2294. struct qeth_ipa_cmd *cmd;
  2295. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETADAPTERPARMS,
  2296. QETH_PROT_IPV4);
  2297. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  2298. cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
  2299. cmd->data.setadapterparms.hdr.command_code = command;
  2300. cmd->data.setadapterparms.hdr.used_total = 1;
  2301. cmd->data.setadapterparms.hdr.seq_no = 1;
  2302. return iob;
  2303. }
  2304. EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd);
  2305. int qeth_query_setadapterparms(struct qeth_card *card)
  2306. {
  2307. int rc;
  2308. struct qeth_cmd_buffer *iob;
  2309. QETH_CARD_TEXT(card, 3, "queryadp");
  2310. iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
  2311. sizeof(struct qeth_ipacmd_setadpparms));
  2312. rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
  2313. return rc;
  2314. }
  2315. EXPORT_SYMBOL_GPL(qeth_query_setadapterparms);
  2316. int qeth_check_qdio_errors(struct qeth_card *card, struct qdio_buffer *buf,
  2317. unsigned int qdio_error, const char *dbftext)
  2318. {
  2319. if (qdio_error) {
  2320. QETH_CARD_TEXT(card, 2, dbftext);
  2321. QETH_CARD_TEXT_(card, 2, " F15=%02X",
  2322. buf->element[15].flags & 0xff);
  2323. QETH_CARD_TEXT_(card, 2, " F14=%02X",
  2324. buf->element[14].flags & 0xff);
  2325. QETH_CARD_TEXT_(card, 2, " qerr=%X", qdio_error);
  2326. if ((buf->element[15].flags & 0xff) == 0x12) {
  2327. card->stats.rx_dropped++;
  2328. return 0;
  2329. } else
  2330. return 1;
  2331. }
  2332. return 0;
  2333. }
  2334. EXPORT_SYMBOL_GPL(qeth_check_qdio_errors);
  2335. void qeth_queue_input_buffer(struct qeth_card *card, int index)
  2336. {
  2337. struct qeth_qdio_q *queue = card->qdio.in_q;
  2338. int count;
  2339. int i;
  2340. int rc;
  2341. int newcount = 0;
  2342. count = (index < queue->next_buf_to_init)?
  2343. card->qdio.in_buf_pool.buf_count -
  2344. (queue->next_buf_to_init - index) :
  2345. card->qdio.in_buf_pool.buf_count -
  2346. (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
  2347. /* only requeue at a certain threshold to avoid SIGAs */
  2348. if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)) {
  2349. for (i = queue->next_buf_to_init;
  2350. i < queue->next_buf_to_init + count; ++i) {
  2351. if (qeth_init_input_buffer(card,
  2352. &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q])) {
  2353. break;
  2354. } else {
  2355. newcount++;
  2356. }
  2357. }
  2358. if (newcount < count) {
  2359. /* we are in memory shortage so we switch back to
  2360. traditional skb allocation and drop packages */
  2361. atomic_set(&card->force_alloc_skb, 3);
  2362. count = newcount;
  2363. } else {
  2364. atomic_add_unless(&card->force_alloc_skb, -1, 0);
  2365. }
  2366. /*
  2367. * according to old code it should be avoided to requeue all
  2368. * 128 buffers in order to benefit from PCI avoidance.
  2369. * this function keeps at least one buffer (the buffer at
  2370. * 'index') un-requeued -> this buffer is the first buffer that
  2371. * will be requeued the next time
  2372. */
  2373. if (card->options.performance_stats) {
  2374. card->perf_stats.inbound_do_qdio_cnt++;
  2375. card->perf_stats.inbound_do_qdio_start_time =
  2376. qeth_get_micros();
  2377. }
  2378. rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0,
  2379. queue->next_buf_to_init, count);
  2380. if (card->options.performance_stats)
  2381. card->perf_stats.inbound_do_qdio_time +=
  2382. qeth_get_micros() -
  2383. card->perf_stats.inbound_do_qdio_start_time;
  2384. if (rc) {
  2385. dev_warn(&card->gdev->dev,
  2386. "QDIO reported an error, rc=%i\n", rc);
  2387. QETH_CARD_TEXT(card, 2, "qinberr");
  2388. }
  2389. queue->next_buf_to_init = (queue->next_buf_to_init + count) %
  2390. QDIO_MAX_BUFFERS_PER_Q;
  2391. }
  2392. }
  2393. EXPORT_SYMBOL_GPL(qeth_queue_input_buffer);
  2394. static int qeth_handle_send_error(struct qeth_card *card,
  2395. struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err)
  2396. {
  2397. int sbalf15 = buffer->buffer->element[15].flags & 0xff;
  2398. QETH_CARD_TEXT(card, 6, "hdsnderr");
  2399. if (card->info.type == QETH_CARD_TYPE_IQD) {
  2400. if (sbalf15 == 0) {
  2401. qdio_err = 0;
  2402. } else {
  2403. qdio_err = 1;
  2404. }
  2405. }
  2406. qeth_check_qdio_errors(card, buffer->buffer, qdio_err, "qouterr");
  2407. if (!qdio_err)
  2408. return QETH_SEND_ERROR_NONE;
  2409. if ((sbalf15 >= 15) && (sbalf15 <= 31))
  2410. return QETH_SEND_ERROR_RETRY;
  2411. QETH_CARD_TEXT(card, 1, "lnkfail");
  2412. QETH_CARD_TEXT_(card, 1, "%04x %02x",
  2413. (u16)qdio_err, (u8)sbalf15);
  2414. return QETH_SEND_ERROR_LINK_FAILURE;
  2415. }
  2416. /*
  2417. * Switched to packing state if the number of used buffers on a queue
  2418. * reaches a certain limit.
  2419. */
  2420. static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
  2421. {
  2422. if (!queue->do_pack) {
  2423. if (atomic_read(&queue->used_buffers)
  2424. >= QETH_HIGH_WATERMARK_PACK){
  2425. /* switch non-PACKING -> PACKING */
  2426. QETH_CARD_TEXT(queue->card, 6, "np->pack");
  2427. if (queue->card->options.performance_stats)
  2428. queue->card->perf_stats.sc_dp_p++;
  2429. queue->do_pack = 1;
  2430. }
  2431. }
  2432. }
  2433. /*
  2434. * Switches from packing to non-packing mode. If there is a packing
  2435. * buffer on the queue this buffer will be prepared to be flushed.
  2436. * In that case 1 is returned to inform the caller. If no buffer
  2437. * has to be flushed, zero is returned.
  2438. */
  2439. static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
  2440. {
  2441. struct qeth_qdio_out_buffer *buffer;
  2442. int flush_count = 0;
  2443. if (queue->do_pack) {
  2444. if (atomic_read(&queue->used_buffers)
  2445. <= QETH_LOW_WATERMARK_PACK) {
  2446. /* switch PACKING -> non-PACKING */
  2447. QETH_CARD_TEXT(queue->card, 6, "pack->np");
  2448. if (queue->card->options.performance_stats)
  2449. queue->card->perf_stats.sc_p_dp++;
  2450. queue->do_pack = 0;
  2451. /* flush packing buffers */
  2452. buffer = &queue->bufs[queue->next_buf_to_fill];
  2453. if ((atomic_read(&buffer->state) ==
  2454. QETH_QDIO_BUF_EMPTY) &&
  2455. (buffer->next_element_to_fill > 0)) {
  2456. atomic_set(&buffer->state,
  2457. QETH_QDIO_BUF_PRIMED);
  2458. flush_count++;
  2459. queue->next_buf_to_fill =
  2460. (queue->next_buf_to_fill + 1) %
  2461. QDIO_MAX_BUFFERS_PER_Q;
  2462. }
  2463. }
  2464. }
  2465. return flush_count;
  2466. }
  2467. /*
  2468. * Called to flush a packing buffer if no more pci flags are on the queue.
  2469. * Checks if there is a packing buffer and prepares it to be flushed.
  2470. * In that case returns 1, otherwise zero.
  2471. */
  2472. static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
  2473. {
  2474. struct qeth_qdio_out_buffer *buffer;
  2475. buffer = &queue->bufs[queue->next_buf_to_fill];
  2476. if ((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
  2477. (buffer->next_element_to_fill > 0)) {
  2478. /* it's a packing buffer */
  2479. atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
  2480. queue->next_buf_to_fill =
  2481. (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
  2482. return 1;
  2483. }
  2484. return 0;
  2485. }
  2486. static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index,
  2487. int count)
  2488. {
  2489. struct qeth_qdio_out_buffer *buf;
  2490. int rc;
  2491. int i;
  2492. unsigned int qdio_flags;
  2493. for (i = index; i < index + count; ++i) {
  2494. buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
  2495. buf->buffer->element[buf->next_element_to_fill - 1].flags |=
  2496. SBAL_FLAGS_LAST_ENTRY;
  2497. if (queue->card->info.type == QETH_CARD_TYPE_IQD)
  2498. continue;
  2499. if (!queue->do_pack) {
  2500. if ((atomic_read(&queue->used_buffers) >=
  2501. (QETH_HIGH_WATERMARK_PACK -
  2502. QETH_WATERMARK_PACK_FUZZ)) &&
  2503. !atomic_read(&queue->set_pci_flags_count)) {
  2504. /* it's likely that we'll go to packing
  2505. * mode soon */
  2506. atomic_inc(&queue->set_pci_flags_count);
  2507. buf->buffer->element[0].flags |= 0x40;
  2508. }
  2509. } else {
  2510. if (!atomic_read(&queue->set_pci_flags_count)) {
  2511. /*
  2512. * there's no outstanding PCI any more, so we
  2513. * have to request a PCI to be sure the the PCI
  2514. * will wake at some time in the future then we
  2515. * can flush packed buffers that might still be
  2516. * hanging around, which can happen if no
  2517. * further send was requested by the stack
  2518. */
  2519. atomic_inc(&queue->set_pci_flags_count);
  2520. buf->buffer->element[0].flags |= 0x40;
  2521. }
  2522. }
  2523. }
  2524. queue->sync_iqdio_error = 0;
  2525. queue->card->dev->trans_start = jiffies;
  2526. if (queue->card->options.performance_stats) {
  2527. queue->card->perf_stats.outbound_do_qdio_cnt++;
  2528. queue->card->perf_stats.outbound_do_qdio_start_time =
  2529. qeth_get_micros();
  2530. }
  2531. qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
  2532. if (atomic_read(&queue->set_pci_flags_count))
  2533. qdio_flags |= QDIO_FLAG_PCI_OUT;
  2534. rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
  2535. queue->queue_no, index, count);
  2536. if (queue->card->options.performance_stats)
  2537. queue->card->perf_stats.outbound_do_qdio_time +=
  2538. qeth_get_micros() -
  2539. queue->card->perf_stats.outbound_do_qdio_start_time;
  2540. if (rc > 0) {
  2541. if (!(rc & QDIO_ERROR_SIGA_BUSY))
  2542. queue->sync_iqdio_error = rc & 3;
  2543. }
  2544. if (rc) {
  2545. queue->card->stats.tx_errors += count;
  2546. /* ignore temporary SIGA errors without busy condition */
  2547. if (rc == QDIO_ERROR_SIGA_TARGET)
  2548. return;
  2549. QETH_CARD_TEXT(queue->card, 2, "flushbuf");
  2550. QETH_CARD_TEXT_(queue->card, 2, " err%d", rc);
  2551. /* this must not happen under normal circumstances. if it
  2552. * happens something is really wrong -> recover */
  2553. qeth_schedule_recovery(queue->card);
  2554. return;
  2555. }
  2556. atomic_add(count, &queue->used_buffers);
  2557. if (queue->card->options.performance_stats)
  2558. queue->card->perf_stats.bufs_sent += count;
  2559. }
  2560. static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
  2561. {
  2562. int index;
  2563. int flush_cnt = 0;
  2564. int q_was_packing = 0;
  2565. /*
  2566. * check if weed have to switch to non-packing mode or if
  2567. * we have to get a pci flag out on the queue
  2568. */
  2569. if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
  2570. !atomic_read(&queue->set_pci_flags_count)) {
  2571. if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
  2572. QETH_OUT_Q_UNLOCKED) {
  2573. /*
  2574. * If we get in here, there was no action in
  2575. * do_send_packet. So, we check if there is a
  2576. * packing buffer to be flushed here.
  2577. */
  2578. netif_stop_queue(queue->card->dev);
  2579. index = queue->next_buf_to_fill;
  2580. q_was_packing = queue->do_pack;
  2581. /* queue->do_pack may change */
  2582. barrier();
  2583. flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
  2584. if (!flush_cnt &&
  2585. !atomic_read(&queue->set_pci_flags_count))
  2586. flush_cnt +=
  2587. qeth_flush_buffers_on_no_pci(queue);
  2588. if (queue->card->options.performance_stats &&
  2589. q_was_packing)
  2590. queue->card->perf_stats.bufs_sent_pack +=
  2591. flush_cnt;
  2592. if (flush_cnt)
  2593. qeth_flush_buffers(queue, index, flush_cnt);
  2594. atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
  2595. }
  2596. }
  2597. }
  2598. void qeth_qdio_output_handler(struct ccw_device *ccwdev,
  2599. unsigned int qdio_error, int __queue, int first_element,
  2600. int count, unsigned long card_ptr)
  2601. {
  2602. struct qeth_card *card = (struct qeth_card *) card_ptr;
  2603. struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
  2604. struct qeth_qdio_out_buffer *buffer;
  2605. int i;
  2606. unsigned qeth_send_err;
  2607. QETH_CARD_TEXT(card, 6, "qdouhdl");
  2608. if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
  2609. QETH_CARD_TEXT(card, 2, "achkcond");
  2610. netif_stop_queue(card->dev);
  2611. qeth_schedule_recovery(card);
  2612. return;
  2613. }
  2614. if (card->options.performance_stats) {
  2615. card->perf_stats.outbound_handler_cnt++;
  2616. card->perf_stats.outbound_handler_start_time =
  2617. qeth_get_micros();
  2618. }
  2619. for (i = first_element; i < (first_element + count); ++i) {
  2620. buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
  2621. qeth_send_err = qeth_handle_send_error(card, buffer, qdio_error);
  2622. __qeth_clear_output_buffer(queue, buffer,
  2623. (qeth_send_err == QETH_SEND_ERROR_RETRY) ? 1 : 0);
  2624. }
  2625. atomic_sub(count, &queue->used_buffers);
  2626. /* check if we need to do something on this outbound queue */
  2627. if (card->info.type != QETH_CARD_TYPE_IQD)
  2628. qeth_check_outbound_queue(queue);
  2629. netif_wake_queue(queue->card->dev);
  2630. if (card->options.performance_stats)
  2631. card->perf_stats.outbound_handler_time += qeth_get_micros() -
  2632. card->perf_stats.outbound_handler_start_time;
  2633. }
  2634. EXPORT_SYMBOL_GPL(qeth_qdio_output_handler);
  2635. int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
  2636. int ipv, int cast_type)
  2637. {
  2638. if (!ipv && (card->info.type == QETH_CARD_TYPE_OSD ||
  2639. card->info.type == QETH_CARD_TYPE_OSX))
  2640. return card->qdio.default_out_queue;
  2641. switch (card->qdio.no_out_queues) {
  2642. case 4:
  2643. if (cast_type && card->info.is_multicast_different)
  2644. return card->info.is_multicast_different &
  2645. (card->qdio.no_out_queues - 1);
  2646. if (card->qdio.do_prio_queueing && (ipv == 4)) {
  2647. const u8 tos = ip_hdr(skb)->tos;
  2648. if (card->qdio.do_prio_queueing ==
  2649. QETH_PRIO_Q_ING_TOS) {
  2650. if (tos & IP_TOS_NOTIMPORTANT)
  2651. return 3;
  2652. if (tos & IP_TOS_HIGHRELIABILITY)
  2653. return 2;
  2654. if (tos & IP_TOS_HIGHTHROUGHPUT)
  2655. return 1;
  2656. if (tos & IP_TOS_LOWDELAY)
  2657. return 0;
  2658. }
  2659. if (card->qdio.do_prio_queueing ==
  2660. QETH_PRIO_Q_ING_PREC)
  2661. return 3 - (tos >> 6);
  2662. } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
  2663. /* TODO: IPv6!!! */
  2664. }
  2665. return card->qdio.default_out_queue;
  2666. case 1: /* fallthrough for single-out-queue 1920-device */
  2667. default:
  2668. return card->qdio.default_out_queue;
  2669. }
  2670. }
  2671. EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
  2672. int qeth_get_elements_no(struct qeth_card *card, void *hdr,
  2673. struct sk_buff *skb, int elems)
  2674. {
  2675. int dlen = skb->len - skb->data_len;
  2676. int elements_needed = PFN_UP((unsigned long)skb->data + dlen - 1) -
  2677. PFN_DOWN((unsigned long)skb->data);
  2678. elements_needed += skb_shinfo(skb)->nr_frags;
  2679. if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
  2680. QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
  2681. "(Number=%d / Length=%d). Discarded.\n",
  2682. (elements_needed+elems), skb->len);
  2683. return 0;
  2684. }
  2685. return elements_needed;
  2686. }
  2687. EXPORT_SYMBOL_GPL(qeth_get_elements_no);
  2688. int qeth_hdr_chk_and_bounce(struct sk_buff *skb, int len)
  2689. {
  2690. int hroom, inpage, rest;
  2691. if (((unsigned long)skb->data & PAGE_MASK) !=
  2692. (((unsigned long)skb->data + len - 1) & PAGE_MASK)) {
  2693. hroom = skb_headroom(skb);
  2694. inpage = PAGE_SIZE - ((unsigned long) skb->data % PAGE_SIZE);
  2695. rest = len - inpage;
  2696. if (rest > hroom)
  2697. return 1;
  2698. memmove(skb->data - rest, skb->data, skb->len - skb->data_len);
  2699. skb->data -= rest;
  2700. QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len, rest);
  2701. }
  2702. return 0;
  2703. }
  2704. EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce);
  2705. static inline void __qeth_fill_buffer(struct sk_buff *skb,
  2706. struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill,
  2707. int offset)
  2708. {
  2709. int length = skb->len - skb->data_len;
  2710. int length_here;
  2711. int element;
  2712. char *data;
  2713. int first_lap, cnt;
  2714. struct skb_frag_struct *frag;
  2715. element = *next_element_to_fill;
  2716. data = skb->data;
  2717. first_lap = (is_tso == 0 ? 1 : 0);
  2718. if (offset >= 0) {
  2719. data = skb->data + offset;
  2720. length -= offset;
  2721. first_lap = 0;
  2722. }
  2723. while (length > 0) {
  2724. /* length_here is the remaining amount of data in this page */
  2725. length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
  2726. if (length < length_here)
  2727. length_here = length;
  2728. buffer->element[element].addr = data;
  2729. buffer->element[element].length = length_here;
  2730. length -= length_here;
  2731. if (!length) {
  2732. if (first_lap)
  2733. if (skb_shinfo(skb)->nr_frags)
  2734. buffer->element[element].flags =
  2735. SBAL_FLAGS_FIRST_FRAG;
  2736. else
  2737. buffer->element[element].flags = 0;
  2738. else
  2739. buffer->element[element].flags =
  2740. SBAL_FLAGS_MIDDLE_FRAG;
  2741. } else {
  2742. if (first_lap)
  2743. buffer->element[element].flags =
  2744. SBAL_FLAGS_FIRST_FRAG;
  2745. else
  2746. buffer->element[element].flags =
  2747. SBAL_FLAGS_MIDDLE_FRAG;
  2748. }
  2749. data += length_here;
  2750. element++;
  2751. first_lap = 0;
  2752. }
  2753. for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
  2754. frag = &skb_shinfo(skb)->frags[cnt];
  2755. buffer->element[element].addr = (char *)page_to_phys(frag->page)
  2756. + frag->page_offset;
  2757. buffer->element[element].length = frag->size;
  2758. buffer->element[element].flags = SBAL_FLAGS_MIDDLE_FRAG;
  2759. element++;
  2760. }
  2761. if (buffer->element[element - 1].flags)
  2762. buffer->element[element - 1].flags = SBAL_FLAGS_LAST_FRAG;
  2763. *next_element_to_fill = element;
  2764. }
  2765. static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
  2766. struct qeth_qdio_out_buffer *buf, struct sk_buff *skb,
  2767. struct qeth_hdr *hdr, int offset, int hd_len)
  2768. {
  2769. struct qdio_buffer *buffer;
  2770. int flush_cnt = 0, hdr_len, large_send = 0;
  2771. buffer = buf->buffer;
  2772. atomic_inc(&skb->users);
  2773. skb_queue_tail(&buf->skb_list, skb);
  2774. /*check first on TSO ....*/
  2775. if (hdr->hdr.l3.id == QETH_HEADER_TYPE_TSO) {
  2776. int element = buf->next_element_to_fill;
  2777. hdr_len = sizeof(struct qeth_hdr_tso) +
  2778. ((struct qeth_hdr_tso *)hdr)->ext.dg_hdr_len;
  2779. /*fill first buffer entry only with header information */
  2780. buffer->element[element].addr = skb->data;
  2781. buffer->element[element].length = hdr_len;
  2782. buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
  2783. buf->next_element_to_fill++;
  2784. skb->data += hdr_len;
  2785. skb->len -= hdr_len;
  2786. large_send = 1;
  2787. }
  2788. if (offset >= 0) {
  2789. int element = buf->next_element_to_fill;
  2790. buffer->element[element].addr = hdr;
  2791. buffer->element[element].length = sizeof(struct qeth_hdr) +
  2792. hd_len;
  2793. buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
  2794. buf->is_header[element] = 1;
  2795. buf->next_element_to_fill++;
  2796. }
  2797. __qeth_fill_buffer(skb, buffer, large_send,
  2798. (int *)&buf->next_element_to_fill, offset);
  2799. if (!queue->do_pack) {
  2800. QETH_CARD_TEXT(queue->card, 6, "fillbfnp");
  2801. /* set state to PRIMED -> will be flushed */
  2802. atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
  2803. flush_cnt = 1;
  2804. } else {
  2805. QETH_CARD_TEXT(queue->card, 6, "fillbfpa");
  2806. if (queue->card->options.performance_stats)
  2807. queue->card->perf_stats.skbs_sent_pack++;
  2808. if (buf->next_element_to_fill >=
  2809. QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
  2810. /*
  2811. * packed buffer if full -> set state PRIMED
  2812. * -> will be flushed
  2813. */
  2814. atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
  2815. flush_cnt = 1;
  2816. }
  2817. }
  2818. return flush_cnt;
  2819. }
  2820. int qeth_do_send_packet_fast(struct qeth_card *card,
  2821. struct qeth_qdio_out_q *queue, struct sk_buff *skb,
  2822. struct qeth_hdr *hdr, int elements_needed,
  2823. int offset, int hd_len)
  2824. {
  2825. struct qeth_qdio_out_buffer *buffer;
  2826. struct sk_buff *skb1;
  2827. struct qeth_skb_data *retry_ctrl;
  2828. int index;
  2829. int rc;
  2830. /* spin until we get the queue ... */
  2831. while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
  2832. QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
  2833. /* ... now we've got the queue */
  2834. index = queue->next_buf_to_fill;
  2835. buffer = &queue->bufs[queue->next_buf_to_fill];
  2836. /*
  2837. * check if buffer is empty to make sure that we do not 'overtake'
  2838. * ourselves and try to fill a buffer that is already primed
  2839. */
  2840. if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
  2841. goto out;
  2842. queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
  2843. QDIO_MAX_BUFFERS_PER_Q;
  2844. atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
  2845. qeth_fill_buffer(queue, buffer, skb, hdr, offset, hd_len);
  2846. qeth_flush_buffers(queue, index, 1);
  2847. if (queue->sync_iqdio_error == 2) {
  2848. skb1 = skb_dequeue(&buffer->skb_list);
  2849. while (skb1) {
  2850. atomic_dec(&skb1->users);
  2851. skb1 = skb_dequeue(&buffer->skb_list);
  2852. }
  2853. retry_ctrl = (struct qeth_skb_data *) &skb->cb[16];
  2854. if (retry_ctrl->magic != QETH_SKB_MAGIC) {
  2855. retry_ctrl->magic = QETH_SKB_MAGIC;
  2856. retry_ctrl->count = 0;
  2857. }
  2858. if (retry_ctrl->count < QETH_SIGA_CC2_RETRIES) {
  2859. retry_ctrl->count++;
  2860. rc = dev_queue_xmit(skb);
  2861. } else {
  2862. dev_kfree_skb_any(skb);
  2863. QETH_CARD_TEXT(card, 2, "qrdrop");
  2864. }
  2865. }
  2866. return 0;
  2867. out:
  2868. atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
  2869. return -EBUSY;
  2870. }
  2871. EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast);
  2872. int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
  2873. struct sk_buff *skb, struct qeth_hdr *hdr,
  2874. int elements_needed)
  2875. {
  2876. struct qeth_qdio_out_buffer *buffer;
  2877. int start_index;
  2878. int flush_count = 0;
  2879. int do_pack = 0;
  2880. int tmp;
  2881. int rc = 0;
  2882. /* spin until we get the queue ... */
  2883. while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
  2884. QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
  2885. start_index = queue->next_buf_to_fill;
  2886. buffer = &queue->bufs[queue->next_buf_to_fill];
  2887. /*
  2888. * check if buffer is empty to make sure that we do not 'overtake'
  2889. * ourselves and try to fill a buffer that is already primed
  2890. */
  2891. if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
  2892. atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
  2893. return -EBUSY;
  2894. }
  2895. /* check if we need to switch packing state of this queue */
  2896. qeth_switch_to_packing_if_needed(queue);
  2897. if (queue->do_pack) {
  2898. do_pack = 1;
  2899. /* does packet fit in current buffer? */
  2900. if ((QETH_MAX_BUFFER_ELEMENTS(card) -
  2901. buffer->next_element_to_fill) < elements_needed) {
  2902. /* ... no -> set state PRIMED */
  2903. atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
  2904. flush_count++;
  2905. queue->next_buf_to_fill =
  2906. (queue->next_buf_to_fill + 1) %
  2907. QDIO_MAX_BUFFERS_PER_Q;
  2908. buffer = &queue->bufs[queue->next_buf_to_fill];
  2909. /* we did a step forward, so check buffer state
  2910. * again */
  2911. if (atomic_read(&buffer->state) !=
  2912. QETH_QDIO_BUF_EMPTY) {
  2913. qeth_flush_buffers(queue, start_index,
  2914. flush_count);
  2915. atomic_set(&queue->state,
  2916. QETH_OUT_Q_UNLOCKED);
  2917. return -EBUSY;
  2918. }
  2919. }
  2920. }
  2921. tmp = qeth_fill_buffer(queue, buffer, skb, hdr, -1, 0);
  2922. queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
  2923. QDIO_MAX_BUFFERS_PER_Q;
  2924. flush_count += tmp;
  2925. if (flush_count)
  2926. qeth_flush_buffers(queue, start_index, flush_count);
  2927. else if (!atomic_read(&queue->set_pci_flags_count))
  2928. atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
  2929. /*
  2930. * queue->state will go from LOCKED -> UNLOCKED or from
  2931. * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
  2932. * (switch packing state or flush buffer to get another pci flag out).
  2933. * In that case we will enter this loop
  2934. */
  2935. while (atomic_dec_return(&queue->state)) {
  2936. flush_count = 0;
  2937. start_index = queue->next_buf_to_fill;
  2938. /* check if we can go back to non-packing state */
  2939. flush_count += qeth_switch_to_nonpacking_if_needed(queue);
  2940. /*
  2941. * check if we need to flush a packing buffer to get a pci
  2942. * flag out on the queue
  2943. */
  2944. if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
  2945. flush_count += qeth_flush_buffers_on_no_pci(queue);
  2946. if (flush_count)
  2947. qeth_flush_buffers(queue, start_index, flush_count);
  2948. }
  2949. /* at this point the queue is UNLOCKED again */
  2950. if (queue->card->options.performance_stats && do_pack)
  2951. queue->card->perf_stats.bufs_sent_pack += flush_count;
  2952. return rc;
  2953. }
  2954. EXPORT_SYMBOL_GPL(qeth_do_send_packet);
  2955. static int qeth_setadp_promisc_mode_cb(struct qeth_card *card,
  2956. struct qeth_reply *reply, unsigned long data)
  2957. {
  2958. struct qeth_ipa_cmd *cmd;
  2959. struct qeth_ipacmd_setadpparms *setparms;
  2960. QETH_CARD_TEXT(card, 4, "prmadpcb");
  2961. cmd = (struct qeth_ipa_cmd *) data;
  2962. setparms = &(cmd->data.setadapterparms);
  2963. qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
  2964. if (cmd->hdr.return_code) {
  2965. QETH_CARD_TEXT_(card, 4, "prmrc%2.2x", cmd->hdr.return_code);
  2966. setparms->data.mode = SET_PROMISC_MODE_OFF;
  2967. }
  2968. card->info.promisc_mode = setparms->data.mode;
  2969. return 0;
  2970. }
  2971. void qeth_setadp_promisc_mode(struct qeth_card *card)
  2972. {
  2973. enum qeth_ipa_promisc_modes mode;
  2974. struct net_device *dev = card->dev;
  2975. struct qeth_cmd_buffer *iob;
  2976. struct qeth_ipa_cmd *cmd;
  2977. QETH_CARD_TEXT(card, 4, "setprom");
  2978. if (((dev->flags & IFF_PROMISC) &&
  2979. (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
  2980. (!(dev->flags & IFF_PROMISC) &&
  2981. (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
  2982. return;
  2983. mode = SET_PROMISC_MODE_OFF;
  2984. if (dev->flags & IFF_PROMISC)
  2985. mode = SET_PROMISC_MODE_ON;
  2986. QETH_CARD_TEXT_(card, 4, "mode:%x", mode);
  2987. iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
  2988. sizeof(struct qeth_ipacmd_setadpparms));
  2989. cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
  2990. cmd->data.setadapterparms.data.mode = mode;
  2991. qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
  2992. }
  2993. EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode);
  2994. int qeth_change_mtu(struct net_device *dev, int new_mtu)
  2995. {
  2996. struct qeth_card *card;
  2997. char dbf_text[15];
  2998. card = dev->ml_priv;
  2999. QETH_CARD_TEXT(card, 4, "chgmtu");
  3000. sprintf(dbf_text, "%8x", new_mtu);
  3001. QETH_CARD_TEXT(card, 4, dbf_text);
  3002. if (new_mtu < 64)
  3003. return -EINVAL;
  3004. if (new_mtu > 65535)
  3005. return -EINVAL;
  3006. if ((!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) &&
  3007. (!qeth_mtu_is_valid(card, new_mtu)))
  3008. return -EINVAL;
  3009. dev->mtu = new_mtu;
  3010. return 0;
  3011. }
  3012. EXPORT_SYMBOL_GPL(qeth_change_mtu);
  3013. struct net_device_stats *qeth_get_stats(struct net_device *dev)
  3014. {
  3015. struct qeth_card *card;
  3016. card = dev->ml_priv;
  3017. QETH_CARD_TEXT(card, 5, "getstat");
  3018. return &card->stats;
  3019. }
  3020. EXPORT_SYMBOL_GPL(qeth_get_stats);
  3021. static int qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
  3022. struct qeth_reply *reply, unsigned long data)
  3023. {
  3024. struct qeth_ipa_cmd *cmd;
  3025. QETH_CARD_TEXT(card, 4, "chgmaccb");
  3026. cmd = (struct qeth_ipa_cmd *) data;
  3027. if (!card->options.layer2 ||
  3028. !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
  3029. memcpy(card->dev->dev_addr,
  3030. &cmd->data.setadapterparms.data.change_addr.addr,
  3031. OSA_ADDR_LEN);
  3032. card->info.mac_bits |= QETH_LAYER2_MAC_READ;
  3033. }
  3034. qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
  3035. return 0;
  3036. }
  3037. int qeth_setadpparms_change_macaddr(struct qeth_card *card)
  3038. {
  3039. int rc;
  3040. struct qeth_cmd_buffer *iob;
  3041. struct qeth_ipa_cmd *cmd;
  3042. QETH_CARD_TEXT(card, 4, "chgmac");
  3043. iob = qeth_get_adapter_cmd(card, IPA_SETADP_ALTER_MAC_ADDRESS,
  3044. sizeof(struct qeth_ipacmd_setadpparms));
  3045. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  3046. cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
  3047. cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
  3048. memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
  3049. card->dev->dev_addr, OSA_ADDR_LEN);
  3050. rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
  3051. NULL);
  3052. return rc;
  3053. }
  3054. EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr);
  3055. static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card *card,
  3056. struct qeth_reply *reply, unsigned long data)
  3057. {
  3058. struct qeth_ipa_cmd *cmd;
  3059. struct qeth_set_access_ctrl *access_ctrl_req;
  3060. int rc;
  3061. QETH_CARD_TEXT(card, 4, "setaccb");
  3062. cmd = (struct qeth_ipa_cmd *) data;
  3063. access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
  3064. QETH_DBF_TEXT_(SETUP, 2, "setaccb");
  3065. QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
  3066. QETH_DBF_TEXT_(SETUP, 2, "rc=%d",
  3067. cmd->data.setadapterparms.hdr.return_code);
  3068. switch (cmd->data.setadapterparms.hdr.return_code) {
  3069. case SET_ACCESS_CTRL_RC_SUCCESS:
  3070. case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED:
  3071. case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED:
  3072. {
  3073. card->options.isolation = access_ctrl_req->subcmd_code;
  3074. if (card->options.isolation == ISOLATION_MODE_NONE) {
  3075. dev_info(&card->gdev->dev,
  3076. "QDIO data connection isolation is deactivated\n");
  3077. } else {
  3078. dev_info(&card->gdev->dev,
  3079. "QDIO data connection isolation is activated\n");
  3080. }
  3081. QETH_DBF_MESSAGE(3, "OK:SET_ACCESS_CTRL(%s, %d)==%d\n",
  3082. card->gdev->dev.kobj.name,
  3083. access_ctrl_req->subcmd_code,
  3084. cmd->data.setadapterparms.hdr.return_code);
  3085. rc = 0;
  3086. break;
  3087. }
  3088. case SET_ACCESS_CTRL_RC_NOT_SUPPORTED:
  3089. {
  3090. QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
  3091. card->gdev->dev.kobj.name,
  3092. access_ctrl_req->subcmd_code,
  3093. cmd->data.setadapterparms.hdr.return_code);
  3094. dev_err(&card->gdev->dev, "Adapter does not "
  3095. "support QDIO data connection isolation\n");
  3096. /* ensure isolation mode is "none" */
  3097. card->options.isolation = ISOLATION_MODE_NONE;
  3098. rc = -EOPNOTSUPP;
  3099. break;
  3100. }
  3101. case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER:
  3102. {
  3103. QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
  3104. card->gdev->dev.kobj.name,
  3105. access_ctrl_req->subcmd_code,
  3106. cmd->data.setadapterparms.hdr.return_code);
  3107. dev_err(&card->gdev->dev,
  3108. "Adapter is dedicated. "
  3109. "QDIO data connection isolation not supported\n");
  3110. /* ensure isolation mode is "none" */
  3111. card->options.isolation = ISOLATION_MODE_NONE;
  3112. rc = -EOPNOTSUPP;
  3113. break;
  3114. }
  3115. case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF:
  3116. {
  3117. QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
  3118. card->gdev->dev.kobj.name,
  3119. access_ctrl_req->subcmd_code,
  3120. cmd->data.setadapterparms.hdr.return_code);
  3121. dev_err(&card->gdev->dev,
  3122. "TSO does not permit QDIO data connection isolation\n");
  3123. /* ensure isolation mode is "none" */
  3124. card->options.isolation = ISOLATION_MODE_NONE;
  3125. rc = -EPERM;
  3126. break;
  3127. }
  3128. default:
  3129. {
  3130. /* this should never happen */
  3131. QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d"
  3132. "==UNKNOWN\n",
  3133. card->gdev->dev.kobj.name,
  3134. access_ctrl_req->subcmd_code,
  3135. cmd->data.setadapterparms.hdr.return_code);
  3136. /* ensure isolation mode is "none" */
  3137. card->options.isolation = ISOLATION_MODE_NONE;
  3138. rc = 0;
  3139. break;
  3140. }
  3141. }
  3142. qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
  3143. return rc;
  3144. }
  3145. static int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
  3146. enum qeth_ipa_isolation_modes isolation)
  3147. {
  3148. int rc;
  3149. struct qeth_cmd_buffer *iob;
  3150. struct qeth_ipa_cmd *cmd;
  3151. struct qeth_set_access_ctrl *access_ctrl_req;
  3152. QETH_CARD_TEXT(card, 4, "setacctl");
  3153. QETH_DBF_TEXT_(SETUP, 2, "setacctl");
  3154. QETH_DBF_TEXT_(SETUP, 2, "%s", card->gdev->dev.kobj.name);
  3155. iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_ACCESS_CONTROL,
  3156. sizeof(struct qeth_ipacmd_setadpparms_hdr) +
  3157. sizeof(struct qeth_set_access_ctrl));
  3158. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  3159. access_ctrl_req = &cmd->data.setadapterparms.data.set_access_ctrl;
  3160. access_ctrl_req->subcmd_code = isolation;
  3161. rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_set_access_ctrl_cb,
  3162. NULL);
  3163. QETH_DBF_TEXT_(SETUP, 2, "rc=%d", rc);
  3164. return rc;
  3165. }
  3166. int qeth_set_access_ctrl_online(struct qeth_card *card)
  3167. {
  3168. int rc = 0;
  3169. QETH_CARD_TEXT(card, 4, "setactlo");
  3170. if ((card->info.type == QETH_CARD_TYPE_OSD ||
  3171. card->info.type == QETH_CARD_TYPE_OSX) &&
  3172. qeth_adp_supported(card, IPA_SETADP_SET_ACCESS_CONTROL)) {
  3173. rc = qeth_setadpparms_set_access_ctrl(card,
  3174. card->options.isolation);
  3175. if (rc) {
  3176. QETH_DBF_MESSAGE(3,
  3177. "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
  3178. card->gdev->dev.kobj.name,
  3179. rc);
  3180. }
  3181. } else if (card->options.isolation != ISOLATION_MODE_NONE) {
  3182. card->options.isolation = ISOLATION_MODE_NONE;
  3183. dev_err(&card->gdev->dev, "Adapter does not "
  3184. "support QDIO data connection isolation\n");
  3185. rc = -EOPNOTSUPP;
  3186. }
  3187. return rc;
  3188. }
  3189. EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online);
  3190. void qeth_tx_timeout(struct net_device *dev)
  3191. {
  3192. struct qeth_card *card;
  3193. card = dev->ml_priv;
  3194. QETH_CARD_TEXT(card, 4, "txtimeo");
  3195. card->stats.tx_errors++;
  3196. qeth_schedule_recovery(card);
  3197. }
  3198. EXPORT_SYMBOL_GPL(qeth_tx_timeout);
  3199. int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
  3200. {
  3201. struct qeth_card *card = dev->ml_priv;
  3202. int rc = 0;
  3203. switch (regnum) {
  3204. case MII_BMCR: /* Basic mode control register */
  3205. rc = BMCR_FULLDPLX;
  3206. if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH) &&
  3207. (card->info.link_type != QETH_LINK_TYPE_OSN) &&
  3208. (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
  3209. rc |= BMCR_SPEED100;
  3210. break;
  3211. case MII_BMSR: /* Basic mode status register */
  3212. rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
  3213. BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
  3214. BMSR_100BASE4;
  3215. break;
  3216. case MII_PHYSID1: /* PHYS ID 1 */
  3217. rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
  3218. dev->dev_addr[2];
  3219. rc = (rc >> 5) & 0xFFFF;
  3220. break;
  3221. case MII_PHYSID2: /* PHYS ID 2 */
  3222. rc = (dev->dev_addr[2] << 10) & 0xFFFF;
  3223. break;
  3224. case MII_ADVERTISE: /* Advertisement control reg */
  3225. rc = ADVERTISE_ALL;
  3226. break;
  3227. case MII_LPA: /* Link partner ability reg */
  3228. rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
  3229. LPA_100BASE4 | LPA_LPACK;
  3230. break;
  3231. case MII_EXPANSION: /* Expansion register */
  3232. break;
  3233. case MII_DCOUNTER: /* disconnect counter */
  3234. break;
  3235. case MII_FCSCOUNTER: /* false carrier counter */
  3236. break;
  3237. case MII_NWAYTEST: /* N-way auto-neg test register */
  3238. break;
  3239. case MII_RERRCOUNTER: /* rx error counter */
  3240. rc = card->stats.rx_errors;
  3241. break;
  3242. case MII_SREVISION: /* silicon revision */
  3243. break;
  3244. case MII_RESV1: /* reserved 1 */
  3245. break;
  3246. case MII_LBRERROR: /* loopback, rx, bypass error */
  3247. break;
  3248. case MII_PHYADDR: /* physical address */
  3249. break;
  3250. case MII_RESV2: /* reserved 2 */
  3251. break;
  3252. case MII_TPISTATUS: /* TPI status for 10mbps */
  3253. break;
  3254. case MII_NCONFIG: /* network interface config */
  3255. break;
  3256. default:
  3257. break;
  3258. }
  3259. return rc;
  3260. }
  3261. EXPORT_SYMBOL_GPL(qeth_mdio_read);
  3262. static int qeth_send_ipa_snmp_cmd(struct qeth_card *card,
  3263. struct qeth_cmd_buffer *iob, int len,
  3264. int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
  3265. unsigned long),
  3266. void *reply_param)
  3267. {
  3268. u16 s1, s2;
  3269. QETH_CARD_TEXT(card, 4, "sendsnmp");
  3270. memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
  3271. memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
  3272. &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
  3273. /* adjust PDU length fields in IPA_PDU_HEADER */
  3274. s1 = (u32) IPA_PDU_HEADER_SIZE + len;
  3275. s2 = (u32) len;
  3276. memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
  3277. memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
  3278. memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
  3279. memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
  3280. return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
  3281. reply_cb, reply_param);
  3282. }
  3283. static int qeth_snmp_command_cb(struct qeth_card *card,
  3284. struct qeth_reply *reply, unsigned long sdata)
  3285. {
  3286. struct qeth_ipa_cmd *cmd;
  3287. struct qeth_arp_query_info *qinfo;
  3288. struct qeth_snmp_cmd *snmp;
  3289. unsigned char *data;
  3290. __u16 data_len;
  3291. QETH_CARD_TEXT(card, 3, "snpcmdcb");
  3292. cmd = (struct qeth_ipa_cmd *) sdata;
  3293. data = (unsigned char *)((char *)cmd - reply->offset);
  3294. qinfo = (struct qeth_arp_query_info *) reply->param;
  3295. snmp = &cmd->data.setadapterparms.data.snmp;
  3296. if (cmd->hdr.return_code) {
  3297. QETH_CARD_TEXT_(card, 4, "scer1%i", cmd->hdr.return_code);
  3298. return 0;
  3299. }
  3300. if (cmd->data.setadapterparms.hdr.return_code) {
  3301. cmd->hdr.return_code =
  3302. cmd->data.setadapterparms.hdr.return_code;
  3303. QETH_CARD_TEXT_(card, 4, "scer2%i", cmd->hdr.return_code);
  3304. return 0;
  3305. }
  3306. data_len = *((__u16 *)QETH_IPA_PDU_LEN_PDU1(data));
  3307. if (cmd->data.setadapterparms.hdr.seq_no == 1)
  3308. data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
  3309. else
  3310. data_len -= (__u16)((char *)&snmp->request - (char *)cmd);
  3311. /* check if there is enough room in userspace */
  3312. if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
  3313. QETH_CARD_TEXT_(card, 4, "scer3%i", -ENOMEM);
  3314. cmd->hdr.return_code = -ENOMEM;
  3315. return 0;
  3316. }
  3317. QETH_CARD_TEXT_(card, 4, "snore%i",
  3318. cmd->data.setadapterparms.hdr.used_total);
  3319. QETH_CARD_TEXT_(card, 4, "sseqn%i",
  3320. cmd->data.setadapterparms.hdr.seq_no);
  3321. /*copy entries to user buffer*/
  3322. if (cmd->data.setadapterparms.hdr.seq_no == 1) {
  3323. memcpy(qinfo->udata + qinfo->udata_offset,
  3324. (char *)snmp,
  3325. data_len + offsetof(struct qeth_snmp_cmd, data));
  3326. qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
  3327. } else {
  3328. memcpy(qinfo->udata + qinfo->udata_offset,
  3329. (char *)&snmp->request, data_len);
  3330. }
  3331. qinfo->udata_offset += data_len;
  3332. /* check if all replies received ... */
  3333. QETH_CARD_TEXT_(card, 4, "srtot%i",
  3334. cmd->data.setadapterparms.hdr.used_total);
  3335. QETH_CARD_TEXT_(card, 4, "srseq%i",
  3336. cmd->data.setadapterparms.hdr.seq_no);
  3337. if (cmd->data.setadapterparms.hdr.seq_no <
  3338. cmd->data.setadapterparms.hdr.used_total)
  3339. return 1;
  3340. return 0;
  3341. }
  3342. int qeth_snmp_command(struct qeth_card *card, char __user *udata)
  3343. {
  3344. struct qeth_cmd_buffer *iob;
  3345. struct qeth_ipa_cmd *cmd;
  3346. struct qeth_snmp_ureq *ureq;
  3347. int req_len;
  3348. struct qeth_arp_query_info qinfo = {0, };
  3349. int rc = 0;
  3350. QETH_CARD_TEXT(card, 3, "snmpcmd");
  3351. if (card->info.guestlan)
  3352. return -EOPNOTSUPP;
  3353. if ((!qeth_adp_supported(card, IPA_SETADP_SET_SNMP_CONTROL)) &&
  3354. (!card->options.layer2)) {
  3355. return -EOPNOTSUPP;
  3356. }
  3357. /* skip 4 bytes (data_len struct member) to get req_len */
  3358. if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
  3359. return -EFAULT;
  3360. ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
  3361. if (!ureq) {
  3362. QETH_CARD_TEXT(card, 2, "snmpnome");
  3363. return -ENOMEM;
  3364. }
  3365. if (copy_from_user(ureq, udata,
  3366. req_len + sizeof(struct qeth_snmp_ureq_hdr))) {
  3367. kfree(ureq);
  3368. return -EFAULT;
  3369. }
  3370. qinfo.udata_len = ureq->hdr.data_len;
  3371. qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
  3372. if (!qinfo.udata) {
  3373. kfree(ureq);
  3374. return -ENOMEM;
  3375. }
  3376. qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
  3377. iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
  3378. QETH_SNMP_SETADP_CMDLENGTH + req_len);
  3379. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  3380. memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
  3381. rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
  3382. qeth_snmp_command_cb, (void *)&qinfo);
  3383. if (rc)
  3384. QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
  3385. QETH_CARD_IFNAME(card), rc);
  3386. else {
  3387. if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
  3388. rc = -EFAULT;
  3389. }
  3390. kfree(ureq);
  3391. kfree(qinfo.udata);
  3392. return rc;
  3393. }
  3394. EXPORT_SYMBOL_GPL(qeth_snmp_command);
  3395. static inline int qeth_get_qdio_q_format(struct qeth_card *card)
  3396. {
  3397. switch (card->info.type) {
  3398. case QETH_CARD_TYPE_IQD:
  3399. return 2;
  3400. default:
  3401. return 0;
  3402. }
  3403. }
  3404. static int qeth_qdio_establish(struct qeth_card *card)
  3405. {
  3406. struct qdio_initialize init_data;
  3407. char *qib_param_field;
  3408. struct qdio_buffer **in_sbal_ptrs;
  3409. struct qdio_buffer **out_sbal_ptrs;
  3410. int i, j, k;
  3411. int rc = 0;
  3412. QETH_DBF_TEXT(SETUP, 2, "qdioest");
  3413. qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
  3414. GFP_KERNEL);
  3415. if (!qib_param_field)
  3416. return -ENOMEM;
  3417. qeth_create_qib_param_field(card, qib_param_field);
  3418. qeth_create_qib_param_field_blkt(card, qib_param_field);
  3419. in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
  3420. GFP_KERNEL);
  3421. if (!in_sbal_ptrs) {
  3422. kfree(qib_param_field);
  3423. return -ENOMEM;
  3424. }
  3425. for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
  3426. in_sbal_ptrs[i] = (struct qdio_buffer *)
  3427. virt_to_phys(card->qdio.in_q->bufs[i].buffer);
  3428. out_sbal_ptrs =
  3429. kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
  3430. sizeof(void *), GFP_KERNEL);
  3431. if (!out_sbal_ptrs) {
  3432. kfree(in_sbal_ptrs);
  3433. kfree(qib_param_field);
  3434. return -ENOMEM;
  3435. }
  3436. for (i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
  3437. for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k) {
  3438. out_sbal_ptrs[k] = (struct qdio_buffer *)virt_to_phys(
  3439. card->qdio.out_qs[i]->bufs[j].buffer);
  3440. }
  3441. memset(&init_data, 0, sizeof(struct qdio_initialize));
  3442. init_data.cdev = CARD_DDEV(card);
  3443. init_data.q_format = qeth_get_qdio_q_format(card);
  3444. init_data.qib_param_field_format = 0;
  3445. init_data.qib_param_field = qib_param_field;
  3446. init_data.no_input_qs = 1;
  3447. init_data.no_output_qs = card->qdio.no_out_queues;
  3448. init_data.input_handler = card->discipline.input_handler;
  3449. init_data.output_handler = card->discipline.output_handler;
  3450. init_data.int_parm = (unsigned long) card;
  3451. init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
  3452. init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
  3453. if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
  3454. QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
  3455. rc = qdio_allocate(&init_data);
  3456. if (rc) {
  3457. atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
  3458. goto out;
  3459. }
  3460. rc = qdio_establish(&init_data);
  3461. if (rc) {
  3462. atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
  3463. qdio_free(CARD_DDEV(card));
  3464. }
  3465. }
  3466. out:
  3467. kfree(out_sbal_ptrs);
  3468. kfree(in_sbal_ptrs);
  3469. kfree(qib_param_field);
  3470. return rc;
  3471. }
  3472. static void qeth_core_free_card(struct qeth_card *card)
  3473. {
  3474. QETH_DBF_TEXT(SETUP, 2, "freecrd");
  3475. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  3476. qeth_clean_channel(&card->read);
  3477. qeth_clean_channel(&card->write);
  3478. if (card->dev)
  3479. free_netdev(card->dev);
  3480. kfree(card->ip_tbd_list);
  3481. qeth_free_qdio_buffers(card);
  3482. unregister_service_level(&card->qeth_service_level);
  3483. kfree(card);
  3484. }
  3485. static struct ccw_device_id qeth_ids[] = {
  3486. {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
  3487. .driver_info = QETH_CARD_TYPE_OSD},
  3488. {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
  3489. .driver_info = QETH_CARD_TYPE_IQD},
  3490. {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
  3491. .driver_info = QETH_CARD_TYPE_OSN},
  3492. {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
  3493. .driver_info = QETH_CARD_TYPE_OSM},
  3494. {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
  3495. .driver_info = QETH_CARD_TYPE_OSX},
  3496. {},
  3497. };
  3498. MODULE_DEVICE_TABLE(ccw, qeth_ids);
  3499. static struct ccw_driver qeth_ccw_driver = {
  3500. .name = "qeth",
  3501. .ids = qeth_ids,
  3502. .probe = ccwgroup_probe_ccwdev,
  3503. .remove = ccwgroup_remove_ccwdev,
  3504. };
  3505. static int qeth_core_driver_group(const char *buf, struct device *root_dev,
  3506. unsigned long driver_id)
  3507. {
  3508. return ccwgroup_create_from_string(root_dev, driver_id,
  3509. &qeth_ccw_driver, 3, buf);
  3510. }
  3511. int qeth_core_hardsetup_card(struct qeth_card *card)
  3512. {
  3513. int retries = 0;
  3514. int rc;
  3515. QETH_DBF_TEXT(SETUP, 2, "hrdsetup");
  3516. atomic_set(&card->force_alloc_skb, 0);
  3517. retry:
  3518. if (retries)
  3519. QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
  3520. dev_name(&card->gdev->dev));
  3521. ccw_device_set_offline(CARD_DDEV(card));
  3522. ccw_device_set_offline(CARD_WDEV(card));
  3523. ccw_device_set_offline(CARD_RDEV(card));
  3524. rc = ccw_device_set_online(CARD_RDEV(card));
  3525. if (rc)
  3526. goto retriable;
  3527. rc = ccw_device_set_online(CARD_WDEV(card));
  3528. if (rc)
  3529. goto retriable;
  3530. rc = ccw_device_set_online(CARD_DDEV(card));
  3531. if (rc)
  3532. goto retriable;
  3533. rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
  3534. retriable:
  3535. if (rc == -ERESTARTSYS) {
  3536. QETH_DBF_TEXT(SETUP, 2, "break1");
  3537. return rc;
  3538. } else if (rc) {
  3539. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  3540. if (++retries > 3)
  3541. goto out;
  3542. else
  3543. goto retry;
  3544. }
  3545. qeth_init_tokens(card);
  3546. qeth_init_func_level(card);
  3547. rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
  3548. if (rc == -ERESTARTSYS) {
  3549. QETH_DBF_TEXT(SETUP, 2, "break2");
  3550. return rc;
  3551. } else if (rc) {
  3552. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  3553. if (--retries < 0)
  3554. goto out;
  3555. else
  3556. goto retry;
  3557. }
  3558. rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
  3559. if (rc == -ERESTARTSYS) {
  3560. QETH_DBF_TEXT(SETUP, 2, "break3");
  3561. return rc;
  3562. } else if (rc) {
  3563. QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc);
  3564. if (--retries < 0)
  3565. goto out;
  3566. else
  3567. goto retry;
  3568. }
  3569. rc = qeth_mpc_initialize(card);
  3570. if (rc) {
  3571. QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
  3572. goto out;
  3573. }
  3574. return 0;
  3575. out:
  3576. dev_warn(&card->gdev->dev, "The qeth device driver failed to recover "
  3577. "an error on the device\n");
  3578. QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
  3579. dev_name(&card->gdev->dev), rc);
  3580. return rc;
  3581. }
  3582. EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
  3583. static inline int qeth_create_skb_frag(struct qdio_buffer_element *element,
  3584. struct sk_buff **pskb, int offset, int *pfrag, int data_len)
  3585. {
  3586. struct page *page = virt_to_page(element->addr);
  3587. if (*pskb == NULL) {
  3588. /* the upper protocol layers assume that there is data in the
  3589. * skb itself. Copy a small amount (64 bytes) to make them
  3590. * happy. */
  3591. *pskb = dev_alloc_skb(64 + ETH_HLEN);
  3592. if (!(*pskb))
  3593. return -ENOMEM;
  3594. skb_reserve(*pskb, ETH_HLEN);
  3595. if (data_len <= 64) {
  3596. memcpy(skb_put(*pskb, data_len), element->addr + offset,
  3597. data_len);
  3598. } else {
  3599. get_page(page);
  3600. memcpy(skb_put(*pskb, 64), element->addr + offset, 64);
  3601. skb_fill_page_desc(*pskb, *pfrag, page, offset + 64,
  3602. data_len - 64);
  3603. (*pskb)->data_len += data_len - 64;
  3604. (*pskb)->len += data_len - 64;
  3605. (*pskb)->truesize += data_len - 64;
  3606. (*pfrag)++;
  3607. }
  3608. } else {
  3609. get_page(page);
  3610. skb_fill_page_desc(*pskb, *pfrag, page, offset, data_len);
  3611. (*pskb)->data_len += data_len;
  3612. (*pskb)->len += data_len;
  3613. (*pskb)->truesize += data_len;
  3614. (*pfrag)++;
  3615. }
  3616. return 0;
  3617. }
  3618. struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
  3619. struct qdio_buffer *buffer,
  3620. struct qdio_buffer_element **__element, int *__offset,
  3621. struct qeth_hdr **hdr)
  3622. {
  3623. struct qdio_buffer_element *element = *__element;
  3624. int offset = *__offset;
  3625. struct sk_buff *skb = NULL;
  3626. int skb_len = 0;
  3627. void *data_ptr;
  3628. int data_len;
  3629. int headroom = 0;
  3630. int use_rx_sg = 0;
  3631. int frag = 0;
  3632. /* qeth_hdr must not cross element boundaries */
  3633. if (element->length < offset + sizeof(struct qeth_hdr)) {
  3634. if (qeth_is_last_sbale(element))
  3635. return NULL;
  3636. element++;
  3637. offset = 0;
  3638. if (element->length < sizeof(struct qeth_hdr))
  3639. return NULL;
  3640. }
  3641. *hdr = element->addr + offset;
  3642. offset += sizeof(struct qeth_hdr);
  3643. switch ((*hdr)->hdr.l2.id) {
  3644. case QETH_HEADER_TYPE_LAYER2:
  3645. skb_len = (*hdr)->hdr.l2.pkt_length;
  3646. break;
  3647. case QETH_HEADER_TYPE_LAYER3:
  3648. skb_len = (*hdr)->hdr.l3.length;
  3649. if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
  3650. (card->info.link_type == QETH_LINK_TYPE_HSTR))
  3651. headroom = TR_HLEN;
  3652. else
  3653. headroom = ETH_HLEN;
  3654. break;
  3655. case QETH_HEADER_TYPE_OSN:
  3656. skb_len = (*hdr)->hdr.osn.pdu_length;
  3657. headroom = sizeof(struct qeth_hdr);
  3658. break;
  3659. default:
  3660. break;
  3661. }
  3662. if (!skb_len)
  3663. return NULL;
  3664. if ((skb_len >= card->options.rx_sg_cb) &&
  3665. (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
  3666. (!atomic_read(&card->force_alloc_skb))) {
  3667. use_rx_sg = 1;
  3668. } else {
  3669. skb = dev_alloc_skb(skb_len + headroom);
  3670. if (!skb)
  3671. goto no_mem;
  3672. if (headroom)
  3673. skb_reserve(skb, headroom);
  3674. }
  3675. data_ptr = element->addr + offset;
  3676. while (skb_len) {
  3677. data_len = min(skb_len, (int)(element->length - offset));
  3678. if (data_len) {
  3679. if (use_rx_sg) {
  3680. if (qeth_create_skb_frag(element, &skb, offset,
  3681. &frag, data_len))
  3682. goto no_mem;
  3683. } else {
  3684. memcpy(skb_put(skb, data_len), data_ptr,
  3685. data_len);
  3686. }
  3687. }
  3688. skb_len -= data_len;
  3689. if (skb_len) {
  3690. if (qeth_is_last_sbale(element)) {
  3691. QETH_CARD_TEXT(card, 4, "unexeob");
  3692. QETH_CARD_HEX(card, 2, buffer, sizeof(void *));
  3693. dev_kfree_skb_any(skb);
  3694. card->stats.rx_errors++;
  3695. return NULL;
  3696. }
  3697. element++;
  3698. offset = 0;
  3699. data_ptr = element->addr;
  3700. } else {
  3701. offset += data_len;
  3702. }
  3703. }
  3704. *__element = element;
  3705. *__offset = offset;
  3706. if (use_rx_sg && card->options.performance_stats) {
  3707. card->perf_stats.sg_skbs_rx++;
  3708. card->perf_stats.sg_frags_rx += skb_shinfo(skb)->nr_frags;
  3709. }
  3710. return skb;
  3711. no_mem:
  3712. if (net_ratelimit()) {
  3713. QETH_CARD_TEXT(card, 2, "noskbmem");
  3714. }
  3715. card->stats.rx_dropped++;
  3716. return NULL;
  3717. }
  3718. EXPORT_SYMBOL_GPL(qeth_core_get_next_skb);
  3719. static void qeth_unregister_dbf_views(void)
  3720. {
  3721. int x;
  3722. for (x = 0; x < QETH_DBF_INFOS; x++) {
  3723. debug_unregister(qeth_dbf[x].id);
  3724. qeth_dbf[x].id = NULL;
  3725. }
  3726. }
  3727. void qeth_dbf_longtext(debug_info_t *id, int level, char *fmt, ...)
  3728. {
  3729. char dbf_txt_buf[32];
  3730. va_list args;
  3731. if (level > id->level)
  3732. return;
  3733. va_start(args, fmt);
  3734. vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
  3735. va_end(args);
  3736. debug_text_event(id, level, dbf_txt_buf);
  3737. }
  3738. EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
  3739. static int qeth_register_dbf_views(void)
  3740. {
  3741. int ret;
  3742. int x;
  3743. for (x = 0; x < QETH_DBF_INFOS; x++) {
  3744. /* register the areas */
  3745. qeth_dbf[x].id = debug_register(qeth_dbf[x].name,
  3746. qeth_dbf[x].pages,
  3747. qeth_dbf[x].areas,
  3748. qeth_dbf[x].len);
  3749. if (qeth_dbf[x].id == NULL) {
  3750. qeth_unregister_dbf_views();
  3751. return -ENOMEM;
  3752. }
  3753. /* register a view */
  3754. ret = debug_register_view(qeth_dbf[x].id, qeth_dbf[x].view);
  3755. if (ret) {
  3756. qeth_unregister_dbf_views();
  3757. return ret;
  3758. }
  3759. /* set a passing level */
  3760. debug_set_level(qeth_dbf[x].id, qeth_dbf[x].level);
  3761. }
  3762. return 0;
  3763. }
  3764. int qeth_core_load_discipline(struct qeth_card *card,
  3765. enum qeth_discipline_id discipline)
  3766. {
  3767. int rc = 0;
  3768. switch (discipline) {
  3769. case QETH_DISCIPLINE_LAYER3:
  3770. card->discipline.ccwgdriver = try_then_request_module(
  3771. symbol_get(qeth_l3_ccwgroup_driver),
  3772. "qeth_l3");
  3773. break;
  3774. case QETH_DISCIPLINE_LAYER2:
  3775. card->discipline.ccwgdriver = try_then_request_module(
  3776. symbol_get(qeth_l2_ccwgroup_driver),
  3777. "qeth_l2");
  3778. break;
  3779. }
  3780. if (!card->discipline.ccwgdriver) {
  3781. dev_err(&card->gdev->dev, "There is no kernel module to "
  3782. "support discipline %d\n", discipline);
  3783. rc = -EINVAL;
  3784. }
  3785. return rc;
  3786. }
  3787. void qeth_core_free_discipline(struct qeth_card *card)
  3788. {
  3789. if (card->options.layer2)
  3790. symbol_put(qeth_l2_ccwgroup_driver);
  3791. else
  3792. symbol_put(qeth_l3_ccwgroup_driver);
  3793. card->discipline.ccwgdriver = NULL;
  3794. }
  3795. static void qeth_determine_capabilities(struct qeth_card *card)
  3796. {
  3797. int rc;
  3798. int length;
  3799. char *prcd;
  3800. QETH_DBF_TEXT(SETUP, 2, "detcapab");
  3801. rc = ccw_device_set_online(CARD_DDEV(card));
  3802. if (rc) {
  3803. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  3804. goto out;
  3805. }
  3806. rc = qeth_read_conf_data(card, (void **) &prcd, &length);
  3807. if (rc) {
  3808. QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
  3809. dev_name(&card->gdev->dev), rc);
  3810. QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc);
  3811. goto out_offline;
  3812. }
  3813. qeth_configure_unitaddr(card, prcd);
  3814. qeth_configure_blkt_default(card, prcd);
  3815. kfree(prcd);
  3816. rc = qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
  3817. if (rc)
  3818. QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
  3819. out_offline:
  3820. ccw_device_set_offline(CARD_DDEV(card));
  3821. out:
  3822. return;
  3823. }
  3824. static int qeth_core_probe_device(struct ccwgroup_device *gdev)
  3825. {
  3826. struct qeth_card *card;
  3827. struct device *dev;
  3828. int rc;
  3829. unsigned long flags;
  3830. char dbf_name[20];
  3831. QETH_DBF_TEXT(SETUP, 2, "probedev");
  3832. dev = &gdev->dev;
  3833. if (!get_device(dev))
  3834. return -ENODEV;
  3835. QETH_DBF_TEXT_(SETUP, 2, "%s", dev_name(&gdev->dev));
  3836. card = qeth_alloc_card();
  3837. if (!card) {
  3838. QETH_DBF_TEXT_(SETUP, 2, "1err%d", -ENOMEM);
  3839. rc = -ENOMEM;
  3840. goto err_dev;
  3841. }
  3842. snprintf(dbf_name, sizeof(dbf_name), "qeth_card_%s",
  3843. dev_name(&gdev->dev));
  3844. card->debug = debug_register(dbf_name, 2, 1, 8);
  3845. if (!card->debug) {
  3846. QETH_DBF_TEXT_(SETUP, 2, "%s", "qcdbf");
  3847. rc = -ENOMEM;
  3848. goto err_card;
  3849. }
  3850. debug_register_view(card->debug, &debug_hex_ascii_view);
  3851. card->read.ccwdev = gdev->cdev[0];
  3852. card->write.ccwdev = gdev->cdev[1];
  3853. card->data.ccwdev = gdev->cdev[2];
  3854. dev_set_drvdata(&gdev->dev, card);
  3855. card->gdev = gdev;
  3856. gdev->cdev[0]->handler = qeth_irq;
  3857. gdev->cdev[1]->handler = qeth_irq;
  3858. gdev->cdev[2]->handler = qeth_irq;
  3859. rc = qeth_determine_card_type(card);
  3860. if (rc) {
  3861. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  3862. goto err_dbf;
  3863. }
  3864. rc = qeth_setup_card(card);
  3865. if (rc) {
  3866. QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
  3867. goto err_dbf;
  3868. }
  3869. if (card->info.type == QETH_CARD_TYPE_OSN)
  3870. rc = qeth_core_create_osn_attributes(dev);
  3871. else
  3872. rc = qeth_core_create_device_attributes(dev);
  3873. if (rc)
  3874. goto err_dbf;
  3875. switch (card->info.type) {
  3876. case QETH_CARD_TYPE_OSN:
  3877. case QETH_CARD_TYPE_OSM:
  3878. rc = qeth_core_load_discipline(card, QETH_DISCIPLINE_LAYER2);
  3879. if (rc)
  3880. goto err_attr;
  3881. rc = card->discipline.ccwgdriver->probe(card->gdev);
  3882. if (rc)
  3883. goto err_disc;
  3884. case QETH_CARD_TYPE_OSD:
  3885. case QETH_CARD_TYPE_OSX:
  3886. default:
  3887. break;
  3888. }
  3889. write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
  3890. list_add_tail(&card->list, &qeth_core_card_list.list);
  3891. write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
  3892. qeth_determine_capabilities(card);
  3893. return 0;
  3894. err_disc:
  3895. qeth_core_free_discipline(card);
  3896. err_attr:
  3897. if (card->info.type == QETH_CARD_TYPE_OSN)
  3898. qeth_core_remove_osn_attributes(dev);
  3899. else
  3900. qeth_core_remove_device_attributes(dev);
  3901. err_dbf:
  3902. debug_unregister(card->debug);
  3903. err_card:
  3904. qeth_core_free_card(card);
  3905. err_dev:
  3906. put_device(dev);
  3907. return rc;
  3908. }
  3909. static void qeth_core_remove_device(struct ccwgroup_device *gdev)
  3910. {
  3911. unsigned long flags;
  3912. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3913. QETH_DBF_TEXT(SETUP, 2, "removedv");
  3914. if (card->info.type == QETH_CARD_TYPE_OSN) {
  3915. qeth_core_remove_osn_attributes(&gdev->dev);
  3916. } else {
  3917. qeth_core_remove_device_attributes(&gdev->dev);
  3918. }
  3919. if (card->discipline.ccwgdriver) {
  3920. card->discipline.ccwgdriver->remove(gdev);
  3921. qeth_core_free_discipline(card);
  3922. }
  3923. debug_unregister(card->debug);
  3924. write_lock_irqsave(&qeth_core_card_list.rwlock, flags);
  3925. list_del(&card->list);
  3926. write_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
  3927. qeth_core_free_card(card);
  3928. dev_set_drvdata(&gdev->dev, NULL);
  3929. put_device(&gdev->dev);
  3930. return;
  3931. }
  3932. static int qeth_core_set_online(struct ccwgroup_device *gdev)
  3933. {
  3934. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3935. int rc = 0;
  3936. int def_discipline;
  3937. if (!card->discipline.ccwgdriver) {
  3938. if (card->info.type == QETH_CARD_TYPE_IQD)
  3939. def_discipline = QETH_DISCIPLINE_LAYER3;
  3940. else
  3941. def_discipline = QETH_DISCIPLINE_LAYER2;
  3942. rc = qeth_core_load_discipline(card, def_discipline);
  3943. if (rc)
  3944. goto err;
  3945. rc = card->discipline.ccwgdriver->probe(card->gdev);
  3946. if (rc)
  3947. goto err;
  3948. }
  3949. rc = card->discipline.ccwgdriver->set_online(gdev);
  3950. err:
  3951. return rc;
  3952. }
  3953. static int qeth_core_set_offline(struct ccwgroup_device *gdev)
  3954. {
  3955. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3956. return card->discipline.ccwgdriver->set_offline(gdev);
  3957. }
  3958. static void qeth_core_shutdown(struct ccwgroup_device *gdev)
  3959. {
  3960. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3961. if (card->discipline.ccwgdriver &&
  3962. card->discipline.ccwgdriver->shutdown)
  3963. card->discipline.ccwgdriver->shutdown(gdev);
  3964. }
  3965. static int qeth_core_prepare(struct ccwgroup_device *gdev)
  3966. {
  3967. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3968. if (card->discipline.ccwgdriver &&
  3969. card->discipline.ccwgdriver->prepare)
  3970. return card->discipline.ccwgdriver->prepare(gdev);
  3971. return 0;
  3972. }
  3973. static void qeth_core_complete(struct ccwgroup_device *gdev)
  3974. {
  3975. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3976. if (card->discipline.ccwgdriver &&
  3977. card->discipline.ccwgdriver->complete)
  3978. card->discipline.ccwgdriver->complete(gdev);
  3979. }
  3980. static int qeth_core_freeze(struct ccwgroup_device *gdev)
  3981. {
  3982. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3983. if (card->discipline.ccwgdriver &&
  3984. card->discipline.ccwgdriver->freeze)
  3985. return card->discipline.ccwgdriver->freeze(gdev);
  3986. return 0;
  3987. }
  3988. static int qeth_core_thaw(struct ccwgroup_device *gdev)
  3989. {
  3990. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3991. if (card->discipline.ccwgdriver &&
  3992. card->discipline.ccwgdriver->thaw)
  3993. return card->discipline.ccwgdriver->thaw(gdev);
  3994. return 0;
  3995. }
  3996. static int qeth_core_restore(struct ccwgroup_device *gdev)
  3997. {
  3998. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3999. if (card->discipline.ccwgdriver &&
  4000. card->discipline.ccwgdriver->restore)
  4001. return card->discipline.ccwgdriver->restore(gdev);
  4002. return 0;
  4003. }
  4004. static struct ccwgroup_driver qeth_core_ccwgroup_driver = {
  4005. .owner = THIS_MODULE,
  4006. .name = "qeth",
  4007. .driver_id = 0xD8C5E3C8,
  4008. .probe = qeth_core_probe_device,
  4009. .remove = qeth_core_remove_device,
  4010. .set_online = qeth_core_set_online,
  4011. .set_offline = qeth_core_set_offline,
  4012. .shutdown = qeth_core_shutdown,
  4013. .prepare = qeth_core_prepare,
  4014. .complete = qeth_core_complete,
  4015. .freeze = qeth_core_freeze,
  4016. .thaw = qeth_core_thaw,
  4017. .restore = qeth_core_restore,
  4018. };
  4019. static ssize_t
  4020. qeth_core_driver_group_store(struct device_driver *ddrv, const char *buf,
  4021. size_t count)
  4022. {
  4023. int err;
  4024. err = qeth_core_driver_group(buf, qeth_core_root_dev,
  4025. qeth_core_ccwgroup_driver.driver_id);
  4026. if (err)
  4027. return err;
  4028. else
  4029. return count;
  4030. }
  4031. static DRIVER_ATTR(group, 0200, NULL, qeth_core_driver_group_store);
  4032. static struct {
  4033. const char str[ETH_GSTRING_LEN];
  4034. } qeth_ethtool_stats_keys[] = {
  4035. /* 0 */{"rx skbs"},
  4036. {"rx buffers"},
  4037. {"tx skbs"},
  4038. {"tx buffers"},
  4039. {"tx skbs no packing"},
  4040. {"tx buffers no packing"},
  4041. {"tx skbs packing"},
  4042. {"tx buffers packing"},
  4043. {"tx sg skbs"},
  4044. {"tx sg frags"},
  4045. /* 10 */{"rx sg skbs"},
  4046. {"rx sg frags"},
  4047. {"rx sg page allocs"},
  4048. {"tx large kbytes"},
  4049. {"tx large count"},
  4050. {"tx pk state ch n->p"},
  4051. {"tx pk state ch p->n"},
  4052. {"tx pk watermark low"},
  4053. {"tx pk watermark high"},
  4054. {"queue 0 buffer usage"},
  4055. /* 20 */{"queue 1 buffer usage"},
  4056. {"queue 2 buffer usage"},
  4057. {"queue 3 buffer usage"},
  4058. {"rx handler time"},
  4059. {"rx handler count"},
  4060. {"rx do_QDIO time"},
  4061. {"rx do_QDIO count"},
  4062. {"tx handler time"},
  4063. {"tx handler count"},
  4064. {"tx time"},
  4065. /* 30 */{"tx count"},
  4066. {"tx do_QDIO time"},
  4067. {"tx do_QDIO count"},
  4068. {"tx csum"},
  4069. {"tx lin"},
  4070. };
  4071. int qeth_core_get_sset_count(struct net_device *dev, int stringset)
  4072. {
  4073. switch (stringset) {
  4074. case ETH_SS_STATS:
  4075. return (sizeof(qeth_ethtool_stats_keys) / ETH_GSTRING_LEN);
  4076. default:
  4077. return -EINVAL;
  4078. }
  4079. }
  4080. EXPORT_SYMBOL_GPL(qeth_core_get_sset_count);
  4081. void qeth_core_get_ethtool_stats(struct net_device *dev,
  4082. struct ethtool_stats *stats, u64 *data)
  4083. {
  4084. struct qeth_card *card = dev->ml_priv;
  4085. data[0] = card->stats.rx_packets -
  4086. card->perf_stats.initial_rx_packets;
  4087. data[1] = card->perf_stats.bufs_rec;
  4088. data[2] = card->stats.tx_packets -
  4089. card->perf_stats.initial_tx_packets;
  4090. data[3] = card->perf_stats.bufs_sent;
  4091. data[4] = card->stats.tx_packets - card->perf_stats.initial_tx_packets
  4092. - card->perf_stats.skbs_sent_pack;
  4093. data[5] = card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack;
  4094. data[6] = card->perf_stats.skbs_sent_pack;
  4095. data[7] = card->perf_stats.bufs_sent_pack;
  4096. data[8] = card->perf_stats.sg_skbs_sent;
  4097. data[9] = card->perf_stats.sg_frags_sent;
  4098. data[10] = card->perf_stats.sg_skbs_rx;
  4099. data[11] = card->perf_stats.sg_frags_rx;
  4100. data[12] = card->perf_stats.sg_alloc_page_rx;
  4101. data[13] = (card->perf_stats.large_send_bytes >> 10);
  4102. data[14] = card->perf_stats.large_send_cnt;
  4103. data[15] = card->perf_stats.sc_dp_p;
  4104. data[16] = card->perf_stats.sc_p_dp;
  4105. data[17] = QETH_LOW_WATERMARK_PACK;
  4106. data[18] = QETH_HIGH_WATERMARK_PACK;
  4107. data[19] = atomic_read(&card->qdio.out_qs[0]->used_buffers);
  4108. data[20] = (card->qdio.no_out_queues > 1) ?
  4109. atomic_read(&card->qdio.out_qs[1]->used_buffers) : 0;
  4110. data[21] = (card->qdio.no_out_queues > 2) ?
  4111. atomic_read(&card->qdio.out_qs[2]->used_buffers) : 0;
  4112. data[22] = (card->qdio.no_out_queues > 3) ?
  4113. atomic_read(&card->qdio.out_qs[3]->used_buffers) : 0;
  4114. data[23] = card->perf_stats.inbound_time;
  4115. data[24] = card->perf_stats.inbound_cnt;
  4116. data[25] = card->perf_stats.inbound_do_qdio_time;
  4117. data[26] = card->perf_stats.inbound_do_qdio_cnt;
  4118. data[27] = card->perf_stats.outbound_handler_time;
  4119. data[28] = card->perf_stats.outbound_handler_cnt;
  4120. data[29] = card->perf_stats.outbound_time;
  4121. data[30] = card->perf_stats.outbound_cnt;
  4122. data[31] = card->perf_stats.outbound_do_qdio_time;
  4123. data[32] = card->perf_stats.outbound_do_qdio_cnt;
  4124. data[33] = card->perf_stats.tx_csum;
  4125. data[34] = card->perf_stats.tx_lin;
  4126. }
  4127. EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats);
  4128. void qeth_core_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  4129. {
  4130. switch (stringset) {
  4131. case ETH_SS_STATS:
  4132. memcpy(data, &qeth_ethtool_stats_keys,
  4133. sizeof(qeth_ethtool_stats_keys));
  4134. break;
  4135. default:
  4136. WARN_ON(1);
  4137. break;
  4138. }
  4139. }
  4140. EXPORT_SYMBOL_GPL(qeth_core_get_strings);
  4141. void qeth_core_get_drvinfo(struct net_device *dev,
  4142. struct ethtool_drvinfo *info)
  4143. {
  4144. struct qeth_card *card = dev->ml_priv;
  4145. if (card->options.layer2)
  4146. strcpy(info->driver, "qeth_l2");
  4147. else
  4148. strcpy(info->driver, "qeth_l3");
  4149. strcpy(info->version, "1.0");
  4150. strcpy(info->fw_version, card->info.mcl_level);
  4151. sprintf(info->bus_info, "%s/%s/%s",
  4152. CARD_RDEV_ID(card),
  4153. CARD_WDEV_ID(card),
  4154. CARD_DDEV_ID(card));
  4155. }
  4156. EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
  4157. int qeth_core_ethtool_get_settings(struct net_device *netdev,
  4158. struct ethtool_cmd *ecmd)
  4159. {
  4160. struct qeth_card *card = netdev->ml_priv;
  4161. enum qeth_link_types link_type;
  4162. if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
  4163. link_type = QETH_LINK_TYPE_10GBIT_ETH;
  4164. else
  4165. link_type = card->info.link_type;
  4166. ecmd->transceiver = XCVR_INTERNAL;
  4167. ecmd->supported = SUPPORTED_Autoneg;
  4168. ecmd->advertising = ADVERTISED_Autoneg;
  4169. ecmd->duplex = DUPLEX_FULL;
  4170. ecmd->autoneg = AUTONEG_ENABLE;
  4171. switch (link_type) {
  4172. case QETH_LINK_TYPE_FAST_ETH:
  4173. case QETH_LINK_TYPE_LANE_ETH100:
  4174. ecmd->supported |= SUPPORTED_10baseT_Half |
  4175. SUPPORTED_10baseT_Full |
  4176. SUPPORTED_100baseT_Half |
  4177. SUPPORTED_100baseT_Full |
  4178. SUPPORTED_TP;
  4179. ecmd->advertising |= ADVERTISED_10baseT_Half |
  4180. ADVERTISED_10baseT_Full |
  4181. ADVERTISED_100baseT_Half |
  4182. ADVERTISED_100baseT_Full |
  4183. ADVERTISED_TP;
  4184. ecmd->speed = SPEED_100;
  4185. ecmd->port = PORT_TP;
  4186. break;
  4187. case QETH_LINK_TYPE_GBIT_ETH:
  4188. case QETH_LINK_TYPE_LANE_ETH1000:
  4189. ecmd->supported |= SUPPORTED_10baseT_Half |
  4190. SUPPORTED_10baseT_Full |
  4191. SUPPORTED_100baseT_Half |
  4192. SUPPORTED_100baseT_Full |
  4193. SUPPORTED_1000baseT_Half |
  4194. SUPPORTED_1000baseT_Full |
  4195. SUPPORTED_FIBRE;
  4196. ecmd->advertising |= ADVERTISED_10baseT_Half |
  4197. ADVERTISED_10baseT_Full |
  4198. ADVERTISED_100baseT_Half |
  4199. ADVERTISED_100baseT_Full |
  4200. ADVERTISED_1000baseT_Half |
  4201. ADVERTISED_1000baseT_Full |
  4202. ADVERTISED_FIBRE;
  4203. ecmd->speed = SPEED_1000;
  4204. ecmd->port = PORT_FIBRE;
  4205. break;
  4206. case QETH_LINK_TYPE_10GBIT_ETH:
  4207. ecmd->supported |= SUPPORTED_10baseT_Half |
  4208. SUPPORTED_10baseT_Full |
  4209. SUPPORTED_100baseT_Half |
  4210. SUPPORTED_100baseT_Full |
  4211. SUPPORTED_1000baseT_Half |
  4212. SUPPORTED_1000baseT_Full |
  4213. SUPPORTED_10000baseT_Full |
  4214. SUPPORTED_FIBRE;
  4215. ecmd->advertising |= ADVERTISED_10baseT_Half |
  4216. ADVERTISED_10baseT_Full |
  4217. ADVERTISED_100baseT_Half |
  4218. ADVERTISED_100baseT_Full |
  4219. ADVERTISED_1000baseT_Half |
  4220. ADVERTISED_1000baseT_Full |
  4221. ADVERTISED_10000baseT_Full |
  4222. ADVERTISED_FIBRE;
  4223. ecmd->speed = SPEED_10000;
  4224. ecmd->port = PORT_FIBRE;
  4225. break;
  4226. default:
  4227. ecmd->supported |= SUPPORTED_10baseT_Half |
  4228. SUPPORTED_10baseT_Full |
  4229. SUPPORTED_TP;
  4230. ecmd->advertising |= ADVERTISED_10baseT_Half |
  4231. ADVERTISED_10baseT_Full |
  4232. ADVERTISED_TP;
  4233. ecmd->speed = SPEED_10;
  4234. ecmd->port = PORT_TP;
  4235. }
  4236. return 0;
  4237. }
  4238. EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
  4239. static int __init qeth_core_init(void)
  4240. {
  4241. int rc;
  4242. pr_info("loading core functions\n");
  4243. INIT_LIST_HEAD(&qeth_core_card_list.list);
  4244. rwlock_init(&qeth_core_card_list.rwlock);
  4245. rc = qeth_register_dbf_views();
  4246. if (rc)
  4247. goto out_err;
  4248. rc = ccw_driver_register(&qeth_ccw_driver);
  4249. if (rc)
  4250. goto ccw_err;
  4251. rc = ccwgroup_driver_register(&qeth_core_ccwgroup_driver);
  4252. if (rc)
  4253. goto ccwgroup_err;
  4254. rc = driver_create_file(&qeth_core_ccwgroup_driver.driver,
  4255. &driver_attr_group);
  4256. if (rc)
  4257. goto driver_err;
  4258. qeth_core_root_dev = root_device_register("qeth");
  4259. rc = IS_ERR(qeth_core_root_dev) ? PTR_ERR(qeth_core_root_dev) : 0;
  4260. if (rc)
  4261. goto register_err;
  4262. qeth_core_header_cache = kmem_cache_create("qeth_hdr",
  4263. sizeof(struct qeth_hdr) + ETH_HLEN, 64, 0, NULL);
  4264. if (!qeth_core_header_cache) {
  4265. rc = -ENOMEM;
  4266. goto slab_err;
  4267. }
  4268. return 0;
  4269. slab_err:
  4270. root_device_unregister(qeth_core_root_dev);
  4271. register_err:
  4272. driver_remove_file(&qeth_core_ccwgroup_driver.driver,
  4273. &driver_attr_group);
  4274. driver_err:
  4275. ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
  4276. ccwgroup_err:
  4277. ccw_driver_unregister(&qeth_ccw_driver);
  4278. ccw_err:
  4279. QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc);
  4280. qeth_unregister_dbf_views();
  4281. out_err:
  4282. pr_err("Initializing the qeth device driver failed\n");
  4283. return rc;
  4284. }
  4285. static void __exit qeth_core_exit(void)
  4286. {
  4287. root_device_unregister(qeth_core_root_dev);
  4288. driver_remove_file(&qeth_core_ccwgroup_driver.driver,
  4289. &driver_attr_group);
  4290. ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver);
  4291. ccw_driver_unregister(&qeth_ccw_driver);
  4292. kmem_cache_destroy(qeth_core_header_cache);
  4293. qeth_unregister_dbf_views();
  4294. pr_info("core functions removed\n");
  4295. }
  4296. module_init(qeth_core_init);
  4297. module_exit(qeth_core_exit);
  4298. MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
  4299. MODULE_DESCRIPTION("qeth core functions");
  4300. MODULE_LICENSE("GPL");