scsi_transport_iscsi.c 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612
  1. /*
  2. * iSCSI transport class definitions
  3. *
  4. * Copyright (C) IBM Corporation, 2004
  5. * Copyright (C) Mike Christie, 2004 - 2005
  6. * Copyright (C) Dmitry Yusupov, 2004 - 2005
  7. * Copyright (C) Alex Aizman, 2004 - 2005
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/mutex.h>
  25. #include <linux/slab.h>
  26. #include <linux/bsg-lib.h>
  27. #include <linux/idr.h>
  28. #include <net/tcp.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_transport.h>
  33. #include <scsi/scsi_transport_iscsi.h>
  34. #include <scsi/iscsi_if.h>
  35. #include <scsi/scsi_cmnd.h>
  36. #include <scsi/scsi_bsg_iscsi.h>
  37. #define ISCSI_TRANSPORT_VERSION "2.0-870"
  38. static int dbg_session;
  39. module_param_named(debug_session, dbg_session, int,
  40. S_IRUGO | S_IWUSR);
  41. MODULE_PARM_DESC(debug_session,
  42. "Turn on debugging for sessions in scsi_transport_iscsi "
  43. "module. Set to 1 to turn on, and zero to turn off. Default "
  44. "is off.");
  45. static int dbg_conn;
  46. module_param_named(debug_conn, dbg_conn, int,
  47. S_IRUGO | S_IWUSR);
  48. MODULE_PARM_DESC(debug_conn,
  49. "Turn on debugging for connections in scsi_transport_iscsi "
  50. "module. Set to 1 to turn on, and zero to turn off. Default "
  51. "is off.");
  52. #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \
  53. do { \
  54. if (dbg_session) \
  55. iscsi_cls_session_printk(KERN_INFO, _session, \
  56. "%s: " dbg_fmt, \
  57. __func__, ##arg); \
  58. } while (0);
  59. #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \
  60. do { \
  61. if (dbg_conn) \
  62. iscsi_cls_conn_printk(KERN_INFO, _conn, \
  63. "%s: " dbg_fmt, \
  64. __func__, ##arg); \
  65. } while (0);
  66. struct iscsi_internal {
  67. struct scsi_transport_template t;
  68. struct iscsi_transport *iscsi_transport;
  69. struct list_head list;
  70. struct device dev;
  71. struct transport_container conn_cont;
  72. struct transport_container session_cont;
  73. };
  74. static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
  75. static struct workqueue_struct *iscsi_eh_timer_workq;
  76. static DEFINE_IDA(iscsi_sess_ida);
  77. /*
  78. * list of registered transports and lock that must
  79. * be held while accessing list. The iscsi_transport_lock must
  80. * be acquired after the rx_queue_mutex.
  81. */
  82. static LIST_HEAD(iscsi_transports);
  83. static DEFINE_SPINLOCK(iscsi_transport_lock);
  84. #define to_iscsi_internal(tmpl) \
  85. container_of(tmpl, struct iscsi_internal, t)
  86. #define dev_to_iscsi_internal(_dev) \
  87. container_of(_dev, struct iscsi_internal, dev)
  88. static void iscsi_transport_release(struct device *dev)
  89. {
  90. struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
  91. kfree(priv);
  92. }
  93. /*
  94. * iscsi_transport_class represents the iscsi_transports that are
  95. * registered.
  96. */
  97. static struct class iscsi_transport_class = {
  98. .name = "iscsi_transport",
  99. .dev_release = iscsi_transport_release,
  100. };
  101. static ssize_t
  102. show_transport_handle(struct device *dev, struct device_attribute *attr,
  103. char *buf)
  104. {
  105. struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
  106. return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport));
  107. }
  108. static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
  109. #define show_transport_attr(name, format) \
  110. static ssize_t \
  111. show_transport_##name(struct device *dev, \
  112. struct device_attribute *attr,char *buf) \
  113. { \
  114. struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
  115. return sprintf(buf, format"\n", priv->iscsi_transport->name); \
  116. } \
  117. static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
  118. show_transport_attr(caps, "0x%x");
  119. static struct attribute *iscsi_transport_attrs[] = {
  120. &dev_attr_handle.attr,
  121. &dev_attr_caps.attr,
  122. NULL,
  123. };
  124. static struct attribute_group iscsi_transport_group = {
  125. .attrs = iscsi_transport_attrs,
  126. };
  127. /*
  128. * iSCSI endpoint attrs
  129. */
  130. #define iscsi_dev_to_endpoint(_dev) \
  131. container_of(_dev, struct iscsi_endpoint, dev)
  132. #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
  133. struct device_attribute dev_attr_##_prefix##_##_name = \
  134. __ATTR(_name,_mode,_show,_store)
  135. static void iscsi_endpoint_release(struct device *dev)
  136. {
  137. struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
  138. kfree(ep);
  139. }
  140. static struct class iscsi_endpoint_class = {
  141. .name = "iscsi_endpoint",
  142. .dev_release = iscsi_endpoint_release,
  143. };
  144. static ssize_t
  145. show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
  146. {
  147. struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
  148. return sprintf(buf, "%llu\n", (unsigned long long) ep->id);
  149. }
  150. static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
  151. static struct attribute *iscsi_endpoint_attrs[] = {
  152. &dev_attr_ep_handle.attr,
  153. NULL,
  154. };
  155. static struct attribute_group iscsi_endpoint_group = {
  156. .attrs = iscsi_endpoint_attrs,
  157. };
  158. #define ISCSI_MAX_EPID -1
  159. static int iscsi_match_epid(struct device *dev, const void *data)
  160. {
  161. struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
  162. const uint64_t *epid = data;
  163. return *epid == ep->id;
  164. }
  165. struct iscsi_endpoint *
  166. iscsi_create_endpoint(int dd_size)
  167. {
  168. struct device *dev;
  169. struct iscsi_endpoint *ep;
  170. uint64_t id;
  171. int err;
  172. for (id = 1; id < ISCSI_MAX_EPID; id++) {
  173. dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
  174. iscsi_match_epid);
  175. if (!dev)
  176. break;
  177. else
  178. put_device(dev);
  179. }
  180. if (id == ISCSI_MAX_EPID) {
  181. printk(KERN_ERR "Too many connections. Max supported %u\n",
  182. ISCSI_MAX_EPID - 1);
  183. return NULL;
  184. }
  185. ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
  186. if (!ep)
  187. return NULL;
  188. ep->id = id;
  189. ep->dev.class = &iscsi_endpoint_class;
  190. dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id);
  191. err = device_register(&ep->dev);
  192. if (err)
  193. goto free_ep;
  194. err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
  195. if (err)
  196. goto unregister_dev;
  197. if (dd_size)
  198. ep->dd_data = &ep[1];
  199. return ep;
  200. unregister_dev:
  201. device_unregister(&ep->dev);
  202. return NULL;
  203. free_ep:
  204. kfree(ep);
  205. return NULL;
  206. }
  207. EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
  208. void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
  209. {
  210. sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
  211. device_unregister(&ep->dev);
  212. }
  213. EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
  214. struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
  215. {
  216. struct iscsi_endpoint *ep;
  217. struct device *dev;
  218. dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
  219. iscsi_match_epid);
  220. if (!dev)
  221. return NULL;
  222. ep = iscsi_dev_to_endpoint(dev);
  223. /*
  224. * we can drop this now because the interface will prevent
  225. * removals and lookups from racing.
  226. */
  227. put_device(dev);
  228. return ep;
  229. }
  230. EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
  231. /*
  232. * Interface to display network param to sysfs
  233. */
  234. static void iscsi_iface_release(struct device *dev)
  235. {
  236. struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
  237. struct device *parent = iface->dev.parent;
  238. kfree(iface);
  239. put_device(parent);
  240. }
  241. static struct class iscsi_iface_class = {
  242. .name = "iscsi_iface",
  243. .dev_release = iscsi_iface_release,
  244. };
  245. #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
  246. struct device_attribute dev_attr_##_prefix##_##_name = \
  247. __ATTR(_name, _mode, _show, _store)
  248. /* iface attrs show */
  249. #define iscsi_iface_attr_show(type, name, param_type, param) \
  250. static ssize_t \
  251. show_##type##_##name(struct device *dev, struct device_attribute *attr, \
  252. char *buf) \
  253. { \
  254. struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
  255. struct iscsi_transport *t = iface->transport; \
  256. return t->get_iface_param(iface, param_type, param, buf); \
  257. } \
  258. #define iscsi_iface_net_attr(type, name, param) \
  259. iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
  260. static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
  261. #define iscsi_iface_attr(type, name, param) \
  262. iscsi_iface_attr_show(type, name, ISCSI_IFACE_PARAM, param) \
  263. static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
  264. /* generic read only ipv4 attribute */
  265. iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR);
  266. iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW);
  267. iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET);
  268. iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO);
  269. iscsi_iface_net_attr(ipv4_iface, dhcp_dns_address_en,
  270. ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN);
  271. iscsi_iface_net_attr(ipv4_iface, dhcp_slp_da_info_en,
  272. ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN);
  273. iscsi_iface_net_attr(ipv4_iface, tos_en, ISCSI_NET_PARAM_IPV4_TOS_EN);
  274. iscsi_iface_net_attr(ipv4_iface, tos, ISCSI_NET_PARAM_IPV4_TOS);
  275. iscsi_iface_net_attr(ipv4_iface, grat_arp_en,
  276. ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN);
  277. iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id_en,
  278. ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN);
  279. iscsi_iface_net_attr(ipv4_iface, dhcp_alt_client_id,
  280. ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID);
  281. iscsi_iface_net_attr(ipv4_iface, dhcp_req_vendor_id_en,
  282. ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN);
  283. iscsi_iface_net_attr(ipv4_iface, dhcp_use_vendor_id_en,
  284. ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN);
  285. iscsi_iface_net_attr(ipv4_iface, dhcp_vendor_id,
  286. ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID);
  287. iscsi_iface_net_attr(ipv4_iface, dhcp_learn_iqn_en,
  288. ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN);
  289. iscsi_iface_net_attr(ipv4_iface, fragment_disable,
  290. ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE);
  291. iscsi_iface_net_attr(ipv4_iface, incoming_forwarding_en,
  292. ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN);
  293. iscsi_iface_net_attr(ipv4_iface, ttl, ISCSI_NET_PARAM_IPV4_TTL);
  294. /* generic read only ipv6 attribute */
  295. iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR);
  296. iscsi_iface_net_attr(ipv6_iface, link_local_addr,
  297. ISCSI_NET_PARAM_IPV6_LINKLOCAL);
  298. iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER);
  299. iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg,
  300. ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG);
  301. iscsi_iface_net_attr(ipv6_iface, link_local_autocfg,
  302. ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG);
  303. iscsi_iface_net_attr(ipv6_iface, link_local_state,
  304. ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE);
  305. iscsi_iface_net_attr(ipv6_iface, router_state,
  306. ISCSI_NET_PARAM_IPV6_ROUTER_STATE);
  307. iscsi_iface_net_attr(ipv6_iface, grat_neighbor_adv_en,
  308. ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN);
  309. iscsi_iface_net_attr(ipv6_iface, mld_en, ISCSI_NET_PARAM_IPV6_MLD_EN);
  310. iscsi_iface_net_attr(ipv6_iface, flow_label, ISCSI_NET_PARAM_IPV6_FLOW_LABEL);
  311. iscsi_iface_net_attr(ipv6_iface, traffic_class,
  312. ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS);
  313. iscsi_iface_net_attr(ipv6_iface, hop_limit, ISCSI_NET_PARAM_IPV6_HOP_LIMIT);
  314. iscsi_iface_net_attr(ipv6_iface, nd_reachable_tmo,
  315. ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO);
  316. iscsi_iface_net_attr(ipv6_iface, nd_rexmit_time,
  317. ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME);
  318. iscsi_iface_net_attr(ipv6_iface, nd_stale_tmo,
  319. ISCSI_NET_PARAM_IPV6_ND_STALE_TMO);
  320. iscsi_iface_net_attr(ipv6_iface, dup_addr_detect_cnt,
  321. ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT);
  322. iscsi_iface_net_attr(ipv6_iface, router_adv_link_mtu,
  323. ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU);
  324. /* common read only iface attribute */
  325. iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE);
  326. iscsi_iface_net_attr(iface, vlan_id, ISCSI_NET_PARAM_VLAN_ID);
  327. iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY);
  328. iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED);
  329. iscsi_iface_net_attr(iface, mtu, ISCSI_NET_PARAM_MTU);
  330. iscsi_iface_net_attr(iface, port, ISCSI_NET_PARAM_PORT);
  331. iscsi_iface_net_attr(iface, ipaddress_state, ISCSI_NET_PARAM_IPADDR_STATE);
  332. iscsi_iface_net_attr(iface, delayed_ack_en, ISCSI_NET_PARAM_DELAYED_ACK_EN);
  333. iscsi_iface_net_attr(iface, tcp_nagle_disable,
  334. ISCSI_NET_PARAM_TCP_NAGLE_DISABLE);
  335. iscsi_iface_net_attr(iface, tcp_wsf_disable, ISCSI_NET_PARAM_TCP_WSF_DISABLE);
  336. iscsi_iface_net_attr(iface, tcp_wsf, ISCSI_NET_PARAM_TCP_WSF);
  337. iscsi_iface_net_attr(iface, tcp_timer_scale, ISCSI_NET_PARAM_TCP_TIMER_SCALE);
  338. iscsi_iface_net_attr(iface, tcp_timestamp_en, ISCSI_NET_PARAM_TCP_TIMESTAMP_EN);
  339. iscsi_iface_net_attr(iface, cache_id, ISCSI_NET_PARAM_CACHE_ID);
  340. iscsi_iface_net_attr(iface, redirect_en, ISCSI_NET_PARAM_REDIRECT_EN);
  341. /* common iscsi specific settings attributes */
  342. iscsi_iface_attr(iface, def_taskmgmt_tmo, ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO);
  343. iscsi_iface_attr(iface, header_digest, ISCSI_IFACE_PARAM_HDRDGST_EN);
  344. iscsi_iface_attr(iface, data_digest, ISCSI_IFACE_PARAM_DATADGST_EN);
  345. iscsi_iface_attr(iface, immediate_data, ISCSI_IFACE_PARAM_IMM_DATA_EN);
  346. iscsi_iface_attr(iface, initial_r2t, ISCSI_IFACE_PARAM_INITIAL_R2T_EN);
  347. iscsi_iface_attr(iface, data_seq_in_order,
  348. ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN);
  349. iscsi_iface_attr(iface, data_pdu_in_order, ISCSI_IFACE_PARAM_PDU_INORDER_EN);
  350. iscsi_iface_attr(iface, erl, ISCSI_IFACE_PARAM_ERL);
  351. iscsi_iface_attr(iface, max_recv_dlength, ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH);
  352. iscsi_iface_attr(iface, first_burst_len, ISCSI_IFACE_PARAM_FIRST_BURST);
  353. iscsi_iface_attr(iface, max_outstanding_r2t, ISCSI_IFACE_PARAM_MAX_R2T);
  354. iscsi_iface_attr(iface, max_burst_len, ISCSI_IFACE_PARAM_MAX_BURST);
  355. iscsi_iface_attr(iface, chap_auth, ISCSI_IFACE_PARAM_CHAP_AUTH_EN);
  356. iscsi_iface_attr(iface, bidi_chap, ISCSI_IFACE_PARAM_BIDI_CHAP_EN);
  357. iscsi_iface_attr(iface, discovery_auth_optional,
  358. ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL);
  359. iscsi_iface_attr(iface, discovery_logout,
  360. ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN);
  361. iscsi_iface_attr(iface, strict_login_comp_en,
  362. ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN);
  363. iscsi_iface_attr(iface, initiator_name, ISCSI_IFACE_PARAM_INITIATOR_NAME);
  364. static umode_t iscsi_iface_attr_is_visible(struct kobject *kobj,
  365. struct attribute *attr, int i)
  366. {
  367. struct device *dev = container_of(kobj, struct device, kobj);
  368. struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
  369. struct iscsi_transport *t = iface->transport;
  370. int param;
  371. int param_type;
  372. if (attr == &dev_attr_iface_enabled.attr)
  373. param = ISCSI_NET_PARAM_IFACE_ENABLE;
  374. else if (attr == &dev_attr_iface_vlan_id.attr)
  375. param = ISCSI_NET_PARAM_VLAN_ID;
  376. else if (attr == &dev_attr_iface_vlan_priority.attr)
  377. param = ISCSI_NET_PARAM_VLAN_PRIORITY;
  378. else if (attr == &dev_attr_iface_vlan_enabled.attr)
  379. param = ISCSI_NET_PARAM_VLAN_ENABLED;
  380. else if (attr == &dev_attr_iface_mtu.attr)
  381. param = ISCSI_NET_PARAM_MTU;
  382. else if (attr == &dev_attr_iface_port.attr)
  383. param = ISCSI_NET_PARAM_PORT;
  384. else if (attr == &dev_attr_iface_ipaddress_state.attr)
  385. param = ISCSI_NET_PARAM_IPADDR_STATE;
  386. else if (attr == &dev_attr_iface_delayed_ack_en.attr)
  387. param = ISCSI_NET_PARAM_DELAYED_ACK_EN;
  388. else if (attr == &dev_attr_iface_tcp_nagle_disable.attr)
  389. param = ISCSI_NET_PARAM_TCP_NAGLE_DISABLE;
  390. else if (attr == &dev_attr_iface_tcp_wsf_disable.attr)
  391. param = ISCSI_NET_PARAM_TCP_WSF_DISABLE;
  392. else if (attr == &dev_attr_iface_tcp_wsf.attr)
  393. param = ISCSI_NET_PARAM_TCP_WSF;
  394. else if (attr == &dev_attr_iface_tcp_timer_scale.attr)
  395. param = ISCSI_NET_PARAM_TCP_TIMER_SCALE;
  396. else if (attr == &dev_attr_iface_tcp_timestamp_en.attr)
  397. param = ISCSI_NET_PARAM_TCP_TIMESTAMP_EN;
  398. else if (attr == &dev_attr_iface_cache_id.attr)
  399. param = ISCSI_NET_PARAM_CACHE_ID;
  400. else if (attr == &dev_attr_iface_redirect_en.attr)
  401. param = ISCSI_NET_PARAM_REDIRECT_EN;
  402. else if (attr == &dev_attr_iface_def_taskmgmt_tmo.attr)
  403. param = ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO;
  404. else if (attr == &dev_attr_iface_header_digest.attr)
  405. param = ISCSI_IFACE_PARAM_HDRDGST_EN;
  406. else if (attr == &dev_attr_iface_data_digest.attr)
  407. param = ISCSI_IFACE_PARAM_DATADGST_EN;
  408. else if (attr == &dev_attr_iface_immediate_data.attr)
  409. param = ISCSI_IFACE_PARAM_IMM_DATA_EN;
  410. else if (attr == &dev_attr_iface_initial_r2t.attr)
  411. param = ISCSI_IFACE_PARAM_INITIAL_R2T_EN;
  412. else if (attr == &dev_attr_iface_data_seq_in_order.attr)
  413. param = ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN;
  414. else if (attr == &dev_attr_iface_data_pdu_in_order.attr)
  415. param = ISCSI_IFACE_PARAM_PDU_INORDER_EN;
  416. else if (attr == &dev_attr_iface_erl.attr)
  417. param = ISCSI_IFACE_PARAM_ERL;
  418. else if (attr == &dev_attr_iface_max_recv_dlength.attr)
  419. param = ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH;
  420. else if (attr == &dev_attr_iface_first_burst_len.attr)
  421. param = ISCSI_IFACE_PARAM_FIRST_BURST;
  422. else if (attr == &dev_attr_iface_max_outstanding_r2t.attr)
  423. param = ISCSI_IFACE_PARAM_MAX_R2T;
  424. else if (attr == &dev_attr_iface_max_burst_len.attr)
  425. param = ISCSI_IFACE_PARAM_MAX_BURST;
  426. else if (attr == &dev_attr_iface_chap_auth.attr)
  427. param = ISCSI_IFACE_PARAM_CHAP_AUTH_EN;
  428. else if (attr == &dev_attr_iface_bidi_chap.attr)
  429. param = ISCSI_IFACE_PARAM_BIDI_CHAP_EN;
  430. else if (attr == &dev_attr_iface_discovery_auth_optional.attr)
  431. param = ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL;
  432. else if (attr == &dev_attr_iface_discovery_logout.attr)
  433. param = ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN;
  434. else if (attr == &dev_attr_iface_strict_login_comp_en.attr)
  435. param = ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN;
  436. else if (attr == &dev_attr_iface_initiator_name.attr)
  437. param = ISCSI_IFACE_PARAM_INITIATOR_NAME;
  438. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  439. if (attr == &dev_attr_ipv4_iface_ipaddress.attr)
  440. param = ISCSI_NET_PARAM_IPV4_ADDR;
  441. else if (attr == &dev_attr_ipv4_iface_gateway.attr)
  442. param = ISCSI_NET_PARAM_IPV4_GW;
  443. else if (attr == &dev_attr_ipv4_iface_subnet.attr)
  444. param = ISCSI_NET_PARAM_IPV4_SUBNET;
  445. else if (attr == &dev_attr_ipv4_iface_bootproto.attr)
  446. param = ISCSI_NET_PARAM_IPV4_BOOTPROTO;
  447. else if (attr ==
  448. &dev_attr_ipv4_iface_dhcp_dns_address_en.attr)
  449. param = ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN;
  450. else if (attr ==
  451. &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr)
  452. param = ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN;
  453. else if (attr == &dev_attr_ipv4_iface_tos_en.attr)
  454. param = ISCSI_NET_PARAM_IPV4_TOS_EN;
  455. else if (attr == &dev_attr_ipv4_iface_tos.attr)
  456. param = ISCSI_NET_PARAM_IPV4_TOS;
  457. else if (attr == &dev_attr_ipv4_iface_grat_arp_en.attr)
  458. param = ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN;
  459. else if (attr ==
  460. &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr)
  461. param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN;
  462. else if (attr == &dev_attr_ipv4_iface_dhcp_alt_client_id.attr)
  463. param = ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID;
  464. else if (attr ==
  465. &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr)
  466. param = ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN;
  467. else if (attr ==
  468. &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr)
  469. param = ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN;
  470. else if (attr == &dev_attr_ipv4_iface_dhcp_vendor_id.attr)
  471. param = ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID;
  472. else if (attr ==
  473. &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr)
  474. param = ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN;
  475. else if (attr ==
  476. &dev_attr_ipv4_iface_fragment_disable.attr)
  477. param = ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE;
  478. else if (attr ==
  479. &dev_attr_ipv4_iface_incoming_forwarding_en.attr)
  480. param = ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN;
  481. else if (attr == &dev_attr_ipv4_iface_ttl.attr)
  482. param = ISCSI_NET_PARAM_IPV4_TTL;
  483. else
  484. return 0;
  485. } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) {
  486. if (attr == &dev_attr_ipv6_iface_ipaddress.attr)
  487. param = ISCSI_NET_PARAM_IPV6_ADDR;
  488. else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr)
  489. param = ISCSI_NET_PARAM_IPV6_LINKLOCAL;
  490. else if (attr == &dev_attr_ipv6_iface_router_addr.attr)
  491. param = ISCSI_NET_PARAM_IPV6_ROUTER;
  492. else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr)
  493. param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG;
  494. else if (attr == &dev_attr_ipv6_iface_link_local_autocfg.attr)
  495. param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG;
  496. else if (attr == &dev_attr_ipv6_iface_link_local_state.attr)
  497. param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE;
  498. else if (attr == &dev_attr_ipv6_iface_router_state.attr)
  499. param = ISCSI_NET_PARAM_IPV6_ROUTER_STATE;
  500. else if (attr ==
  501. &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr)
  502. param = ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN;
  503. else if (attr == &dev_attr_ipv6_iface_mld_en.attr)
  504. param = ISCSI_NET_PARAM_IPV6_MLD_EN;
  505. else if (attr == &dev_attr_ipv6_iface_flow_label.attr)
  506. param = ISCSI_NET_PARAM_IPV6_FLOW_LABEL;
  507. else if (attr == &dev_attr_ipv6_iface_traffic_class.attr)
  508. param = ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS;
  509. else if (attr == &dev_attr_ipv6_iface_hop_limit.attr)
  510. param = ISCSI_NET_PARAM_IPV6_HOP_LIMIT;
  511. else if (attr == &dev_attr_ipv6_iface_nd_reachable_tmo.attr)
  512. param = ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO;
  513. else if (attr == &dev_attr_ipv6_iface_nd_rexmit_time.attr)
  514. param = ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME;
  515. else if (attr == &dev_attr_ipv6_iface_nd_stale_tmo.attr)
  516. param = ISCSI_NET_PARAM_IPV6_ND_STALE_TMO;
  517. else if (attr == &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr)
  518. param = ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT;
  519. else if (attr == &dev_attr_ipv6_iface_router_adv_link_mtu.attr)
  520. param = ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU;
  521. else
  522. return 0;
  523. } else {
  524. WARN_ONCE(1, "Invalid iface attr");
  525. return 0;
  526. }
  527. switch (param) {
  528. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  529. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  530. case ISCSI_IFACE_PARAM_DATADGST_EN:
  531. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  532. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  533. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  534. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  535. case ISCSI_IFACE_PARAM_ERL:
  536. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  537. case ISCSI_IFACE_PARAM_FIRST_BURST:
  538. case ISCSI_IFACE_PARAM_MAX_R2T:
  539. case ISCSI_IFACE_PARAM_MAX_BURST:
  540. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  541. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  542. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  543. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  544. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  545. case ISCSI_IFACE_PARAM_INITIATOR_NAME:
  546. param_type = ISCSI_IFACE_PARAM;
  547. break;
  548. default:
  549. param_type = ISCSI_NET_PARAM;
  550. }
  551. return t->attr_is_visible(param_type, param);
  552. }
  553. static struct attribute *iscsi_iface_attrs[] = {
  554. &dev_attr_iface_enabled.attr,
  555. &dev_attr_iface_vlan_id.attr,
  556. &dev_attr_iface_vlan_priority.attr,
  557. &dev_attr_iface_vlan_enabled.attr,
  558. &dev_attr_ipv4_iface_ipaddress.attr,
  559. &dev_attr_ipv4_iface_gateway.attr,
  560. &dev_attr_ipv4_iface_subnet.attr,
  561. &dev_attr_ipv4_iface_bootproto.attr,
  562. &dev_attr_ipv6_iface_ipaddress.attr,
  563. &dev_attr_ipv6_iface_link_local_addr.attr,
  564. &dev_attr_ipv6_iface_router_addr.attr,
  565. &dev_attr_ipv6_iface_ipaddr_autocfg.attr,
  566. &dev_attr_ipv6_iface_link_local_autocfg.attr,
  567. &dev_attr_iface_mtu.attr,
  568. &dev_attr_iface_port.attr,
  569. &dev_attr_iface_ipaddress_state.attr,
  570. &dev_attr_iface_delayed_ack_en.attr,
  571. &dev_attr_iface_tcp_nagle_disable.attr,
  572. &dev_attr_iface_tcp_wsf_disable.attr,
  573. &dev_attr_iface_tcp_wsf.attr,
  574. &dev_attr_iface_tcp_timer_scale.attr,
  575. &dev_attr_iface_tcp_timestamp_en.attr,
  576. &dev_attr_iface_cache_id.attr,
  577. &dev_attr_iface_redirect_en.attr,
  578. &dev_attr_iface_def_taskmgmt_tmo.attr,
  579. &dev_attr_iface_header_digest.attr,
  580. &dev_attr_iface_data_digest.attr,
  581. &dev_attr_iface_immediate_data.attr,
  582. &dev_attr_iface_initial_r2t.attr,
  583. &dev_attr_iface_data_seq_in_order.attr,
  584. &dev_attr_iface_data_pdu_in_order.attr,
  585. &dev_attr_iface_erl.attr,
  586. &dev_attr_iface_max_recv_dlength.attr,
  587. &dev_attr_iface_first_burst_len.attr,
  588. &dev_attr_iface_max_outstanding_r2t.attr,
  589. &dev_attr_iface_max_burst_len.attr,
  590. &dev_attr_iface_chap_auth.attr,
  591. &dev_attr_iface_bidi_chap.attr,
  592. &dev_attr_iface_discovery_auth_optional.attr,
  593. &dev_attr_iface_discovery_logout.attr,
  594. &dev_attr_iface_strict_login_comp_en.attr,
  595. &dev_attr_iface_initiator_name.attr,
  596. &dev_attr_ipv4_iface_dhcp_dns_address_en.attr,
  597. &dev_attr_ipv4_iface_dhcp_slp_da_info_en.attr,
  598. &dev_attr_ipv4_iface_tos_en.attr,
  599. &dev_attr_ipv4_iface_tos.attr,
  600. &dev_attr_ipv4_iface_grat_arp_en.attr,
  601. &dev_attr_ipv4_iface_dhcp_alt_client_id_en.attr,
  602. &dev_attr_ipv4_iface_dhcp_alt_client_id.attr,
  603. &dev_attr_ipv4_iface_dhcp_req_vendor_id_en.attr,
  604. &dev_attr_ipv4_iface_dhcp_use_vendor_id_en.attr,
  605. &dev_attr_ipv4_iface_dhcp_vendor_id.attr,
  606. &dev_attr_ipv4_iface_dhcp_learn_iqn_en.attr,
  607. &dev_attr_ipv4_iface_fragment_disable.attr,
  608. &dev_attr_ipv4_iface_incoming_forwarding_en.attr,
  609. &dev_attr_ipv4_iface_ttl.attr,
  610. &dev_attr_ipv6_iface_link_local_state.attr,
  611. &dev_attr_ipv6_iface_router_state.attr,
  612. &dev_attr_ipv6_iface_grat_neighbor_adv_en.attr,
  613. &dev_attr_ipv6_iface_mld_en.attr,
  614. &dev_attr_ipv6_iface_flow_label.attr,
  615. &dev_attr_ipv6_iface_traffic_class.attr,
  616. &dev_attr_ipv6_iface_hop_limit.attr,
  617. &dev_attr_ipv6_iface_nd_reachable_tmo.attr,
  618. &dev_attr_ipv6_iface_nd_rexmit_time.attr,
  619. &dev_attr_ipv6_iface_nd_stale_tmo.attr,
  620. &dev_attr_ipv6_iface_dup_addr_detect_cnt.attr,
  621. &dev_attr_ipv6_iface_router_adv_link_mtu.attr,
  622. NULL,
  623. };
  624. static struct attribute_group iscsi_iface_group = {
  625. .attrs = iscsi_iface_attrs,
  626. .is_visible = iscsi_iface_attr_is_visible,
  627. };
  628. /* convert iscsi_ipaddress_state values to ascii string name */
  629. static const struct {
  630. enum iscsi_ipaddress_state value;
  631. char *name;
  632. } iscsi_ipaddress_state_names[] = {
  633. {ISCSI_IPDDRESS_STATE_UNCONFIGURED, "Unconfigured" },
  634. {ISCSI_IPDDRESS_STATE_ACQUIRING, "Acquiring" },
  635. {ISCSI_IPDDRESS_STATE_TENTATIVE, "Tentative" },
  636. {ISCSI_IPDDRESS_STATE_VALID, "Valid" },
  637. {ISCSI_IPDDRESS_STATE_DISABLING, "Disabling" },
  638. {ISCSI_IPDDRESS_STATE_INVALID, "Invalid" },
  639. {ISCSI_IPDDRESS_STATE_DEPRECATED, "Deprecated" },
  640. };
  641. char *iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state)
  642. {
  643. int i;
  644. char *state = NULL;
  645. for (i = 0; i < ARRAY_SIZE(iscsi_ipaddress_state_names); i++) {
  646. if (iscsi_ipaddress_state_names[i].value == port_state) {
  647. state = iscsi_ipaddress_state_names[i].name;
  648. break;
  649. }
  650. }
  651. return state;
  652. }
  653. EXPORT_SYMBOL_GPL(iscsi_get_ipaddress_state_name);
  654. /* convert iscsi_router_state values to ascii string name */
  655. static const struct {
  656. enum iscsi_router_state value;
  657. char *name;
  658. } iscsi_router_state_names[] = {
  659. {ISCSI_ROUTER_STATE_UNKNOWN, "Unknown" },
  660. {ISCSI_ROUTER_STATE_ADVERTISED, "Advertised" },
  661. {ISCSI_ROUTER_STATE_MANUAL, "Manual" },
  662. {ISCSI_ROUTER_STATE_STALE, "Stale" },
  663. };
  664. char *iscsi_get_router_state_name(enum iscsi_router_state router_state)
  665. {
  666. int i;
  667. char *state = NULL;
  668. for (i = 0; i < ARRAY_SIZE(iscsi_router_state_names); i++) {
  669. if (iscsi_router_state_names[i].value == router_state) {
  670. state = iscsi_router_state_names[i].name;
  671. break;
  672. }
  673. }
  674. return state;
  675. }
  676. EXPORT_SYMBOL_GPL(iscsi_get_router_state_name);
  677. struct iscsi_iface *
  678. iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport,
  679. uint32_t iface_type, uint32_t iface_num, int dd_size)
  680. {
  681. struct iscsi_iface *iface;
  682. int err;
  683. iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL);
  684. if (!iface)
  685. return NULL;
  686. iface->transport = transport;
  687. iface->iface_type = iface_type;
  688. iface->iface_num = iface_num;
  689. iface->dev.release = iscsi_iface_release;
  690. iface->dev.class = &iscsi_iface_class;
  691. /* parent reference released in iscsi_iface_release */
  692. iface->dev.parent = get_device(&shost->shost_gendev);
  693. if (iface_type == ISCSI_IFACE_TYPE_IPV4)
  694. dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no,
  695. iface_num);
  696. else
  697. dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no,
  698. iface_num);
  699. err = device_register(&iface->dev);
  700. if (err)
  701. goto free_iface;
  702. err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group);
  703. if (err)
  704. goto unreg_iface;
  705. if (dd_size)
  706. iface->dd_data = &iface[1];
  707. return iface;
  708. unreg_iface:
  709. device_unregister(&iface->dev);
  710. return NULL;
  711. free_iface:
  712. put_device(iface->dev.parent);
  713. kfree(iface);
  714. return NULL;
  715. }
  716. EXPORT_SYMBOL_GPL(iscsi_create_iface);
  717. void iscsi_destroy_iface(struct iscsi_iface *iface)
  718. {
  719. sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group);
  720. device_unregister(&iface->dev);
  721. }
  722. EXPORT_SYMBOL_GPL(iscsi_destroy_iface);
  723. /*
  724. * Interface to display flash node params to sysfs
  725. */
  726. #define ISCSI_FLASHNODE_ATTR(_prefix, _name, _mode, _show, _store) \
  727. struct device_attribute dev_attr_##_prefix##_##_name = \
  728. __ATTR(_name, _mode, _show, _store)
  729. /* flash node session attrs show */
  730. #define iscsi_flashnode_sess_attr_show(type, name, param) \
  731. static ssize_t \
  732. show_##type##_##name(struct device *dev, struct device_attribute *attr, \
  733. char *buf) \
  734. { \
  735. struct iscsi_bus_flash_session *fnode_sess = \
  736. iscsi_dev_to_flash_session(dev);\
  737. struct iscsi_transport *t = fnode_sess->transport; \
  738. return t->get_flashnode_param(fnode_sess, param, buf); \
  739. } \
  740. #define iscsi_flashnode_sess_attr(type, name, param) \
  741. iscsi_flashnode_sess_attr_show(type, name, param) \
  742. static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
  743. show_##type##_##name, NULL);
  744. /* Flash node session attributes */
  745. iscsi_flashnode_sess_attr(fnode, auto_snd_tgt_disable,
  746. ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE);
  747. iscsi_flashnode_sess_attr(fnode, discovery_session,
  748. ISCSI_FLASHNODE_DISCOVERY_SESS);
  749. iscsi_flashnode_sess_attr(fnode, portal_type, ISCSI_FLASHNODE_PORTAL_TYPE);
  750. iscsi_flashnode_sess_attr(fnode, entry_enable, ISCSI_FLASHNODE_ENTRY_EN);
  751. iscsi_flashnode_sess_attr(fnode, immediate_data, ISCSI_FLASHNODE_IMM_DATA_EN);
  752. iscsi_flashnode_sess_attr(fnode, initial_r2t, ISCSI_FLASHNODE_INITIAL_R2T_EN);
  753. iscsi_flashnode_sess_attr(fnode, data_seq_in_order,
  754. ISCSI_FLASHNODE_DATASEQ_INORDER);
  755. iscsi_flashnode_sess_attr(fnode, data_pdu_in_order,
  756. ISCSI_FLASHNODE_PDU_INORDER);
  757. iscsi_flashnode_sess_attr(fnode, chap_auth, ISCSI_FLASHNODE_CHAP_AUTH_EN);
  758. iscsi_flashnode_sess_attr(fnode, discovery_logout,
  759. ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN);
  760. iscsi_flashnode_sess_attr(fnode, bidi_chap, ISCSI_FLASHNODE_BIDI_CHAP_EN);
  761. iscsi_flashnode_sess_attr(fnode, discovery_auth_optional,
  762. ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL);
  763. iscsi_flashnode_sess_attr(fnode, erl, ISCSI_FLASHNODE_ERL);
  764. iscsi_flashnode_sess_attr(fnode, first_burst_len, ISCSI_FLASHNODE_FIRST_BURST);
  765. iscsi_flashnode_sess_attr(fnode, def_time2wait, ISCSI_FLASHNODE_DEF_TIME2WAIT);
  766. iscsi_flashnode_sess_attr(fnode, def_time2retain,
  767. ISCSI_FLASHNODE_DEF_TIME2RETAIN);
  768. iscsi_flashnode_sess_attr(fnode, max_outstanding_r2t, ISCSI_FLASHNODE_MAX_R2T);
  769. iscsi_flashnode_sess_attr(fnode, isid, ISCSI_FLASHNODE_ISID);
  770. iscsi_flashnode_sess_attr(fnode, tsid, ISCSI_FLASHNODE_TSID);
  771. iscsi_flashnode_sess_attr(fnode, max_burst_len, ISCSI_FLASHNODE_MAX_BURST);
  772. iscsi_flashnode_sess_attr(fnode, def_taskmgmt_tmo,
  773. ISCSI_FLASHNODE_DEF_TASKMGMT_TMO);
  774. iscsi_flashnode_sess_attr(fnode, targetalias, ISCSI_FLASHNODE_ALIAS);
  775. iscsi_flashnode_sess_attr(fnode, targetname, ISCSI_FLASHNODE_NAME);
  776. iscsi_flashnode_sess_attr(fnode, tpgt, ISCSI_FLASHNODE_TPGT);
  777. iscsi_flashnode_sess_attr(fnode, discovery_parent_idx,
  778. ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX);
  779. iscsi_flashnode_sess_attr(fnode, discovery_parent_type,
  780. ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE);
  781. iscsi_flashnode_sess_attr(fnode, chap_in_idx, ISCSI_FLASHNODE_CHAP_IN_IDX);
  782. iscsi_flashnode_sess_attr(fnode, chap_out_idx, ISCSI_FLASHNODE_CHAP_OUT_IDX);
  783. iscsi_flashnode_sess_attr(fnode, username, ISCSI_FLASHNODE_USERNAME);
  784. iscsi_flashnode_sess_attr(fnode, username_in, ISCSI_FLASHNODE_USERNAME_IN);
  785. iscsi_flashnode_sess_attr(fnode, password, ISCSI_FLASHNODE_PASSWORD);
  786. iscsi_flashnode_sess_attr(fnode, password_in, ISCSI_FLASHNODE_PASSWORD_IN);
  787. iscsi_flashnode_sess_attr(fnode, is_boot_target, ISCSI_FLASHNODE_IS_BOOT_TGT);
  788. static struct attribute *iscsi_flashnode_sess_attrs[] = {
  789. &dev_attr_fnode_auto_snd_tgt_disable.attr,
  790. &dev_attr_fnode_discovery_session.attr,
  791. &dev_attr_fnode_portal_type.attr,
  792. &dev_attr_fnode_entry_enable.attr,
  793. &dev_attr_fnode_immediate_data.attr,
  794. &dev_attr_fnode_initial_r2t.attr,
  795. &dev_attr_fnode_data_seq_in_order.attr,
  796. &dev_attr_fnode_data_pdu_in_order.attr,
  797. &dev_attr_fnode_chap_auth.attr,
  798. &dev_attr_fnode_discovery_logout.attr,
  799. &dev_attr_fnode_bidi_chap.attr,
  800. &dev_attr_fnode_discovery_auth_optional.attr,
  801. &dev_attr_fnode_erl.attr,
  802. &dev_attr_fnode_first_burst_len.attr,
  803. &dev_attr_fnode_def_time2wait.attr,
  804. &dev_attr_fnode_def_time2retain.attr,
  805. &dev_attr_fnode_max_outstanding_r2t.attr,
  806. &dev_attr_fnode_isid.attr,
  807. &dev_attr_fnode_tsid.attr,
  808. &dev_attr_fnode_max_burst_len.attr,
  809. &dev_attr_fnode_def_taskmgmt_tmo.attr,
  810. &dev_attr_fnode_targetalias.attr,
  811. &dev_attr_fnode_targetname.attr,
  812. &dev_attr_fnode_tpgt.attr,
  813. &dev_attr_fnode_discovery_parent_idx.attr,
  814. &dev_attr_fnode_discovery_parent_type.attr,
  815. &dev_attr_fnode_chap_in_idx.attr,
  816. &dev_attr_fnode_chap_out_idx.attr,
  817. &dev_attr_fnode_username.attr,
  818. &dev_attr_fnode_username_in.attr,
  819. &dev_attr_fnode_password.attr,
  820. &dev_attr_fnode_password_in.attr,
  821. &dev_attr_fnode_is_boot_target.attr,
  822. NULL,
  823. };
  824. static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj,
  825. struct attribute *attr,
  826. int i)
  827. {
  828. struct device *dev = container_of(kobj, struct device, kobj);
  829. struct iscsi_bus_flash_session *fnode_sess =
  830. iscsi_dev_to_flash_session(dev);
  831. struct iscsi_transport *t = fnode_sess->transport;
  832. int param;
  833. if (attr == &dev_attr_fnode_auto_snd_tgt_disable.attr) {
  834. param = ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE;
  835. } else if (attr == &dev_attr_fnode_discovery_session.attr) {
  836. param = ISCSI_FLASHNODE_DISCOVERY_SESS;
  837. } else if (attr == &dev_attr_fnode_portal_type.attr) {
  838. param = ISCSI_FLASHNODE_PORTAL_TYPE;
  839. } else if (attr == &dev_attr_fnode_entry_enable.attr) {
  840. param = ISCSI_FLASHNODE_ENTRY_EN;
  841. } else if (attr == &dev_attr_fnode_immediate_data.attr) {
  842. param = ISCSI_FLASHNODE_IMM_DATA_EN;
  843. } else if (attr == &dev_attr_fnode_initial_r2t.attr) {
  844. param = ISCSI_FLASHNODE_INITIAL_R2T_EN;
  845. } else if (attr == &dev_attr_fnode_data_seq_in_order.attr) {
  846. param = ISCSI_FLASHNODE_DATASEQ_INORDER;
  847. } else if (attr == &dev_attr_fnode_data_pdu_in_order.attr) {
  848. param = ISCSI_FLASHNODE_PDU_INORDER;
  849. } else if (attr == &dev_attr_fnode_chap_auth.attr) {
  850. param = ISCSI_FLASHNODE_CHAP_AUTH_EN;
  851. } else if (attr == &dev_attr_fnode_discovery_logout.attr) {
  852. param = ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN;
  853. } else if (attr == &dev_attr_fnode_bidi_chap.attr) {
  854. param = ISCSI_FLASHNODE_BIDI_CHAP_EN;
  855. } else if (attr == &dev_attr_fnode_discovery_auth_optional.attr) {
  856. param = ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL;
  857. } else if (attr == &dev_attr_fnode_erl.attr) {
  858. param = ISCSI_FLASHNODE_ERL;
  859. } else if (attr == &dev_attr_fnode_first_burst_len.attr) {
  860. param = ISCSI_FLASHNODE_FIRST_BURST;
  861. } else if (attr == &dev_attr_fnode_def_time2wait.attr) {
  862. param = ISCSI_FLASHNODE_DEF_TIME2WAIT;
  863. } else if (attr == &dev_attr_fnode_def_time2retain.attr) {
  864. param = ISCSI_FLASHNODE_DEF_TIME2RETAIN;
  865. } else if (attr == &dev_attr_fnode_max_outstanding_r2t.attr) {
  866. param = ISCSI_FLASHNODE_MAX_R2T;
  867. } else if (attr == &dev_attr_fnode_isid.attr) {
  868. param = ISCSI_FLASHNODE_ISID;
  869. } else if (attr == &dev_attr_fnode_tsid.attr) {
  870. param = ISCSI_FLASHNODE_TSID;
  871. } else if (attr == &dev_attr_fnode_max_burst_len.attr) {
  872. param = ISCSI_FLASHNODE_MAX_BURST;
  873. } else if (attr == &dev_attr_fnode_def_taskmgmt_tmo.attr) {
  874. param = ISCSI_FLASHNODE_DEF_TASKMGMT_TMO;
  875. } else if (attr == &dev_attr_fnode_targetalias.attr) {
  876. param = ISCSI_FLASHNODE_ALIAS;
  877. } else if (attr == &dev_attr_fnode_targetname.attr) {
  878. param = ISCSI_FLASHNODE_NAME;
  879. } else if (attr == &dev_attr_fnode_tpgt.attr) {
  880. param = ISCSI_FLASHNODE_TPGT;
  881. } else if (attr == &dev_attr_fnode_discovery_parent_idx.attr) {
  882. param = ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX;
  883. } else if (attr == &dev_attr_fnode_discovery_parent_type.attr) {
  884. param = ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE;
  885. } else if (attr == &dev_attr_fnode_chap_in_idx.attr) {
  886. param = ISCSI_FLASHNODE_CHAP_IN_IDX;
  887. } else if (attr == &dev_attr_fnode_chap_out_idx.attr) {
  888. param = ISCSI_FLASHNODE_CHAP_OUT_IDX;
  889. } else if (attr == &dev_attr_fnode_username.attr) {
  890. param = ISCSI_FLASHNODE_USERNAME;
  891. } else if (attr == &dev_attr_fnode_username_in.attr) {
  892. param = ISCSI_FLASHNODE_USERNAME_IN;
  893. } else if (attr == &dev_attr_fnode_password.attr) {
  894. param = ISCSI_FLASHNODE_PASSWORD;
  895. } else if (attr == &dev_attr_fnode_password_in.attr) {
  896. param = ISCSI_FLASHNODE_PASSWORD_IN;
  897. } else if (attr == &dev_attr_fnode_is_boot_target.attr) {
  898. param = ISCSI_FLASHNODE_IS_BOOT_TGT;
  899. } else {
  900. WARN_ONCE(1, "Invalid flashnode session attr");
  901. return 0;
  902. }
  903. return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
  904. }
  905. static struct attribute_group iscsi_flashnode_sess_attr_group = {
  906. .attrs = iscsi_flashnode_sess_attrs,
  907. .is_visible = iscsi_flashnode_sess_attr_is_visible,
  908. };
  909. static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = {
  910. &iscsi_flashnode_sess_attr_group,
  911. NULL,
  912. };
  913. static void iscsi_flashnode_sess_release(struct device *dev)
  914. {
  915. struct iscsi_bus_flash_session *fnode_sess =
  916. iscsi_dev_to_flash_session(dev);
  917. kfree(fnode_sess->targetname);
  918. kfree(fnode_sess->targetalias);
  919. kfree(fnode_sess->portal_type);
  920. kfree(fnode_sess);
  921. }
  922. static struct device_type iscsi_flashnode_sess_dev_type = {
  923. .name = "iscsi_flashnode_sess_dev_type",
  924. .groups = iscsi_flashnode_sess_attr_groups,
  925. .release = iscsi_flashnode_sess_release,
  926. };
  927. /* flash node connection attrs show */
  928. #define iscsi_flashnode_conn_attr_show(type, name, param) \
  929. static ssize_t \
  930. show_##type##_##name(struct device *dev, struct device_attribute *attr, \
  931. char *buf) \
  932. { \
  933. struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\
  934. struct iscsi_bus_flash_session *fnode_sess = \
  935. iscsi_flash_conn_to_flash_session(fnode_conn);\
  936. struct iscsi_transport *t = fnode_conn->transport; \
  937. return t->get_flashnode_param(fnode_sess, param, buf); \
  938. } \
  939. #define iscsi_flashnode_conn_attr(type, name, param) \
  940. iscsi_flashnode_conn_attr_show(type, name, param) \
  941. static ISCSI_FLASHNODE_ATTR(type, name, S_IRUGO, \
  942. show_##type##_##name, NULL);
  943. /* Flash node connection attributes */
  944. iscsi_flashnode_conn_attr(fnode, is_fw_assigned_ipv6,
  945. ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6);
  946. iscsi_flashnode_conn_attr(fnode, header_digest, ISCSI_FLASHNODE_HDR_DGST_EN);
  947. iscsi_flashnode_conn_attr(fnode, data_digest, ISCSI_FLASHNODE_DATA_DGST_EN);
  948. iscsi_flashnode_conn_attr(fnode, snack_req, ISCSI_FLASHNODE_SNACK_REQ_EN);
  949. iscsi_flashnode_conn_attr(fnode, tcp_timestamp_stat,
  950. ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT);
  951. iscsi_flashnode_conn_attr(fnode, tcp_nagle_disable,
  952. ISCSI_FLASHNODE_TCP_NAGLE_DISABLE);
  953. iscsi_flashnode_conn_attr(fnode, tcp_wsf_disable,
  954. ISCSI_FLASHNODE_TCP_WSF_DISABLE);
  955. iscsi_flashnode_conn_attr(fnode, tcp_timer_scale,
  956. ISCSI_FLASHNODE_TCP_TIMER_SCALE);
  957. iscsi_flashnode_conn_attr(fnode, tcp_timestamp_enable,
  958. ISCSI_FLASHNODE_TCP_TIMESTAMP_EN);
  959. iscsi_flashnode_conn_attr(fnode, fragment_disable,
  960. ISCSI_FLASHNODE_IP_FRAG_DISABLE);
  961. iscsi_flashnode_conn_attr(fnode, keepalive_tmo, ISCSI_FLASHNODE_KEEPALIVE_TMO);
  962. iscsi_flashnode_conn_attr(fnode, port, ISCSI_FLASHNODE_PORT);
  963. iscsi_flashnode_conn_attr(fnode, ipaddress, ISCSI_FLASHNODE_IPADDR);
  964. iscsi_flashnode_conn_attr(fnode, max_recv_dlength,
  965. ISCSI_FLASHNODE_MAX_RECV_DLENGTH);
  966. iscsi_flashnode_conn_attr(fnode, max_xmit_dlength,
  967. ISCSI_FLASHNODE_MAX_XMIT_DLENGTH);
  968. iscsi_flashnode_conn_attr(fnode, local_port, ISCSI_FLASHNODE_LOCAL_PORT);
  969. iscsi_flashnode_conn_attr(fnode, ipv4_tos, ISCSI_FLASHNODE_IPV4_TOS);
  970. iscsi_flashnode_conn_attr(fnode, ipv6_traffic_class, ISCSI_FLASHNODE_IPV6_TC);
  971. iscsi_flashnode_conn_attr(fnode, ipv6_flow_label,
  972. ISCSI_FLASHNODE_IPV6_FLOW_LABEL);
  973. iscsi_flashnode_conn_attr(fnode, redirect_ipaddr,
  974. ISCSI_FLASHNODE_REDIRECT_IPADDR);
  975. iscsi_flashnode_conn_attr(fnode, max_segment_size,
  976. ISCSI_FLASHNODE_MAX_SEGMENT_SIZE);
  977. iscsi_flashnode_conn_attr(fnode, link_local_ipv6,
  978. ISCSI_FLASHNODE_LINK_LOCAL_IPV6);
  979. iscsi_flashnode_conn_attr(fnode, tcp_xmit_wsf, ISCSI_FLASHNODE_TCP_XMIT_WSF);
  980. iscsi_flashnode_conn_attr(fnode, tcp_recv_wsf, ISCSI_FLASHNODE_TCP_RECV_WSF);
  981. iscsi_flashnode_conn_attr(fnode, statsn, ISCSI_FLASHNODE_STATSN);
  982. iscsi_flashnode_conn_attr(fnode, exp_statsn, ISCSI_FLASHNODE_EXP_STATSN);
  983. static struct attribute *iscsi_flashnode_conn_attrs[] = {
  984. &dev_attr_fnode_is_fw_assigned_ipv6.attr,
  985. &dev_attr_fnode_header_digest.attr,
  986. &dev_attr_fnode_data_digest.attr,
  987. &dev_attr_fnode_snack_req.attr,
  988. &dev_attr_fnode_tcp_timestamp_stat.attr,
  989. &dev_attr_fnode_tcp_nagle_disable.attr,
  990. &dev_attr_fnode_tcp_wsf_disable.attr,
  991. &dev_attr_fnode_tcp_timer_scale.attr,
  992. &dev_attr_fnode_tcp_timestamp_enable.attr,
  993. &dev_attr_fnode_fragment_disable.attr,
  994. &dev_attr_fnode_max_recv_dlength.attr,
  995. &dev_attr_fnode_max_xmit_dlength.attr,
  996. &dev_attr_fnode_keepalive_tmo.attr,
  997. &dev_attr_fnode_port.attr,
  998. &dev_attr_fnode_ipaddress.attr,
  999. &dev_attr_fnode_redirect_ipaddr.attr,
  1000. &dev_attr_fnode_max_segment_size.attr,
  1001. &dev_attr_fnode_local_port.attr,
  1002. &dev_attr_fnode_ipv4_tos.attr,
  1003. &dev_attr_fnode_ipv6_traffic_class.attr,
  1004. &dev_attr_fnode_ipv6_flow_label.attr,
  1005. &dev_attr_fnode_link_local_ipv6.attr,
  1006. &dev_attr_fnode_tcp_xmit_wsf.attr,
  1007. &dev_attr_fnode_tcp_recv_wsf.attr,
  1008. &dev_attr_fnode_statsn.attr,
  1009. &dev_attr_fnode_exp_statsn.attr,
  1010. NULL,
  1011. };
  1012. static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj,
  1013. struct attribute *attr,
  1014. int i)
  1015. {
  1016. struct device *dev = container_of(kobj, struct device, kobj);
  1017. struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
  1018. struct iscsi_transport *t = fnode_conn->transport;
  1019. int param;
  1020. if (attr == &dev_attr_fnode_is_fw_assigned_ipv6.attr) {
  1021. param = ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6;
  1022. } else if (attr == &dev_attr_fnode_header_digest.attr) {
  1023. param = ISCSI_FLASHNODE_HDR_DGST_EN;
  1024. } else if (attr == &dev_attr_fnode_data_digest.attr) {
  1025. param = ISCSI_FLASHNODE_DATA_DGST_EN;
  1026. } else if (attr == &dev_attr_fnode_snack_req.attr) {
  1027. param = ISCSI_FLASHNODE_SNACK_REQ_EN;
  1028. } else if (attr == &dev_attr_fnode_tcp_timestamp_stat.attr) {
  1029. param = ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT;
  1030. } else if (attr == &dev_attr_fnode_tcp_nagle_disable.attr) {
  1031. param = ISCSI_FLASHNODE_TCP_NAGLE_DISABLE;
  1032. } else if (attr == &dev_attr_fnode_tcp_wsf_disable.attr) {
  1033. param = ISCSI_FLASHNODE_TCP_WSF_DISABLE;
  1034. } else if (attr == &dev_attr_fnode_tcp_timer_scale.attr) {
  1035. param = ISCSI_FLASHNODE_TCP_TIMER_SCALE;
  1036. } else if (attr == &dev_attr_fnode_tcp_timestamp_enable.attr) {
  1037. param = ISCSI_FLASHNODE_TCP_TIMESTAMP_EN;
  1038. } else if (attr == &dev_attr_fnode_fragment_disable.attr) {
  1039. param = ISCSI_FLASHNODE_IP_FRAG_DISABLE;
  1040. } else if (attr == &dev_attr_fnode_max_recv_dlength.attr) {
  1041. param = ISCSI_FLASHNODE_MAX_RECV_DLENGTH;
  1042. } else if (attr == &dev_attr_fnode_max_xmit_dlength.attr) {
  1043. param = ISCSI_FLASHNODE_MAX_XMIT_DLENGTH;
  1044. } else if (attr == &dev_attr_fnode_keepalive_tmo.attr) {
  1045. param = ISCSI_FLASHNODE_KEEPALIVE_TMO;
  1046. } else if (attr == &dev_attr_fnode_port.attr) {
  1047. param = ISCSI_FLASHNODE_PORT;
  1048. } else if (attr == &dev_attr_fnode_ipaddress.attr) {
  1049. param = ISCSI_FLASHNODE_IPADDR;
  1050. } else if (attr == &dev_attr_fnode_redirect_ipaddr.attr) {
  1051. param = ISCSI_FLASHNODE_REDIRECT_IPADDR;
  1052. } else if (attr == &dev_attr_fnode_max_segment_size.attr) {
  1053. param = ISCSI_FLASHNODE_MAX_SEGMENT_SIZE;
  1054. } else if (attr == &dev_attr_fnode_local_port.attr) {
  1055. param = ISCSI_FLASHNODE_LOCAL_PORT;
  1056. } else if (attr == &dev_attr_fnode_ipv4_tos.attr) {
  1057. param = ISCSI_FLASHNODE_IPV4_TOS;
  1058. } else if (attr == &dev_attr_fnode_ipv6_traffic_class.attr) {
  1059. param = ISCSI_FLASHNODE_IPV6_TC;
  1060. } else if (attr == &dev_attr_fnode_ipv6_flow_label.attr) {
  1061. param = ISCSI_FLASHNODE_IPV6_FLOW_LABEL;
  1062. } else if (attr == &dev_attr_fnode_link_local_ipv6.attr) {
  1063. param = ISCSI_FLASHNODE_LINK_LOCAL_IPV6;
  1064. } else if (attr == &dev_attr_fnode_tcp_xmit_wsf.attr) {
  1065. param = ISCSI_FLASHNODE_TCP_XMIT_WSF;
  1066. } else if (attr == &dev_attr_fnode_tcp_recv_wsf.attr) {
  1067. param = ISCSI_FLASHNODE_TCP_RECV_WSF;
  1068. } else if (attr == &dev_attr_fnode_statsn.attr) {
  1069. param = ISCSI_FLASHNODE_STATSN;
  1070. } else if (attr == &dev_attr_fnode_exp_statsn.attr) {
  1071. param = ISCSI_FLASHNODE_EXP_STATSN;
  1072. } else {
  1073. WARN_ONCE(1, "Invalid flashnode connection attr");
  1074. return 0;
  1075. }
  1076. return t->attr_is_visible(ISCSI_FLASHNODE_PARAM, param);
  1077. }
  1078. static struct attribute_group iscsi_flashnode_conn_attr_group = {
  1079. .attrs = iscsi_flashnode_conn_attrs,
  1080. .is_visible = iscsi_flashnode_conn_attr_is_visible,
  1081. };
  1082. static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = {
  1083. &iscsi_flashnode_conn_attr_group,
  1084. NULL,
  1085. };
  1086. static void iscsi_flashnode_conn_release(struct device *dev)
  1087. {
  1088. struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);
  1089. kfree(fnode_conn->ipaddress);
  1090. kfree(fnode_conn->redirect_ipaddr);
  1091. kfree(fnode_conn->link_local_ipv6_addr);
  1092. kfree(fnode_conn);
  1093. }
  1094. static struct device_type iscsi_flashnode_conn_dev_type = {
  1095. .name = "iscsi_flashnode_conn_dev_type",
  1096. .groups = iscsi_flashnode_conn_attr_groups,
  1097. .release = iscsi_flashnode_conn_release,
  1098. };
  1099. static struct bus_type iscsi_flashnode_bus;
  1100. int iscsi_flashnode_bus_match(struct device *dev,
  1101. struct device_driver *drv)
  1102. {
  1103. if (dev->bus == &iscsi_flashnode_bus)
  1104. return 1;
  1105. return 0;
  1106. }
  1107. EXPORT_SYMBOL_GPL(iscsi_flashnode_bus_match);
  1108. static struct bus_type iscsi_flashnode_bus = {
  1109. .name = "iscsi_flashnode",
  1110. .match = &iscsi_flashnode_bus_match,
  1111. };
  1112. /**
  1113. * iscsi_create_flashnode_sess - Add flashnode session entry in sysfs
  1114. * @shost: pointer to host data
  1115. * @index: index of flashnode to add in sysfs
  1116. * @transport: pointer to transport data
  1117. * @dd_size: total size to allocate
  1118. *
  1119. * Adds a sysfs entry for the flashnode session attributes
  1120. *
  1121. * Returns:
  1122. * pointer to allocated flashnode sess on success
  1123. * %NULL on failure
  1124. */
  1125. struct iscsi_bus_flash_session *
  1126. iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
  1127. struct iscsi_transport *transport,
  1128. int dd_size)
  1129. {
  1130. struct iscsi_bus_flash_session *fnode_sess;
  1131. int err;
  1132. fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL);
  1133. if (!fnode_sess)
  1134. return NULL;
  1135. fnode_sess->transport = transport;
  1136. fnode_sess->target_id = index;
  1137. fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type;
  1138. fnode_sess->dev.bus = &iscsi_flashnode_bus;
  1139. fnode_sess->dev.parent = &shost->shost_gendev;
  1140. dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u",
  1141. shost->host_no, index);
  1142. err = device_register(&fnode_sess->dev);
  1143. if (err)
  1144. goto free_fnode_sess;
  1145. if (dd_size)
  1146. fnode_sess->dd_data = &fnode_sess[1];
  1147. return fnode_sess;
  1148. free_fnode_sess:
  1149. kfree(fnode_sess);
  1150. return NULL;
  1151. }
  1152. EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess);
  1153. /**
  1154. * iscsi_create_flashnode_conn - Add flashnode conn entry in sysfs
  1155. * @shost: pointer to host data
  1156. * @fnode_sess: pointer to the parent flashnode session entry
  1157. * @transport: pointer to transport data
  1158. * @dd_size: total size to allocate
  1159. *
  1160. * Adds a sysfs entry for the flashnode connection attributes
  1161. *
  1162. * Returns:
  1163. * pointer to allocated flashnode conn on success
  1164. * %NULL on failure
  1165. */
  1166. struct iscsi_bus_flash_conn *
  1167. iscsi_create_flashnode_conn(struct Scsi_Host *shost,
  1168. struct iscsi_bus_flash_session *fnode_sess,
  1169. struct iscsi_transport *transport,
  1170. int dd_size)
  1171. {
  1172. struct iscsi_bus_flash_conn *fnode_conn;
  1173. int err;
  1174. fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL);
  1175. if (!fnode_conn)
  1176. return NULL;
  1177. fnode_conn->transport = transport;
  1178. fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type;
  1179. fnode_conn->dev.bus = &iscsi_flashnode_bus;
  1180. fnode_conn->dev.parent = &fnode_sess->dev;
  1181. dev_set_name(&fnode_conn->dev, "flashnode_conn-%u:%u:0",
  1182. shost->host_no, fnode_sess->target_id);
  1183. err = device_register(&fnode_conn->dev);
  1184. if (err)
  1185. goto free_fnode_conn;
  1186. if (dd_size)
  1187. fnode_conn->dd_data = &fnode_conn[1];
  1188. return fnode_conn;
  1189. free_fnode_conn:
  1190. kfree(fnode_conn);
  1191. return NULL;
  1192. }
  1193. EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
  1194. /**
  1195. * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn
  1196. * @dev: device to verify
  1197. * @data: pointer to data containing value to use for verification
  1198. *
  1199. * Verifies if the passed device is flashnode conn device
  1200. *
  1201. * Returns:
  1202. * 1 on success
  1203. * 0 on failure
  1204. */
  1205. static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
  1206. {
  1207. return dev->bus == &iscsi_flashnode_bus;
  1208. }
  1209. static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
  1210. {
  1211. device_unregister(&fnode_conn->dev);
  1212. return 0;
  1213. }
  1214. static int flashnode_match_index(struct device *dev, void *data)
  1215. {
  1216. struct iscsi_bus_flash_session *fnode_sess = NULL;
  1217. int ret = 0;
  1218. if (!iscsi_flashnode_bus_match(dev, NULL))
  1219. goto exit_match_index;
  1220. fnode_sess = iscsi_dev_to_flash_session(dev);
  1221. ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
  1222. exit_match_index:
  1223. return ret;
  1224. }
  1225. /**
  1226. * iscsi_get_flashnode_by_index -finds flashnode session entry by index
  1227. * @shost: pointer to host data
  1228. * @idx: index to match
  1229. *
  1230. * Finds the flashnode session object for the passed index
  1231. *
  1232. * Returns:
  1233. * pointer to found flashnode session object on success
  1234. * %NULL on failure
  1235. */
  1236. static struct iscsi_bus_flash_session *
  1237. iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
  1238. {
  1239. struct iscsi_bus_flash_session *fnode_sess = NULL;
  1240. struct device *dev;
  1241. dev = device_find_child(&shost->shost_gendev, &idx,
  1242. flashnode_match_index);
  1243. if (dev)
  1244. fnode_sess = iscsi_dev_to_flash_session(dev);
  1245. return fnode_sess;
  1246. }
  1247. /**
  1248. * iscsi_find_flashnode_sess - finds flashnode session entry
  1249. * @shost: pointer to host data
  1250. * @data: pointer to data containing value to use for comparison
  1251. * @fn: function pointer that does actual comparison
  1252. *
  1253. * Finds the flashnode session object comparing the data passed using logic
  1254. * defined in passed function pointer
  1255. *
  1256. * Returns:
  1257. * pointer to found flashnode session device object on success
  1258. * %NULL on failure
  1259. */
  1260. struct device *
  1261. iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
  1262. int (*fn)(struct device *dev, void *data))
  1263. {
  1264. return device_find_child(&shost->shost_gendev, data, fn);
  1265. }
  1266. EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
  1267. /**
  1268. * iscsi_find_flashnode_conn - finds flashnode connection entry
  1269. * @fnode_sess: pointer to parent flashnode session entry
  1270. *
  1271. * Finds the flashnode connection object comparing the data passed using logic
  1272. * defined in passed function pointer
  1273. *
  1274. * Returns:
  1275. * pointer to found flashnode connection device object on success
  1276. * %NULL on failure
  1277. */
  1278. struct device *
  1279. iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
  1280. {
  1281. return device_find_child(&fnode_sess->dev, NULL,
  1282. iscsi_is_flashnode_conn_dev);
  1283. }
  1284. EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);
  1285. static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data)
  1286. {
  1287. if (!iscsi_is_flashnode_conn_dev(dev, NULL))
  1288. return 0;
  1289. return iscsi_destroy_flashnode_conn(iscsi_dev_to_flash_conn(dev));
  1290. }
  1291. /**
  1292. * iscsi_destroy_flashnode_sess - destroy flashnode session entry
  1293. * @fnode_sess: pointer to flashnode session entry to be destroyed
  1294. *
  1295. * Deletes the flashnode session entry and all children flashnode connection
  1296. * entries from sysfs
  1297. */
  1298. void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess)
  1299. {
  1300. int err;
  1301. err = device_for_each_child(&fnode_sess->dev, NULL,
  1302. iscsi_iter_destroy_flashnode_conn_fn);
  1303. if (err)
  1304. pr_err("Could not delete all connections for %s. Error %d.\n",
  1305. fnode_sess->dev.kobj.name, err);
  1306. device_unregister(&fnode_sess->dev);
  1307. }
  1308. EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);
  1309. static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data)
  1310. {
  1311. if (!iscsi_flashnode_bus_match(dev, NULL))
  1312. return 0;
  1313. iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev));
  1314. return 0;
  1315. }
  1316. /**
  1317. * iscsi_destroy_all_flashnode - destroy all flashnode session entries
  1318. * @shost: pointer to host data
  1319. *
  1320. * Destroys all the flashnode session entries and all corresponding children
  1321. * flashnode connection entries from sysfs
  1322. */
  1323. void iscsi_destroy_all_flashnode(struct Scsi_Host *shost)
  1324. {
  1325. device_for_each_child(&shost->shost_gendev, NULL,
  1326. iscsi_iter_destroy_flashnode_fn);
  1327. }
  1328. EXPORT_SYMBOL_GPL(iscsi_destroy_all_flashnode);
  1329. /*
  1330. * BSG support
  1331. */
  1332. /**
  1333. * iscsi_bsg_host_dispatch - Dispatch command to LLD.
  1334. * @job: bsg job to be processed
  1335. */
  1336. static int iscsi_bsg_host_dispatch(struct bsg_job *job)
  1337. {
  1338. struct Scsi_Host *shost = iscsi_job_to_shost(job);
  1339. struct iscsi_bsg_request *req = job->request;
  1340. struct iscsi_bsg_reply *reply = job->reply;
  1341. struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
  1342. int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
  1343. int ret;
  1344. /* check if we have the msgcode value at least */
  1345. if (job->request_len < sizeof(uint32_t)) {
  1346. ret = -ENOMSG;
  1347. goto fail_host_msg;
  1348. }
  1349. /* Validate the host command */
  1350. switch (req->msgcode) {
  1351. case ISCSI_BSG_HST_VENDOR:
  1352. cmdlen += sizeof(struct iscsi_bsg_host_vendor);
  1353. if ((shost->hostt->vendor_id == 0L) ||
  1354. (req->rqst_data.h_vendor.vendor_id !=
  1355. shost->hostt->vendor_id)) {
  1356. ret = -ESRCH;
  1357. goto fail_host_msg;
  1358. }
  1359. break;
  1360. default:
  1361. ret = -EBADR;
  1362. goto fail_host_msg;
  1363. }
  1364. /* check if we really have all the request data needed */
  1365. if (job->request_len < cmdlen) {
  1366. ret = -ENOMSG;
  1367. goto fail_host_msg;
  1368. }
  1369. ret = i->iscsi_transport->bsg_request(job);
  1370. if (!ret)
  1371. return 0;
  1372. fail_host_msg:
  1373. /* return the errno failure code as the only status */
  1374. BUG_ON(job->reply_len < sizeof(uint32_t));
  1375. reply->reply_payload_rcv_len = 0;
  1376. reply->result = ret;
  1377. job->reply_len = sizeof(uint32_t);
  1378. bsg_job_done(job, ret, 0);
  1379. return 0;
  1380. }
  1381. /**
  1382. * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
  1383. * @shost: shost for iscsi_host
  1384. * @ihost: iscsi_cls_host adding the structures to
  1385. */
  1386. static int
  1387. iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
  1388. {
  1389. struct device *dev = &shost->shost_gendev;
  1390. struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
  1391. struct request_queue *q;
  1392. char bsg_name[20];
  1393. int ret;
  1394. if (!i->iscsi_transport->bsg_request)
  1395. return -ENOTSUPP;
  1396. snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
  1397. q = __scsi_alloc_queue(shost, bsg_request_fn);
  1398. if (!q)
  1399. return -ENOMEM;
  1400. ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0);
  1401. if (ret) {
  1402. shost_printk(KERN_ERR, shost, "bsg interface failed to "
  1403. "initialize - no request queue\n");
  1404. blk_cleanup_queue(q);
  1405. return ret;
  1406. }
  1407. ihost->bsg_q = q;
  1408. return 0;
  1409. }
  1410. static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
  1411. struct device *cdev)
  1412. {
  1413. struct Scsi_Host *shost = dev_to_shost(dev);
  1414. struct iscsi_cls_host *ihost = shost->shost_data;
  1415. memset(ihost, 0, sizeof(*ihost));
  1416. atomic_set(&ihost->nr_scans, 0);
  1417. mutex_init(&ihost->mutex);
  1418. iscsi_bsg_host_add(shost, ihost);
  1419. /* ignore any bsg add error - we just can't do sgio */
  1420. return 0;
  1421. }
  1422. static int iscsi_remove_host(struct transport_container *tc,
  1423. struct device *dev, struct device *cdev)
  1424. {
  1425. struct Scsi_Host *shost = dev_to_shost(dev);
  1426. struct iscsi_cls_host *ihost = shost->shost_data;
  1427. if (ihost->bsg_q) {
  1428. bsg_unregister_queue(ihost->bsg_q);
  1429. blk_cleanup_queue(ihost->bsg_q);
  1430. }
  1431. return 0;
  1432. }
  1433. static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
  1434. "iscsi_host",
  1435. iscsi_setup_host,
  1436. iscsi_remove_host,
  1437. NULL);
  1438. static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
  1439. "iscsi_session",
  1440. NULL,
  1441. NULL,
  1442. NULL);
  1443. static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
  1444. "iscsi_connection",
  1445. NULL,
  1446. NULL,
  1447. NULL);
  1448. static struct sock *nls;
  1449. static DEFINE_MUTEX(rx_queue_mutex);
  1450. static LIST_HEAD(sesslist);
  1451. static DEFINE_SPINLOCK(sesslock);
  1452. static LIST_HEAD(connlist);
  1453. static DEFINE_SPINLOCK(connlock);
  1454. static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
  1455. {
  1456. struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
  1457. return sess->sid;
  1458. }
  1459. /*
  1460. * Returns the matching session to a given sid
  1461. */
  1462. static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
  1463. {
  1464. unsigned long flags;
  1465. struct iscsi_cls_session *sess;
  1466. spin_lock_irqsave(&sesslock, flags);
  1467. list_for_each_entry(sess, &sesslist, sess_list) {
  1468. if (sess->sid == sid) {
  1469. spin_unlock_irqrestore(&sesslock, flags);
  1470. return sess;
  1471. }
  1472. }
  1473. spin_unlock_irqrestore(&sesslock, flags);
  1474. return NULL;
  1475. }
  1476. /*
  1477. * Returns the matching connection to a given sid / cid tuple
  1478. */
  1479. static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
  1480. {
  1481. unsigned long flags;
  1482. struct iscsi_cls_conn *conn;
  1483. spin_lock_irqsave(&connlock, flags);
  1484. list_for_each_entry(conn, &connlist, conn_list) {
  1485. if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
  1486. spin_unlock_irqrestore(&connlock, flags);
  1487. return conn;
  1488. }
  1489. }
  1490. spin_unlock_irqrestore(&connlock, flags);
  1491. return NULL;
  1492. }
  1493. /*
  1494. * The following functions can be used by LLDs that allocate
  1495. * their own scsi_hosts or by software iscsi LLDs
  1496. */
  1497. static struct {
  1498. int value;
  1499. char *name;
  1500. } iscsi_session_state_names[] = {
  1501. { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
  1502. { ISCSI_SESSION_FAILED, "FAILED" },
  1503. { ISCSI_SESSION_FREE, "FREE" },
  1504. };
  1505. static const char *iscsi_session_state_name(int state)
  1506. {
  1507. int i;
  1508. char *name = NULL;
  1509. for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
  1510. if (iscsi_session_state_names[i].value == state) {
  1511. name = iscsi_session_state_names[i].name;
  1512. break;
  1513. }
  1514. }
  1515. return name;
  1516. }
  1517. int iscsi_session_chkready(struct iscsi_cls_session *session)
  1518. {
  1519. unsigned long flags;
  1520. int err;
  1521. spin_lock_irqsave(&session->lock, flags);
  1522. switch (session->state) {
  1523. case ISCSI_SESSION_LOGGED_IN:
  1524. err = 0;
  1525. break;
  1526. case ISCSI_SESSION_FAILED:
  1527. err = DID_IMM_RETRY << 16;
  1528. break;
  1529. case ISCSI_SESSION_FREE:
  1530. err = DID_TRANSPORT_FAILFAST << 16;
  1531. break;
  1532. default:
  1533. err = DID_NO_CONNECT << 16;
  1534. break;
  1535. }
  1536. spin_unlock_irqrestore(&session->lock, flags);
  1537. return err;
  1538. }
  1539. EXPORT_SYMBOL_GPL(iscsi_session_chkready);
  1540. int iscsi_is_session_online(struct iscsi_cls_session *session)
  1541. {
  1542. unsigned long flags;
  1543. int ret = 0;
  1544. spin_lock_irqsave(&session->lock, flags);
  1545. if (session->state == ISCSI_SESSION_LOGGED_IN)
  1546. ret = 1;
  1547. spin_unlock_irqrestore(&session->lock, flags);
  1548. return ret;
  1549. }
  1550. EXPORT_SYMBOL_GPL(iscsi_is_session_online);
  1551. static void iscsi_session_release(struct device *dev)
  1552. {
  1553. struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
  1554. struct Scsi_Host *shost;
  1555. shost = iscsi_session_to_shost(session);
  1556. scsi_host_put(shost);
  1557. ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n");
  1558. kfree(session);
  1559. }
  1560. int iscsi_is_session_dev(const struct device *dev)
  1561. {
  1562. return dev->release == iscsi_session_release;
  1563. }
  1564. EXPORT_SYMBOL_GPL(iscsi_is_session_dev);
  1565. static int iscsi_iter_session_fn(struct device *dev, void *data)
  1566. {
  1567. void (* fn) (struct iscsi_cls_session *) = data;
  1568. if (!iscsi_is_session_dev(dev))
  1569. return 0;
  1570. fn(iscsi_dev_to_session(dev));
  1571. return 0;
  1572. }
  1573. void iscsi_host_for_each_session(struct Scsi_Host *shost,
  1574. void (*fn)(struct iscsi_cls_session *))
  1575. {
  1576. device_for_each_child(&shost->shost_gendev, fn,
  1577. iscsi_iter_session_fn);
  1578. }
  1579. EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
  1580. /**
  1581. * iscsi_scan_finished - helper to report when running scans are done
  1582. * @shost: scsi host
  1583. * @time: scan run time
  1584. *
  1585. * This function can be used by drives like qla4xxx to report to the scsi
  1586. * layer when the scans it kicked off at module load time are done.
  1587. */
  1588. int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1589. {
  1590. struct iscsi_cls_host *ihost = shost->shost_data;
  1591. /*
  1592. * qla4xxx will have kicked off some session unblocks before calling
  1593. * scsi_scan_host, so just wait for them to complete.
  1594. */
  1595. return !atomic_read(&ihost->nr_scans);
  1596. }
  1597. EXPORT_SYMBOL_GPL(iscsi_scan_finished);
  1598. struct iscsi_scan_data {
  1599. unsigned int channel;
  1600. unsigned int id;
  1601. u64 lun;
  1602. enum scsi_scan_mode rescan;
  1603. };
  1604. static int iscsi_user_scan_session(struct device *dev, void *data)
  1605. {
  1606. struct iscsi_scan_data *scan_data = data;
  1607. struct iscsi_cls_session *session;
  1608. struct Scsi_Host *shost;
  1609. struct iscsi_cls_host *ihost;
  1610. unsigned long flags;
  1611. unsigned int id;
  1612. if (!iscsi_is_session_dev(dev))
  1613. return 0;
  1614. session = iscsi_dev_to_session(dev);
  1615. ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n");
  1616. shost = iscsi_session_to_shost(session);
  1617. ihost = shost->shost_data;
  1618. mutex_lock(&ihost->mutex);
  1619. spin_lock_irqsave(&session->lock, flags);
  1620. if (session->state != ISCSI_SESSION_LOGGED_IN) {
  1621. spin_unlock_irqrestore(&session->lock, flags);
  1622. goto user_scan_exit;
  1623. }
  1624. id = session->target_id;
  1625. spin_unlock_irqrestore(&session->lock, flags);
  1626. if (id != ISCSI_MAX_TARGET) {
  1627. if ((scan_data->channel == SCAN_WILD_CARD ||
  1628. scan_data->channel == 0) &&
  1629. (scan_data->id == SCAN_WILD_CARD ||
  1630. scan_data->id == id))
  1631. scsi_scan_target(&session->dev, 0, id,
  1632. scan_data->lun, scan_data->rescan);
  1633. }
  1634. user_scan_exit:
  1635. mutex_unlock(&ihost->mutex);
  1636. ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n");
  1637. return 0;
  1638. }
  1639. static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
  1640. uint id, u64 lun)
  1641. {
  1642. struct iscsi_scan_data scan_data;
  1643. scan_data.channel = channel;
  1644. scan_data.id = id;
  1645. scan_data.lun = lun;
  1646. scan_data.rescan = SCSI_SCAN_MANUAL;
  1647. return device_for_each_child(&shost->shost_gendev, &scan_data,
  1648. iscsi_user_scan_session);
  1649. }
  1650. static void iscsi_scan_session(struct work_struct *work)
  1651. {
  1652. struct iscsi_cls_session *session =
  1653. container_of(work, struct iscsi_cls_session, scan_work);
  1654. struct Scsi_Host *shost = iscsi_session_to_shost(session);
  1655. struct iscsi_cls_host *ihost = shost->shost_data;
  1656. struct iscsi_scan_data scan_data;
  1657. scan_data.channel = 0;
  1658. scan_data.id = SCAN_WILD_CARD;
  1659. scan_data.lun = SCAN_WILD_CARD;
  1660. scan_data.rescan = SCSI_SCAN_RESCAN;
  1661. iscsi_user_scan_session(&session->dev, &scan_data);
  1662. atomic_dec(&ihost->nr_scans);
  1663. }
  1664. /**
  1665. * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
  1666. * @cmd: scsi cmd passed to scsi eh handler
  1667. *
  1668. * If the session is down this function will wait for the recovery
  1669. * timer to fire or for the session to be logged back in. If the
  1670. * recovery timer fires then FAST_IO_FAIL is returned. The caller
  1671. * should pass this error value to the scsi eh.
  1672. */
  1673. int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
  1674. {
  1675. struct iscsi_cls_session *session =
  1676. starget_to_session(scsi_target(cmd->device));
  1677. unsigned long flags;
  1678. int ret = 0;
  1679. spin_lock_irqsave(&session->lock, flags);
  1680. while (session->state != ISCSI_SESSION_LOGGED_IN) {
  1681. if (session->state == ISCSI_SESSION_FREE) {
  1682. ret = FAST_IO_FAIL;
  1683. break;
  1684. }
  1685. spin_unlock_irqrestore(&session->lock, flags);
  1686. msleep(1000);
  1687. spin_lock_irqsave(&session->lock, flags);
  1688. }
  1689. spin_unlock_irqrestore(&session->lock, flags);
  1690. return ret;
  1691. }
  1692. EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
  1693. static void session_recovery_timedout(struct work_struct *work)
  1694. {
  1695. struct iscsi_cls_session *session =
  1696. container_of(work, struct iscsi_cls_session,
  1697. recovery_work.work);
  1698. unsigned long flags;
  1699. iscsi_cls_session_printk(KERN_INFO, session,
  1700. "session recovery timed out after %d secs\n",
  1701. session->recovery_tmo);
  1702. spin_lock_irqsave(&session->lock, flags);
  1703. switch (session->state) {
  1704. case ISCSI_SESSION_FAILED:
  1705. session->state = ISCSI_SESSION_FREE;
  1706. break;
  1707. case ISCSI_SESSION_LOGGED_IN:
  1708. case ISCSI_SESSION_FREE:
  1709. /* we raced with the unblock's flush */
  1710. spin_unlock_irqrestore(&session->lock, flags);
  1711. return;
  1712. }
  1713. spin_unlock_irqrestore(&session->lock, flags);
  1714. if (session->transport->session_recovery_timedout)
  1715. session->transport->session_recovery_timedout(session);
  1716. ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n");
  1717. scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
  1718. ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n");
  1719. }
  1720. static void __iscsi_unblock_session(struct work_struct *work)
  1721. {
  1722. struct iscsi_cls_session *session =
  1723. container_of(work, struct iscsi_cls_session,
  1724. unblock_work);
  1725. struct Scsi_Host *shost = iscsi_session_to_shost(session);
  1726. struct iscsi_cls_host *ihost = shost->shost_data;
  1727. unsigned long flags;
  1728. ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n");
  1729. /*
  1730. * The recovery and unblock work get run from the same workqueue,
  1731. * so try to cancel it if it was going to run after this unblock.
  1732. */
  1733. cancel_delayed_work(&session->recovery_work);
  1734. spin_lock_irqsave(&session->lock, flags);
  1735. session->state = ISCSI_SESSION_LOGGED_IN;
  1736. spin_unlock_irqrestore(&session->lock, flags);
  1737. /* start IO */
  1738. scsi_target_unblock(&session->dev, SDEV_RUNNING);
  1739. /*
  1740. * Only do kernel scanning if the driver is properly hooked into
  1741. * the async scanning code (drivers like iscsi_tcp do login and
  1742. * scanning from userspace).
  1743. */
  1744. if (shost->hostt->scan_finished) {
  1745. if (scsi_queue_work(shost, &session->scan_work))
  1746. atomic_inc(&ihost->nr_scans);
  1747. }
  1748. ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n");
  1749. }
  1750. /**
  1751. * iscsi_unblock_session - set a session as logged in and start IO.
  1752. * @session: iscsi session
  1753. *
  1754. * Mark a session as ready to accept IO.
  1755. */
  1756. void iscsi_unblock_session(struct iscsi_cls_session *session)
  1757. {
  1758. queue_work(iscsi_eh_timer_workq, &session->unblock_work);
  1759. /*
  1760. * make sure all the events have completed before tell the driver
  1761. * it is safe
  1762. */
  1763. flush_workqueue(iscsi_eh_timer_workq);
  1764. }
  1765. EXPORT_SYMBOL_GPL(iscsi_unblock_session);
  1766. static void __iscsi_block_session(struct work_struct *work)
  1767. {
  1768. struct iscsi_cls_session *session =
  1769. container_of(work, struct iscsi_cls_session,
  1770. block_work);
  1771. unsigned long flags;
  1772. ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n");
  1773. spin_lock_irqsave(&session->lock, flags);
  1774. session->state = ISCSI_SESSION_FAILED;
  1775. spin_unlock_irqrestore(&session->lock, flags);
  1776. scsi_target_block(&session->dev);
  1777. ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n");
  1778. if (session->recovery_tmo >= 0)
  1779. queue_delayed_work(iscsi_eh_timer_workq,
  1780. &session->recovery_work,
  1781. session->recovery_tmo * HZ);
  1782. }
  1783. void iscsi_block_session(struct iscsi_cls_session *session)
  1784. {
  1785. queue_work(iscsi_eh_timer_workq, &session->block_work);
  1786. }
  1787. EXPORT_SYMBOL_GPL(iscsi_block_session);
  1788. static void __iscsi_unbind_session(struct work_struct *work)
  1789. {
  1790. struct iscsi_cls_session *session =
  1791. container_of(work, struct iscsi_cls_session,
  1792. unbind_work);
  1793. struct Scsi_Host *shost = iscsi_session_to_shost(session);
  1794. struct iscsi_cls_host *ihost = shost->shost_data;
  1795. unsigned long flags;
  1796. unsigned int target_id;
  1797. ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n");
  1798. /* Prevent new scans and make sure scanning is not in progress */
  1799. mutex_lock(&ihost->mutex);
  1800. spin_lock_irqsave(&session->lock, flags);
  1801. if (session->target_id == ISCSI_MAX_TARGET) {
  1802. spin_unlock_irqrestore(&session->lock, flags);
  1803. mutex_unlock(&ihost->mutex);
  1804. return;
  1805. }
  1806. target_id = session->target_id;
  1807. session->target_id = ISCSI_MAX_TARGET;
  1808. spin_unlock_irqrestore(&session->lock, flags);
  1809. mutex_unlock(&ihost->mutex);
  1810. if (session->ida_used)
  1811. ida_simple_remove(&iscsi_sess_ida, target_id);
  1812. scsi_remove_target(&session->dev);
  1813. iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
  1814. ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
  1815. }
  1816. struct iscsi_cls_session *
  1817. iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
  1818. int dd_size)
  1819. {
  1820. struct iscsi_cls_session *session;
  1821. session = kzalloc(sizeof(*session) + dd_size,
  1822. GFP_KERNEL);
  1823. if (!session)
  1824. return NULL;
  1825. session->transport = transport;
  1826. session->creator = -1;
  1827. session->recovery_tmo = 120;
  1828. session->recovery_tmo_sysfs_override = false;
  1829. session->state = ISCSI_SESSION_FREE;
  1830. INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
  1831. INIT_LIST_HEAD(&session->sess_list);
  1832. INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
  1833. INIT_WORK(&session->block_work, __iscsi_block_session);
  1834. INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
  1835. INIT_WORK(&session->scan_work, iscsi_scan_session);
  1836. spin_lock_init(&session->lock);
  1837. /* this is released in the dev's release function */
  1838. scsi_host_get(shost);
  1839. session->dev.parent = &shost->shost_gendev;
  1840. session->dev.release = iscsi_session_release;
  1841. device_initialize(&session->dev);
  1842. if (dd_size)
  1843. session->dd_data = &session[1];
  1844. ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n");
  1845. return session;
  1846. }
  1847. EXPORT_SYMBOL_GPL(iscsi_alloc_session);
  1848. int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
  1849. {
  1850. unsigned long flags;
  1851. int id = 0;
  1852. int err;
  1853. session->sid = atomic_add_return(1, &iscsi_session_nr);
  1854. if (target_id == ISCSI_MAX_TARGET) {
  1855. id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
  1856. if (id < 0) {
  1857. iscsi_cls_session_printk(KERN_ERR, session,
  1858. "Failure in Target ID Allocation\n");
  1859. return id;
  1860. }
  1861. session->target_id = (unsigned int)id;
  1862. session->ida_used = true;
  1863. } else
  1864. session->target_id = target_id;
  1865. dev_set_name(&session->dev, "session%u", session->sid);
  1866. err = device_add(&session->dev);
  1867. if (err) {
  1868. iscsi_cls_session_printk(KERN_ERR, session,
  1869. "could not register session's dev\n");
  1870. goto release_ida;
  1871. }
  1872. transport_register_device(&session->dev);
  1873. spin_lock_irqsave(&sesslock, flags);
  1874. list_add(&session->sess_list, &sesslist);
  1875. spin_unlock_irqrestore(&sesslock, flags);
  1876. iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
  1877. ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n");
  1878. return 0;
  1879. release_ida:
  1880. if (session->ida_used)
  1881. ida_simple_remove(&iscsi_sess_ida, session->target_id);
  1882. return err;
  1883. }
  1884. EXPORT_SYMBOL_GPL(iscsi_add_session);
  1885. /**
  1886. * iscsi_create_session - create iscsi class session
  1887. * @shost: scsi host
  1888. * @transport: iscsi transport
  1889. * @dd_size: private driver data size
  1890. * @target_id: which target
  1891. *
  1892. * This can be called from a LLD or iscsi_transport.
  1893. */
  1894. struct iscsi_cls_session *
  1895. iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
  1896. int dd_size, unsigned int target_id)
  1897. {
  1898. struct iscsi_cls_session *session;
  1899. session = iscsi_alloc_session(shost, transport, dd_size);
  1900. if (!session)
  1901. return NULL;
  1902. if (iscsi_add_session(session, target_id)) {
  1903. iscsi_free_session(session);
  1904. return NULL;
  1905. }
  1906. return session;
  1907. }
  1908. EXPORT_SYMBOL_GPL(iscsi_create_session);
  1909. static void iscsi_conn_release(struct device *dev)
  1910. {
  1911. struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
  1912. struct device *parent = conn->dev.parent;
  1913. ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n");
  1914. kfree(conn);
  1915. put_device(parent);
  1916. }
  1917. static int iscsi_is_conn_dev(const struct device *dev)
  1918. {
  1919. return dev->release == iscsi_conn_release;
  1920. }
  1921. static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
  1922. {
  1923. if (!iscsi_is_conn_dev(dev))
  1924. return 0;
  1925. return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
  1926. }
  1927. void iscsi_remove_session(struct iscsi_cls_session *session)
  1928. {
  1929. struct Scsi_Host *shost = iscsi_session_to_shost(session);
  1930. unsigned long flags;
  1931. int err;
  1932. ISCSI_DBG_TRANS_SESSION(session, "Removing session\n");
  1933. spin_lock_irqsave(&sesslock, flags);
  1934. list_del(&session->sess_list);
  1935. spin_unlock_irqrestore(&sesslock, flags);
  1936. /* make sure there are no blocks/unblocks queued */
  1937. flush_workqueue(iscsi_eh_timer_workq);
  1938. /* make sure the timedout callout is not running */
  1939. if (!cancel_delayed_work(&session->recovery_work))
  1940. flush_workqueue(iscsi_eh_timer_workq);
  1941. /*
  1942. * If we are blocked let commands flow again. The lld or iscsi
  1943. * layer should set up the queuecommand to fail commands.
  1944. * We assume that LLD will not be calling block/unblock while
  1945. * removing the session.
  1946. */
  1947. spin_lock_irqsave(&session->lock, flags);
  1948. session->state = ISCSI_SESSION_FREE;
  1949. spin_unlock_irqrestore(&session->lock, flags);
  1950. scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
  1951. /* flush running scans then delete devices */
  1952. scsi_flush_work(shost);
  1953. __iscsi_unbind_session(&session->unbind_work);
  1954. /* hw iscsi may not have removed all connections from session */
  1955. err = device_for_each_child(&session->dev, NULL,
  1956. iscsi_iter_destroy_conn_fn);
  1957. if (err)
  1958. iscsi_cls_session_printk(KERN_ERR, session,
  1959. "Could not delete all connections "
  1960. "for session. Error %d.\n", err);
  1961. transport_unregister_device(&session->dev);
  1962. ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n");
  1963. device_del(&session->dev);
  1964. }
  1965. EXPORT_SYMBOL_GPL(iscsi_remove_session);
  1966. void iscsi_free_session(struct iscsi_cls_session *session)
  1967. {
  1968. ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n");
  1969. iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
  1970. put_device(&session->dev);
  1971. }
  1972. EXPORT_SYMBOL_GPL(iscsi_free_session);
  1973. /**
  1974. * iscsi_destroy_session - destroy iscsi session
  1975. * @session: iscsi_session
  1976. *
  1977. * Can be called by a LLD or iscsi_transport. There must not be
  1978. * any running connections.
  1979. */
  1980. int iscsi_destroy_session(struct iscsi_cls_session *session)
  1981. {
  1982. iscsi_remove_session(session);
  1983. ISCSI_DBG_TRANS_SESSION(session, "Completing session destruction\n");
  1984. iscsi_free_session(session);
  1985. return 0;
  1986. }
  1987. EXPORT_SYMBOL_GPL(iscsi_destroy_session);
  1988. /**
  1989. * iscsi_create_conn - create iscsi class connection
  1990. * @session: iscsi cls session
  1991. * @dd_size: private driver data size
  1992. * @cid: connection id
  1993. *
  1994. * This can be called from a LLD or iscsi_transport. The connection
  1995. * is child of the session so cid must be unique for all connections
  1996. * on the session.
  1997. *
  1998. * Since we do not support MCS, cid will normally be zero. In some cases
  1999. * for software iscsi we could be trying to preallocate a connection struct
  2000. * in which case there could be two connection structs and cid would be
  2001. * non-zero.
  2002. */
  2003. struct iscsi_cls_conn *
  2004. iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
  2005. {
  2006. struct iscsi_transport *transport = session->transport;
  2007. struct iscsi_cls_conn *conn;
  2008. unsigned long flags;
  2009. int err;
  2010. conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
  2011. if (!conn)
  2012. return NULL;
  2013. if (dd_size)
  2014. conn->dd_data = &conn[1];
  2015. mutex_init(&conn->ep_mutex);
  2016. INIT_LIST_HEAD(&conn->conn_list);
  2017. conn->transport = transport;
  2018. conn->cid = cid;
  2019. /* this is released in the dev's release function */
  2020. if (!get_device(&session->dev))
  2021. goto free_conn;
  2022. dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
  2023. conn->dev.parent = &session->dev;
  2024. conn->dev.release = iscsi_conn_release;
  2025. err = device_register(&conn->dev);
  2026. if (err) {
  2027. iscsi_cls_session_printk(KERN_ERR, session, "could not "
  2028. "register connection's dev\n");
  2029. goto release_parent_ref;
  2030. }
  2031. transport_register_device(&conn->dev);
  2032. spin_lock_irqsave(&connlock, flags);
  2033. list_add(&conn->conn_list, &connlist);
  2034. spin_unlock_irqrestore(&connlock, flags);
  2035. ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
  2036. return conn;
  2037. release_parent_ref:
  2038. put_device(&session->dev);
  2039. free_conn:
  2040. kfree(conn);
  2041. return NULL;
  2042. }
  2043. EXPORT_SYMBOL_GPL(iscsi_create_conn);
  2044. /**
  2045. * iscsi_destroy_conn - destroy iscsi class connection
  2046. * @conn: iscsi cls session
  2047. *
  2048. * This can be called from a LLD or iscsi_transport.
  2049. */
  2050. int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
  2051. {
  2052. unsigned long flags;
  2053. spin_lock_irqsave(&connlock, flags);
  2054. list_del(&conn->conn_list);
  2055. spin_unlock_irqrestore(&connlock, flags);
  2056. transport_unregister_device(&conn->dev);
  2057. ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n");
  2058. device_unregister(&conn->dev);
  2059. return 0;
  2060. }
  2061. EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
  2062. /*
  2063. * iscsi interface functions
  2064. */
  2065. static struct iscsi_internal *
  2066. iscsi_if_transport_lookup(struct iscsi_transport *tt)
  2067. {
  2068. struct iscsi_internal *priv;
  2069. unsigned long flags;
  2070. spin_lock_irqsave(&iscsi_transport_lock, flags);
  2071. list_for_each_entry(priv, &iscsi_transports, list) {
  2072. if (tt == priv->iscsi_transport) {
  2073. spin_unlock_irqrestore(&iscsi_transport_lock, flags);
  2074. return priv;
  2075. }
  2076. }
  2077. spin_unlock_irqrestore(&iscsi_transport_lock, flags);
  2078. return NULL;
  2079. }
  2080. static int
  2081. iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp)
  2082. {
  2083. return nlmsg_multicast(nls, skb, 0, group, gfp);
  2084. }
  2085. int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  2086. char *data, uint32_t data_size)
  2087. {
  2088. struct nlmsghdr *nlh;
  2089. struct sk_buff *skb;
  2090. struct iscsi_uevent *ev;
  2091. char *pdu;
  2092. struct iscsi_internal *priv;
  2093. int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
  2094. data_size);
  2095. priv = iscsi_if_transport_lookup(conn->transport);
  2096. if (!priv)
  2097. return -EINVAL;
  2098. skb = alloc_skb(len, GFP_ATOMIC);
  2099. if (!skb) {
  2100. iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
  2101. iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
  2102. "control PDU: OOM\n");
  2103. return -ENOMEM;
  2104. }
  2105. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2106. ev = nlmsg_data(nlh);
  2107. memset(ev, 0, sizeof(*ev));
  2108. ev->transport_handle = iscsi_handle(conn->transport);
  2109. ev->type = ISCSI_KEVENT_RECV_PDU;
  2110. ev->r.recv_req.cid = conn->cid;
  2111. ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
  2112. pdu = (char*)ev + sizeof(*ev);
  2113. memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
  2114. memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
  2115. return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
  2116. }
  2117. EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
  2118. int iscsi_offload_mesg(struct Scsi_Host *shost,
  2119. struct iscsi_transport *transport, uint32_t type,
  2120. char *data, uint16_t data_size)
  2121. {
  2122. struct nlmsghdr *nlh;
  2123. struct sk_buff *skb;
  2124. struct iscsi_uevent *ev;
  2125. int len = nlmsg_total_size(sizeof(*ev) + data_size);
  2126. skb = alloc_skb(len, GFP_ATOMIC);
  2127. if (!skb) {
  2128. printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
  2129. return -ENOMEM;
  2130. }
  2131. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2132. ev = nlmsg_data(nlh);
  2133. memset(ev, 0, sizeof(*ev));
  2134. ev->type = type;
  2135. ev->transport_handle = iscsi_handle(transport);
  2136. switch (type) {
  2137. case ISCSI_KEVENT_PATH_REQ:
  2138. ev->r.req_path.host_no = shost->host_no;
  2139. break;
  2140. case ISCSI_KEVENT_IF_DOWN:
  2141. ev->r.notify_if_down.host_no = shost->host_no;
  2142. break;
  2143. }
  2144. memcpy((char *)ev + sizeof(*ev), data, data_size);
  2145. return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
  2146. }
  2147. EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
  2148. void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
  2149. {
  2150. struct nlmsghdr *nlh;
  2151. struct sk_buff *skb;
  2152. struct iscsi_uevent *ev;
  2153. struct iscsi_internal *priv;
  2154. int len = nlmsg_total_size(sizeof(*ev));
  2155. priv = iscsi_if_transport_lookup(conn->transport);
  2156. if (!priv)
  2157. return;
  2158. skb = alloc_skb(len, GFP_ATOMIC);
  2159. if (!skb) {
  2160. iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
  2161. "conn error (%d)\n", error);
  2162. return;
  2163. }
  2164. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2165. ev = nlmsg_data(nlh);
  2166. ev->transport_handle = iscsi_handle(conn->transport);
  2167. ev->type = ISCSI_KEVENT_CONN_ERROR;
  2168. ev->r.connerror.error = error;
  2169. ev->r.connerror.cid = conn->cid;
  2170. ev->r.connerror.sid = iscsi_conn_get_sid(conn);
  2171. iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
  2172. iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
  2173. error);
  2174. }
  2175. EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
  2176. void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
  2177. enum iscsi_conn_state state)
  2178. {
  2179. struct nlmsghdr *nlh;
  2180. struct sk_buff *skb;
  2181. struct iscsi_uevent *ev;
  2182. struct iscsi_internal *priv;
  2183. int len = nlmsg_total_size(sizeof(*ev));
  2184. priv = iscsi_if_transport_lookup(conn->transport);
  2185. if (!priv)
  2186. return;
  2187. skb = alloc_skb(len, GFP_ATOMIC);
  2188. if (!skb) {
  2189. iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
  2190. "conn login (%d)\n", state);
  2191. return;
  2192. }
  2193. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2194. ev = nlmsg_data(nlh);
  2195. ev->transport_handle = iscsi_handle(conn->transport);
  2196. ev->type = ISCSI_KEVENT_CONN_LOGIN_STATE;
  2197. ev->r.conn_login.state = state;
  2198. ev->r.conn_login.cid = conn->cid;
  2199. ev->r.conn_login.sid = iscsi_conn_get_sid(conn);
  2200. iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC);
  2201. iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn login (%d)\n",
  2202. state);
  2203. }
  2204. EXPORT_SYMBOL_GPL(iscsi_conn_login_event);
  2205. void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,
  2206. enum iscsi_host_event_code code, uint32_t data_size,
  2207. uint8_t *data)
  2208. {
  2209. struct nlmsghdr *nlh;
  2210. struct sk_buff *skb;
  2211. struct iscsi_uevent *ev;
  2212. int len = nlmsg_total_size(sizeof(*ev) + data_size);
  2213. skb = alloc_skb(len, GFP_NOIO);
  2214. if (!skb) {
  2215. printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
  2216. host_no, code);
  2217. return;
  2218. }
  2219. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2220. ev = nlmsg_data(nlh);
  2221. ev->transport_handle = iscsi_handle(transport);
  2222. ev->type = ISCSI_KEVENT_HOST_EVENT;
  2223. ev->r.host_event.host_no = host_no;
  2224. ev->r.host_event.code = code;
  2225. ev->r.host_event.data_size = data_size;
  2226. if (data_size)
  2227. memcpy((char *)ev + sizeof(*ev), data, data_size);
  2228. iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
  2229. }
  2230. EXPORT_SYMBOL_GPL(iscsi_post_host_event);
  2231. void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport,
  2232. uint32_t status, uint32_t pid, uint32_t data_size,
  2233. uint8_t *data)
  2234. {
  2235. struct nlmsghdr *nlh;
  2236. struct sk_buff *skb;
  2237. struct iscsi_uevent *ev;
  2238. int len = nlmsg_total_size(sizeof(*ev) + data_size);
  2239. skb = alloc_skb(len, GFP_NOIO);
  2240. if (!skb) {
  2241. printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
  2242. return;
  2243. }
  2244. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2245. ev = nlmsg_data(nlh);
  2246. ev->transport_handle = iscsi_handle(transport);
  2247. ev->type = ISCSI_KEVENT_PING_COMP;
  2248. ev->r.ping_comp.host_no = host_no;
  2249. ev->r.ping_comp.status = status;
  2250. ev->r.ping_comp.pid = pid;
  2251. ev->r.ping_comp.data_size = data_size;
  2252. memcpy((char *)ev + sizeof(*ev), data, data_size);
  2253. iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
  2254. }
  2255. EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
  2256. static int
  2257. iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi,
  2258. void *payload, int size)
  2259. {
  2260. struct sk_buff *skb;
  2261. struct nlmsghdr *nlh;
  2262. int len = nlmsg_total_size(size);
  2263. int flags = multi ? NLM_F_MULTI : 0;
  2264. int t = done ? NLMSG_DONE : type;
  2265. skb = alloc_skb(len, GFP_ATOMIC);
  2266. if (!skb) {
  2267. printk(KERN_ERR "Could not allocate skb to send reply.\n");
  2268. return -ENOMEM;
  2269. }
  2270. nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0);
  2271. nlh->nlmsg_flags = flags;
  2272. memcpy(nlmsg_data(nlh), payload, size);
  2273. return iscsi_multicast_skb(skb, group, GFP_ATOMIC);
  2274. }
  2275. static int
  2276. iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
  2277. {
  2278. struct iscsi_uevent *ev = nlmsg_data(nlh);
  2279. struct iscsi_stats *stats;
  2280. struct sk_buff *skbstat;
  2281. struct iscsi_cls_conn *conn;
  2282. struct nlmsghdr *nlhstat;
  2283. struct iscsi_uevent *evstat;
  2284. struct iscsi_internal *priv;
  2285. int len = nlmsg_total_size(sizeof(*ev) +
  2286. sizeof(struct iscsi_stats) +
  2287. sizeof(struct iscsi_stats_custom) *
  2288. ISCSI_STATS_CUSTOM_MAX);
  2289. int err = 0;
  2290. priv = iscsi_if_transport_lookup(transport);
  2291. if (!priv)
  2292. return -EINVAL;
  2293. conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
  2294. if (!conn)
  2295. return -EEXIST;
  2296. do {
  2297. int actual_size;
  2298. skbstat = alloc_skb(len, GFP_ATOMIC);
  2299. if (!skbstat) {
  2300. iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
  2301. "deliver stats: OOM\n");
  2302. return -ENOMEM;
  2303. }
  2304. nlhstat = __nlmsg_put(skbstat, 0, 0, 0,
  2305. (len - sizeof(*nlhstat)), 0);
  2306. evstat = nlmsg_data(nlhstat);
  2307. memset(evstat, 0, sizeof(*evstat));
  2308. evstat->transport_handle = iscsi_handle(conn->transport);
  2309. evstat->type = nlh->nlmsg_type;
  2310. evstat->u.get_stats.cid =
  2311. ev->u.get_stats.cid;
  2312. evstat->u.get_stats.sid =
  2313. ev->u.get_stats.sid;
  2314. stats = (struct iscsi_stats *)
  2315. ((char*)evstat + sizeof(*evstat));
  2316. memset(stats, 0, sizeof(*stats));
  2317. transport->get_stats(conn, stats);
  2318. actual_size = nlmsg_total_size(sizeof(struct iscsi_uevent) +
  2319. sizeof(struct iscsi_stats) +
  2320. sizeof(struct iscsi_stats_custom) *
  2321. stats->custom_length);
  2322. actual_size -= sizeof(*nlhstat);
  2323. actual_size = nlmsg_msg_size(actual_size);
  2324. skb_trim(skbstat, NLMSG_ALIGN(actual_size));
  2325. nlhstat->nlmsg_len = actual_size;
  2326. err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID,
  2327. GFP_ATOMIC);
  2328. } while (err < 0 && err != -ECONNREFUSED);
  2329. return err;
  2330. }
  2331. /**
  2332. * iscsi_session_event - send session destr. completion event
  2333. * @session: iscsi class session
  2334. * @event: type of event
  2335. */
  2336. int iscsi_session_event(struct iscsi_cls_session *session,
  2337. enum iscsi_uevent_e event)
  2338. {
  2339. struct iscsi_internal *priv;
  2340. struct Scsi_Host *shost;
  2341. struct iscsi_uevent *ev;
  2342. struct sk_buff *skb;
  2343. struct nlmsghdr *nlh;
  2344. int rc, len = nlmsg_total_size(sizeof(*ev));
  2345. priv = iscsi_if_transport_lookup(session->transport);
  2346. if (!priv)
  2347. return -EINVAL;
  2348. shost = iscsi_session_to_shost(session);
  2349. skb = alloc_skb(len, GFP_KERNEL);
  2350. if (!skb) {
  2351. iscsi_cls_session_printk(KERN_ERR, session,
  2352. "Cannot notify userspace of session "
  2353. "event %u\n", event);
  2354. return -ENOMEM;
  2355. }
  2356. nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0);
  2357. ev = nlmsg_data(nlh);
  2358. ev->transport_handle = iscsi_handle(session->transport);
  2359. ev->type = event;
  2360. switch (event) {
  2361. case ISCSI_KEVENT_DESTROY_SESSION:
  2362. ev->r.d_session.host_no = shost->host_no;
  2363. ev->r.d_session.sid = session->sid;
  2364. break;
  2365. case ISCSI_KEVENT_CREATE_SESSION:
  2366. ev->r.c_session_ret.host_no = shost->host_no;
  2367. ev->r.c_session_ret.sid = session->sid;
  2368. break;
  2369. case ISCSI_KEVENT_UNBIND_SESSION:
  2370. ev->r.unbind_session.host_no = shost->host_no;
  2371. ev->r.unbind_session.sid = session->sid;
  2372. break;
  2373. default:
  2374. iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
  2375. "%u.\n", event);
  2376. kfree_skb(skb);
  2377. return -EINVAL;
  2378. }
  2379. /*
  2380. * this will occur if the daemon is not up, so we just warn
  2381. * the user and when the daemon is restarted it will handle it
  2382. */
  2383. rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
  2384. if (rc == -ESRCH)
  2385. iscsi_cls_session_printk(KERN_ERR, session,
  2386. "Cannot notify userspace of session "
  2387. "event %u. Check iscsi daemon\n",
  2388. event);
  2389. ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n",
  2390. event, rc);
  2391. return rc;
  2392. }
  2393. EXPORT_SYMBOL_GPL(iscsi_session_event);
  2394. static int
  2395. iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
  2396. struct iscsi_uevent *ev, pid_t pid,
  2397. uint32_t initial_cmdsn, uint16_t cmds_max,
  2398. uint16_t queue_depth)
  2399. {
  2400. struct iscsi_transport *transport = priv->iscsi_transport;
  2401. struct iscsi_cls_session *session;
  2402. struct Scsi_Host *shost;
  2403. session = transport->create_session(ep, cmds_max, queue_depth,
  2404. initial_cmdsn);
  2405. if (!session)
  2406. return -ENOMEM;
  2407. session->creator = pid;
  2408. shost = iscsi_session_to_shost(session);
  2409. ev->r.c_session_ret.host_no = shost->host_no;
  2410. ev->r.c_session_ret.sid = session->sid;
  2411. ISCSI_DBG_TRANS_SESSION(session,
  2412. "Completed creating transport session\n");
  2413. return 0;
  2414. }
  2415. static int
  2416. iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
  2417. {
  2418. struct iscsi_cls_conn *conn;
  2419. struct iscsi_cls_session *session;
  2420. session = iscsi_session_lookup(ev->u.c_conn.sid);
  2421. if (!session) {
  2422. printk(KERN_ERR "iscsi: invalid session %d.\n",
  2423. ev->u.c_conn.sid);
  2424. return -EINVAL;
  2425. }
  2426. conn = transport->create_conn(session, ev->u.c_conn.cid);
  2427. if (!conn) {
  2428. iscsi_cls_session_printk(KERN_ERR, session,
  2429. "couldn't create a new connection.");
  2430. return -ENOMEM;
  2431. }
  2432. ev->r.c_conn_ret.sid = session->sid;
  2433. ev->r.c_conn_ret.cid = conn->cid;
  2434. ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n");
  2435. return 0;
  2436. }
  2437. static int
  2438. iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
  2439. {
  2440. struct iscsi_cls_conn *conn;
  2441. conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
  2442. if (!conn)
  2443. return -EINVAL;
  2444. ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n");
  2445. if (transport->destroy_conn)
  2446. transport->destroy_conn(conn);
  2447. return 0;
  2448. }
  2449. static int
  2450. iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
  2451. {
  2452. char *data = (char*)ev + sizeof(*ev);
  2453. struct iscsi_cls_conn *conn;
  2454. struct iscsi_cls_session *session;
  2455. int err = 0, value = 0;
  2456. session = iscsi_session_lookup(ev->u.set_param.sid);
  2457. conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
  2458. if (!conn || !session)
  2459. return -EINVAL;
  2460. switch (ev->u.set_param.param) {
  2461. case ISCSI_PARAM_SESS_RECOVERY_TMO:
  2462. sscanf(data, "%d", &value);
  2463. if (!session->recovery_tmo_sysfs_override)
  2464. session->recovery_tmo = value;
  2465. break;
  2466. default:
  2467. err = transport->set_param(conn, ev->u.set_param.param,
  2468. data, ev->u.set_param.len);
  2469. }
  2470. return err;
  2471. }
  2472. static int iscsi_if_ep_connect(struct iscsi_transport *transport,
  2473. struct iscsi_uevent *ev, int msg_type)
  2474. {
  2475. struct iscsi_endpoint *ep;
  2476. struct sockaddr *dst_addr;
  2477. struct Scsi_Host *shost = NULL;
  2478. int non_blocking, err = 0;
  2479. if (!transport->ep_connect)
  2480. return -EINVAL;
  2481. if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) {
  2482. shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no);
  2483. if (!shost) {
  2484. printk(KERN_ERR "ep connect failed. Could not find "
  2485. "host no %u\n",
  2486. ev->u.ep_connect_through_host.host_no);
  2487. return -ENODEV;
  2488. }
  2489. non_blocking = ev->u.ep_connect_through_host.non_blocking;
  2490. } else
  2491. non_blocking = ev->u.ep_connect.non_blocking;
  2492. dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
  2493. ep = transport->ep_connect(shost, dst_addr, non_blocking);
  2494. if (IS_ERR(ep)) {
  2495. err = PTR_ERR(ep);
  2496. goto release_host;
  2497. }
  2498. ev->r.ep_connect_ret.handle = ep->id;
  2499. release_host:
  2500. if (shost)
  2501. scsi_host_put(shost);
  2502. return err;
  2503. }
  2504. static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
  2505. u64 ep_handle)
  2506. {
  2507. struct iscsi_cls_conn *conn;
  2508. struct iscsi_endpoint *ep;
  2509. if (!transport->ep_disconnect)
  2510. return -EINVAL;
  2511. ep = iscsi_lookup_endpoint(ep_handle);
  2512. if (!ep)
  2513. return -EINVAL;
  2514. conn = ep->conn;
  2515. if (conn) {
  2516. mutex_lock(&conn->ep_mutex);
  2517. conn->ep = NULL;
  2518. mutex_unlock(&conn->ep_mutex);
  2519. }
  2520. transport->ep_disconnect(ep);
  2521. return 0;
  2522. }
  2523. static int
  2524. iscsi_if_transport_ep(struct iscsi_transport *transport,
  2525. struct iscsi_uevent *ev, int msg_type)
  2526. {
  2527. struct iscsi_endpoint *ep;
  2528. int rc = 0;
  2529. switch (msg_type) {
  2530. case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
  2531. case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
  2532. rc = iscsi_if_ep_connect(transport, ev, msg_type);
  2533. break;
  2534. case ISCSI_UEVENT_TRANSPORT_EP_POLL:
  2535. if (!transport->ep_poll)
  2536. return -EINVAL;
  2537. ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
  2538. if (!ep)
  2539. return -EINVAL;
  2540. ev->r.retcode = transport->ep_poll(ep,
  2541. ev->u.ep_poll.timeout_ms);
  2542. break;
  2543. case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
  2544. rc = iscsi_if_ep_disconnect(transport,
  2545. ev->u.ep_disconnect.ep_handle);
  2546. break;
  2547. }
  2548. return rc;
  2549. }
  2550. static int
  2551. iscsi_tgt_dscvr(struct iscsi_transport *transport,
  2552. struct iscsi_uevent *ev)
  2553. {
  2554. struct Scsi_Host *shost;
  2555. struct sockaddr *dst_addr;
  2556. int err;
  2557. if (!transport->tgt_dscvr)
  2558. return -EINVAL;
  2559. shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
  2560. if (!shost) {
  2561. printk(KERN_ERR "target discovery could not find host no %u\n",
  2562. ev->u.tgt_dscvr.host_no);
  2563. return -ENODEV;
  2564. }
  2565. dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
  2566. err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
  2567. ev->u.tgt_dscvr.enable, dst_addr);
  2568. scsi_host_put(shost);
  2569. return err;
  2570. }
  2571. static int
  2572. iscsi_set_host_param(struct iscsi_transport *transport,
  2573. struct iscsi_uevent *ev)
  2574. {
  2575. char *data = (char*)ev + sizeof(*ev);
  2576. struct Scsi_Host *shost;
  2577. int err;
  2578. if (!transport->set_host_param)
  2579. return -ENOSYS;
  2580. shost = scsi_host_lookup(ev->u.set_host_param.host_no);
  2581. if (!shost) {
  2582. printk(KERN_ERR "set_host_param could not find host no %u\n",
  2583. ev->u.set_host_param.host_no);
  2584. return -ENODEV;
  2585. }
  2586. err = transport->set_host_param(shost, ev->u.set_host_param.param,
  2587. data, ev->u.set_host_param.len);
  2588. scsi_host_put(shost);
  2589. return err;
  2590. }
  2591. static int
  2592. iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
  2593. {
  2594. struct Scsi_Host *shost;
  2595. struct iscsi_path *params;
  2596. int err;
  2597. if (!transport->set_path)
  2598. return -ENOSYS;
  2599. shost = scsi_host_lookup(ev->u.set_path.host_no);
  2600. if (!shost) {
  2601. printk(KERN_ERR "set path could not find host no %u\n",
  2602. ev->u.set_path.host_no);
  2603. return -ENODEV;
  2604. }
  2605. params = (struct iscsi_path *)((char *)ev + sizeof(*ev));
  2606. err = transport->set_path(shost, params);
  2607. scsi_host_put(shost);
  2608. return err;
  2609. }
  2610. static int
  2611. iscsi_set_iface_params(struct iscsi_transport *transport,
  2612. struct iscsi_uevent *ev, uint32_t len)
  2613. {
  2614. char *data = (char *)ev + sizeof(*ev);
  2615. struct Scsi_Host *shost;
  2616. int err;
  2617. if (!transport->set_iface_param)
  2618. return -ENOSYS;
  2619. shost = scsi_host_lookup(ev->u.set_iface_params.host_no);
  2620. if (!shost) {
  2621. printk(KERN_ERR "set_iface_params could not find host no %u\n",
  2622. ev->u.set_iface_params.host_no);
  2623. return -ENODEV;
  2624. }
  2625. err = transport->set_iface_param(shost, data, len);
  2626. scsi_host_put(shost);
  2627. return err;
  2628. }
  2629. static int
  2630. iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev)
  2631. {
  2632. struct Scsi_Host *shost;
  2633. struct sockaddr *dst_addr;
  2634. int err;
  2635. if (!transport->send_ping)
  2636. return -ENOSYS;
  2637. shost = scsi_host_lookup(ev->u.iscsi_ping.host_no);
  2638. if (!shost) {
  2639. printk(KERN_ERR "iscsi_ping could not find host no %u\n",
  2640. ev->u.iscsi_ping.host_no);
  2641. return -ENODEV;
  2642. }
  2643. dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev));
  2644. err = transport->send_ping(shost, ev->u.iscsi_ping.iface_num,
  2645. ev->u.iscsi_ping.iface_type,
  2646. ev->u.iscsi_ping.payload_size,
  2647. ev->u.iscsi_ping.pid,
  2648. dst_addr);
  2649. scsi_host_put(shost);
  2650. return err;
  2651. }
  2652. static int
  2653. iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)
  2654. {
  2655. struct iscsi_uevent *ev = nlmsg_data(nlh);
  2656. struct Scsi_Host *shost = NULL;
  2657. struct iscsi_chap_rec *chap_rec;
  2658. struct iscsi_internal *priv;
  2659. struct sk_buff *skbchap;
  2660. struct nlmsghdr *nlhchap;
  2661. struct iscsi_uevent *evchap;
  2662. uint32_t chap_buf_size;
  2663. int len, err = 0;
  2664. char *buf;
  2665. if (!transport->get_chap)
  2666. return -EINVAL;
  2667. priv = iscsi_if_transport_lookup(transport);
  2668. if (!priv)
  2669. return -EINVAL;
  2670. chap_buf_size = (ev->u.get_chap.num_entries * sizeof(*chap_rec));
  2671. len = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
  2672. shost = scsi_host_lookup(ev->u.get_chap.host_no);
  2673. if (!shost) {
  2674. printk(KERN_ERR "%s: failed. Could not find host no %u\n",
  2675. __func__, ev->u.get_chap.host_no);
  2676. return -ENODEV;
  2677. }
  2678. do {
  2679. int actual_size;
  2680. skbchap = alloc_skb(len, GFP_KERNEL);
  2681. if (!skbchap) {
  2682. printk(KERN_ERR "can not deliver chap: OOM\n");
  2683. err = -ENOMEM;
  2684. goto exit_get_chap;
  2685. }
  2686. nlhchap = __nlmsg_put(skbchap, 0, 0, 0,
  2687. (len - sizeof(*nlhchap)), 0);
  2688. evchap = nlmsg_data(nlhchap);
  2689. memset(evchap, 0, sizeof(*evchap));
  2690. evchap->transport_handle = iscsi_handle(transport);
  2691. evchap->type = nlh->nlmsg_type;
  2692. evchap->u.get_chap.host_no = ev->u.get_chap.host_no;
  2693. evchap->u.get_chap.chap_tbl_idx = ev->u.get_chap.chap_tbl_idx;
  2694. evchap->u.get_chap.num_entries = ev->u.get_chap.num_entries;
  2695. buf = (char *)evchap + sizeof(*evchap);
  2696. memset(buf, 0, chap_buf_size);
  2697. err = transport->get_chap(shost, ev->u.get_chap.chap_tbl_idx,
  2698. &evchap->u.get_chap.num_entries, buf);
  2699. actual_size = nlmsg_total_size(sizeof(*ev) + chap_buf_size);
  2700. skb_trim(skbchap, NLMSG_ALIGN(actual_size));
  2701. nlhchap->nlmsg_len = actual_size;
  2702. err = iscsi_multicast_skb(skbchap, ISCSI_NL_GRP_ISCSID,
  2703. GFP_KERNEL);
  2704. } while (err < 0 && err != -ECONNREFUSED);
  2705. exit_get_chap:
  2706. scsi_host_put(shost);
  2707. return err;
  2708. }
  2709. static int iscsi_set_chap(struct iscsi_transport *transport,
  2710. struct iscsi_uevent *ev, uint32_t len)
  2711. {
  2712. char *data = (char *)ev + sizeof(*ev);
  2713. struct Scsi_Host *shost;
  2714. int err = 0;
  2715. if (!transport->set_chap)
  2716. return -ENOSYS;
  2717. shost = scsi_host_lookup(ev->u.set_path.host_no);
  2718. if (!shost) {
  2719. pr_err("%s could not find host no %u\n",
  2720. __func__, ev->u.set_path.host_no);
  2721. return -ENODEV;
  2722. }
  2723. err = transport->set_chap(shost, data, len);
  2724. scsi_host_put(shost);
  2725. return err;
  2726. }
  2727. static int iscsi_delete_chap(struct iscsi_transport *transport,
  2728. struct iscsi_uevent *ev)
  2729. {
  2730. struct Scsi_Host *shost;
  2731. int err = 0;
  2732. if (!transport->delete_chap)
  2733. return -ENOSYS;
  2734. shost = scsi_host_lookup(ev->u.delete_chap.host_no);
  2735. if (!shost) {
  2736. printk(KERN_ERR "%s could not find host no %u\n",
  2737. __func__, ev->u.delete_chap.host_no);
  2738. return -ENODEV;
  2739. }
  2740. err = transport->delete_chap(shost, ev->u.delete_chap.chap_tbl_idx);
  2741. scsi_host_put(shost);
  2742. return err;
  2743. }
  2744. static const struct {
  2745. enum iscsi_discovery_parent_type value;
  2746. char *name;
  2747. } iscsi_discovery_parent_names[] = {
  2748. {ISCSI_DISC_PARENT_UNKNOWN, "Unknown" },
  2749. {ISCSI_DISC_PARENT_SENDTGT, "Sendtarget" },
  2750. {ISCSI_DISC_PARENT_ISNS, "isns" },
  2751. };
  2752. char *iscsi_get_discovery_parent_name(int parent_type)
  2753. {
  2754. int i;
  2755. char *state = "Unknown!";
  2756. for (i = 0; i < ARRAY_SIZE(iscsi_discovery_parent_names); i++) {
  2757. if (iscsi_discovery_parent_names[i].value & parent_type) {
  2758. state = iscsi_discovery_parent_names[i].name;
  2759. break;
  2760. }
  2761. }
  2762. return state;
  2763. }
  2764. EXPORT_SYMBOL_GPL(iscsi_get_discovery_parent_name);
  2765. static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
  2766. struct iscsi_uevent *ev, uint32_t len)
  2767. {
  2768. char *data = (char *)ev + sizeof(*ev);
  2769. struct Scsi_Host *shost;
  2770. struct iscsi_bus_flash_session *fnode_sess;
  2771. struct iscsi_bus_flash_conn *fnode_conn;
  2772. struct device *dev;
  2773. uint32_t idx;
  2774. int err = 0;
  2775. if (!transport->set_flashnode_param) {
  2776. err = -ENOSYS;
  2777. goto exit_set_fnode;
  2778. }
  2779. shost = scsi_host_lookup(ev->u.set_flashnode.host_no);
  2780. if (!shost) {
  2781. pr_err("%s could not find host no %u\n",
  2782. __func__, ev->u.set_flashnode.host_no);
  2783. err = -ENODEV;
  2784. goto put_host;
  2785. }
  2786. idx = ev->u.set_flashnode.flashnode_idx;
  2787. fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
  2788. if (!fnode_sess) {
  2789. pr_err("%s could not find flashnode %u for host no %u\n",
  2790. __func__, idx, ev->u.set_flashnode.host_no);
  2791. err = -ENODEV;
  2792. goto put_host;
  2793. }
  2794. dev = iscsi_find_flashnode_conn(fnode_sess);
  2795. if (!dev) {
  2796. err = -ENODEV;
  2797. goto put_sess;
  2798. }
  2799. fnode_conn = iscsi_dev_to_flash_conn(dev);
  2800. err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
  2801. put_device(dev);
  2802. put_sess:
  2803. put_device(&fnode_sess->dev);
  2804. put_host:
  2805. scsi_host_put(shost);
  2806. exit_set_fnode:
  2807. return err;
  2808. }
  2809. static int iscsi_new_flashnode(struct iscsi_transport *transport,
  2810. struct iscsi_uevent *ev, uint32_t len)
  2811. {
  2812. char *data = (char *)ev + sizeof(*ev);
  2813. struct Scsi_Host *shost;
  2814. int index;
  2815. int err = 0;
  2816. if (!transport->new_flashnode) {
  2817. err = -ENOSYS;
  2818. goto exit_new_fnode;
  2819. }
  2820. shost = scsi_host_lookup(ev->u.new_flashnode.host_no);
  2821. if (!shost) {
  2822. pr_err("%s could not find host no %u\n",
  2823. __func__, ev->u.new_flashnode.host_no);
  2824. err = -ENODEV;
  2825. goto put_host;
  2826. }
  2827. index = transport->new_flashnode(shost, data, len);
  2828. if (index >= 0)
  2829. ev->r.new_flashnode_ret.flashnode_idx = index;
  2830. else
  2831. err = -EIO;
  2832. put_host:
  2833. scsi_host_put(shost);
  2834. exit_new_fnode:
  2835. return err;
  2836. }
  2837. static int iscsi_del_flashnode(struct iscsi_transport *transport,
  2838. struct iscsi_uevent *ev)
  2839. {
  2840. struct Scsi_Host *shost;
  2841. struct iscsi_bus_flash_session *fnode_sess;
  2842. uint32_t idx;
  2843. int err = 0;
  2844. if (!transport->del_flashnode) {
  2845. err = -ENOSYS;
  2846. goto exit_del_fnode;
  2847. }
  2848. shost = scsi_host_lookup(ev->u.del_flashnode.host_no);
  2849. if (!shost) {
  2850. pr_err("%s could not find host no %u\n",
  2851. __func__, ev->u.del_flashnode.host_no);
  2852. err = -ENODEV;
  2853. goto put_host;
  2854. }
  2855. idx = ev->u.del_flashnode.flashnode_idx;
  2856. fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
  2857. if (!fnode_sess) {
  2858. pr_err("%s could not find flashnode %u for host no %u\n",
  2859. __func__, idx, ev->u.del_flashnode.host_no);
  2860. err = -ENODEV;
  2861. goto put_host;
  2862. }
  2863. err = transport->del_flashnode(fnode_sess);
  2864. put_device(&fnode_sess->dev);
  2865. put_host:
  2866. scsi_host_put(shost);
  2867. exit_del_fnode:
  2868. return err;
  2869. }
  2870. static int iscsi_login_flashnode(struct iscsi_transport *transport,
  2871. struct iscsi_uevent *ev)
  2872. {
  2873. struct Scsi_Host *shost;
  2874. struct iscsi_bus_flash_session *fnode_sess;
  2875. struct iscsi_bus_flash_conn *fnode_conn;
  2876. struct device *dev;
  2877. uint32_t idx;
  2878. int err = 0;
  2879. if (!transport->login_flashnode) {
  2880. err = -ENOSYS;
  2881. goto exit_login_fnode;
  2882. }
  2883. shost = scsi_host_lookup(ev->u.login_flashnode.host_no);
  2884. if (!shost) {
  2885. pr_err("%s could not find host no %u\n",
  2886. __func__, ev->u.login_flashnode.host_no);
  2887. err = -ENODEV;
  2888. goto put_host;
  2889. }
  2890. idx = ev->u.login_flashnode.flashnode_idx;
  2891. fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
  2892. if (!fnode_sess) {
  2893. pr_err("%s could not find flashnode %u for host no %u\n",
  2894. __func__, idx, ev->u.login_flashnode.host_no);
  2895. err = -ENODEV;
  2896. goto put_host;
  2897. }
  2898. dev = iscsi_find_flashnode_conn(fnode_sess);
  2899. if (!dev) {
  2900. err = -ENODEV;
  2901. goto put_sess;
  2902. }
  2903. fnode_conn = iscsi_dev_to_flash_conn(dev);
  2904. err = transport->login_flashnode(fnode_sess, fnode_conn);
  2905. put_device(dev);
  2906. put_sess:
  2907. put_device(&fnode_sess->dev);
  2908. put_host:
  2909. scsi_host_put(shost);
  2910. exit_login_fnode:
  2911. return err;
  2912. }
  2913. static int iscsi_logout_flashnode(struct iscsi_transport *transport,
  2914. struct iscsi_uevent *ev)
  2915. {
  2916. struct Scsi_Host *shost;
  2917. struct iscsi_bus_flash_session *fnode_sess;
  2918. struct iscsi_bus_flash_conn *fnode_conn;
  2919. struct device *dev;
  2920. uint32_t idx;
  2921. int err = 0;
  2922. if (!transport->logout_flashnode) {
  2923. err = -ENOSYS;
  2924. goto exit_logout_fnode;
  2925. }
  2926. shost = scsi_host_lookup(ev->u.logout_flashnode.host_no);
  2927. if (!shost) {
  2928. pr_err("%s could not find host no %u\n",
  2929. __func__, ev->u.logout_flashnode.host_no);
  2930. err = -ENODEV;
  2931. goto put_host;
  2932. }
  2933. idx = ev->u.logout_flashnode.flashnode_idx;
  2934. fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
  2935. if (!fnode_sess) {
  2936. pr_err("%s could not find flashnode %u for host no %u\n",
  2937. __func__, idx, ev->u.logout_flashnode.host_no);
  2938. err = -ENODEV;
  2939. goto put_host;
  2940. }
  2941. dev = iscsi_find_flashnode_conn(fnode_sess);
  2942. if (!dev) {
  2943. err = -ENODEV;
  2944. goto put_sess;
  2945. }
  2946. fnode_conn = iscsi_dev_to_flash_conn(dev);
  2947. err = transport->logout_flashnode(fnode_sess, fnode_conn);
  2948. put_device(dev);
  2949. put_sess:
  2950. put_device(&fnode_sess->dev);
  2951. put_host:
  2952. scsi_host_put(shost);
  2953. exit_logout_fnode:
  2954. return err;
  2955. }
  2956. static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport,
  2957. struct iscsi_uevent *ev)
  2958. {
  2959. struct Scsi_Host *shost;
  2960. struct iscsi_cls_session *session;
  2961. int err = 0;
  2962. if (!transport->logout_flashnode_sid) {
  2963. err = -ENOSYS;
  2964. goto exit_logout_sid;
  2965. }
  2966. shost = scsi_host_lookup(ev->u.logout_flashnode_sid.host_no);
  2967. if (!shost) {
  2968. pr_err("%s could not find host no %u\n",
  2969. __func__, ev->u.logout_flashnode.host_no);
  2970. err = -ENODEV;
  2971. goto put_host;
  2972. }
  2973. session = iscsi_session_lookup(ev->u.logout_flashnode_sid.sid);
  2974. if (!session) {
  2975. pr_err("%s could not find session id %u\n",
  2976. __func__, ev->u.logout_flashnode_sid.sid);
  2977. err = -EINVAL;
  2978. goto put_host;
  2979. }
  2980. err = transport->logout_flashnode_sid(session);
  2981. put_host:
  2982. scsi_host_put(shost);
  2983. exit_logout_sid:
  2984. return err;
  2985. }
  2986. static int
  2987. iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
  2988. {
  2989. struct iscsi_uevent *ev = nlmsg_data(nlh);
  2990. struct Scsi_Host *shost = NULL;
  2991. struct iscsi_internal *priv;
  2992. struct sk_buff *skbhost_stats;
  2993. struct nlmsghdr *nlhhost_stats;
  2994. struct iscsi_uevent *evhost_stats;
  2995. int host_stats_size = 0;
  2996. int len, err = 0;
  2997. char *buf;
  2998. if (!transport->get_host_stats)
  2999. return -ENOSYS;
  3000. priv = iscsi_if_transport_lookup(transport);
  3001. if (!priv)
  3002. return -EINVAL;
  3003. host_stats_size = sizeof(struct iscsi_offload_host_stats);
  3004. len = nlmsg_total_size(sizeof(*ev) + host_stats_size);
  3005. shost = scsi_host_lookup(ev->u.get_host_stats.host_no);
  3006. if (!shost) {
  3007. pr_err("%s: failed. Cound not find host no %u\n",
  3008. __func__, ev->u.get_host_stats.host_no);
  3009. return -ENODEV;
  3010. }
  3011. do {
  3012. int actual_size;
  3013. skbhost_stats = alloc_skb(len, GFP_KERNEL);
  3014. if (!skbhost_stats) {
  3015. pr_err("cannot deliver host stats: OOM\n");
  3016. err = -ENOMEM;
  3017. goto exit_host_stats;
  3018. }
  3019. nlhhost_stats = __nlmsg_put(skbhost_stats, 0, 0, 0,
  3020. (len - sizeof(*nlhhost_stats)), 0);
  3021. evhost_stats = nlmsg_data(nlhhost_stats);
  3022. memset(evhost_stats, 0, sizeof(*evhost_stats));
  3023. evhost_stats->transport_handle = iscsi_handle(transport);
  3024. evhost_stats->type = nlh->nlmsg_type;
  3025. evhost_stats->u.get_host_stats.host_no =
  3026. ev->u.get_host_stats.host_no;
  3027. buf = (char *)evhost_stats + sizeof(*evhost_stats);
  3028. memset(buf, 0, host_stats_size);
  3029. err = transport->get_host_stats(shost, buf, host_stats_size);
  3030. if (err) {
  3031. kfree_skb(skbhost_stats);
  3032. goto exit_host_stats;
  3033. }
  3034. actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size);
  3035. skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size));
  3036. nlhhost_stats->nlmsg_len = actual_size;
  3037. err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID,
  3038. GFP_KERNEL);
  3039. } while (err < 0 && err != -ECONNREFUSED);
  3040. exit_host_stats:
  3041. scsi_host_put(shost);
  3042. return err;
  3043. }
  3044. static int
  3045. iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
  3046. {
  3047. int err = 0;
  3048. struct iscsi_uevent *ev = nlmsg_data(nlh);
  3049. struct iscsi_transport *transport = NULL;
  3050. struct iscsi_internal *priv;
  3051. struct iscsi_cls_session *session;
  3052. struct iscsi_cls_conn *conn;
  3053. struct iscsi_endpoint *ep = NULL;
  3054. if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
  3055. *group = ISCSI_NL_GRP_UIP;
  3056. else
  3057. *group = ISCSI_NL_GRP_ISCSID;
  3058. priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
  3059. if (!priv)
  3060. return -EINVAL;
  3061. transport = priv->iscsi_transport;
  3062. if (!try_module_get(transport->owner))
  3063. return -EINVAL;
  3064. switch (nlh->nlmsg_type) {
  3065. case ISCSI_UEVENT_CREATE_SESSION:
  3066. err = iscsi_if_create_session(priv, ep, ev,
  3067. NETLINK_CB(skb).portid,
  3068. ev->u.c_session.initial_cmdsn,
  3069. ev->u.c_session.cmds_max,
  3070. ev->u.c_session.queue_depth);
  3071. break;
  3072. case ISCSI_UEVENT_CREATE_BOUND_SESSION:
  3073. ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
  3074. if (!ep) {
  3075. err = -EINVAL;
  3076. break;
  3077. }
  3078. err = iscsi_if_create_session(priv, ep, ev,
  3079. NETLINK_CB(skb).portid,
  3080. ev->u.c_bound_session.initial_cmdsn,
  3081. ev->u.c_bound_session.cmds_max,
  3082. ev->u.c_bound_session.queue_depth);
  3083. break;
  3084. case ISCSI_UEVENT_DESTROY_SESSION:
  3085. session = iscsi_session_lookup(ev->u.d_session.sid);
  3086. if (session)
  3087. transport->destroy_session(session);
  3088. else
  3089. err = -EINVAL;
  3090. break;
  3091. case ISCSI_UEVENT_UNBIND_SESSION:
  3092. session = iscsi_session_lookup(ev->u.d_session.sid);
  3093. if (session)
  3094. scsi_queue_work(iscsi_session_to_shost(session),
  3095. &session->unbind_work);
  3096. else
  3097. err = -EINVAL;
  3098. break;
  3099. case ISCSI_UEVENT_CREATE_CONN:
  3100. err = iscsi_if_create_conn(transport, ev);
  3101. break;
  3102. case ISCSI_UEVENT_DESTROY_CONN:
  3103. err = iscsi_if_destroy_conn(transport, ev);
  3104. break;
  3105. case ISCSI_UEVENT_BIND_CONN:
  3106. session = iscsi_session_lookup(ev->u.b_conn.sid);
  3107. conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
  3108. if (conn && conn->ep)
  3109. iscsi_if_ep_disconnect(transport, conn->ep->id);
  3110. if (!session || !conn) {
  3111. err = -EINVAL;
  3112. break;
  3113. }
  3114. ev->r.retcode = transport->bind_conn(session, conn,
  3115. ev->u.b_conn.transport_eph,
  3116. ev->u.b_conn.is_leading);
  3117. if (ev->r.retcode || !transport->ep_connect)
  3118. break;
  3119. ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
  3120. if (ep) {
  3121. ep->conn = conn;
  3122. mutex_lock(&conn->ep_mutex);
  3123. conn->ep = ep;
  3124. mutex_unlock(&conn->ep_mutex);
  3125. } else
  3126. iscsi_cls_conn_printk(KERN_ERR, conn,
  3127. "Could not set ep conn "
  3128. "binding\n");
  3129. break;
  3130. case ISCSI_UEVENT_SET_PARAM:
  3131. err = iscsi_set_param(transport, ev);
  3132. break;
  3133. case ISCSI_UEVENT_START_CONN:
  3134. conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid);
  3135. if (conn)
  3136. ev->r.retcode = transport->start_conn(conn);
  3137. else
  3138. err = -EINVAL;
  3139. break;
  3140. case ISCSI_UEVENT_STOP_CONN:
  3141. conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
  3142. if (conn)
  3143. transport->stop_conn(conn, ev->u.stop_conn.flag);
  3144. else
  3145. err = -EINVAL;
  3146. break;
  3147. case ISCSI_UEVENT_SEND_PDU:
  3148. conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
  3149. if (conn)
  3150. ev->r.retcode = transport->send_pdu(conn,
  3151. (struct iscsi_hdr*)((char*)ev + sizeof(*ev)),
  3152. (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
  3153. ev->u.send_pdu.data_size);
  3154. else
  3155. err = -EINVAL;
  3156. break;
  3157. case ISCSI_UEVENT_GET_STATS:
  3158. err = iscsi_if_get_stats(transport, nlh);
  3159. break;
  3160. case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
  3161. case ISCSI_UEVENT_TRANSPORT_EP_POLL:
  3162. case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
  3163. case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST:
  3164. err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
  3165. break;
  3166. case ISCSI_UEVENT_TGT_DSCVR:
  3167. err = iscsi_tgt_dscvr(transport, ev);
  3168. break;
  3169. case ISCSI_UEVENT_SET_HOST_PARAM:
  3170. err = iscsi_set_host_param(transport, ev);
  3171. break;
  3172. case ISCSI_UEVENT_PATH_UPDATE:
  3173. err = iscsi_set_path(transport, ev);
  3174. break;
  3175. case ISCSI_UEVENT_SET_IFACE_PARAMS:
  3176. err = iscsi_set_iface_params(transport, ev,
  3177. nlmsg_attrlen(nlh, sizeof(*ev)));
  3178. break;
  3179. case ISCSI_UEVENT_PING:
  3180. err = iscsi_send_ping(transport, ev);
  3181. break;
  3182. case ISCSI_UEVENT_GET_CHAP:
  3183. err = iscsi_get_chap(transport, nlh);
  3184. break;
  3185. case ISCSI_UEVENT_DELETE_CHAP:
  3186. err = iscsi_delete_chap(transport, ev);
  3187. break;
  3188. case ISCSI_UEVENT_SET_FLASHNODE_PARAMS:
  3189. err = iscsi_set_flashnode_param(transport, ev,
  3190. nlmsg_attrlen(nlh,
  3191. sizeof(*ev)));
  3192. break;
  3193. case ISCSI_UEVENT_NEW_FLASHNODE:
  3194. err = iscsi_new_flashnode(transport, ev,
  3195. nlmsg_attrlen(nlh, sizeof(*ev)));
  3196. break;
  3197. case ISCSI_UEVENT_DEL_FLASHNODE:
  3198. err = iscsi_del_flashnode(transport, ev);
  3199. break;
  3200. case ISCSI_UEVENT_LOGIN_FLASHNODE:
  3201. err = iscsi_login_flashnode(transport, ev);
  3202. break;
  3203. case ISCSI_UEVENT_LOGOUT_FLASHNODE:
  3204. err = iscsi_logout_flashnode(transport, ev);
  3205. break;
  3206. case ISCSI_UEVENT_LOGOUT_FLASHNODE_SID:
  3207. err = iscsi_logout_flashnode_sid(transport, ev);
  3208. break;
  3209. case ISCSI_UEVENT_SET_CHAP:
  3210. err = iscsi_set_chap(transport, ev,
  3211. nlmsg_attrlen(nlh, sizeof(*ev)));
  3212. break;
  3213. case ISCSI_UEVENT_GET_HOST_STATS:
  3214. err = iscsi_get_host_stats(transport, nlh);
  3215. break;
  3216. default:
  3217. err = -ENOSYS;
  3218. break;
  3219. }
  3220. module_put(transport->owner);
  3221. return err;
  3222. }
  3223. /*
  3224. * Get message from skb. Each message is processed by iscsi_if_recv_msg.
  3225. * Malformed skbs with wrong lengths or invalid creds are not processed.
  3226. */
  3227. static void
  3228. iscsi_if_rx(struct sk_buff *skb)
  3229. {
  3230. mutex_lock(&rx_queue_mutex);
  3231. while (skb->len >= NLMSG_HDRLEN) {
  3232. int err;
  3233. uint32_t rlen;
  3234. struct nlmsghdr *nlh;
  3235. struct iscsi_uevent *ev;
  3236. uint32_t group;
  3237. nlh = nlmsg_hdr(skb);
  3238. if (nlh->nlmsg_len < sizeof(*nlh) + sizeof(*ev) ||
  3239. skb->len < nlh->nlmsg_len) {
  3240. break;
  3241. }
  3242. ev = nlmsg_data(nlh);
  3243. rlen = NLMSG_ALIGN(nlh->nlmsg_len);
  3244. if (rlen > skb->len)
  3245. rlen = skb->len;
  3246. err = iscsi_if_recv_msg(skb, nlh, &group);
  3247. if (err) {
  3248. ev->type = ISCSI_KEVENT_IF_ERROR;
  3249. ev->iferror = err;
  3250. }
  3251. do {
  3252. /*
  3253. * special case for GET_STATS:
  3254. * on success - sending reply and stats from
  3255. * inside of if_recv_msg(),
  3256. * on error - fall through.
  3257. */
  3258. if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
  3259. break;
  3260. if (ev->type == ISCSI_UEVENT_GET_CHAP && !err)
  3261. break;
  3262. err = iscsi_if_send_reply(group, nlh->nlmsg_seq,
  3263. nlh->nlmsg_type, 0, 0, ev, sizeof(*ev));
  3264. } while (err < 0 && err != -ECONNREFUSED && err != -ESRCH);
  3265. skb_pull(skb, rlen);
  3266. }
  3267. mutex_unlock(&rx_queue_mutex);
  3268. }
  3269. #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
  3270. struct device_attribute dev_attr_##_prefix##_##_name = \
  3271. __ATTR(_name,_mode,_show,_store)
  3272. /*
  3273. * iSCSI connection attrs
  3274. */
  3275. #define iscsi_conn_attr_show(param) \
  3276. static ssize_t \
  3277. show_conn_param_##param(struct device *dev, \
  3278. struct device_attribute *attr, char *buf) \
  3279. { \
  3280. struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
  3281. struct iscsi_transport *t = conn->transport; \
  3282. return t->get_conn_param(conn, param, buf); \
  3283. }
  3284. #define iscsi_conn_attr(field, param) \
  3285. iscsi_conn_attr_show(param) \
  3286. static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
  3287. NULL);
  3288. iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
  3289. iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
  3290. iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
  3291. iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
  3292. iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
  3293. iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
  3294. iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
  3295. iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
  3296. iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
  3297. iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
  3298. iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
  3299. iscsi_conn_attr(local_port, ISCSI_PARAM_LOCAL_PORT);
  3300. iscsi_conn_attr(statsn, ISCSI_PARAM_STATSN);
  3301. iscsi_conn_attr(keepalive_tmo, ISCSI_PARAM_KEEPALIVE_TMO);
  3302. iscsi_conn_attr(max_segment_size, ISCSI_PARAM_MAX_SEGMENT_SIZE);
  3303. iscsi_conn_attr(tcp_timestamp_stat, ISCSI_PARAM_TCP_TIMESTAMP_STAT);
  3304. iscsi_conn_attr(tcp_wsf_disable, ISCSI_PARAM_TCP_WSF_DISABLE);
  3305. iscsi_conn_attr(tcp_nagle_disable, ISCSI_PARAM_TCP_NAGLE_DISABLE);
  3306. iscsi_conn_attr(tcp_timer_scale, ISCSI_PARAM_TCP_TIMER_SCALE);
  3307. iscsi_conn_attr(tcp_timestamp_enable, ISCSI_PARAM_TCP_TIMESTAMP_EN);
  3308. iscsi_conn_attr(fragment_disable, ISCSI_PARAM_IP_FRAGMENT_DISABLE);
  3309. iscsi_conn_attr(ipv4_tos, ISCSI_PARAM_IPV4_TOS);
  3310. iscsi_conn_attr(ipv6_traffic_class, ISCSI_PARAM_IPV6_TC);
  3311. iscsi_conn_attr(ipv6_flow_label, ISCSI_PARAM_IPV6_FLOW_LABEL);
  3312. iscsi_conn_attr(is_fw_assigned_ipv6, ISCSI_PARAM_IS_FW_ASSIGNED_IPV6);
  3313. iscsi_conn_attr(tcp_xmit_wsf, ISCSI_PARAM_TCP_XMIT_WSF);
  3314. iscsi_conn_attr(tcp_recv_wsf, ISCSI_PARAM_TCP_RECV_WSF);
  3315. iscsi_conn_attr(local_ipaddr, ISCSI_PARAM_LOCAL_IPADDR);
  3316. #define iscsi_conn_ep_attr_show(param) \
  3317. static ssize_t show_conn_ep_param_##param(struct device *dev, \
  3318. struct device_attribute *attr,\
  3319. char *buf) \
  3320. { \
  3321. struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
  3322. struct iscsi_transport *t = conn->transport; \
  3323. struct iscsi_endpoint *ep; \
  3324. ssize_t rc; \
  3325. \
  3326. /* \
  3327. * Need to make sure ep_disconnect does not free the LLD's \
  3328. * interconnect resources while we are trying to read them. \
  3329. */ \
  3330. mutex_lock(&conn->ep_mutex); \
  3331. ep = conn->ep; \
  3332. if (!ep && t->ep_connect) { \
  3333. mutex_unlock(&conn->ep_mutex); \
  3334. return -ENOTCONN; \
  3335. } \
  3336. \
  3337. if (ep) \
  3338. rc = t->get_ep_param(ep, param, buf); \
  3339. else \
  3340. rc = t->get_conn_param(conn, param, buf); \
  3341. mutex_unlock(&conn->ep_mutex); \
  3342. return rc; \
  3343. }
  3344. #define iscsi_conn_ep_attr(field, param) \
  3345. iscsi_conn_ep_attr_show(param) \
  3346. static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
  3347. show_conn_ep_param_##param, NULL);
  3348. iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
  3349. iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
  3350. static struct attribute *iscsi_conn_attrs[] = {
  3351. &dev_attr_conn_max_recv_dlength.attr,
  3352. &dev_attr_conn_max_xmit_dlength.attr,
  3353. &dev_attr_conn_header_digest.attr,
  3354. &dev_attr_conn_data_digest.attr,
  3355. &dev_attr_conn_ifmarker.attr,
  3356. &dev_attr_conn_ofmarker.attr,
  3357. &dev_attr_conn_address.attr,
  3358. &dev_attr_conn_port.attr,
  3359. &dev_attr_conn_exp_statsn.attr,
  3360. &dev_attr_conn_persistent_address.attr,
  3361. &dev_attr_conn_persistent_port.attr,
  3362. &dev_attr_conn_ping_tmo.attr,
  3363. &dev_attr_conn_recv_tmo.attr,
  3364. &dev_attr_conn_local_port.attr,
  3365. &dev_attr_conn_statsn.attr,
  3366. &dev_attr_conn_keepalive_tmo.attr,
  3367. &dev_attr_conn_max_segment_size.attr,
  3368. &dev_attr_conn_tcp_timestamp_stat.attr,
  3369. &dev_attr_conn_tcp_wsf_disable.attr,
  3370. &dev_attr_conn_tcp_nagle_disable.attr,
  3371. &dev_attr_conn_tcp_timer_scale.attr,
  3372. &dev_attr_conn_tcp_timestamp_enable.attr,
  3373. &dev_attr_conn_fragment_disable.attr,
  3374. &dev_attr_conn_ipv4_tos.attr,
  3375. &dev_attr_conn_ipv6_traffic_class.attr,
  3376. &dev_attr_conn_ipv6_flow_label.attr,
  3377. &dev_attr_conn_is_fw_assigned_ipv6.attr,
  3378. &dev_attr_conn_tcp_xmit_wsf.attr,
  3379. &dev_attr_conn_tcp_recv_wsf.attr,
  3380. &dev_attr_conn_local_ipaddr.attr,
  3381. NULL,
  3382. };
  3383. static umode_t iscsi_conn_attr_is_visible(struct kobject *kobj,
  3384. struct attribute *attr, int i)
  3385. {
  3386. struct device *cdev = container_of(kobj, struct device, kobj);
  3387. struct iscsi_cls_conn *conn = transport_class_to_conn(cdev);
  3388. struct iscsi_transport *t = conn->transport;
  3389. int param;
  3390. if (attr == &dev_attr_conn_max_recv_dlength.attr)
  3391. param = ISCSI_PARAM_MAX_RECV_DLENGTH;
  3392. else if (attr == &dev_attr_conn_max_xmit_dlength.attr)
  3393. param = ISCSI_PARAM_MAX_XMIT_DLENGTH;
  3394. else if (attr == &dev_attr_conn_header_digest.attr)
  3395. param = ISCSI_PARAM_HDRDGST_EN;
  3396. else if (attr == &dev_attr_conn_data_digest.attr)
  3397. param = ISCSI_PARAM_DATADGST_EN;
  3398. else if (attr == &dev_attr_conn_ifmarker.attr)
  3399. param = ISCSI_PARAM_IFMARKER_EN;
  3400. else if (attr == &dev_attr_conn_ofmarker.attr)
  3401. param = ISCSI_PARAM_OFMARKER_EN;
  3402. else if (attr == &dev_attr_conn_address.attr)
  3403. param = ISCSI_PARAM_CONN_ADDRESS;
  3404. else if (attr == &dev_attr_conn_port.attr)
  3405. param = ISCSI_PARAM_CONN_PORT;
  3406. else if (attr == &dev_attr_conn_exp_statsn.attr)
  3407. param = ISCSI_PARAM_EXP_STATSN;
  3408. else if (attr == &dev_attr_conn_persistent_address.attr)
  3409. param = ISCSI_PARAM_PERSISTENT_ADDRESS;
  3410. else if (attr == &dev_attr_conn_persistent_port.attr)
  3411. param = ISCSI_PARAM_PERSISTENT_PORT;
  3412. else if (attr == &dev_attr_conn_ping_tmo.attr)
  3413. param = ISCSI_PARAM_PING_TMO;
  3414. else if (attr == &dev_attr_conn_recv_tmo.attr)
  3415. param = ISCSI_PARAM_RECV_TMO;
  3416. else if (attr == &dev_attr_conn_local_port.attr)
  3417. param = ISCSI_PARAM_LOCAL_PORT;
  3418. else if (attr == &dev_attr_conn_statsn.attr)
  3419. param = ISCSI_PARAM_STATSN;
  3420. else if (attr == &dev_attr_conn_keepalive_tmo.attr)
  3421. param = ISCSI_PARAM_KEEPALIVE_TMO;
  3422. else if (attr == &dev_attr_conn_max_segment_size.attr)
  3423. param = ISCSI_PARAM_MAX_SEGMENT_SIZE;
  3424. else if (attr == &dev_attr_conn_tcp_timestamp_stat.attr)
  3425. param = ISCSI_PARAM_TCP_TIMESTAMP_STAT;
  3426. else if (attr == &dev_attr_conn_tcp_wsf_disable.attr)
  3427. param = ISCSI_PARAM_TCP_WSF_DISABLE;
  3428. else if (attr == &dev_attr_conn_tcp_nagle_disable.attr)
  3429. param = ISCSI_PARAM_TCP_NAGLE_DISABLE;
  3430. else if (attr == &dev_attr_conn_tcp_timer_scale.attr)
  3431. param = ISCSI_PARAM_TCP_TIMER_SCALE;
  3432. else if (attr == &dev_attr_conn_tcp_timestamp_enable.attr)
  3433. param = ISCSI_PARAM_TCP_TIMESTAMP_EN;
  3434. else if (attr == &dev_attr_conn_fragment_disable.attr)
  3435. param = ISCSI_PARAM_IP_FRAGMENT_DISABLE;
  3436. else if (attr == &dev_attr_conn_ipv4_tos.attr)
  3437. param = ISCSI_PARAM_IPV4_TOS;
  3438. else if (attr == &dev_attr_conn_ipv6_traffic_class.attr)
  3439. param = ISCSI_PARAM_IPV6_TC;
  3440. else if (attr == &dev_attr_conn_ipv6_flow_label.attr)
  3441. param = ISCSI_PARAM_IPV6_FLOW_LABEL;
  3442. else if (attr == &dev_attr_conn_is_fw_assigned_ipv6.attr)
  3443. param = ISCSI_PARAM_IS_FW_ASSIGNED_IPV6;
  3444. else if (attr == &dev_attr_conn_tcp_xmit_wsf.attr)
  3445. param = ISCSI_PARAM_TCP_XMIT_WSF;
  3446. else if (attr == &dev_attr_conn_tcp_recv_wsf.attr)
  3447. param = ISCSI_PARAM_TCP_RECV_WSF;
  3448. else if (attr == &dev_attr_conn_local_ipaddr.attr)
  3449. param = ISCSI_PARAM_LOCAL_IPADDR;
  3450. else {
  3451. WARN_ONCE(1, "Invalid conn attr");
  3452. return 0;
  3453. }
  3454. return t->attr_is_visible(ISCSI_PARAM, param);
  3455. }
  3456. static struct attribute_group iscsi_conn_group = {
  3457. .attrs = iscsi_conn_attrs,
  3458. .is_visible = iscsi_conn_attr_is_visible,
  3459. };
  3460. /*
  3461. * iSCSI session attrs
  3462. */
  3463. #define iscsi_session_attr_show(param, perm) \
  3464. static ssize_t \
  3465. show_session_param_##param(struct device *dev, \
  3466. struct device_attribute *attr, char *buf) \
  3467. { \
  3468. struct iscsi_cls_session *session = \
  3469. iscsi_dev_to_session(dev->parent); \
  3470. struct iscsi_transport *t = session->transport; \
  3471. \
  3472. if (perm && !capable(CAP_SYS_ADMIN)) \
  3473. return -EACCES; \
  3474. return t->get_session_param(session, param, buf); \
  3475. }
  3476. #define iscsi_session_attr(field, param, perm) \
  3477. iscsi_session_attr_show(param, perm) \
  3478. static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
  3479. NULL);
  3480. iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
  3481. iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
  3482. iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
  3483. iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
  3484. iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
  3485. iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
  3486. iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
  3487. iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
  3488. iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
  3489. iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
  3490. iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
  3491. iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
  3492. iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
  3493. iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
  3494. iscsi_session_attr(chap_out_idx, ISCSI_PARAM_CHAP_OUT_IDX, 1);
  3495. iscsi_session_attr(chap_in_idx, ISCSI_PARAM_CHAP_IN_IDX, 1);
  3496. iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
  3497. iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
  3498. iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
  3499. iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0);
  3500. iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
  3501. iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0);
  3502. iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0);
  3503. iscsi_session_attr(boot_root, ISCSI_PARAM_BOOT_ROOT, 0);
  3504. iscsi_session_attr(boot_nic, ISCSI_PARAM_BOOT_NIC, 0);
  3505. iscsi_session_attr(boot_target, ISCSI_PARAM_BOOT_TARGET, 0);
  3506. iscsi_session_attr(auto_snd_tgt_disable, ISCSI_PARAM_AUTO_SND_TGT_DISABLE, 0);
  3507. iscsi_session_attr(discovery_session, ISCSI_PARAM_DISCOVERY_SESS, 0);
  3508. iscsi_session_attr(portal_type, ISCSI_PARAM_PORTAL_TYPE, 0);
  3509. iscsi_session_attr(chap_auth, ISCSI_PARAM_CHAP_AUTH_EN, 0);
  3510. iscsi_session_attr(discovery_logout, ISCSI_PARAM_DISCOVERY_LOGOUT_EN, 0);
  3511. iscsi_session_attr(bidi_chap, ISCSI_PARAM_BIDI_CHAP_EN, 0);
  3512. iscsi_session_attr(discovery_auth_optional,
  3513. ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL, 0);
  3514. iscsi_session_attr(def_time2wait, ISCSI_PARAM_DEF_TIME2WAIT, 0);
  3515. iscsi_session_attr(def_time2retain, ISCSI_PARAM_DEF_TIME2RETAIN, 0);
  3516. iscsi_session_attr(isid, ISCSI_PARAM_ISID, 0);
  3517. iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0);
  3518. iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0);
  3519. iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0);
  3520. iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0);
  3521. static ssize_t
  3522. show_priv_session_state(struct device *dev, struct device_attribute *attr,
  3523. char *buf)
  3524. {
  3525. struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
  3526. return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
  3527. }
  3528. static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
  3529. NULL);
  3530. static ssize_t
  3531. show_priv_session_creator(struct device *dev, struct device_attribute *attr,
  3532. char *buf)
  3533. {
  3534. struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
  3535. return sprintf(buf, "%d\n", session->creator);
  3536. }
  3537. static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
  3538. NULL);
  3539. static ssize_t
  3540. show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
  3541. char *buf)
  3542. {
  3543. struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
  3544. return sprintf(buf, "%d\n", session->target_id);
  3545. }
  3546. static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
  3547. show_priv_session_target_id, NULL);
  3548. #define iscsi_priv_session_attr_show(field, format) \
  3549. static ssize_t \
  3550. show_priv_session_##field(struct device *dev, \
  3551. struct device_attribute *attr, char *buf) \
  3552. { \
  3553. struct iscsi_cls_session *session = \
  3554. iscsi_dev_to_session(dev->parent); \
  3555. if (session->field == -1) \
  3556. return sprintf(buf, "off\n"); \
  3557. return sprintf(buf, format"\n", session->field); \
  3558. }
  3559. #define iscsi_priv_session_attr_store(field) \
  3560. static ssize_t \
  3561. store_priv_session_##field(struct device *dev, \
  3562. struct device_attribute *attr, \
  3563. const char *buf, size_t count) \
  3564. { \
  3565. int val; \
  3566. char *cp; \
  3567. struct iscsi_cls_session *session = \
  3568. iscsi_dev_to_session(dev->parent); \
  3569. if ((session->state == ISCSI_SESSION_FREE) || \
  3570. (session->state == ISCSI_SESSION_FAILED)) \
  3571. return -EBUSY; \
  3572. if (strncmp(buf, "off", 3) == 0) { \
  3573. session->field = -1; \
  3574. session->field##_sysfs_override = true; \
  3575. } else { \
  3576. val = simple_strtoul(buf, &cp, 0); \
  3577. if (*cp != '\0' && *cp != '\n') \
  3578. return -EINVAL; \
  3579. session->field = val; \
  3580. session->field##_sysfs_override = true; \
  3581. } \
  3582. return count; \
  3583. }
  3584. #define iscsi_priv_session_rw_attr(field, format) \
  3585. iscsi_priv_session_attr_show(field, format) \
  3586. iscsi_priv_session_attr_store(field) \
  3587. static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
  3588. show_priv_session_##field, \
  3589. store_priv_session_##field)
  3590. iscsi_priv_session_rw_attr(recovery_tmo, "%d");
  3591. static struct attribute *iscsi_session_attrs[] = {
  3592. &dev_attr_sess_initial_r2t.attr,
  3593. &dev_attr_sess_max_outstanding_r2t.attr,
  3594. &dev_attr_sess_immediate_data.attr,
  3595. &dev_attr_sess_first_burst_len.attr,
  3596. &dev_attr_sess_max_burst_len.attr,
  3597. &dev_attr_sess_data_pdu_in_order.attr,
  3598. &dev_attr_sess_data_seq_in_order.attr,
  3599. &dev_attr_sess_erl.attr,
  3600. &dev_attr_sess_targetname.attr,
  3601. &dev_attr_sess_tpgt.attr,
  3602. &dev_attr_sess_password.attr,
  3603. &dev_attr_sess_password_in.attr,
  3604. &dev_attr_sess_username.attr,
  3605. &dev_attr_sess_username_in.attr,
  3606. &dev_attr_sess_fast_abort.attr,
  3607. &dev_attr_sess_abort_tmo.attr,
  3608. &dev_attr_sess_lu_reset_tmo.attr,
  3609. &dev_attr_sess_tgt_reset_tmo.attr,
  3610. &dev_attr_sess_ifacename.attr,
  3611. &dev_attr_sess_initiatorname.attr,
  3612. &dev_attr_sess_targetalias.attr,
  3613. &dev_attr_sess_boot_root.attr,
  3614. &dev_attr_sess_boot_nic.attr,
  3615. &dev_attr_sess_boot_target.attr,
  3616. &dev_attr_priv_sess_recovery_tmo.attr,
  3617. &dev_attr_priv_sess_state.attr,
  3618. &dev_attr_priv_sess_creator.attr,
  3619. &dev_attr_sess_chap_out_idx.attr,
  3620. &dev_attr_sess_chap_in_idx.attr,
  3621. &dev_attr_priv_sess_target_id.attr,
  3622. &dev_attr_sess_auto_snd_tgt_disable.attr,
  3623. &dev_attr_sess_discovery_session.attr,
  3624. &dev_attr_sess_portal_type.attr,
  3625. &dev_attr_sess_chap_auth.attr,
  3626. &dev_attr_sess_discovery_logout.attr,
  3627. &dev_attr_sess_bidi_chap.attr,
  3628. &dev_attr_sess_discovery_auth_optional.attr,
  3629. &dev_attr_sess_def_time2wait.attr,
  3630. &dev_attr_sess_def_time2retain.attr,
  3631. &dev_attr_sess_isid.attr,
  3632. &dev_attr_sess_tsid.attr,
  3633. &dev_attr_sess_def_taskmgmt_tmo.attr,
  3634. &dev_attr_sess_discovery_parent_idx.attr,
  3635. &dev_attr_sess_discovery_parent_type.attr,
  3636. NULL,
  3637. };
  3638. static umode_t iscsi_session_attr_is_visible(struct kobject *kobj,
  3639. struct attribute *attr, int i)
  3640. {
  3641. struct device *cdev = container_of(kobj, struct device, kobj);
  3642. struct iscsi_cls_session *session = transport_class_to_session(cdev);
  3643. struct iscsi_transport *t = session->transport;
  3644. int param;
  3645. if (attr == &dev_attr_sess_initial_r2t.attr)
  3646. param = ISCSI_PARAM_INITIAL_R2T_EN;
  3647. else if (attr == &dev_attr_sess_max_outstanding_r2t.attr)
  3648. param = ISCSI_PARAM_MAX_R2T;
  3649. else if (attr == &dev_attr_sess_immediate_data.attr)
  3650. param = ISCSI_PARAM_IMM_DATA_EN;
  3651. else if (attr == &dev_attr_sess_first_burst_len.attr)
  3652. param = ISCSI_PARAM_FIRST_BURST;
  3653. else if (attr == &dev_attr_sess_max_burst_len.attr)
  3654. param = ISCSI_PARAM_MAX_BURST;
  3655. else if (attr == &dev_attr_sess_data_pdu_in_order.attr)
  3656. param = ISCSI_PARAM_PDU_INORDER_EN;
  3657. else if (attr == &dev_attr_sess_data_seq_in_order.attr)
  3658. param = ISCSI_PARAM_DATASEQ_INORDER_EN;
  3659. else if (attr == &dev_attr_sess_erl.attr)
  3660. param = ISCSI_PARAM_ERL;
  3661. else if (attr == &dev_attr_sess_targetname.attr)
  3662. param = ISCSI_PARAM_TARGET_NAME;
  3663. else if (attr == &dev_attr_sess_tpgt.attr)
  3664. param = ISCSI_PARAM_TPGT;
  3665. else if (attr == &dev_attr_sess_chap_in_idx.attr)
  3666. param = ISCSI_PARAM_CHAP_IN_IDX;
  3667. else if (attr == &dev_attr_sess_chap_out_idx.attr)
  3668. param = ISCSI_PARAM_CHAP_OUT_IDX;
  3669. else if (attr == &dev_attr_sess_password.attr)
  3670. param = ISCSI_PARAM_USERNAME;
  3671. else if (attr == &dev_attr_sess_password_in.attr)
  3672. param = ISCSI_PARAM_USERNAME_IN;
  3673. else if (attr == &dev_attr_sess_username.attr)
  3674. param = ISCSI_PARAM_PASSWORD;
  3675. else if (attr == &dev_attr_sess_username_in.attr)
  3676. param = ISCSI_PARAM_PASSWORD_IN;
  3677. else if (attr == &dev_attr_sess_fast_abort.attr)
  3678. param = ISCSI_PARAM_FAST_ABORT;
  3679. else if (attr == &dev_attr_sess_abort_tmo.attr)
  3680. param = ISCSI_PARAM_ABORT_TMO;
  3681. else if (attr == &dev_attr_sess_lu_reset_tmo.attr)
  3682. param = ISCSI_PARAM_LU_RESET_TMO;
  3683. else if (attr == &dev_attr_sess_tgt_reset_tmo.attr)
  3684. param = ISCSI_PARAM_TGT_RESET_TMO;
  3685. else if (attr == &dev_attr_sess_ifacename.attr)
  3686. param = ISCSI_PARAM_IFACE_NAME;
  3687. else if (attr == &dev_attr_sess_initiatorname.attr)
  3688. param = ISCSI_PARAM_INITIATOR_NAME;
  3689. else if (attr == &dev_attr_sess_targetalias.attr)
  3690. param = ISCSI_PARAM_TARGET_ALIAS;
  3691. else if (attr == &dev_attr_sess_boot_root.attr)
  3692. param = ISCSI_PARAM_BOOT_ROOT;
  3693. else if (attr == &dev_attr_sess_boot_nic.attr)
  3694. param = ISCSI_PARAM_BOOT_NIC;
  3695. else if (attr == &dev_attr_sess_boot_target.attr)
  3696. param = ISCSI_PARAM_BOOT_TARGET;
  3697. else if (attr == &dev_attr_sess_auto_snd_tgt_disable.attr)
  3698. param = ISCSI_PARAM_AUTO_SND_TGT_DISABLE;
  3699. else if (attr == &dev_attr_sess_discovery_session.attr)
  3700. param = ISCSI_PARAM_DISCOVERY_SESS;
  3701. else if (attr == &dev_attr_sess_portal_type.attr)
  3702. param = ISCSI_PARAM_PORTAL_TYPE;
  3703. else if (attr == &dev_attr_sess_chap_auth.attr)
  3704. param = ISCSI_PARAM_CHAP_AUTH_EN;
  3705. else if (attr == &dev_attr_sess_discovery_logout.attr)
  3706. param = ISCSI_PARAM_DISCOVERY_LOGOUT_EN;
  3707. else if (attr == &dev_attr_sess_bidi_chap.attr)
  3708. param = ISCSI_PARAM_BIDI_CHAP_EN;
  3709. else if (attr == &dev_attr_sess_discovery_auth_optional.attr)
  3710. param = ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL;
  3711. else if (attr == &dev_attr_sess_def_time2wait.attr)
  3712. param = ISCSI_PARAM_DEF_TIME2WAIT;
  3713. else if (attr == &dev_attr_sess_def_time2retain.attr)
  3714. param = ISCSI_PARAM_DEF_TIME2RETAIN;
  3715. else if (attr == &dev_attr_sess_isid.attr)
  3716. param = ISCSI_PARAM_ISID;
  3717. else if (attr == &dev_attr_sess_tsid.attr)
  3718. param = ISCSI_PARAM_TSID;
  3719. else if (attr == &dev_attr_sess_def_taskmgmt_tmo.attr)
  3720. param = ISCSI_PARAM_DEF_TASKMGMT_TMO;
  3721. else if (attr == &dev_attr_sess_discovery_parent_idx.attr)
  3722. param = ISCSI_PARAM_DISCOVERY_PARENT_IDX;
  3723. else if (attr == &dev_attr_sess_discovery_parent_type.attr)
  3724. param = ISCSI_PARAM_DISCOVERY_PARENT_TYPE;
  3725. else if (attr == &dev_attr_priv_sess_recovery_tmo.attr)
  3726. return S_IRUGO | S_IWUSR;
  3727. else if (attr == &dev_attr_priv_sess_state.attr)
  3728. return S_IRUGO;
  3729. else if (attr == &dev_attr_priv_sess_creator.attr)
  3730. return S_IRUGO;
  3731. else if (attr == &dev_attr_priv_sess_target_id.attr)
  3732. return S_IRUGO;
  3733. else {
  3734. WARN_ONCE(1, "Invalid session attr");
  3735. return 0;
  3736. }
  3737. return t->attr_is_visible(ISCSI_PARAM, param);
  3738. }
  3739. static struct attribute_group iscsi_session_group = {
  3740. .attrs = iscsi_session_attrs,
  3741. .is_visible = iscsi_session_attr_is_visible,
  3742. };
  3743. /*
  3744. * iSCSI host attrs
  3745. */
  3746. #define iscsi_host_attr_show(param) \
  3747. static ssize_t \
  3748. show_host_param_##param(struct device *dev, \
  3749. struct device_attribute *attr, char *buf) \
  3750. { \
  3751. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  3752. struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
  3753. return priv->iscsi_transport->get_host_param(shost, param, buf); \
  3754. }
  3755. #define iscsi_host_attr(field, param) \
  3756. iscsi_host_attr_show(param) \
  3757. static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
  3758. NULL);
  3759. iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
  3760. iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
  3761. iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
  3762. iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
  3763. iscsi_host_attr(port_state, ISCSI_HOST_PARAM_PORT_STATE);
  3764. iscsi_host_attr(port_speed, ISCSI_HOST_PARAM_PORT_SPEED);
  3765. static struct attribute *iscsi_host_attrs[] = {
  3766. &dev_attr_host_netdev.attr,
  3767. &dev_attr_host_hwaddress.attr,
  3768. &dev_attr_host_ipaddress.attr,
  3769. &dev_attr_host_initiatorname.attr,
  3770. &dev_attr_host_port_state.attr,
  3771. &dev_attr_host_port_speed.attr,
  3772. NULL,
  3773. };
  3774. static umode_t iscsi_host_attr_is_visible(struct kobject *kobj,
  3775. struct attribute *attr, int i)
  3776. {
  3777. struct device *cdev = container_of(kobj, struct device, kobj);
  3778. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  3779. struct iscsi_internal *priv = to_iscsi_internal(shost->transportt);
  3780. int param;
  3781. if (attr == &dev_attr_host_netdev.attr)
  3782. param = ISCSI_HOST_PARAM_NETDEV_NAME;
  3783. else if (attr == &dev_attr_host_hwaddress.attr)
  3784. param = ISCSI_HOST_PARAM_HWADDRESS;
  3785. else if (attr == &dev_attr_host_ipaddress.attr)
  3786. param = ISCSI_HOST_PARAM_IPADDRESS;
  3787. else if (attr == &dev_attr_host_initiatorname.attr)
  3788. param = ISCSI_HOST_PARAM_INITIATOR_NAME;
  3789. else if (attr == &dev_attr_host_port_state.attr)
  3790. param = ISCSI_HOST_PARAM_PORT_STATE;
  3791. else if (attr == &dev_attr_host_port_speed.attr)
  3792. param = ISCSI_HOST_PARAM_PORT_SPEED;
  3793. else {
  3794. WARN_ONCE(1, "Invalid host attr");
  3795. return 0;
  3796. }
  3797. return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param);
  3798. }
  3799. static struct attribute_group iscsi_host_group = {
  3800. .attrs = iscsi_host_attrs,
  3801. .is_visible = iscsi_host_attr_is_visible,
  3802. };
  3803. /* convert iscsi_port_speed values to ascii string name */
  3804. static const struct {
  3805. enum iscsi_port_speed value;
  3806. char *name;
  3807. } iscsi_port_speed_names[] = {
  3808. {ISCSI_PORT_SPEED_UNKNOWN, "Unknown" },
  3809. {ISCSI_PORT_SPEED_10MBPS, "10 Mbps" },
  3810. {ISCSI_PORT_SPEED_100MBPS, "100 Mbps" },
  3811. {ISCSI_PORT_SPEED_1GBPS, "1 Gbps" },
  3812. {ISCSI_PORT_SPEED_10GBPS, "10 Gbps" },
  3813. {ISCSI_PORT_SPEED_25GBPS, "25 Gbps" },
  3814. {ISCSI_PORT_SPEED_40GBPS, "40 Gbps" },
  3815. };
  3816. char *iscsi_get_port_speed_name(struct Scsi_Host *shost)
  3817. {
  3818. int i;
  3819. char *speed = "Unknown!";
  3820. struct iscsi_cls_host *ihost = shost->shost_data;
  3821. uint32_t port_speed = ihost->port_speed;
  3822. for (i = 0; i < ARRAY_SIZE(iscsi_port_speed_names); i++) {
  3823. if (iscsi_port_speed_names[i].value & port_speed) {
  3824. speed = iscsi_port_speed_names[i].name;
  3825. break;
  3826. }
  3827. }
  3828. return speed;
  3829. }
  3830. EXPORT_SYMBOL_GPL(iscsi_get_port_speed_name);
  3831. /* convert iscsi_port_state values to ascii string name */
  3832. static const struct {
  3833. enum iscsi_port_state value;
  3834. char *name;
  3835. } iscsi_port_state_names[] = {
  3836. {ISCSI_PORT_STATE_DOWN, "LINK DOWN" },
  3837. {ISCSI_PORT_STATE_UP, "LINK UP" },
  3838. };
  3839. char *iscsi_get_port_state_name(struct Scsi_Host *shost)
  3840. {
  3841. int i;
  3842. char *state = "Unknown!";
  3843. struct iscsi_cls_host *ihost = shost->shost_data;
  3844. uint32_t port_state = ihost->port_state;
  3845. for (i = 0; i < ARRAY_SIZE(iscsi_port_state_names); i++) {
  3846. if (iscsi_port_state_names[i].value & port_state) {
  3847. state = iscsi_port_state_names[i].name;
  3848. break;
  3849. }
  3850. }
  3851. return state;
  3852. }
  3853. EXPORT_SYMBOL_GPL(iscsi_get_port_state_name);
  3854. static int iscsi_session_match(struct attribute_container *cont,
  3855. struct device *dev)
  3856. {
  3857. struct iscsi_cls_session *session;
  3858. struct Scsi_Host *shost;
  3859. struct iscsi_internal *priv;
  3860. if (!iscsi_is_session_dev(dev))
  3861. return 0;
  3862. session = iscsi_dev_to_session(dev);
  3863. shost = iscsi_session_to_shost(session);
  3864. if (!shost->transportt)
  3865. return 0;
  3866. priv = to_iscsi_internal(shost->transportt);
  3867. if (priv->session_cont.ac.class != &iscsi_session_class.class)
  3868. return 0;
  3869. return &priv->session_cont.ac == cont;
  3870. }
  3871. static int iscsi_conn_match(struct attribute_container *cont,
  3872. struct device *dev)
  3873. {
  3874. struct iscsi_cls_session *session;
  3875. struct iscsi_cls_conn *conn;
  3876. struct Scsi_Host *shost;
  3877. struct iscsi_internal *priv;
  3878. if (!iscsi_is_conn_dev(dev))
  3879. return 0;
  3880. conn = iscsi_dev_to_conn(dev);
  3881. session = iscsi_dev_to_session(conn->dev.parent);
  3882. shost = iscsi_session_to_shost(session);
  3883. if (!shost->transportt)
  3884. return 0;
  3885. priv = to_iscsi_internal(shost->transportt);
  3886. if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
  3887. return 0;
  3888. return &priv->conn_cont.ac == cont;
  3889. }
  3890. static int iscsi_host_match(struct attribute_container *cont,
  3891. struct device *dev)
  3892. {
  3893. struct Scsi_Host *shost;
  3894. struct iscsi_internal *priv;
  3895. if (!scsi_is_host_device(dev))
  3896. return 0;
  3897. shost = dev_to_shost(dev);
  3898. if (!shost->transportt ||
  3899. shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
  3900. return 0;
  3901. priv = to_iscsi_internal(shost->transportt);
  3902. return &priv->t.host_attrs.ac == cont;
  3903. }
  3904. struct scsi_transport_template *
  3905. iscsi_register_transport(struct iscsi_transport *tt)
  3906. {
  3907. struct iscsi_internal *priv;
  3908. unsigned long flags;
  3909. int err;
  3910. BUG_ON(!tt);
  3911. priv = iscsi_if_transport_lookup(tt);
  3912. if (priv)
  3913. return NULL;
  3914. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  3915. if (!priv)
  3916. return NULL;
  3917. INIT_LIST_HEAD(&priv->list);
  3918. priv->iscsi_transport = tt;
  3919. priv->t.user_scan = iscsi_user_scan;
  3920. priv->t.create_work_queue = 1;
  3921. priv->dev.class = &iscsi_transport_class;
  3922. dev_set_name(&priv->dev, "%s", tt->name);
  3923. err = device_register(&priv->dev);
  3924. if (err)
  3925. goto free_priv;
  3926. err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
  3927. if (err)
  3928. goto unregister_dev;
  3929. /* host parameters */
  3930. priv->t.host_attrs.ac.class = &iscsi_host_class.class;
  3931. priv->t.host_attrs.ac.match = iscsi_host_match;
  3932. priv->t.host_attrs.ac.grp = &iscsi_host_group;
  3933. priv->t.host_size = sizeof(struct iscsi_cls_host);
  3934. transport_container_register(&priv->t.host_attrs);
  3935. /* connection parameters */
  3936. priv->conn_cont.ac.class = &iscsi_connection_class.class;
  3937. priv->conn_cont.ac.match = iscsi_conn_match;
  3938. priv->conn_cont.ac.grp = &iscsi_conn_group;
  3939. transport_container_register(&priv->conn_cont);
  3940. /* session parameters */
  3941. priv->session_cont.ac.class = &iscsi_session_class.class;
  3942. priv->session_cont.ac.match = iscsi_session_match;
  3943. priv->session_cont.ac.grp = &iscsi_session_group;
  3944. transport_container_register(&priv->session_cont);
  3945. spin_lock_irqsave(&iscsi_transport_lock, flags);
  3946. list_add(&priv->list, &iscsi_transports);
  3947. spin_unlock_irqrestore(&iscsi_transport_lock, flags);
  3948. printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
  3949. return &priv->t;
  3950. unregister_dev:
  3951. device_unregister(&priv->dev);
  3952. return NULL;
  3953. free_priv:
  3954. kfree(priv);
  3955. return NULL;
  3956. }
  3957. EXPORT_SYMBOL_GPL(iscsi_register_transport);
  3958. int iscsi_unregister_transport(struct iscsi_transport *tt)
  3959. {
  3960. struct iscsi_internal *priv;
  3961. unsigned long flags;
  3962. BUG_ON(!tt);
  3963. mutex_lock(&rx_queue_mutex);
  3964. priv = iscsi_if_transport_lookup(tt);
  3965. BUG_ON (!priv);
  3966. spin_lock_irqsave(&iscsi_transport_lock, flags);
  3967. list_del(&priv->list);
  3968. spin_unlock_irqrestore(&iscsi_transport_lock, flags);
  3969. transport_container_unregister(&priv->conn_cont);
  3970. transport_container_unregister(&priv->session_cont);
  3971. transport_container_unregister(&priv->t.host_attrs);
  3972. sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
  3973. device_unregister(&priv->dev);
  3974. mutex_unlock(&rx_queue_mutex);
  3975. return 0;
  3976. }
  3977. EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
  3978. static __init int iscsi_transport_init(void)
  3979. {
  3980. int err;
  3981. struct netlink_kernel_cfg cfg = {
  3982. .groups = 1,
  3983. .input = iscsi_if_rx,
  3984. };
  3985. printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
  3986. ISCSI_TRANSPORT_VERSION);
  3987. atomic_set(&iscsi_session_nr, 0);
  3988. err = class_register(&iscsi_transport_class);
  3989. if (err)
  3990. return err;
  3991. err = class_register(&iscsi_endpoint_class);
  3992. if (err)
  3993. goto unregister_transport_class;
  3994. err = class_register(&iscsi_iface_class);
  3995. if (err)
  3996. goto unregister_endpoint_class;
  3997. err = transport_class_register(&iscsi_host_class);
  3998. if (err)
  3999. goto unregister_iface_class;
  4000. err = transport_class_register(&iscsi_connection_class);
  4001. if (err)
  4002. goto unregister_host_class;
  4003. err = transport_class_register(&iscsi_session_class);
  4004. if (err)
  4005. goto unregister_conn_class;
  4006. err = bus_register(&iscsi_flashnode_bus);
  4007. if (err)
  4008. goto unregister_session_class;
  4009. nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, &cfg);
  4010. if (!nls) {
  4011. err = -ENOBUFS;
  4012. goto unregister_flashnode_bus;
  4013. }
  4014. iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh");
  4015. if (!iscsi_eh_timer_workq) {
  4016. err = -ENOMEM;
  4017. goto release_nls;
  4018. }
  4019. return 0;
  4020. release_nls:
  4021. netlink_kernel_release(nls);
  4022. unregister_flashnode_bus:
  4023. bus_unregister(&iscsi_flashnode_bus);
  4024. unregister_session_class:
  4025. transport_class_unregister(&iscsi_session_class);
  4026. unregister_conn_class:
  4027. transport_class_unregister(&iscsi_connection_class);
  4028. unregister_host_class:
  4029. transport_class_unregister(&iscsi_host_class);
  4030. unregister_iface_class:
  4031. class_unregister(&iscsi_iface_class);
  4032. unregister_endpoint_class:
  4033. class_unregister(&iscsi_endpoint_class);
  4034. unregister_transport_class:
  4035. class_unregister(&iscsi_transport_class);
  4036. return err;
  4037. }
  4038. static void __exit iscsi_transport_exit(void)
  4039. {
  4040. destroy_workqueue(iscsi_eh_timer_workq);
  4041. netlink_kernel_release(nls);
  4042. bus_unregister(&iscsi_flashnode_bus);
  4043. transport_class_unregister(&iscsi_connection_class);
  4044. transport_class_unregister(&iscsi_session_class);
  4045. transport_class_unregister(&iscsi_host_class);
  4046. class_unregister(&iscsi_endpoint_class);
  4047. class_unregister(&iscsi_iface_class);
  4048. class_unregister(&iscsi_transport_class);
  4049. }
  4050. module_init(iscsi_transport_init);
  4051. module_exit(iscsi_transport_exit);
  4052. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
  4053. "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
  4054. "Alex Aizman <itn780@yahoo.com>");
  4055. MODULE_DESCRIPTION("iSCSI Transport Interface");
  4056. MODULE_LICENSE("GPL");
  4057. MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
  4058. MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI);