bfad_bsg.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595
  1. /*
  2. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  3. * Copyright (c) 2014- QLogic Corporation.
  4. * All rights reserved
  5. * www.qlogic.com
  6. *
  7. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License (GPL) Version 2 as
  11. * published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #include <linux/uaccess.h>
  19. #include "bfad_drv.h"
  20. #include "bfad_im.h"
  21. #include "bfad_bsg.h"
  22. BFA_TRC_FILE(LDRV, BSG);
  23. int
  24. bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd)
  25. {
  26. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  27. unsigned long flags;
  28. spin_lock_irqsave(&bfad->bfad_lock, flags);
  29. /* If IOC is not in disabled state - return */
  30. if (!bfa_ioc_is_disabled(&bfad->bfa.ioc)) {
  31. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  32. iocmd->status = BFA_STATUS_OK;
  33. return 0;
  34. }
  35. init_completion(&bfad->enable_comp);
  36. bfa_iocfc_enable(&bfad->bfa);
  37. iocmd->status = BFA_STATUS_OK;
  38. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  39. wait_for_completion(&bfad->enable_comp);
  40. return 0;
  41. }
  42. int
  43. bfad_iocmd_ioc_disable(struct bfad_s *bfad, void *cmd)
  44. {
  45. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  46. unsigned long flags;
  47. spin_lock_irqsave(&bfad->bfad_lock, flags);
  48. if (bfa_ioc_is_disabled(&bfad->bfa.ioc)) {
  49. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  50. iocmd->status = BFA_STATUS_OK;
  51. return 0;
  52. }
  53. if (bfad->disable_active) {
  54. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  55. return -EBUSY;
  56. }
  57. bfad->disable_active = BFA_TRUE;
  58. init_completion(&bfad->disable_comp);
  59. bfa_iocfc_disable(&bfad->bfa);
  60. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  61. wait_for_completion(&bfad->disable_comp);
  62. bfad->disable_active = BFA_FALSE;
  63. iocmd->status = BFA_STATUS_OK;
  64. return 0;
  65. }
  66. static int
  67. bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd)
  68. {
  69. int i;
  70. struct bfa_bsg_ioc_info_s *iocmd = (struct bfa_bsg_ioc_info_s *)cmd;
  71. struct bfad_im_port_s *im_port;
  72. struct bfa_port_attr_s pattr;
  73. unsigned long flags;
  74. spin_lock_irqsave(&bfad->bfad_lock, flags);
  75. bfa_fcport_get_attr(&bfad->bfa, &pattr);
  76. iocmd->nwwn = pattr.nwwn;
  77. iocmd->pwwn = pattr.pwwn;
  78. iocmd->ioc_type = bfa_get_type(&bfad->bfa);
  79. iocmd->mac = bfa_get_mac(&bfad->bfa);
  80. iocmd->factory_mac = bfa_get_mfg_mac(&bfad->bfa);
  81. bfa_get_adapter_serial_num(&bfad->bfa, iocmd->serialnum);
  82. iocmd->factorynwwn = pattr.factorynwwn;
  83. iocmd->factorypwwn = pattr.factorypwwn;
  84. iocmd->bfad_num = bfad->inst_no;
  85. im_port = bfad->pport.im_port;
  86. iocmd->host = im_port->shost->host_no;
  87. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  88. strcpy(iocmd->name, bfad->adapter_name);
  89. strcpy(iocmd->port_name, bfad->port_name);
  90. strcpy(iocmd->hwpath, bfad->pci_name);
  91. /* set adapter hw path */
  92. strcpy(iocmd->adapter_hwpath, bfad->pci_name);
  93. for (i = 0; iocmd->adapter_hwpath[i] != ':' && i < BFA_STRING_32; i++)
  94. ;
  95. for (; iocmd->adapter_hwpath[++i] != ':' && i < BFA_STRING_32; )
  96. ;
  97. iocmd->adapter_hwpath[i] = '\0';
  98. iocmd->status = BFA_STATUS_OK;
  99. return 0;
  100. }
  101. static int
  102. bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd)
  103. {
  104. struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd;
  105. unsigned long flags;
  106. spin_lock_irqsave(&bfad->bfad_lock, flags);
  107. bfa_ioc_get_attr(&bfad->bfa.ioc, &iocmd->ioc_attr);
  108. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  109. /* fill in driver attr info */
  110. strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
  111. strlcpy(iocmd->ioc_attr.driver_attr.driver_ver,
  112. BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
  113. strcpy(iocmd->ioc_attr.driver_attr.fw_ver,
  114. iocmd->ioc_attr.adapter_attr.fw_ver);
  115. strcpy(iocmd->ioc_attr.driver_attr.bios_ver,
  116. iocmd->ioc_attr.adapter_attr.optrom_ver);
  117. /* copy chip rev info first otherwise it will be overwritten */
  118. memcpy(bfad->pci_attr.chip_rev, iocmd->ioc_attr.pci_attr.chip_rev,
  119. sizeof(bfad->pci_attr.chip_rev));
  120. memcpy(&iocmd->ioc_attr.pci_attr, &bfad->pci_attr,
  121. sizeof(struct bfa_ioc_pci_attr_s));
  122. iocmd->status = BFA_STATUS_OK;
  123. return 0;
  124. }
  125. int
  126. bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd)
  127. {
  128. struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd;
  129. bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats);
  130. iocmd->status = BFA_STATUS_OK;
  131. return 0;
  132. }
  133. int
  134. bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd,
  135. unsigned int payload_len)
  136. {
  137. struct bfa_bsg_ioc_fwstats_s *iocmd =
  138. (struct bfa_bsg_ioc_fwstats_s *)cmd;
  139. void *iocmd_bufptr;
  140. unsigned long flags;
  141. if (bfad_chk_iocmd_sz(payload_len,
  142. sizeof(struct bfa_bsg_ioc_fwstats_s),
  143. sizeof(struct bfa_fw_stats_s)) != BFA_STATUS_OK) {
  144. iocmd->status = BFA_STATUS_VERSION_FAIL;
  145. goto out;
  146. }
  147. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_ioc_fwstats_s);
  148. spin_lock_irqsave(&bfad->bfad_lock, flags);
  149. iocmd->status = bfa_ioc_fw_stats_get(&bfad->bfa.ioc, iocmd_bufptr);
  150. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  151. if (iocmd->status != BFA_STATUS_OK) {
  152. bfa_trc(bfad, iocmd->status);
  153. goto out;
  154. }
  155. out:
  156. bfa_trc(bfad, 0x6666);
  157. return 0;
  158. }
  159. int
  160. bfad_iocmd_ioc_reset_stats(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  161. {
  162. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  163. unsigned long flags;
  164. if (v_cmd == IOCMD_IOC_RESET_STATS) {
  165. bfa_ioc_clear_stats(&bfad->bfa);
  166. iocmd->status = BFA_STATUS_OK;
  167. } else if (v_cmd == IOCMD_IOC_RESET_FWSTATS) {
  168. spin_lock_irqsave(&bfad->bfad_lock, flags);
  169. iocmd->status = bfa_ioc_fw_stats_clear(&bfad->bfa.ioc);
  170. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  171. }
  172. return 0;
  173. }
  174. int
  175. bfad_iocmd_ioc_set_name(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  176. {
  177. struct bfa_bsg_ioc_name_s *iocmd = (struct bfa_bsg_ioc_name_s *) cmd;
  178. if (v_cmd == IOCMD_IOC_SET_ADAPTER_NAME)
  179. strcpy(bfad->adapter_name, iocmd->name);
  180. else if (v_cmd == IOCMD_IOC_SET_PORT_NAME)
  181. strcpy(bfad->port_name, iocmd->name);
  182. iocmd->status = BFA_STATUS_OK;
  183. return 0;
  184. }
  185. int
  186. bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd)
  187. {
  188. struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd;
  189. iocmd->status = BFA_STATUS_OK;
  190. bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr);
  191. return 0;
  192. }
  193. int
  194. bfad_iocmd_ioc_fw_sig_inv(struct bfad_s *bfad, void *cmd)
  195. {
  196. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  197. unsigned long flags;
  198. spin_lock_irqsave(&bfad->bfad_lock, flags);
  199. iocmd->status = bfa_ioc_fwsig_invalidate(&bfad->bfa.ioc);
  200. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  201. return 0;
  202. }
  203. int
  204. bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd)
  205. {
  206. struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd;
  207. unsigned long flags;
  208. spin_lock_irqsave(&bfad->bfad_lock, flags);
  209. iocmd->status = bfa_iocfc_israttr_set(&bfad->bfa, &iocmd->attr);
  210. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  211. return 0;
  212. }
  213. int
  214. bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd)
  215. {
  216. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  217. struct bfad_hal_comp fcomp;
  218. unsigned long flags;
  219. init_completion(&fcomp.comp);
  220. spin_lock_irqsave(&bfad->bfad_lock, flags);
  221. iocmd->status = bfa_port_enable(&bfad->bfa.modules.port,
  222. bfad_hcb_comp, &fcomp);
  223. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  224. if (iocmd->status != BFA_STATUS_OK) {
  225. bfa_trc(bfad, iocmd->status);
  226. return 0;
  227. }
  228. wait_for_completion(&fcomp.comp);
  229. iocmd->status = fcomp.status;
  230. return 0;
  231. }
  232. int
  233. bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd)
  234. {
  235. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  236. struct bfad_hal_comp fcomp;
  237. unsigned long flags;
  238. init_completion(&fcomp.comp);
  239. spin_lock_irqsave(&bfad->bfad_lock, flags);
  240. iocmd->status = bfa_port_disable(&bfad->bfa.modules.port,
  241. bfad_hcb_comp, &fcomp);
  242. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  243. if (iocmd->status != BFA_STATUS_OK) {
  244. bfa_trc(bfad, iocmd->status);
  245. return 0;
  246. }
  247. wait_for_completion(&fcomp.comp);
  248. iocmd->status = fcomp.status;
  249. return 0;
  250. }
  251. static int
  252. bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd)
  253. {
  254. struct bfa_bsg_port_attr_s *iocmd = (struct bfa_bsg_port_attr_s *)cmd;
  255. struct bfa_lport_attr_s port_attr;
  256. unsigned long flags;
  257. spin_lock_irqsave(&bfad->bfad_lock, flags);
  258. bfa_fcport_get_attr(&bfad->bfa, &iocmd->attr);
  259. bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
  260. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  261. if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE)
  262. iocmd->attr.pid = port_attr.pid;
  263. else
  264. iocmd->attr.pid = 0;
  265. iocmd->attr.port_type = port_attr.port_type;
  266. iocmd->attr.loopback = port_attr.loopback;
  267. iocmd->attr.authfail = port_attr.authfail;
  268. strlcpy(iocmd->attr.port_symname.symname,
  269. port_attr.port_cfg.sym_name.symname,
  270. sizeof(iocmd->attr.port_symname.symname));
  271. iocmd->status = BFA_STATUS_OK;
  272. return 0;
  273. }
  274. int
  275. bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd,
  276. unsigned int payload_len)
  277. {
  278. struct bfa_bsg_port_stats_s *iocmd = (struct bfa_bsg_port_stats_s *)cmd;
  279. struct bfad_hal_comp fcomp;
  280. void *iocmd_bufptr;
  281. unsigned long flags;
  282. if (bfad_chk_iocmd_sz(payload_len,
  283. sizeof(struct bfa_bsg_port_stats_s),
  284. sizeof(union bfa_port_stats_u)) != BFA_STATUS_OK) {
  285. iocmd->status = BFA_STATUS_VERSION_FAIL;
  286. return 0;
  287. }
  288. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s);
  289. init_completion(&fcomp.comp);
  290. spin_lock_irqsave(&bfad->bfad_lock, flags);
  291. iocmd->status = bfa_port_get_stats(&bfad->bfa.modules.port,
  292. iocmd_bufptr, bfad_hcb_comp, &fcomp);
  293. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  294. if (iocmd->status != BFA_STATUS_OK) {
  295. bfa_trc(bfad, iocmd->status);
  296. goto out;
  297. }
  298. wait_for_completion(&fcomp.comp);
  299. iocmd->status = fcomp.status;
  300. out:
  301. return 0;
  302. }
  303. int
  304. bfad_iocmd_port_reset_stats(struct bfad_s *bfad, void *cmd)
  305. {
  306. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  307. struct bfad_hal_comp fcomp;
  308. unsigned long flags;
  309. init_completion(&fcomp.comp);
  310. spin_lock_irqsave(&bfad->bfad_lock, flags);
  311. iocmd->status = bfa_port_clear_stats(&bfad->bfa.modules.port,
  312. bfad_hcb_comp, &fcomp);
  313. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  314. if (iocmd->status != BFA_STATUS_OK) {
  315. bfa_trc(bfad, iocmd->status);
  316. return 0;
  317. }
  318. wait_for_completion(&fcomp.comp);
  319. iocmd->status = fcomp.status;
  320. return 0;
  321. }
  322. int
  323. bfad_iocmd_set_port_cfg(struct bfad_s *bfad, void *iocmd, unsigned int v_cmd)
  324. {
  325. struct bfa_bsg_port_cfg_s *cmd = (struct bfa_bsg_port_cfg_s *)iocmd;
  326. unsigned long flags;
  327. spin_lock_irqsave(&bfad->bfad_lock, flags);
  328. if (v_cmd == IOCMD_PORT_CFG_TOPO)
  329. cmd->status = bfa_fcport_cfg_topology(&bfad->bfa, cmd->param);
  330. else if (v_cmd == IOCMD_PORT_CFG_SPEED)
  331. cmd->status = bfa_fcport_cfg_speed(&bfad->bfa, cmd->param);
  332. else if (v_cmd == IOCMD_PORT_CFG_ALPA)
  333. cmd->status = bfa_fcport_cfg_hardalpa(&bfad->bfa, cmd->param);
  334. else if (v_cmd == IOCMD_PORT_CLR_ALPA)
  335. cmd->status = bfa_fcport_clr_hardalpa(&bfad->bfa);
  336. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  337. return 0;
  338. }
  339. int
  340. bfad_iocmd_port_cfg_maxfrsize(struct bfad_s *bfad, void *cmd)
  341. {
  342. struct bfa_bsg_port_cfg_maxfrsize_s *iocmd =
  343. (struct bfa_bsg_port_cfg_maxfrsize_s *)cmd;
  344. unsigned long flags;
  345. spin_lock_irqsave(&bfad->bfad_lock, flags);
  346. iocmd->status = bfa_fcport_cfg_maxfrsize(&bfad->bfa, iocmd->maxfrsize);
  347. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  348. return 0;
  349. }
  350. int
  351. bfad_iocmd_port_cfg_bbcr(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
  352. {
  353. struct bfa_bsg_bbcr_enable_s *iocmd =
  354. (struct bfa_bsg_bbcr_enable_s *)pcmd;
  355. unsigned long flags;
  356. int rc;
  357. spin_lock_irqsave(&bfad->bfad_lock, flags);
  358. if (cmd == IOCMD_PORT_BBCR_ENABLE)
  359. rc = bfa_fcport_cfg_bbcr(&bfad->bfa, BFA_TRUE, iocmd->bb_scn);
  360. else if (cmd == IOCMD_PORT_BBCR_DISABLE)
  361. rc = bfa_fcport_cfg_bbcr(&bfad->bfa, BFA_FALSE, 0);
  362. else {
  363. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  364. return -EINVAL;
  365. }
  366. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  367. iocmd->status = rc;
  368. return 0;
  369. }
  370. int
  371. bfad_iocmd_port_get_bbcr_attr(struct bfad_s *bfad, void *pcmd)
  372. {
  373. struct bfa_bsg_bbcr_attr_s *iocmd = (struct bfa_bsg_bbcr_attr_s *) pcmd;
  374. unsigned long flags;
  375. spin_lock_irqsave(&bfad->bfad_lock, flags);
  376. iocmd->status =
  377. bfa_fcport_get_bbcr_attr(&bfad->bfa, &iocmd->attr);
  378. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  379. return 0;
  380. }
  381. static int
  382. bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd)
  383. {
  384. struct bfa_fcs_lport_s *fcs_port;
  385. struct bfa_bsg_lport_attr_s *iocmd = (struct bfa_bsg_lport_attr_s *)cmd;
  386. unsigned long flags;
  387. spin_lock_irqsave(&bfad->bfad_lock, flags);
  388. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  389. iocmd->vf_id, iocmd->pwwn);
  390. if (fcs_port == NULL) {
  391. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  392. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  393. goto out;
  394. }
  395. bfa_fcs_lport_get_attr(fcs_port, &iocmd->port_attr);
  396. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  397. iocmd->status = BFA_STATUS_OK;
  398. out:
  399. return 0;
  400. }
  401. int
  402. bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd)
  403. {
  404. struct bfa_fcs_lport_s *fcs_port;
  405. struct bfa_bsg_lport_stats_s *iocmd =
  406. (struct bfa_bsg_lport_stats_s *)cmd;
  407. unsigned long flags;
  408. spin_lock_irqsave(&bfad->bfad_lock, flags);
  409. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  410. iocmd->vf_id, iocmd->pwwn);
  411. if (fcs_port == NULL) {
  412. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  413. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  414. goto out;
  415. }
  416. bfa_fcs_lport_get_stats(fcs_port, &iocmd->port_stats);
  417. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  418. iocmd->status = BFA_STATUS_OK;
  419. out:
  420. return 0;
  421. }
  422. int
  423. bfad_iocmd_lport_reset_stats(struct bfad_s *bfad, void *cmd)
  424. {
  425. struct bfa_fcs_lport_s *fcs_port;
  426. struct bfa_bsg_reset_stats_s *iocmd =
  427. (struct bfa_bsg_reset_stats_s *)cmd;
  428. struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
  429. struct list_head *qe, *qen;
  430. struct bfa_itnim_s *itnim;
  431. unsigned long flags;
  432. spin_lock_irqsave(&bfad->bfad_lock, flags);
  433. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  434. iocmd->vf_id, iocmd->vpwwn);
  435. if (fcs_port == NULL) {
  436. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  437. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  438. goto out;
  439. }
  440. bfa_fcs_lport_clear_stats(fcs_port);
  441. /* clear IO stats from all active itnims */
  442. list_for_each_safe(qe, qen, &fcpim->itnim_q) {
  443. itnim = (struct bfa_itnim_s *) qe;
  444. if (itnim->rport->rport_info.lp_tag != fcs_port->lp_tag)
  445. continue;
  446. bfa_itnim_clear_stats(itnim);
  447. }
  448. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  449. iocmd->status = BFA_STATUS_OK;
  450. out:
  451. return 0;
  452. }
  453. int
  454. bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd)
  455. {
  456. struct bfa_fcs_lport_s *fcs_port;
  457. struct bfa_bsg_lport_iostats_s *iocmd =
  458. (struct bfa_bsg_lport_iostats_s *)cmd;
  459. unsigned long flags;
  460. spin_lock_irqsave(&bfad->bfad_lock, flags);
  461. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  462. iocmd->vf_id, iocmd->pwwn);
  463. if (fcs_port == NULL) {
  464. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  465. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  466. goto out;
  467. }
  468. bfa_fcpim_port_iostats(&bfad->bfa, &iocmd->iostats,
  469. fcs_port->lp_tag);
  470. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  471. iocmd->status = BFA_STATUS_OK;
  472. out:
  473. return 0;
  474. }
  475. int
  476. bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd,
  477. unsigned int payload_len)
  478. {
  479. struct bfa_bsg_lport_get_rports_s *iocmd =
  480. (struct bfa_bsg_lport_get_rports_s *)cmd;
  481. struct bfa_fcs_lport_s *fcs_port;
  482. unsigned long flags;
  483. void *iocmd_bufptr;
  484. if (iocmd->nrports == 0)
  485. return -EINVAL;
  486. if (bfad_chk_iocmd_sz(payload_len,
  487. sizeof(struct bfa_bsg_lport_get_rports_s),
  488. sizeof(struct bfa_rport_qualifier_s) * iocmd->nrports)
  489. != BFA_STATUS_OK) {
  490. iocmd->status = BFA_STATUS_VERSION_FAIL;
  491. return 0;
  492. }
  493. iocmd_bufptr = (char *)iocmd +
  494. sizeof(struct bfa_bsg_lport_get_rports_s);
  495. spin_lock_irqsave(&bfad->bfad_lock, flags);
  496. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  497. iocmd->vf_id, iocmd->pwwn);
  498. if (fcs_port == NULL) {
  499. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  500. bfa_trc(bfad, 0);
  501. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  502. goto out;
  503. }
  504. bfa_fcs_lport_get_rport_quals(fcs_port,
  505. (struct bfa_rport_qualifier_s *)iocmd_bufptr,
  506. &iocmd->nrports);
  507. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  508. iocmd->status = BFA_STATUS_OK;
  509. out:
  510. return 0;
  511. }
  512. int
  513. bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd)
  514. {
  515. struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd;
  516. struct bfa_fcs_lport_s *fcs_port;
  517. struct bfa_fcs_rport_s *fcs_rport;
  518. unsigned long flags;
  519. spin_lock_irqsave(&bfad->bfad_lock, flags);
  520. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  521. iocmd->vf_id, iocmd->pwwn);
  522. if (fcs_port == NULL) {
  523. bfa_trc(bfad, 0);
  524. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  525. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  526. goto out;
  527. }
  528. if (iocmd->pid)
  529. fcs_rport = bfa_fcs_lport_get_rport_by_qualifier(fcs_port,
  530. iocmd->rpwwn, iocmd->pid);
  531. else
  532. fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
  533. if (fcs_rport == NULL) {
  534. bfa_trc(bfad, 0);
  535. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  536. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  537. goto out;
  538. }
  539. bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr);
  540. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  541. iocmd->status = BFA_STATUS_OK;
  542. out:
  543. return 0;
  544. }
  545. static int
  546. bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd)
  547. {
  548. struct bfa_bsg_rport_scsi_addr_s *iocmd =
  549. (struct bfa_bsg_rport_scsi_addr_s *)cmd;
  550. struct bfa_fcs_lport_s *fcs_port;
  551. struct bfa_fcs_itnim_s *fcs_itnim;
  552. struct bfad_itnim_s *drv_itnim;
  553. unsigned long flags;
  554. spin_lock_irqsave(&bfad->bfad_lock, flags);
  555. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  556. iocmd->vf_id, iocmd->pwwn);
  557. if (fcs_port == NULL) {
  558. bfa_trc(bfad, 0);
  559. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  560. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  561. goto out;
  562. }
  563. fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  564. if (fcs_itnim == NULL) {
  565. bfa_trc(bfad, 0);
  566. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  567. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  568. goto out;
  569. }
  570. drv_itnim = fcs_itnim->itnim_drv;
  571. if (drv_itnim && drv_itnim->im_port)
  572. iocmd->host = drv_itnim->im_port->shost->host_no;
  573. else {
  574. bfa_trc(bfad, 0);
  575. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  576. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  577. goto out;
  578. }
  579. iocmd->target = drv_itnim->scsi_tgt_id;
  580. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  581. iocmd->bus = 0;
  582. iocmd->lun = 0;
  583. iocmd->status = BFA_STATUS_OK;
  584. out:
  585. return 0;
  586. }
  587. int
  588. bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd)
  589. {
  590. struct bfa_bsg_rport_stats_s *iocmd =
  591. (struct bfa_bsg_rport_stats_s *)cmd;
  592. struct bfa_fcs_lport_s *fcs_port;
  593. struct bfa_fcs_rport_s *fcs_rport;
  594. unsigned long flags;
  595. spin_lock_irqsave(&bfad->bfad_lock, flags);
  596. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  597. iocmd->vf_id, iocmd->pwwn);
  598. if (fcs_port == NULL) {
  599. bfa_trc(bfad, 0);
  600. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  601. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  602. goto out;
  603. }
  604. fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
  605. if (fcs_rport == NULL) {
  606. bfa_trc(bfad, 0);
  607. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  608. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  609. goto out;
  610. }
  611. memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats,
  612. sizeof(struct bfa_rport_stats_s));
  613. if (bfa_fcs_rport_get_halrport(fcs_rport)) {
  614. memcpy((void *)&iocmd->stats.hal_stats,
  615. (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats),
  616. sizeof(struct bfa_rport_hal_stats_s));
  617. }
  618. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  619. iocmd->status = BFA_STATUS_OK;
  620. out:
  621. return 0;
  622. }
  623. int
  624. bfad_iocmd_rport_clr_stats(struct bfad_s *bfad, void *cmd)
  625. {
  626. struct bfa_bsg_rport_reset_stats_s *iocmd =
  627. (struct bfa_bsg_rport_reset_stats_s *)cmd;
  628. struct bfa_fcs_lport_s *fcs_port;
  629. struct bfa_fcs_rport_s *fcs_rport;
  630. struct bfa_rport_s *rport;
  631. unsigned long flags;
  632. spin_lock_irqsave(&bfad->bfad_lock, flags);
  633. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  634. iocmd->vf_id, iocmd->pwwn);
  635. if (fcs_port == NULL) {
  636. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  637. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  638. goto out;
  639. }
  640. fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
  641. if (fcs_rport == NULL) {
  642. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  643. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  644. goto out;
  645. }
  646. memset((char *)&fcs_rport->stats, 0, sizeof(struct bfa_rport_stats_s));
  647. rport = bfa_fcs_rport_get_halrport(fcs_rport);
  648. if (rport)
  649. memset(&rport->stats, 0, sizeof(rport->stats));
  650. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  651. iocmd->status = BFA_STATUS_OK;
  652. out:
  653. return 0;
  654. }
  655. int
  656. bfad_iocmd_rport_set_speed(struct bfad_s *bfad, void *cmd)
  657. {
  658. struct bfa_bsg_rport_set_speed_s *iocmd =
  659. (struct bfa_bsg_rport_set_speed_s *)cmd;
  660. struct bfa_fcs_lport_s *fcs_port;
  661. struct bfa_fcs_rport_s *fcs_rport;
  662. unsigned long flags;
  663. spin_lock_irqsave(&bfad->bfad_lock, flags);
  664. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  665. iocmd->vf_id, iocmd->pwwn);
  666. if (fcs_port == NULL) {
  667. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  668. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  669. goto out;
  670. }
  671. fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
  672. if (fcs_rport == NULL) {
  673. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  674. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  675. goto out;
  676. }
  677. fcs_rport->rpf.assigned_speed = iocmd->speed;
  678. /* Set this speed in f/w only if the RPSC speed is not available */
  679. if (fcs_rport->rpf.rpsc_speed == BFA_PORT_SPEED_UNKNOWN)
  680. if (fcs_rport->bfa_rport)
  681. bfa_rport_speed(fcs_rport->bfa_rport, iocmd->speed);
  682. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  683. iocmd->status = BFA_STATUS_OK;
  684. out:
  685. return 0;
  686. }
  687. int
  688. bfad_iocmd_vport_get_attr(struct bfad_s *bfad, void *cmd)
  689. {
  690. struct bfa_fcs_vport_s *fcs_vport;
  691. struct bfa_bsg_vport_attr_s *iocmd = (struct bfa_bsg_vport_attr_s *)cmd;
  692. unsigned long flags;
  693. spin_lock_irqsave(&bfad->bfad_lock, flags);
  694. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
  695. iocmd->vf_id, iocmd->vpwwn);
  696. if (fcs_vport == NULL) {
  697. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  698. iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
  699. goto out;
  700. }
  701. bfa_fcs_vport_get_attr(fcs_vport, &iocmd->vport_attr);
  702. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  703. iocmd->status = BFA_STATUS_OK;
  704. out:
  705. return 0;
  706. }
  707. int
  708. bfad_iocmd_vport_get_stats(struct bfad_s *bfad, void *cmd)
  709. {
  710. struct bfa_fcs_vport_s *fcs_vport;
  711. struct bfa_bsg_vport_stats_s *iocmd =
  712. (struct bfa_bsg_vport_stats_s *)cmd;
  713. unsigned long flags;
  714. spin_lock_irqsave(&bfad->bfad_lock, flags);
  715. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
  716. iocmd->vf_id, iocmd->vpwwn);
  717. if (fcs_vport == NULL) {
  718. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  719. iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
  720. goto out;
  721. }
  722. memcpy((void *)&iocmd->vport_stats, (void *)&fcs_vport->vport_stats,
  723. sizeof(struct bfa_vport_stats_s));
  724. memcpy((void *)&iocmd->vport_stats.port_stats,
  725. (void *)&fcs_vport->lport.stats,
  726. sizeof(struct bfa_lport_stats_s));
  727. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  728. iocmd->status = BFA_STATUS_OK;
  729. out:
  730. return 0;
  731. }
  732. int
  733. bfad_iocmd_vport_clr_stats(struct bfad_s *bfad, void *cmd)
  734. {
  735. struct bfa_fcs_vport_s *fcs_vport;
  736. struct bfa_bsg_reset_stats_s *iocmd =
  737. (struct bfa_bsg_reset_stats_s *)cmd;
  738. unsigned long flags;
  739. spin_lock_irqsave(&bfad->bfad_lock, flags);
  740. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
  741. iocmd->vf_id, iocmd->vpwwn);
  742. if (fcs_vport == NULL) {
  743. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  744. iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
  745. goto out;
  746. }
  747. memset(&fcs_vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
  748. memset(&fcs_vport->lport.stats, 0, sizeof(struct bfa_lport_stats_s));
  749. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  750. iocmd->status = BFA_STATUS_OK;
  751. out:
  752. return 0;
  753. }
  754. static int
  755. bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
  756. unsigned int payload_len)
  757. {
  758. struct bfa_bsg_fabric_get_lports_s *iocmd =
  759. (struct bfa_bsg_fabric_get_lports_s *)cmd;
  760. bfa_fcs_vf_t *fcs_vf;
  761. uint32_t nports = iocmd->nports;
  762. unsigned long flags;
  763. void *iocmd_bufptr;
  764. if (nports == 0) {
  765. iocmd->status = BFA_STATUS_EINVAL;
  766. goto out;
  767. }
  768. if (bfad_chk_iocmd_sz(payload_len,
  769. sizeof(struct bfa_bsg_fabric_get_lports_s),
  770. sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
  771. iocmd->status = BFA_STATUS_VERSION_FAIL;
  772. goto out;
  773. }
  774. iocmd_bufptr = (char *)iocmd +
  775. sizeof(struct bfa_bsg_fabric_get_lports_s);
  776. spin_lock_irqsave(&bfad->bfad_lock, flags);
  777. fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
  778. if (fcs_vf == NULL) {
  779. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  780. iocmd->status = BFA_STATUS_UNKNOWN_VFID;
  781. goto out;
  782. }
  783. bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports);
  784. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  785. iocmd->nports = nports;
  786. iocmd->status = BFA_STATUS_OK;
  787. out:
  788. return 0;
  789. }
  790. int
  791. bfad_iocmd_qos_set_bw(struct bfad_s *bfad, void *pcmd)
  792. {
  793. struct bfa_bsg_qos_bw_s *iocmd = (struct bfa_bsg_qos_bw_s *)pcmd;
  794. unsigned long flags;
  795. spin_lock_irqsave(&bfad->bfad_lock, flags);
  796. iocmd->status = bfa_fcport_set_qos_bw(&bfad->bfa, &iocmd->qos_bw);
  797. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  798. return 0;
  799. }
  800. int
  801. bfad_iocmd_ratelim(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
  802. {
  803. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
  804. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  805. unsigned long flags;
  806. spin_lock_irqsave(&bfad->bfad_lock, flags);
  807. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  808. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  809. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  810. else {
  811. if (cmd == IOCMD_RATELIM_ENABLE)
  812. fcport->cfg.ratelimit = BFA_TRUE;
  813. else if (cmd == IOCMD_RATELIM_DISABLE)
  814. fcport->cfg.ratelimit = BFA_FALSE;
  815. if (fcport->cfg.trl_def_speed == BFA_PORT_SPEED_UNKNOWN)
  816. fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS;
  817. iocmd->status = BFA_STATUS_OK;
  818. }
  819. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  820. return 0;
  821. }
  822. int
  823. bfad_iocmd_ratelim_speed(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
  824. {
  825. struct bfa_bsg_trl_speed_s *iocmd = (struct bfa_bsg_trl_speed_s *)pcmd;
  826. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  827. unsigned long flags;
  828. spin_lock_irqsave(&bfad->bfad_lock, flags);
  829. /* Auto and speeds greater than the supported speed, are invalid */
  830. if ((iocmd->speed == BFA_PORT_SPEED_AUTO) ||
  831. (iocmd->speed > fcport->speed_sup)) {
  832. iocmd->status = BFA_STATUS_UNSUPP_SPEED;
  833. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  834. return 0;
  835. }
  836. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  837. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  838. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  839. else {
  840. fcport->cfg.trl_def_speed = iocmd->speed;
  841. iocmd->status = BFA_STATUS_OK;
  842. }
  843. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  844. return 0;
  845. }
  846. int
  847. bfad_iocmd_cfg_fcpim(struct bfad_s *bfad, void *cmd)
  848. {
  849. struct bfa_bsg_fcpim_s *iocmd = (struct bfa_bsg_fcpim_s *)cmd;
  850. unsigned long flags;
  851. spin_lock_irqsave(&bfad->bfad_lock, flags);
  852. bfa_fcpim_path_tov_set(&bfad->bfa, iocmd->param);
  853. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  854. iocmd->status = BFA_STATUS_OK;
  855. return 0;
  856. }
  857. int
  858. bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd)
  859. {
  860. struct bfa_bsg_fcpim_modstats_s *iocmd =
  861. (struct bfa_bsg_fcpim_modstats_s *)cmd;
  862. struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
  863. struct list_head *qe, *qen;
  864. struct bfa_itnim_s *itnim;
  865. unsigned long flags;
  866. spin_lock_irqsave(&bfad->bfad_lock, flags);
  867. /* accumulate IO stats from itnim */
  868. memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s));
  869. list_for_each_safe(qe, qen, &fcpim->itnim_q) {
  870. itnim = (struct bfa_itnim_s *) qe;
  871. bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats));
  872. }
  873. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  874. iocmd->status = BFA_STATUS_OK;
  875. return 0;
  876. }
  877. int
  878. bfad_iocmd_fcpim_clr_modstats(struct bfad_s *bfad, void *cmd)
  879. {
  880. struct bfa_bsg_fcpim_modstatsclr_s *iocmd =
  881. (struct bfa_bsg_fcpim_modstatsclr_s *)cmd;
  882. struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
  883. struct list_head *qe, *qen;
  884. struct bfa_itnim_s *itnim;
  885. unsigned long flags;
  886. spin_lock_irqsave(&bfad->bfad_lock, flags);
  887. list_for_each_safe(qe, qen, &fcpim->itnim_q) {
  888. itnim = (struct bfa_itnim_s *) qe;
  889. bfa_itnim_clear_stats(itnim);
  890. }
  891. memset(&fcpim->del_itn_stats, 0,
  892. sizeof(struct bfa_fcpim_del_itn_stats_s));
  893. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  894. iocmd->status = BFA_STATUS_OK;
  895. return 0;
  896. }
  897. int
  898. bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd)
  899. {
  900. struct bfa_bsg_fcpim_del_itn_stats_s *iocmd =
  901. (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd;
  902. struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
  903. unsigned long flags;
  904. spin_lock_irqsave(&bfad->bfad_lock, flags);
  905. memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats,
  906. sizeof(struct bfa_fcpim_del_itn_stats_s));
  907. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  908. iocmd->status = BFA_STATUS_OK;
  909. return 0;
  910. }
  911. static int
  912. bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd)
  913. {
  914. struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd;
  915. struct bfa_fcs_lport_s *fcs_port;
  916. unsigned long flags;
  917. spin_lock_irqsave(&bfad->bfad_lock, flags);
  918. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  919. iocmd->vf_id, iocmd->lpwwn);
  920. if (!fcs_port)
  921. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  922. else
  923. iocmd->status = bfa_fcs_itnim_attr_get(fcs_port,
  924. iocmd->rpwwn, &iocmd->attr);
  925. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  926. return 0;
  927. }
  928. static int
  929. bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd)
  930. {
  931. struct bfa_bsg_itnim_iostats_s *iocmd =
  932. (struct bfa_bsg_itnim_iostats_s *)cmd;
  933. struct bfa_fcs_lport_s *fcs_port;
  934. struct bfa_fcs_itnim_s *itnim;
  935. unsigned long flags;
  936. spin_lock_irqsave(&bfad->bfad_lock, flags);
  937. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  938. iocmd->vf_id, iocmd->lpwwn);
  939. if (!fcs_port) {
  940. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  941. bfa_trc(bfad, 0);
  942. } else {
  943. itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  944. if (itnim == NULL)
  945. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  946. else {
  947. iocmd->status = BFA_STATUS_OK;
  948. if (bfa_fcs_itnim_get_halitn(itnim))
  949. memcpy((void *)&iocmd->iostats, (void *)
  950. &(bfa_fcs_itnim_get_halitn(itnim)->stats),
  951. sizeof(struct bfa_itnim_iostats_s));
  952. }
  953. }
  954. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  955. return 0;
  956. }
  957. static int
  958. bfad_iocmd_itnim_reset_stats(struct bfad_s *bfad, void *cmd)
  959. {
  960. struct bfa_bsg_rport_reset_stats_s *iocmd =
  961. (struct bfa_bsg_rport_reset_stats_s *)cmd;
  962. struct bfa_fcs_lport_s *fcs_port;
  963. struct bfa_fcs_itnim_s *itnim;
  964. unsigned long flags;
  965. spin_lock_irqsave(&bfad->bfad_lock, flags);
  966. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  967. iocmd->vf_id, iocmd->pwwn);
  968. if (!fcs_port)
  969. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  970. else {
  971. itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  972. if (itnim == NULL)
  973. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  974. else {
  975. iocmd->status = BFA_STATUS_OK;
  976. bfa_fcs_itnim_stats_clear(fcs_port, iocmd->rpwwn);
  977. bfa_itnim_clear_stats(bfa_fcs_itnim_get_halitn(itnim));
  978. }
  979. }
  980. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  981. return 0;
  982. }
  983. static int
  984. bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd)
  985. {
  986. struct bfa_bsg_itnim_itnstats_s *iocmd =
  987. (struct bfa_bsg_itnim_itnstats_s *)cmd;
  988. struct bfa_fcs_lport_s *fcs_port;
  989. struct bfa_fcs_itnim_s *itnim;
  990. unsigned long flags;
  991. spin_lock_irqsave(&bfad->bfad_lock, flags);
  992. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  993. iocmd->vf_id, iocmd->lpwwn);
  994. if (!fcs_port) {
  995. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  996. bfa_trc(bfad, 0);
  997. } else {
  998. itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  999. if (itnim == NULL)
  1000. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  1001. else {
  1002. iocmd->status = BFA_STATUS_OK;
  1003. bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn,
  1004. &iocmd->itnstats);
  1005. }
  1006. }
  1007. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1008. return 0;
  1009. }
  1010. int
  1011. bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd)
  1012. {
  1013. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1014. unsigned long flags;
  1015. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1016. iocmd->status = bfa_fcport_enable(&bfad->bfa);
  1017. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1018. return 0;
  1019. }
  1020. int
  1021. bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd)
  1022. {
  1023. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1024. unsigned long flags;
  1025. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1026. iocmd->status = bfa_fcport_disable(&bfad->bfa);
  1027. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1028. return 0;
  1029. }
  1030. int
  1031. bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd)
  1032. {
  1033. struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd;
  1034. struct bfad_hal_comp fcomp;
  1035. unsigned long flags;
  1036. init_completion(&fcomp.comp);
  1037. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1038. iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk,
  1039. &iocmd->pcifn_cfg,
  1040. bfad_hcb_comp, &fcomp);
  1041. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1042. if (iocmd->status != BFA_STATUS_OK)
  1043. goto out;
  1044. wait_for_completion(&fcomp.comp);
  1045. iocmd->status = fcomp.status;
  1046. out:
  1047. return 0;
  1048. }
  1049. int
  1050. bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd)
  1051. {
  1052. struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
  1053. struct bfad_hal_comp fcomp;
  1054. unsigned long flags;
  1055. init_completion(&fcomp.comp);
  1056. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1057. iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk,
  1058. &iocmd->pcifn_id, iocmd->port,
  1059. iocmd->pcifn_class, iocmd->bw_min,
  1060. iocmd->bw_max, bfad_hcb_comp, &fcomp);
  1061. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1062. if (iocmd->status != BFA_STATUS_OK)
  1063. goto out;
  1064. wait_for_completion(&fcomp.comp);
  1065. iocmd->status = fcomp.status;
  1066. out:
  1067. return 0;
  1068. }
  1069. int
  1070. bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd)
  1071. {
  1072. struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
  1073. struct bfad_hal_comp fcomp;
  1074. unsigned long flags;
  1075. init_completion(&fcomp.comp);
  1076. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1077. iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk,
  1078. iocmd->pcifn_id,
  1079. bfad_hcb_comp, &fcomp);
  1080. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1081. if (iocmd->status != BFA_STATUS_OK)
  1082. goto out;
  1083. wait_for_completion(&fcomp.comp);
  1084. iocmd->status = fcomp.status;
  1085. out:
  1086. return 0;
  1087. }
  1088. int
  1089. bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd)
  1090. {
  1091. struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
  1092. struct bfad_hal_comp fcomp;
  1093. unsigned long flags;
  1094. init_completion(&fcomp.comp);
  1095. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1096. iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk,
  1097. iocmd->pcifn_id, iocmd->bw_min,
  1098. iocmd->bw_max, bfad_hcb_comp, &fcomp);
  1099. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1100. bfa_trc(bfad, iocmd->status);
  1101. if (iocmd->status != BFA_STATUS_OK)
  1102. goto out;
  1103. wait_for_completion(&fcomp.comp);
  1104. iocmd->status = fcomp.status;
  1105. bfa_trc(bfad, iocmd->status);
  1106. out:
  1107. return 0;
  1108. }
  1109. int
  1110. bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd)
  1111. {
  1112. struct bfa_bsg_adapter_cfg_mode_s *iocmd =
  1113. (struct bfa_bsg_adapter_cfg_mode_s *)cmd;
  1114. struct bfad_hal_comp fcomp;
  1115. unsigned long flags = 0;
  1116. init_completion(&fcomp.comp);
  1117. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1118. iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk,
  1119. iocmd->cfg.mode, iocmd->cfg.max_pf,
  1120. iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp);
  1121. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1122. if (iocmd->status != BFA_STATUS_OK)
  1123. goto out;
  1124. wait_for_completion(&fcomp.comp);
  1125. iocmd->status = fcomp.status;
  1126. out:
  1127. return 0;
  1128. }
  1129. int
  1130. bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd)
  1131. {
  1132. struct bfa_bsg_port_cfg_mode_s *iocmd =
  1133. (struct bfa_bsg_port_cfg_mode_s *)cmd;
  1134. struct bfad_hal_comp fcomp;
  1135. unsigned long flags = 0;
  1136. init_completion(&fcomp.comp);
  1137. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1138. iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk,
  1139. iocmd->instance, iocmd->cfg.mode,
  1140. iocmd->cfg.max_pf, iocmd->cfg.max_vf,
  1141. bfad_hcb_comp, &fcomp);
  1142. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1143. if (iocmd->status != BFA_STATUS_OK)
  1144. goto out;
  1145. wait_for_completion(&fcomp.comp);
  1146. iocmd->status = fcomp.status;
  1147. out:
  1148. return 0;
  1149. }
  1150. int
  1151. bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
  1152. {
  1153. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
  1154. struct bfad_hal_comp fcomp;
  1155. unsigned long flags;
  1156. init_completion(&fcomp.comp);
  1157. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1158. if (cmd == IOCMD_FLASH_ENABLE_OPTROM)
  1159. iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk,
  1160. bfad_hcb_comp, &fcomp);
  1161. else
  1162. iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk,
  1163. bfad_hcb_comp, &fcomp);
  1164. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1165. if (iocmd->status != BFA_STATUS_OK)
  1166. goto out;
  1167. wait_for_completion(&fcomp.comp);
  1168. iocmd->status = fcomp.status;
  1169. out:
  1170. return 0;
  1171. }
  1172. int
  1173. bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd)
  1174. {
  1175. struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd;
  1176. struct bfad_hal_comp fcomp;
  1177. unsigned long flags;
  1178. init_completion(&fcomp.comp);
  1179. iocmd->status = BFA_STATUS_OK;
  1180. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1181. iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr,
  1182. bfad_hcb_comp, &fcomp);
  1183. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1184. if (iocmd->status != BFA_STATUS_OK)
  1185. goto out;
  1186. wait_for_completion(&fcomp.comp);
  1187. iocmd->status = fcomp.status;
  1188. out:
  1189. return 0;
  1190. }
  1191. int
  1192. bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
  1193. {
  1194. struct bfa_bsg_cee_attr_s *iocmd =
  1195. (struct bfa_bsg_cee_attr_s *)cmd;
  1196. void *iocmd_bufptr;
  1197. struct bfad_hal_comp cee_comp;
  1198. unsigned long flags;
  1199. if (bfad_chk_iocmd_sz(payload_len,
  1200. sizeof(struct bfa_bsg_cee_attr_s),
  1201. sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) {
  1202. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1203. return 0;
  1204. }
  1205. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s);
  1206. cee_comp.status = 0;
  1207. init_completion(&cee_comp.comp);
  1208. mutex_lock(&bfad_mutex);
  1209. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1210. iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr,
  1211. bfad_hcb_comp, &cee_comp);
  1212. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1213. if (iocmd->status != BFA_STATUS_OK) {
  1214. mutex_unlock(&bfad_mutex);
  1215. bfa_trc(bfad, 0x5555);
  1216. goto out;
  1217. }
  1218. wait_for_completion(&cee_comp.comp);
  1219. mutex_unlock(&bfad_mutex);
  1220. out:
  1221. return 0;
  1222. }
  1223. int
  1224. bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd,
  1225. unsigned int payload_len)
  1226. {
  1227. struct bfa_bsg_cee_stats_s *iocmd =
  1228. (struct bfa_bsg_cee_stats_s *)cmd;
  1229. void *iocmd_bufptr;
  1230. struct bfad_hal_comp cee_comp;
  1231. unsigned long flags;
  1232. if (bfad_chk_iocmd_sz(payload_len,
  1233. sizeof(struct bfa_bsg_cee_stats_s),
  1234. sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) {
  1235. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1236. return 0;
  1237. }
  1238. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s);
  1239. cee_comp.status = 0;
  1240. init_completion(&cee_comp.comp);
  1241. mutex_lock(&bfad_mutex);
  1242. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1243. iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr,
  1244. bfad_hcb_comp, &cee_comp);
  1245. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1246. if (iocmd->status != BFA_STATUS_OK) {
  1247. mutex_unlock(&bfad_mutex);
  1248. bfa_trc(bfad, 0x5555);
  1249. goto out;
  1250. }
  1251. wait_for_completion(&cee_comp.comp);
  1252. mutex_unlock(&bfad_mutex);
  1253. out:
  1254. return 0;
  1255. }
  1256. int
  1257. bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd)
  1258. {
  1259. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1260. unsigned long flags;
  1261. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1262. iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL);
  1263. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1264. if (iocmd->status != BFA_STATUS_OK)
  1265. bfa_trc(bfad, 0x5555);
  1266. return 0;
  1267. }
  1268. int
  1269. bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd)
  1270. {
  1271. struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd;
  1272. struct bfad_hal_comp fcomp;
  1273. unsigned long flags;
  1274. init_completion(&fcomp.comp);
  1275. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1276. iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media,
  1277. bfad_hcb_comp, &fcomp);
  1278. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1279. bfa_trc(bfad, iocmd->status);
  1280. if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
  1281. goto out;
  1282. wait_for_completion(&fcomp.comp);
  1283. iocmd->status = fcomp.status;
  1284. out:
  1285. return 0;
  1286. }
  1287. int
  1288. bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd)
  1289. {
  1290. struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd;
  1291. struct bfad_hal_comp fcomp;
  1292. unsigned long flags;
  1293. init_completion(&fcomp.comp);
  1294. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1295. iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed,
  1296. bfad_hcb_comp, &fcomp);
  1297. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1298. bfa_trc(bfad, iocmd->status);
  1299. if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
  1300. goto out;
  1301. wait_for_completion(&fcomp.comp);
  1302. iocmd->status = fcomp.status;
  1303. out:
  1304. return 0;
  1305. }
  1306. int
  1307. bfad_iocmd_flash_get_attr(struct bfad_s *bfad, void *cmd)
  1308. {
  1309. struct bfa_bsg_flash_attr_s *iocmd =
  1310. (struct bfa_bsg_flash_attr_s *)cmd;
  1311. struct bfad_hal_comp fcomp;
  1312. unsigned long flags;
  1313. init_completion(&fcomp.comp);
  1314. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1315. iocmd->status = bfa_flash_get_attr(BFA_FLASH(&bfad->bfa), &iocmd->attr,
  1316. bfad_hcb_comp, &fcomp);
  1317. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1318. if (iocmd->status != BFA_STATUS_OK)
  1319. goto out;
  1320. wait_for_completion(&fcomp.comp);
  1321. iocmd->status = fcomp.status;
  1322. out:
  1323. return 0;
  1324. }
  1325. int
  1326. bfad_iocmd_flash_erase_part(struct bfad_s *bfad, void *cmd)
  1327. {
  1328. struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
  1329. struct bfad_hal_comp fcomp;
  1330. unsigned long flags;
  1331. init_completion(&fcomp.comp);
  1332. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1333. iocmd->status = bfa_flash_erase_part(BFA_FLASH(&bfad->bfa), iocmd->type,
  1334. iocmd->instance, bfad_hcb_comp, &fcomp);
  1335. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1336. if (iocmd->status != BFA_STATUS_OK)
  1337. goto out;
  1338. wait_for_completion(&fcomp.comp);
  1339. iocmd->status = fcomp.status;
  1340. out:
  1341. return 0;
  1342. }
  1343. int
  1344. bfad_iocmd_flash_update_part(struct bfad_s *bfad, void *cmd,
  1345. unsigned int payload_len)
  1346. {
  1347. struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
  1348. void *iocmd_bufptr;
  1349. struct bfad_hal_comp fcomp;
  1350. unsigned long flags;
  1351. if (bfad_chk_iocmd_sz(payload_len,
  1352. sizeof(struct bfa_bsg_flash_s),
  1353. iocmd->bufsz) != BFA_STATUS_OK) {
  1354. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1355. return 0;
  1356. }
  1357. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
  1358. init_completion(&fcomp.comp);
  1359. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1360. iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
  1361. iocmd->type, iocmd->instance, iocmd_bufptr,
  1362. iocmd->bufsz, 0, bfad_hcb_comp, &fcomp);
  1363. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1364. if (iocmd->status != BFA_STATUS_OK)
  1365. goto out;
  1366. wait_for_completion(&fcomp.comp);
  1367. iocmd->status = fcomp.status;
  1368. out:
  1369. return 0;
  1370. }
  1371. int
  1372. bfad_iocmd_flash_read_part(struct bfad_s *bfad, void *cmd,
  1373. unsigned int payload_len)
  1374. {
  1375. struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
  1376. struct bfad_hal_comp fcomp;
  1377. void *iocmd_bufptr;
  1378. unsigned long flags;
  1379. if (bfad_chk_iocmd_sz(payload_len,
  1380. sizeof(struct bfa_bsg_flash_s),
  1381. iocmd->bufsz) != BFA_STATUS_OK) {
  1382. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1383. return 0;
  1384. }
  1385. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
  1386. init_completion(&fcomp.comp);
  1387. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1388. iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), iocmd->type,
  1389. iocmd->instance, iocmd_bufptr, iocmd->bufsz, 0,
  1390. bfad_hcb_comp, &fcomp);
  1391. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1392. if (iocmd->status != BFA_STATUS_OK)
  1393. goto out;
  1394. wait_for_completion(&fcomp.comp);
  1395. iocmd->status = fcomp.status;
  1396. out:
  1397. return 0;
  1398. }
  1399. int
  1400. bfad_iocmd_diag_temp(struct bfad_s *bfad, void *cmd)
  1401. {
  1402. struct bfa_bsg_diag_get_temp_s *iocmd =
  1403. (struct bfa_bsg_diag_get_temp_s *)cmd;
  1404. struct bfad_hal_comp fcomp;
  1405. unsigned long flags;
  1406. init_completion(&fcomp.comp);
  1407. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1408. iocmd->status = bfa_diag_tsensor_query(BFA_DIAG_MOD(&bfad->bfa),
  1409. &iocmd->result, bfad_hcb_comp, &fcomp);
  1410. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1411. bfa_trc(bfad, iocmd->status);
  1412. if (iocmd->status != BFA_STATUS_OK)
  1413. goto out;
  1414. wait_for_completion(&fcomp.comp);
  1415. iocmd->status = fcomp.status;
  1416. out:
  1417. return 0;
  1418. }
  1419. int
  1420. bfad_iocmd_diag_memtest(struct bfad_s *bfad, void *cmd)
  1421. {
  1422. struct bfa_bsg_diag_memtest_s *iocmd =
  1423. (struct bfa_bsg_diag_memtest_s *)cmd;
  1424. struct bfad_hal_comp fcomp;
  1425. unsigned long flags;
  1426. init_completion(&fcomp.comp);
  1427. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1428. iocmd->status = bfa_diag_memtest(BFA_DIAG_MOD(&bfad->bfa),
  1429. &iocmd->memtest, iocmd->pat,
  1430. &iocmd->result, bfad_hcb_comp, &fcomp);
  1431. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1432. bfa_trc(bfad, iocmd->status);
  1433. if (iocmd->status != BFA_STATUS_OK)
  1434. goto out;
  1435. wait_for_completion(&fcomp.comp);
  1436. iocmd->status = fcomp.status;
  1437. out:
  1438. return 0;
  1439. }
  1440. int
  1441. bfad_iocmd_diag_loopback(struct bfad_s *bfad, void *cmd)
  1442. {
  1443. struct bfa_bsg_diag_loopback_s *iocmd =
  1444. (struct bfa_bsg_diag_loopback_s *)cmd;
  1445. struct bfad_hal_comp fcomp;
  1446. unsigned long flags;
  1447. init_completion(&fcomp.comp);
  1448. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1449. iocmd->status = bfa_fcdiag_loopback(&bfad->bfa, iocmd->opmode,
  1450. iocmd->speed, iocmd->lpcnt, iocmd->pat,
  1451. &iocmd->result, bfad_hcb_comp, &fcomp);
  1452. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1453. bfa_trc(bfad, iocmd->status);
  1454. if (iocmd->status != BFA_STATUS_OK)
  1455. goto out;
  1456. wait_for_completion(&fcomp.comp);
  1457. iocmd->status = fcomp.status;
  1458. out:
  1459. return 0;
  1460. }
  1461. int
  1462. bfad_iocmd_diag_fwping(struct bfad_s *bfad, void *cmd)
  1463. {
  1464. struct bfa_bsg_diag_fwping_s *iocmd =
  1465. (struct bfa_bsg_diag_fwping_s *)cmd;
  1466. struct bfad_hal_comp fcomp;
  1467. unsigned long flags;
  1468. init_completion(&fcomp.comp);
  1469. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1470. iocmd->status = bfa_diag_fwping(BFA_DIAG_MOD(&bfad->bfa), iocmd->cnt,
  1471. iocmd->pattern, &iocmd->result,
  1472. bfad_hcb_comp, &fcomp);
  1473. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1474. bfa_trc(bfad, iocmd->status);
  1475. if (iocmd->status != BFA_STATUS_OK)
  1476. goto out;
  1477. bfa_trc(bfad, 0x77771);
  1478. wait_for_completion(&fcomp.comp);
  1479. iocmd->status = fcomp.status;
  1480. out:
  1481. return 0;
  1482. }
  1483. int
  1484. bfad_iocmd_diag_queuetest(struct bfad_s *bfad, void *cmd)
  1485. {
  1486. struct bfa_bsg_diag_qtest_s *iocmd = (struct bfa_bsg_diag_qtest_s *)cmd;
  1487. struct bfad_hal_comp fcomp;
  1488. unsigned long flags;
  1489. init_completion(&fcomp.comp);
  1490. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1491. iocmd->status = bfa_fcdiag_queuetest(&bfad->bfa, iocmd->force,
  1492. iocmd->queue, &iocmd->result,
  1493. bfad_hcb_comp, &fcomp);
  1494. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1495. if (iocmd->status != BFA_STATUS_OK)
  1496. goto out;
  1497. wait_for_completion(&fcomp.comp);
  1498. iocmd->status = fcomp.status;
  1499. out:
  1500. return 0;
  1501. }
  1502. int
  1503. bfad_iocmd_diag_sfp(struct bfad_s *bfad, void *cmd)
  1504. {
  1505. struct bfa_bsg_sfp_show_s *iocmd =
  1506. (struct bfa_bsg_sfp_show_s *)cmd;
  1507. struct bfad_hal_comp fcomp;
  1508. unsigned long flags;
  1509. init_completion(&fcomp.comp);
  1510. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1511. iocmd->status = bfa_sfp_show(BFA_SFP_MOD(&bfad->bfa), &iocmd->sfp,
  1512. bfad_hcb_comp, &fcomp);
  1513. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1514. bfa_trc(bfad, iocmd->status);
  1515. if (iocmd->status != BFA_STATUS_OK)
  1516. goto out;
  1517. wait_for_completion(&fcomp.comp);
  1518. iocmd->status = fcomp.status;
  1519. bfa_trc(bfad, iocmd->status);
  1520. out:
  1521. return 0;
  1522. }
  1523. int
  1524. bfad_iocmd_diag_led(struct bfad_s *bfad, void *cmd)
  1525. {
  1526. struct bfa_bsg_diag_led_s *iocmd = (struct bfa_bsg_diag_led_s *)cmd;
  1527. unsigned long flags;
  1528. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1529. iocmd->status = bfa_diag_ledtest(BFA_DIAG_MOD(&bfad->bfa),
  1530. &iocmd->ledtest);
  1531. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1532. return 0;
  1533. }
  1534. int
  1535. bfad_iocmd_diag_beacon_lport(struct bfad_s *bfad, void *cmd)
  1536. {
  1537. struct bfa_bsg_diag_beacon_s *iocmd =
  1538. (struct bfa_bsg_diag_beacon_s *)cmd;
  1539. unsigned long flags;
  1540. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1541. iocmd->status = bfa_diag_beacon_port(BFA_DIAG_MOD(&bfad->bfa),
  1542. iocmd->beacon, iocmd->link_e2e_beacon,
  1543. iocmd->second);
  1544. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1545. return 0;
  1546. }
  1547. int
  1548. bfad_iocmd_diag_lb_stat(struct bfad_s *bfad, void *cmd)
  1549. {
  1550. struct bfa_bsg_diag_lb_stat_s *iocmd =
  1551. (struct bfa_bsg_diag_lb_stat_s *)cmd;
  1552. unsigned long flags;
  1553. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1554. iocmd->status = bfa_fcdiag_lb_is_running(&bfad->bfa);
  1555. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1556. bfa_trc(bfad, iocmd->status);
  1557. return 0;
  1558. }
  1559. int
  1560. bfad_iocmd_diag_dport_enable(struct bfad_s *bfad, void *pcmd)
  1561. {
  1562. struct bfa_bsg_dport_enable_s *iocmd =
  1563. (struct bfa_bsg_dport_enable_s *)pcmd;
  1564. unsigned long flags;
  1565. struct bfad_hal_comp fcomp;
  1566. init_completion(&fcomp.comp);
  1567. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1568. iocmd->status = bfa_dport_enable(&bfad->bfa, iocmd->lpcnt,
  1569. iocmd->pat, bfad_hcb_comp, &fcomp);
  1570. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1571. if (iocmd->status != BFA_STATUS_OK)
  1572. bfa_trc(bfad, iocmd->status);
  1573. else {
  1574. wait_for_completion(&fcomp.comp);
  1575. iocmd->status = fcomp.status;
  1576. }
  1577. return 0;
  1578. }
  1579. int
  1580. bfad_iocmd_diag_dport_disable(struct bfad_s *bfad, void *pcmd)
  1581. {
  1582. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
  1583. unsigned long flags;
  1584. struct bfad_hal_comp fcomp;
  1585. init_completion(&fcomp.comp);
  1586. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1587. iocmd->status = bfa_dport_disable(&bfad->bfa, bfad_hcb_comp, &fcomp);
  1588. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1589. if (iocmd->status != BFA_STATUS_OK)
  1590. bfa_trc(bfad, iocmd->status);
  1591. else {
  1592. wait_for_completion(&fcomp.comp);
  1593. iocmd->status = fcomp.status;
  1594. }
  1595. return 0;
  1596. }
  1597. int
  1598. bfad_iocmd_diag_dport_start(struct bfad_s *bfad, void *pcmd)
  1599. {
  1600. struct bfa_bsg_dport_enable_s *iocmd =
  1601. (struct bfa_bsg_dport_enable_s *)pcmd;
  1602. unsigned long flags;
  1603. struct bfad_hal_comp fcomp;
  1604. init_completion(&fcomp.comp);
  1605. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1606. iocmd->status = bfa_dport_start(&bfad->bfa, iocmd->lpcnt,
  1607. iocmd->pat, bfad_hcb_comp,
  1608. &fcomp);
  1609. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1610. if (iocmd->status != BFA_STATUS_OK) {
  1611. bfa_trc(bfad, iocmd->status);
  1612. } else {
  1613. wait_for_completion(&fcomp.comp);
  1614. iocmd->status = fcomp.status;
  1615. }
  1616. return 0;
  1617. }
  1618. int
  1619. bfad_iocmd_diag_dport_show(struct bfad_s *bfad, void *pcmd)
  1620. {
  1621. struct bfa_bsg_diag_dport_show_s *iocmd =
  1622. (struct bfa_bsg_diag_dport_show_s *)pcmd;
  1623. unsigned long flags;
  1624. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1625. iocmd->status = bfa_dport_show(&bfad->bfa, &iocmd->result);
  1626. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1627. return 0;
  1628. }
  1629. int
  1630. bfad_iocmd_phy_get_attr(struct bfad_s *bfad, void *cmd)
  1631. {
  1632. struct bfa_bsg_phy_attr_s *iocmd =
  1633. (struct bfa_bsg_phy_attr_s *)cmd;
  1634. struct bfad_hal_comp fcomp;
  1635. unsigned long flags;
  1636. init_completion(&fcomp.comp);
  1637. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1638. iocmd->status = bfa_phy_get_attr(BFA_PHY(&bfad->bfa), iocmd->instance,
  1639. &iocmd->attr, bfad_hcb_comp, &fcomp);
  1640. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1641. if (iocmd->status != BFA_STATUS_OK)
  1642. goto out;
  1643. wait_for_completion(&fcomp.comp);
  1644. iocmd->status = fcomp.status;
  1645. out:
  1646. return 0;
  1647. }
  1648. int
  1649. bfad_iocmd_phy_get_stats(struct bfad_s *bfad, void *cmd)
  1650. {
  1651. struct bfa_bsg_phy_stats_s *iocmd =
  1652. (struct bfa_bsg_phy_stats_s *)cmd;
  1653. struct bfad_hal_comp fcomp;
  1654. unsigned long flags;
  1655. init_completion(&fcomp.comp);
  1656. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1657. iocmd->status = bfa_phy_get_stats(BFA_PHY(&bfad->bfa), iocmd->instance,
  1658. &iocmd->stats, bfad_hcb_comp, &fcomp);
  1659. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1660. if (iocmd->status != BFA_STATUS_OK)
  1661. goto out;
  1662. wait_for_completion(&fcomp.comp);
  1663. iocmd->status = fcomp.status;
  1664. out:
  1665. return 0;
  1666. }
  1667. int
  1668. bfad_iocmd_phy_read(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
  1669. {
  1670. struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
  1671. struct bfad_hal_comp fcomp;
  1672. void *iocmd_bufptr;
  1673. unsigned long flags;
  1674. if (bfad_chk_iocmd_sz(payload_len,
  1675. sizeof(struct bfa_bsg_phy_s),
  1676. iocmd->bufsz) != BFA_STATUS_OK) {
  1677. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1678. return 0;
  1679. }
  1680. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
  1681. init_completion(&fcomp.comp);
  1682. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1683. iocmd->status = bfa_phy_read(BFA_PHY(&bfad->bfa),
  1684. iocmd->instance, iocmd_bufptr, iocmd->bufsz,
  1685. 0, bfad_hcb_comp, &fcomp);
  1686. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1687. if (iocmd->status != BFA_STATUS_OK)
  1688. goto out;
  1689. wait_for_completion(&fcomp.comp);
  1690. iocmd->status = fcomp.status;
  1691. if (iocmd->status != BFA_STATUS_OK)
  1692. goto out;
  1693. out:
  1694. return 0;
  1695. }
  1696. int
  1697. bfad_iocmd_vhba_query(struct bfad_s *bfad, void *cmd)
  1698. {
  1699. struct bfa_bsg_vhba_attr_s *iocmd =
  1700. (struct bfa_bsg_vhba_attr_s *)cmd;
  1701. struct bfa_vhba_attr_s *attr = &iocmd->attr;
  1702. unsigned long flags;
  1703. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1704. attr->pwwn = bfad->bfa.ioc.attr->pwwn;
  1705. attr->nwwn = bfad->bfa.ioc.attr->nwwn;
  1706. attr->plog_enabled = (bfa_boolean_t)bfad->bfa.plog->plog_enabled;
  1707. attr->io_profile = bfa_fcpim_get_io_profile(&bfad->bfa);
  1708. attr->path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
  1709. iocmd->status = BFA_STATUS_OK;
  1710. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1711. return 0;
  1712. }
  1713. int
  1714. bfad_iocmd_phy_update(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
  1715. {
  1716. struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
  1717. void *iocmd_bufptr;
  1718. struct bfad_hal_comp fcomp;
  1719. unsigned long flags;
  1720. if (bfad_chk_iocmd_sz(payload_len,
  1721. sizeof(struct bfa_bsg_phy_s),
  1722. iocmd->bufsz) != BFA_STATUS_OK) {
  1723. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1724. return 0;
  1725. }
  1726. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
  1727. init_completion(&fcomp.comp);
  1728. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1729. iocmd->status = bfa_phy_update(BFA_PHY(&bfad->bfa),
  1730. iocmd->instance, iocmd_bufptr, iocmd->bufsz,
  1731. 0, bfad_hcb_comp, &fcomp);
  1732. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1733. if (iocmd->status != BFA_STATUS_OK)
  1734. goto out;
  1735. wait_for_completion(&fcomp.comp);
  1736. iocmd->status = fcomp.status;
  1737. out:
  1738. return 0;
  1739. }
  1740. int
  1741. bfad_iocmd_porglog_get(struct bfad_s *bfad, void *cmd)
  1742. {
  1743. struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
  1744. void *iocmd_bufptr;
  1745. if (iocmd->bufsz < sizeof(struct bfa_plog_s)) {
  1746. bfa_trc(bfad, sizeof(struct bfa_plog_s));
  1747. iocmd->status = BFA_STATUS_EINVAL;
  1748. goto out;
  1749. }
  1750. iocmd->status = BFA_STATUS_OK;
  1751. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
  1752. memcpy(iocmd_bufptr, (u8 *) &bfad->plog_buf, sizeof(struct bfa_plog_s));
  1753. out:
  1754. return 0;
  1755. }
  1756. #define BFA_DEBUG_FW_CORE_CHUNK_SZ 0x4000U /* 16K chunks for FW dump */
  1757. int
  1758. bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd,
  1759. unsigned int payload_len)
  1760. {
  1761. struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
  1762. void *iocmd_bufptr;
  1763. unsigned long flags;
  1764. u32 offset;
  1765. if (bfad_chk_iocmd_sz(payload_len, sizeof(struct bfa_bsg_debug_s),
  1766. BFA_DEBUG_FW_CORE_CHUNK_SZ) != BFA_STATUS_OK) {
  1767. iocmd->status = BFA_STATUS_VERSION_FAIL;
  1768. return 0;
  1769. }
  1770. if (iocmd->bufsz < BFA_DEBUG_FW_CORE_CHUNK_SZ ||
  1771. !IS_ALIGNED(iocmd->bufsz, sizeof(u16)) ||
  1772. !IS_ALIGNED(iocmd->offset, sizeof(u32))) {
  1773. bfa_trc(bfad, BFA_DEBUG_FW_CORE_CHUNK_SZ);
  1774. iocmd->status = BFA_STATUS_EINVAL;
  1775. goto out;
  1776. }
  1777. iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
  1778. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1779. offset = iocmd->offset;
  1780. iocmd->status = bfa_ioc_debug_fwcore(&bfad->bfa.ioc, iocmd_bufptr,
  1781. &offset, &iocmd->bufsz);
  1782. iocmd->offset = offset;
  1783. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1784. out:
  1785. return 0;
  1786. }
  1787. int
  1788. bfad_iocmd_debug_ctl(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  1789. {
  1790. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1791. unsigned long flags;
  1792. if (v_cmd == IOCMD_DEBUG_FW_STATE_CLR) {
  1793. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1794. bfad->bfa.ioc.dbg_fwsave_once = BFA_TRUE;
  1795. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1796. } else if (v_cmd == IOCMD_DEBUG_PORTLOG_CLR)
  1797. bfad->plog_buf.head = bfad->plog_buf.tail = 0;
  1798. else if (v_cmd == IOCMD_DEBUG_START_DTRC)
  1799. bfa_trc_init(bfad->trcmod);
  1800. else if (v_cmd == IOCMD_DEBUG_STOP_DTRC)
  1801. bfa_trc_stop(bfad->trcmod);
  1802. iocmd->status = BFA_STATUS_OK;
  1803. return 0;
  1804. }
  1805. int
  1806. bfad_iocmd_porglog_ctl(struct bfad_s *bfad, void *cmd)
  1807. {
  1808. struct bfa_bsg_portlogctl_s *iocmd = (struct bfa_bsg_portlogctl_s *)cmd;
  1809. if (iocmd->ctl == BFA_TRUE)
  1810. bfad->plog_buf.plog_enabled = 1;
  1811. else
  1812. bfad->plog_buf.plog_enabled = 0;
  1813. iocmd->status = BFA_STATUS_OK;
  1814. return 0;
  1815. }
  1816. int
  1817. bfad_iocmd_fcpim_cfg_profile(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  1818. {
  1819. struct bfa_bsg_fcpim_profile_s *iocmd =
  1820. (struct bfa_bsg_fcpim_profile_s *)cmd;
  1821. unsigned long flags;
  1822. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1823. if (v_cmd == IOCMD_FCPIM_PROFILE_ON)
  1824. iocmd->status = bfa_fcpim_profile_on(&bfad->bfa, ktime_get_real_seconds());
  1825. else if (v_cmd == IOCMD_FCPIM_PROFILE_OFF)
  1826. iocmd->status = bfa_fcpim_profile_off(&bfad->bfa);
  1827. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1828. return 0;
  1829. }
  1830. static int
  1831. bfad_iocmd_itnim_get_ioprofile(struct bfad_s *bfad, void *cmd)
  1832. {
  1833. struct bfa_bsg_itnim_ioprofile_s *iocmd =
  1834. (struct bfa_bsg_itnim_ioprofile_s *)cmd;
  1835. struct bfa_fcs_lport_s *fcs_port;
  1836. struct bfa_fcs_itnim_s *itnim;
  1837. unsigned long flags;
  1838. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1839. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  1840. iocmd->vf_id, iocmd->lpwwn);
  1841. if (!fcs_port)
  1842. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  1843. else {
  1844. itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  1845. if (itnim == NULL)
  1846. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  1847. else
  1848. iocmd->status = bfa_itnim_get_ioprofile(
  1849. bfa_fcs_itnim_get_halitn(itnim),
  1850. &iocmd->ioprofile);
  1851. }
  1852. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1853. return 0;
  1854. }
  1855. int
  1856. bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)
  1857. {
  1858. struct bfa_bsg_fcport_stats_s *iocmd =
  1859. (struct bfa_bsg_fcport_stats_s *)cmd;
  1860. struct bfad_hal_comp fcomp;
  1861. unsigned long flags;
  1862. struct bfa_cb_pending_q_s cb_qe;
  1863. init_completion(&fcomp.comp);
  1864. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  1865. &fcomp, &iocmd->stats);
  1866. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1867. iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
  1868. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1869. if (iocmd->status != BFA_STATUS_OK) {
  1870. bfa_trc(bfad, iocmd->status);
  1871. goto out;
  1872. }
  1873. wait_for_completion(&fcomp.comp);
  1874. iocmd->status = fcomp.status;
  1875. out:
  1876. return 0;
  1877. }
  1878. int
  1879. bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)
  1880. {
  1881. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1882. struct bfad_hal_comp fcomp;
  1883. unsigned long flags;
  1884. struct bfa_cb_pending_q_s cb_qe;
  1885. init_completion(&fcomp.comp);
  1886. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL);
  1887. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1888. iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
  1889. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1890. if (iocmd->status != BFA_STATUS_OK) {
  1891. bfa_trc(bfad, iocmd->status);
  1892. goto out;
  1893. }
  1894. wait_for_completion(&fcomp.comp);
  1895. iocmd->status = fcomp.status;
  1896. out:
  1897. return 0;
  1898. }
  1899. int
  1900. bfad_iocmd_boot_cfg(struct bfad_s *bfad, void *cmd)
  1901. {
  1902. struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
  1903. struct bfad_hal_comp fcomp;
  1904. unsigned long flags;
  1905. init_completion(&fcomp.comp);
  1906. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1907. iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
  1908. BFA_FLASH_PART_BOOT, bfad->bfa.ioc.port_id,
  1909. &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
  1910. bfad_hcb_comp, &fcomp);
  1911. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1912. if (iocmd->status != BFA_STATUS_OK)
  1913. goto out;
  1914. wait_for_completion(&fcomp.comp);
  1915. iocmd->status = fcomp.status;
  1916. out:
  1917. return 0;
  1918. }
  1919. int
  1920. bfad_iocmd_boot_query(struct bfad_s *bfad, void *cmd)
  1921. {
  1922. struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
  1923. struct bfad_hal_comp fcomp;
  1924. unsigned long flags;
  1925. init_completion(&fcomp.comp);
  1926. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1927. iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
  1928. BFA_FLASH_PART_BOOT, bfad->bfa.ioc.port_id,
  1929. &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
  1930. bfad_hcb_comp, &fcomp);
  1931. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1932. if (iocmd->status != BFA_STATUS_OK)
  1933. goto out;
  1934. wait_for_completion(&fcomp.comp);
  1935. iocmd->status = fcomp.status;
  1936. out:
  1937. return 0;
  1938. }
  1939. int
  1940. bfad_iocmd_preboot_query(struct bfad_s *bfad, void *cmd)
  1941. {
  1942. struct bfa_bsg_preboot_s *iocmd = (struct bfa_bsg_preboot_s *)cmd;
  1943. struct bfi_iocfc_cfgrsp_s *cfgrsp = bfad->bfa.iocfc.cfgrsp;
  1944. struct bfa_boot_pbc_s *pbcfg = &iocmd->cfg;
  1945. unsigned long flags;
  1946. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1947. pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
  1948. pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
  1949. pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
  1950. memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
  1951. iocmd->status = BFA_STATUS_OK;
  1952. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1953. return 0;
  1954. }
  1955. int
  1956. bfad_iocmd_ethboot_cfg(struct bfad_s *bfad, void *cmd)
  1957. {
  1958. struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
  1959. struct bfad_hal_comp fcomp;
  1960. unsigned long flags;
  1961. init_completion(&fcomp.comp);
  1962. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1963. iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
  1964. BFA_FLASH_PART_PXECFG,
  1965. bfad->bfa.ioc.port_id, &iocmd->cfg,
  1966. sizeof(struct bfa_ethboot_cfg_s), 0,
  1967. bfad_hcb_comp, &fcomp);
  1968. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1969. if (iocmd->status != BFA_STATUS_OK)
  1970. goto out;
  1971. wait_for_completion(&fcomp.comp);
  1972. iocmd->status = fcomp.status;
  1973. out:
  1974. return 0;
  1975. }
  1976. int
  1977. bfad_iocmd_ethboot_query(struct bfad_s *bfad, void *cmd)
  1978. {
  1979. struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
  1980. struct bfad_hal_comp fcomp;
  1981. unsigned long flags;
  1982. init_completion(&fcomp.comp);
  1983. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1984. iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
  1985. BFA_FLASH_PART_PXECFG,
  1986. bfad->bfa.ioc.port_id, &iocmd->cfg,
  1987. sizeof(struct bfa_ethboot_cfg_s), 0,
  1988. bfad_hcb_comp, &fcomp);
  1989. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1990. if (iocmd->status != BFA_STATUS_OK)
  1991. goto out;
  1992. wait_for_completion(&fcomp.comp);
  1993. iocmd->status = fcomp.status;
  1994. out:
  1995. return 0;
  1996. }
  1997. int
  1998. bfad_iocmd_cfg_trunk(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  1999. {
  2000. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2001. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2002. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2003. unsigned long flags;
  2004. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2005. if (bfa_fcport_is_dport(&bfad->bfa)) {
  2006. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2007. return BFA_STATUS_DPORT_ERR;
  2008. }
  2009. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
  2010. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2011. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2012. else {
  2013. if (v_cmd == IOCMD_TRUNK_ENABLE) {
  2014. trunk->attr.state = BFA_TRUNK_OFFLINE;
  2015. bfa_fcport_disable(&bfad->bfa);
  2016. fcport->cfg.trunked = BFA_TRUE;
  2017. } else if (v_cmd == IOCMD_TRUNK_DISABLE) {
  2018. trunk->attr.state = BFA_TRUNK_DISABLED;
  2019. bfa_fcport_disable(&bfad->bfa);
  2020. fcport->cfg.trunked = BFA_FALSE;
  2021. }
  2022. if (!bfa_fcport_is_disabled(&bfad->bfa))
  2023. bfa_fcport_enable(&bfad->bfa);
  2024. iocmd->status = BFA_STATUS_OK;
  2025. }
  2026. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2027. return 0;
  2028. }
  2029. int
  2030. bfad_iocmd_trunk_get_attr(struct bfad_s *bfad, void *cmd)
  2031. {
  2032. struct bfa_bsg_trunk_attr_s *iocmd = (struct bfa_bsg_trunk_attr_s *)cmd;
  2033. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2034. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2035. unsigned long flags;
  2036. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2037. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
  2038. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2039. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2040. else {
  2041. memcpy((void *)&iocmd->attr, (void *)&trunk->attr,
  2042. sizeof(struct bfa_trunk_attr_s));
  2043. iocmd->attr.port_id = bfa_lps_get_base_pid(&bfad->bfa);
  2044. iocmd->status = BFA_STATUS_OK;
  2045. }
  2046. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2047. return 0;
  2048. }
  2049. int
  2050. bfad_iocmd_qos(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  2051. {
  2052. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2053. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2054. unsigned long flags;
  2055. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2056. if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) {
  2057. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2058. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2059. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2060. else {
  2061. if (v_cmd == IOCMD_QOS_ENABLE)
  2062. fcport->cfg.qos_enabled = BFA_TRUE;
  2063. else if (v_cmd == IOCMD_QOS_DISABLE) {
  2064. fcport->cfg.qos_enabled = BFA_FALSE;
  2065. fcport->cfg.qos_bw.high = BFA_QOS_BW_HIGH;
  2066. fcport->cfg.qos_bw.med = BFA_QOS_BW_MED;
  2067. fcport->cfg.qos_bw.low = BFA_QOS_BW_LOW;
  2068. }
  2069. }
  2070. }
  2071. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2072. return 0;
  2073. }
  2074. int
  2075. bfad_iocmd_qos_get_attr(struct bfad_s *bfad, void *cmd)
  2076. {
  2077. struct bfa_bsg_qos_attr_s *iocmd = (struct bfa_bsg_qos_attr_s *)cmd;
  2078. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2079. unsigned long flags;
  2080. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2081. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2082. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2083. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2084. else {
  2085. iocmd->attr.state = fcport->qos_attr.state;
  2086. iocmd->attr.total_bb_cr =
  2087. be32_to_cpu(fcport->qos_attr.total_bb_cr);
  2088. iocmd->attr.qos_bw.high = fcport->cfg.qos_bw.high;
  2089. iocmd->attr.qos_bw.med = fcport->cfg.qos_bw.med;
  2090. iocmd->attr.qos_bw.low = fcport->cfg.qos_bw.low;
  2091. iocmd->attr.qos_bw_op = fcport->qos_attr.qos_bw_op;
  2092. iocmd->status = BFA_STATUS_OK;
  2093. }
  2094. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2095. return 0;
  2096. }
  2097. int
  2098. bfad_iocmd_qos_get_vc_attr(struct bfad_s *bfad, void *cmd)
  2099. {
  2100. struct bfa_bsg_qos_vc_attr_s *iocmd =
  2101. (struct bfa_bsg_qos_vc_attr_s *)cmd;
  2102. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2103. struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
  2104. unsigned long flags;
  2105. u32 i = 0;
  2106. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2107. iocmd->attr.total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count);
  2108. iocmd->attr.shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit);
  2109. iocmd->attr.elp_opmode_flags =
  2110. be32_to_cpu(bfa_vc_attr->elp_opmode_flags);
  2111. /* Individual VC info */
  2112. while (i < iocmd->attr.total_vc_count) {
  2113. iocmd->attr.vc_info[i].vc_credit =
  2114. bfa_vc_attr->vc_info[i].vc_credit;
  2115. iocmd->attr.vc_info[i].borrow_credit =
  2116. bfa_vc_attr->vc_info[i].borrow_credit;
  2117. iocmd->attr.vc_info[i].priority =
  2118. bfa_vc_attr->vc_info[i].priority;
  2119. i++;
  2120. }
  2121. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2122. iocmd->status = BFA_STATUS_OK;
  2123. return 0;
  2124. }
  2125. int
  2126. bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd)
  2127. {
  2128. struct bfa_bsg_fcport_stats_s *iocmd =
  2129. (struct bfa_bsg_fcport_stats_s *)cmd;
  2130. struct bfad_hal_comp fcomp;
  2131. unsigned long flags;
  2132. struct bfa_cb_pending_q_s cb_qe;
  2133. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2134. init_completion(&fcomp.comp);
  2135. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  2136. &fcomp, &iocmd->stats);
  2137. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2138. WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
  2139. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2140. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2141. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2142. else
  2143. iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
  2144. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2145. if (iocmd->status != BFA_STATUS_OK) {
  2146. bfa_trc(bfad, iocmd->status);
  2147. goto out;
  2148. }
  2149. wait_for_completion(&fcomp.comp);
  2150. iocmd->status = fcomp.status;
  2151. out:
  2152. return 0;
  2153. }
  2154. int
  2155. bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)
  2156. {
  2157. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2158. struct bfad_hal_comp fcomp;
  2159. unsigned long flags;
  2160. struct bfa_cb_pending_q_s cb_qe;
  2161. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2162. init_completion(&fcomp.comp);
  2163. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  2164. &fcomp, NULL);
  2165. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2166. WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
  2167. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2168. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2169. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2170. else
  2171. iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
  2172. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2173. if (iocmd->status != BFA_STATUS_OK) {
  2174. bfa_trc(bfad, iocmd->status);
  2175. goto out;
  2176. }
  2177. wait_for_completion(&fcomp.comp);
  2178. iocmd->status = fcomp.status;
  2179. out:
  2180. return 0;
  2181. }
  2182. int
  2183. bfad_iocmd_vf_get_stats(struct bfad_s *bfad, void *cmd)
  2184. {
  2185. struct bfa_bsg_vf_stats_s *iocmd =
  2186. (struct bfa_bsg_vf_stats_s *)cmd;
  2187. struct bfa_fcs_fabric_s *fcs_vf;
  2188. unsigned long flags;
  2189. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2190. fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
  2191. if (fcs_vf == NULL) {
  2192. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2193. iocmd->status = BFA_STATUS_UNKNOWN_VFID;
  2194. goto out;
  2195. }
  2196. memcpy((void *)&iocmd->stats, (void *)&fcs_vf->stats,
  2197. sizeof(struct bfa_vf_stats_s));
  2198. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2199. iocmd->status = BFA_STATUS_OK;
  2200. out:
  2201. return 0;
  2202. }
  2203. int
  2204. bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd)
  2205. {
  2206. struct bfa_bsg_vf_reset_stats_s *iocmd =
  2207. (struct bfa_bsg_vf_reset_stats_s *)cmd;
  2208. struct bfa_fcs_fabric_s *fcs_vf;
  2209. unsigned long flags;
  2210. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2211. fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
  2212. if (fcs_vf == NULL) {
  2213. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2214. iocmd->status = BFA_STATUS_UNKNOWN_VFID;
  2215. goto out;
  2216. }
  2217. memset((void *)&fcs_vf->stats, 0, sizeof(struct bfa_vf_stats_s));
  2218. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2219. iocmd->status = BFA_STATUS_OK;
  2220. out:
  2221. return 0;
  2222. }
  2223. /* Function to reset the LUN SCAN mode */
  2224. static void
  2225. bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg)
  2226. {
  2227. struct bfad_im_port_s *pport_im = bfad->pport.im_port;
  2228. struct bfad_vport_s *vport = NULL;
  2229. /* Set the scsi device LUN SCAN flags for base port */
  2230. bfad_reset_sdev_bflags(pport_im, lunmask_cfg);
  2231. /* Set the scsi device LUN SCAN flags for the vports */
  2232. list_for_each_entry(vport, &bfad->vport_list, list_entry)
  2233. bfad_reset_sdev_bflags(vport->drv_port.im_port, lunmask_cfg);
  2234. }
  2235. int
  2236. bfad_iocmd_lunmask(struct bfad_s *bfad, void *pcmd, unsigned int v_cmd)
  2237. {
  2238. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
  2239. unsigned long flags;
  2240. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2241. if (v_cmd == IOCMD_FCPIM_LUNMASK_ENABLE) {
  2242. iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_TRUE);
  2243. /* Set the LUN Scanning mode to be Sequential scan */
  2244. if (iocmd->status == BFA_STATUS_OK)
  2245. bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_TRUE);
  2246. } else if (v_cmd == IOCMD_FCPIM_LUNMASK_DISABLE) {
  2247. iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_FALSE);
  2248. /* Set the LUN Scanning mode to default REPORT_LUNS scan */
  2249. if (iocmd->status == BFA_STATUS_OK)
  2250. bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_FALSE);
  2251. } else if (v_cmd == IOCMD_FCPIM_LUNMASK_CLEAR)
  2252. iocmd->status = bfa_fcpim_lunmask_clear(&bfad->bfa);
  2253. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2254. return 0;
  2255. }
  2256. int
  2257. bfad_iocmd_fcpim_lunmask_query(struct bfad_s *bfad, void *cmd)
  2258. {
  2259. struct bfa_bsg_fcpim_lunmask_query_s *iocmd =
  2260. (struct bfa_bsg_fcpim_lunmask_query_s *)cmd;
  2261. struct bfa_lunmask_cfg_s *lun_mask = &iocmd->lun_mask;
  2262. unsigned long flags;
  2263. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2264. iocmd->status = bfa_fcpim_lunmask_query(&bfad->bfa, lun_mask);
  2265. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2266. return 0;
  2267. }
  2268. int
  2269. bfad_iocmd_fcpim_cfg_lunmask(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  2270. {
  2271. struct bfa_bsg_fcpim_lunmask_s *iocmd =
  2272. (struct bfa_bsg_fcpim_lunmask_s *)cmd;
  2273. unsigned long flags;
  2274. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2275. if (v_cmd == IOCMD_FCPIM_LUNMASK_ADD)
  2276. iocmd->status = bfa_fcpim_lunmask_add(&bfad->bfa, iocmd->vf_id,
  2277. &iocmd->pwwn, iocmd->rpwwn, iocmd->lun);
  2278. else if (v_cmd == IOCMD_FCPIM_LUNMASK_DELETE)
  2279. iocmd->status = bfa_fcpim_lunmask_delete(&bfad->bfa,
  2280. iocmd->vf_id, &iocmd->pwwn,
  2281. iocmd->rpwwn, iocmd->lun);
  2282. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2283. return 0;
  2284. }
  2285. int
  2286. bfad_iocmd_fcpim_throttle_query(struct bfad_s *bfad, void *cmd)
  2287. {
  2288. struct bfa_bsg_fcpim_throttle_s *iocmd =
  2289. (struct bfa_bsg_fcpim_throttle_s *)cmd;
  2290. unsigned long flags;
  2291. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2292. iocmd->status = bfa_fcpim_throttle_get(&bfad->bfa,
  2293. (void *)&iocmd->throttle);
  2294. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2295. return 0;
  2296. }
  2297. int
  2298. bfad_iocmd_fcpim_throttle_set(struct bfad_s *bfad, void *cmd)
  2299. {
  2300. struct bfa_bsg_fcpim_throttle_s *iocmd =
  2301. (struct bfa_bsg_fcpim_throttle_s *)cmd;
  2302. unsigned long flags;
  2303. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2304. iocmd->status = bfa_fcpim_throttle_set(&bfad->bfa,
  2305. iocmd->throttle.cfg_value);
  2306. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2307. return 0;
  2308. }
  2309. int
  2310. bfad_iocmd_tfru_read(struct bfad_s *bfad, void *cmd)
  2311. {
  2312. struct bfa_bsg_tfru_s *iocmd =
  2313. (struct bfa_bsg_tfru_s *)cmd;
  2314. struct bfad_hal_comp fcomp;
  2315. unsigned long flags = 0;
  2316. init_completion(&fcomp.comp);
  2317. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2318. iocmd->status = bfa_tfru_read(BFA_FRU(&bfad->bfa),
  2319. &iocmd->data, iocmd->len, iocmd->offset,
  2320. bfad_hcb_comp, &fcomp);
  2321. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2322. if (iocmd->status == BFA_STATUS_OK) {
  2323. wait_for_completion(&fcomp.comp);
  2324. iocmd->status = fcomp.status;
  2325. }
  2326. return 0;
  2327. }
  2328. int
  2329. bfad_iocmd_tfru_write(struct bfad_s *bfad, void *cmd)
  2330. {
  2331. struct bfa_bsg_tfru_s *iocmd =
  2332. (struct bfa_bsg_tfru_s *)cmd;
  2333. struct bfad_hal_comp fcomp;
  2334. unsigned long flags = 0;
  2335. init_completion(&fcomp.comp);
  2336. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2337. iocmd->status = bfa_tfru_write(BFA_FRU(&bfad->bfa),
  2338. &iocmd->data, iocmd->len, iocmd->offset,
  2339. bfad_hcb_comp, &fcomp);
  2340. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2341. if (iocmd->status == BFA_STATUS_OK) {
  2342. wait_for_completion(&fcomp.comp);
  2343. iocmd->status = fcomp.status;
  2344. }
  2345. return 0;
  2346. }
  2347. int
  2348. bfad_iocmd_fruvpd_read(struct bfad_s *bfad, void *cmd)
  2349. {
  2350. struct bfa_bsg_fruvpd_s *iocmd =
  2351. (struct bfa_bsg_fruvpd_s *)cmd;
  2352. struct bfad_hal_comp fcomp;
  2353. unsigned long flags = 0;
  2354. init_completion(&fcomp.comp);
  2355. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2356. iocmd->status = bfa_fruvpd_read(BFA_FRU(&bfad->bfa),
  2357. &iocmd->data, iocmd->len, iocmd->offset,
  2358. bfad_hcb_comp, &fcomp);
  2359. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2360. if (iocmd->status == BFA_STATUS_OK) {
  2361. wait_for_completion(&fcomp.comp);
  2362. iocmd->status = fcomp.status;
  2363. }
  2364. return 0;
  2365. }
  2366. int
  2367. bfad_iocmd_fruvpd_update(struct bfad_s *bfad, void *cmd)
  2368. {
  2369. struct bfa_bsg_fruvpd_s *iocmd =
  2370. (struct bfa_bsg_fruvpd_s *)cmd;
  2371. struct bfad_hal_comp fcomp;
  2372. unsigned long flags = 0;
  2373. init_completion(&fcomp.comp);
  2374. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2375. iocmd->status = bfa_fruvpd_update(BFA_FRU(&bfad->bfa),
  2376. &iocmd->data, iocmd->len, iocmd->offset,
  2377. bfad_hcb_comp, &fcomp, iocmd->trfr_cmpl);
  2378. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2379. if (iocmd->status == BFA_STATUS_OK) {
  2380. wait_for_completion(&fcomp.comp);
  2381. iocmd->status = fcomp.status;
  2382. }
  2383. return 0;
  2384. }
  2385. int
  2386. bfad_iocmd_fruvpd_get_max_size(struct bfad_s *bfad, void *cmd)
  2387. {
  2388. struct bfa_bsg_fruvpd_max_size_s *iocmd =
  2389. (struct bfa_bsg_fruvpd_max_size_s *)cmd;
  2390. unsigned long flags = 0;
  2391. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2392. iocmd->status = bfa_fruvpd_get_max_size(BFA_FRU(&bfad->bfa),
  2393. &iocmd->max_size);
  2394. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2395. return 0;
  2396. }
  2397. static int
  2398. bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd,
  2399. unsigned int payload_len)
  2400. {
  2401. int rc = -EINVAL;
  2402. switch (cmd) {
  2403. case IOCMD_IOC_ENABLE:
  2404. rc = bfad_iocmd_ioc_enable(bfad, iocmd);
  2405. break;
  2406. case IOCMD_IOC_DISABLE:
  2407. rc = bfad_iocmd_ioc_disable(bfad, iocmd);
  2408. break;
  2409. case IOCMD_IOC_GET_INFO:
  2410. rc = bfad_iocmd_ioc_get_info(bfad, iocmd);
  2411. break;
  2412. case IOCMD_IOC_GET_ATTR:
  2413. rc = bfad_iocmd_ioc_get_attr(bfad, iocmd);
  2414. break;
  2415. case IOCMD_IOC_GET_STATS:
  2416. rc = bfad_iocmd_ioc_get_stats(bfad, iocmd);
  2417. break;
  2418. case IOCMD_IOC_GET_FWSTATS:
  2419. rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len);
  2420. break;
  2421. case IOCMD_IOC_RESET_STATS:
  2422. case IOCMD_IOC_RESET_FWSTATS:
  2423. rc = bfad_iocmd_ioc_reset_stats(bfad, iocmd, cmd);
  2424. break;
  2425. case IOCMD_IOC_SET_ADAPTER_NAME:
  2426. case IOCMD_IOC_SET_PORT_NAME:
  2427. rc = bfad_iocmd_ioc_set_name(bfad, iocmd, cmd);
  2428. break;
  2429. case IOCMD_IOCFC_GET_ATTR:
  2430. rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd);
  2431. break;
  2432. case IOCMD_IOCFC_SET_INTR:
  2433. rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd);
  2434. break;
  2435. case IOCMD_PORT_ENABLE:
  2436. rc = bfad_iocmd_port_enable(bfad, iocmd);
  2437. break;
  2438. case IOCMD_PORT_DISABLE:
  2439. rc = bfad_iocmd_port_disable(bfad, iocmd);
  2440. break;
  2441. case IOCMD_PORT_GET_ATTR:
  2442. rc = bfad_iocmd_port_get_attr(bfad, iocmd);
  2443. break;
  2444. case IOCMD_PORT_GET_STATS:
  2445. rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len);
  2446. break;
  2447. case IOCMD_PORT_RESET_STATS:
  2448. rc = bfad_iocmd_port_reset_stats(bfad, iocmd);
  2449. break;
  2450. case IOCMD_PORT_CFG_TOPO:
  2451. case IOCMD_PORT_CFG_SPEED:
  2452. case IOCMD_PORT_CFG_ALPA:
  2453. case IOCMD_PORT_CLR_ALPA:
  2454. rc = bfad_iocmd_set_port_cfg(bfad, iocmd, cmd);
  2455. break;
  2456. case IOCMD_PORT_CFG_MAXFRSZ:
  2457. rc = bfad_iocmd_port_cfg_maxfrsize(bfad, iocmd);
  2458. break;
  2459. case IOCMD_PORT_BBCR_ENABLE:
  2460. case IOCMD_PORT_BBCR_DISABLE:
  2461. rc = bfad_iocmd_port_cfg_bbcr(bfad, cmd, iocmd);
  2462. break;
  2463. case IOCMD_PORT_BBCR_GET_ATTR:
  2464. rc = bfad_iocmd_port_get_bbcr_attr(bfad, iocmd);
  2465. break;
  2466. case IOCMD_LPORT_GET_ATTR:
  2467. rc = bfad_iocmd_lport_get_attr(bfad, iocmd);
  2468. break;
  2469. case IOCMD_LPORT_GET_STATS:
  2470. rc = bfad_iocmd_lport_get_stats(bfad, iocmd);
  2471. break;
  2472. case IOCMD_LPORT_RESET_STATS:
  2473. rc = bfad_iocmd_lport_reset_stats(bfad, iocmd);
  2474. break;
  2475. case IOCMD_LPORT_GET_IOSTATS:
  2476. rc = bfad_iocmd_lport_get_iostats(bfad, iocmd);
  2477. break;
  2478. case IOCMD_LPORT_GET_RPORTS:
  2479. rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len);
  2480. break;
  2481. case IOCMD_RPORT_GET_ATTR:
  2482. rc = bfad_iocmd_rport_get_attr(bfad, iocmd);
  2483. break;
  2484. case IOCMD_RPORT_GET_ADDR:
  2485. rc = bfad_iocmd_rport_get_addr(bfad, iocmd);
  2486. break;
  2487. case IOCMD_RPORT_GET_STATS:
  2488. rc = bfad_iocmd_rport_get_stats(bfad, iocmd);
  2489. break;
  2490. case IOCMD_RPORT_RESET_STATS:
  2491. rc = bfad_iocmd_rport_clr_stats(bfad, iocmd);
  2492. break;
  2493. case IOCMD_RPORT_SET_SPEED:
  2494. rc = bfad_iocmd_rport_set_speed(bfad, iocmd);
  2495. break;
  2496. case IOCMD_VPORT_GET_ATTR:
  2497. rc = bfad_iocmd_vport_get_attr(bfad, iocmd);
  2498. break;
  2499. case IOCMD_VPORT_GET_STATS:
  2500. rc = bfad_iocmd_vport_get_stats(bfad, iocmd);
  2501. break;
  2502. case IOCMD_VPORT_RESET_STATS:
  2503. rc = bfad_iocmd_vport_clr_stats(bfad, iocmd);
  2504. break;
  2505. case IOCMD_FABRIC_GET_LPORTS:
  2506. rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len);
  2507. break;
  2508. case IOCMD_RATELIM_ENABLE:
  2509. case IOCMD_RATELIM_DISABLE:
  2510. rc = bfad_iocmd_ratelim(bfad, cmd, iocmd);
  2511. break;
  2512. case IOCMD_RATELIM_DEF_SPEED:
  2513. rc = bfad_iocmd_ratelim_speed(bfad, cmd, iocmd);
  2514. break;
  2515. case IOCMD_FCPIM_FAILOVER:
  2516. rc = bfad_iocmd_cfg_fcpim(bfad, iocmd);
  2517. break;
  2518. case IOCMD_FCPIM_MODSTATS:
  2519. rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd);
  2520. break;
  2521. case IOCMD_FCPIM_MODSTATSCLR:
  2522. rc = bfad_iocmd_fcpim_clr_modstats(bfad, iocmd);
  2523. break;
  2524. case IOCMD_FCPIM_DEL_ITN_STATS:
  2525. rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd);
  2526. break;
  2527. case IOCMD_ITNIM_GET_ATTR:
  2528. rc = bfad_iocmd_itnim_get_attr(bfad, iocmd);
  2529. break;
  2530. case IOCMD_ITNIM_GET_IOSTATS:
  2531. rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd);
  2532. break;
  2533. case IOCMD_ITNIM_RESET_STATS:
  2534. rc = bfad_iocmd_itnim_reset_stats(bfad, iocmd);
  2535. break;
  2536. case IOCMD_ITNIM_GET_ITNSTATS:
  2537. rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd);
  2538. break;
  2539. case IOCMD_FCPORT_ENABLE:
  2540. rc = bfad_iocmd_fcport_enable(bfad, iocmd);
  2541. break;
  2542. case IOCMD_FCPORT_DISABLE:
  2543. rc = bfad_iocmd_fcport_disable(bfad, iocmd);
  2544. break;
  2545. case IOCMD_IOC_PCIFN_CFG:
  2546. rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd);
  2547. break;
  2548. case IOCMD_IOC_FW_SIG_INV:
  2549. rc = bfad_iocmd_ioc_fw_sig_inv(bfad, iocmd);
  2550. break;
  2551. case IOCMD_PCIFN_CREATE:
  2552. rc = bfad_iocmd_pcifn_create(bfad, iocmd);
  2553. break;
  2554. case IOCMD_PCIFN_DELETE:
  2555. rc = bfad_iocmd_pcifn_delete(bfad, iocmd);
  2556. break;
  2557. case IOCMD_PCIFN_BW:
  2558. rc = bfad_iocmd_pcifn_bw(bfad, iocmd);
  2559. break;
  2560. case IOCMD_ADAPTER_CFG_MODE:
  2561. rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd);
  2562. break;
  2563. case IOCMD_PORT_CFG_MODE:
  2564. rc = bfad_iocmd_port_cfg_mode(bfad, iocmd);
  2565. break;
  2566. case IOCMD_FLASH_ENABLE_OPTROM:
  2567. case IOCMD_FLASH_DISABLE_OPTROM:
  2568. rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
  2569. break;
  2570. case IOCMD_FAA_QUERY:
  2571. rc = bfad_iocmd_faa_query(bfad, iocmd);
  2572. break;
  2573. case IOCMD_CEE_GET_ATTR:
  2574. rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len);
  2575. break;
  2576. case IOCMD_CEE_GET_STATS:
  2577. rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len);
  2578. break;
  2579. case IOCMD_CEE_RESET_STATS:
  2580. rc = bfad_iocmd_cee_reset_stats(bfad, iocmd);
  2581. break;
  2582. case IOCMD_SFP_MEDIA:
  2583. rc = bfad_iocmd_sfp_media(bfad, iocmd);
  2584. break;
  2585. case IOCMD_SFP_SPEED:
  2586. rc = bfad_iocmd_sfp_speed(bfad, iocmd);
  2587. break;
  2588. case IOCMD_FLASH_GET_ATTR:
  2589. rc = bfad_iocmd_flash_get_attr(bfad, iocmd);
  2590. break;
  2591. case IOCMD_FLASH_ERASE_PART:
  2592. rc = bfad_iocmd_flash_erase_part(bfad, iocmd);
  2593. break;
  2594. case IOCMD_FLASH_UPDATE_PART:
  2595. rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len);
  2596. break;
  2597. case IOCMD_FLASH_READ_PART:
  2598. rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len);
  2599. break;
  2600. case IOCMD_DIAG_TEMP:
  2601. rc = bfad_iocmd_diag_temp(bfad, iocmd);
  2602. break;
  2603. case IOCMD_DIAG_MEMTEST:
  2604. rc = bfad_iocmd_diag_memtest(bfad, iocmd);
  2605. break;
  2606. case IOCMD_DIAG_LOOPBACK:
  2607. rc = bfad_iocmd_diag_loopback(bfad, iocmd);
  2608. break;
  2609. case IOCMD_DIAG_FWPING:
  2610. rc = bfad_iocmd_diag_fwping(bfad, iocmd);
  2611. break;
  2612. case IOCMD_DIAG_QUEUETEST:
  2613. rc = bfad_iocmd_diag_queuetest(bfad, iocmd);
  2614. break;
  2615. case IOCMD_DIAG_SFP:
  2616. rc = bfad_iocmd_diag_sfp(bfad, iocmd);
  2617. break;
  2618. case IOCMD_DIAG_LED:
  2619. rc = bfad_iocmd_diag_led(bfad, iocmd);
  2620. break;
  2621. case IOCMD_DIAG_BEACON_LPORT:
  2622. rc = bfad_iocmd_diag_beacon_lport(bfad, iocmd);
  2623. break;
  2624. case IOCMD_DIAG_LB_STAT:
  2625. rc = bfad_iocmd_diag_lb_stat(bfad, iocmd);
  2626. break;
  2627. case IOCMD_DIAG_DPORT_ENABLE:
  2628. rc = bfad_iocmd_diag_dport_enable(bfad, iocmd);
  2629. break;
  2630. case IOCMD_DIAG_DPORT_DISABLE:
  2631. rc = bfad_iocmd_diag_dport_disable(bfad, iocmd);
  2632. break;
  2633. case IOCMD_DIAG_DPORT_SHOW:
  2634. rc = bfad_iocmd_diag_dport_show(bfad, iocmd);
  2635. break;
  2636. case IOCMD_DIAG_DPORT_START:
  2637. rc = bfad_iocmd_diag_dport_start(bfad, iocmd);
  2638. break;
  2639. case IOCMD_PHY_GET_ATTR:
  2640. rc = bfad_iocmd_phy_get_attr(bfad, iocmd);
  2641. break;
  2642. case IOCMD_PHY_GET_STATS:
  2643. rc = bfad_iocmd_phy_get_stats(bfad, iocmd);
  2644. break;
  2645. case IOCMD_PHY_UPDATE_FW:
  2646. rc = bfad_iocmd_phy_update(bfad, iocmd, payload_len);
  2647. break;
  2648. case IOCMD_PHY_READ_FW:
  2649. rc = bfad_iocmd_phy_read(bfad, iocmd, payload_len);
  2650. break;
  2651. case IOCMD_VHBA_QUERY:
  2652. rc = bfad_iocmd_vhba_query(bfad, iocmd);
  2653. break;
  2654. case IOCMD_DEBUG_PORTLOG:
  2655. rc = bfad_iocmd_porglog_get(bfad, iocmd);
  2656. break;
  2657. case IOCMD_DEBUG_FW_CORE:
  2658. rc = bfad_iocmd_debug_fw_core(bfad, iocmd, payload_len);
  2659. break;
  2660. case IOCMD_DEBUG_FW_STATE_CLR:
  2661. case IOCMD_DEBUG_PORTLOG_CLR:
  2662. case IOCMD_DEBUG_START_DTRC:
  2663. case IOCMD_DEBUG_STOP_DTRC:
  2664. rc = bfad_iocmd_debug_ctl(bfad, iocmd, cmd);
  2665. break;
  2666. case IOCMD_DEBUG_PORTLOG_CTL:
  2667. rc = bfad_iocmd_porglog_ctl(bfad, iocmd);
  2668. break;
  2669. case IOCMD_FCPIM_PROFILE_ON:
  2670. case IOCMD_FCPIM_PROFILE_OFF:
  2671. rc = bfad_iocmd_fcpim_cfg_profile(bfad, iocmd, cmd);
  2672. break;
  2673. case IOCMD_ITNIM_GET_IOPROFILE:
  2674. rc = bfad_iocmd_itnim_get_ioprofile(bfad, iocmd);
  2675. break;
  2676. case IOCMD_FCPORT_GET_STATS:
  2677. rc = bfad_iocmd_fcport_get_stats(bfad, iocmd);
  2678. break;
  2679. case IOCMD_FCPORT_RESET_STATS:
  2680. rc = bfad_iocmd_fcport_reset_stats(bfad, iocmd);
  2681. break;
  2682. case IOCMD_BOOT_CFG:
  2683. rc = bfad_iocmd_boot_cfg(bfad, iocmd);
  2684. break;
  2685. case IOCMD_BOOT_QUERY:
  2686. rc = bfad_iocmd_boot_query(bfad, iocmd);
  2687. break;
  2688. case IOCMD_PREBOOT_QUERY:
  2689. rc = bfad_iocmd_preboot_query(bfad, iocmd);
  2690. break;
  2691. case IOCMD_ETHBOOT_CFG:
  2692. rc = bfad_iocmd_ethboot_cfg(bfad, iocmd);
  2693. break;
  2694. case IOCMD_ETHBOOT_QUERY:
  2695. rc = bfad_iocmd_ethboot_query(bfad, iocmd);
  2696. break;
  2697. case IOCMD_TRUNK_ENABLE:
  2698. case IOCMD_TRUNK_DISABLE:
  2699. rc = bfad_iocmd_cfg_trunk(bfad, iocmd, cmd);
  2700. break;
  2701. case IOCMD_TRUNK_GET_ATTR:
  2702. rc = bfad_iocmd_trunk_get_attr(bfad, iocmd);
  2703. break;
  2704. case IOCMD_QOS_ENABLE:
  2705. case IOCMD_QOS_DISABLE:
  2706. rc = bfad_iocmd_qos(bfad, iocmd, cmd);
  2707. break;
  2708. case IOCMD_QOS_GET_ATTR:
  2709. rc = bfad_iocmd_qos_get_attr(bfad, iocmd);
  2710. break;
  2711. case IOCMD_QOS_GET_VC_ATTR:
  2712. rc = bfad_iocmd_qos_get_vc_attr(bfad, iocmd);
  2713. break;
  2714. case IOCMD_QOS_GET_STATS:
  2715. rc = bfad_iocmd_qos_get_stats(bfad, iocmd);
  2716. break;
  2717. case IOCMD_QOS_RESET_STATS:
  2718. rc = bfad_iocmd_qos_reset_stats(bfad, iocmd);
  2719. break;
  2720. case IOCMD_QOS_SET_BW:
  2721. rc = bfad_iocmd_qos_set_bw(bfad, iocmd);
  2722. break;
  2723. case IOCMD_VF_GET_STATS:
  2724. rc = bfad_iocmd_vf_get_stats(bfad, iocmd);
  2725. break;
  2726. case IOCMD_VF_RESET_STATS:
  2727. rc = bfad_iocmd_vf_clr_stats(bfad, iocmd);
  2728. break;
  2729. case IOCMD_FCPIM_LUNMASK_ENABLE:
  2730. case IOCMD_FCPIM_LUNMASK_DISABLE:
  2731. case IOCMD_FCPIM_LUNMASK_CLEAR:
  2732. rc = bfad_iocmd_lunmask(bfad, iocmd, cmd);
  2733. break;
  2734. case IOCMD_FCPIM_LUNMASK_QUERY:
  2735. rc = bfad_iocmd_fcpim_lunmask_query(bfad, iocmd);
  2736. break;
  2737. case IOCMD_FCPIM_LUNMASK_ADD:
  2738. case IOCMD_FCPIM_LUNMASK_DELETE:
  2739. rc = bfad_iocmd_fcpim_cfg_lunmask(bfad, iocmd, cmd);
  2740. break;
  2741. case IOCMD_FCPIM_THROTTLE_QUERY:
  2742. rc = bfad_iocmd_fcpim_throttle_query(bfad, iocmd);
  2743. break;
  2744. case IOCMD_FCPIM_THROTTLE_SET:
  2745. rc = bfad_iocmd_fcpim_throttle_set(bfad, iocmd);
  2746. break;
  2747. /* TFRU */
  2748. case IOCMD_TFRU_READ:
  2749. rc = bfad_iocmd_tfru_read(bfad, iocmd);
  2750. break;
  2751. case IOCMD_TFRU_WRITE:
  2752. rc = bfad_iocmd_tfru_write(bfad, iocmd);
  2753. break;
  2754. /* FRU */
  2755. case IOCMD_FRUVPD_READ:
  2756. rc = bfad_iocmd_fruvpd_read(bfad, iocmd);
  2757. break;
  2758. case IOCMD_FRUVPD_UPDATE:
  2759. rc = bfad_iocmd_fruvpd_update(bfad, iocmd);
  2760. break;
  2761. case IOCMD_FRUVPD_GET_MAX_SIZE:
  2762. rc = bfad_iocmd_fruvpd_get_max_size(bfad, iocmd);
  2763. break;
  2764. default:
  2765. rc = -EINVAL;
  2766. break;
  2767. }
  2768. return rc;
  2769. }
  2770. static int
  2771. bfad_im_bsg_vendor_request(struct bsg_job *job)
  2772. {
  2773. struct fc_bsg_request *bsg_request = job->request;
  2774. struct fc_bsg_reply *bsg_reply = job->reply;
  2775. uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
  2776. struct Scsi_Host *shost = fc_bsg_to_shost(job);
  2777. struct bfad_im_port_s *im_port = bfad_get_im_port(shost);
  2778. struct bfad_s *bfad = im_port->bfad;
  2779. void *payload_kbuf;
  2780. int rc = -EINVAL;
  2781. /* Allocate a temp buffer to hold the passed in user space command */
  2782. payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
  2783. if (!payload_kbuf) {
  2784. rc = -ENOMEM;
  2785. goto out;
  2786. }
  2787. /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */
  2788. sg_copy_to_buffer(job->request_payload.sg_list,
  2789. job->request_payload.sg_cnt, payload_kbuf,
  2790. job->request_payload.payload_len);
  2791. /* Invoke IOCMD handler - to handle all the vendor command requests */
  2792. rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf,
  2793. job->request_payload.payload_len);
  2794. if (rc != BFA_STATUS_OK)
  2795. goto error;
  2796. /* Copy the response data to the job->reply_payload sg_list */
  2797. sg_copy_from_buffer(job->reply_payload.sg_list,
  2798. job->reply_payload.sg_cnt,
  2799. payload_kbuf,
  2800. job->reply_payload.payload_len);
  2801. /* free the command buffer */
  2802. kfree(payload_kbuf);
  2803. /* Fill the BSG job reply data */
  2804. job->reply_len = job->reply_payload.payload_len;
  2805. bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
  2806. bsg_reply->result = rc;
  2807. bsg_job_done(job, bsg_reply->result,
  2808. bsg_reply->reply_payload_rcv_len);
  2809. return rc;
  2810. error:
  2811. /* free the command buffer */
  2812. kfree(payload_kbuf);
  2813. out:
  2814. bsg_reply->result = rc;
  2815. job->reply_len = sizeof(uint32_t);
  2816. bsg_reply->reply_payload_rcv_len = 0;
  2817. return rc;
  2818. }
  2819. /* FC passthru call backs */
  2820. u64
  2821. bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid)
  2822. {
  2823. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2824. struct bfa_sge_s *sge;
  2825. u64 addr;
  2826. sge = drv_fcxp->req_sge + sgeid;
  2827. addr = (u64)(size_t) sge->sg_addr;
  2828. return addr;
  2829. }
  2830. u32
  2831. bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid)
  2832. {
  2833. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2834. struct bfa_sge_s *sge;
  2835. sge = drv_fcxp->req_sge + sgeid;
  2836. return sge->sg_len;
  2837. }
  2838. u64
  2839. bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid)
  2840. {
  2841. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2842. struct bfa_sge_s *sge;
  2843. u64 addr;
  2844. sge = drv_fcxp->rsp_sge + sgeid;
  2845. addr = (u64)(size_t) sge->sg_addr;
  2846. return addr;
  2847. }
  2848. u32
  2849. bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid)
  2850. {
  2851. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2852. struct bfa_sge_s *sge;
  2853. sge = drv_fcxp->rsp_sge + sgeid;
  2854. return sge->sg_len;
  2855. }
  2856. void
  2857. bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  2858. bfa_status_t req_status, u32 rsp_len, u32 resid_len,
  2859. struct fchs_s *rsp_fchs)
  2860. {
  2861. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2862. drv_fcxp->req_status = req_status;
  2863. drv_fcxp->rsp_len = rsp_len;
  2864. /* bfa_fcxp will be automatically freed by BFA */
  2865. drv_fcxp->bfa_fcxp = NULL;
  2866. complete(&drv_fcxp->comp);
  2867. }
  2868. struct bfad_buf_info *
  2869. bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf,
  2870. uint32_t payload_len, uint32_t *num_sgles)
  2871. {
  2872. struct bfad_buf_info *buf_base, *buf_info;
  2873. struct bfa_sge_s *sg_table;
  2874. int sge_num = 1;
  2875. buf_base = kcalloc(sizeof(struct bfad_buf_info) +
  2876. sizeof(struct bfa_sge_s),
  2877. sge_num, GFP_KERNEL);
  2878. if (!buf_base)
  2879. return NULL;
  2880. sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) +
  2881. (sizeof(struct bfad_buf_info) * sge_num));
  2882. /* Allocate dma coherent memory */
  2883. buf_info = buf_base;
  2884. buf_info->size = payload_len;
  2885. buf_info->virt = dma_zalloc_coherent(&bfad->pcidev->dev,
  2886. buf_info->size, &buf_info->phys,
  2887. GFP_KERNEL);
  2888. if (!buf_info->virt)
  2889. goto out_free_mem;
  2890. /* copy the linear bsg buffer to buf_info */
  2891. memcpy(buf_info->virt, payload_kbuf, buf_info->size);
  2892. /*
  2893. * Setup SG table
  2894. */
  2895. sg_table->sg_len = buf_info->size;
  2896. sg_table->sg_addr = (void *)(size_t) buf_info->phys;
  2897. *num_sgles = sge_num;
  2898. return buf_base;
  2899. out_free_mem:
  2900. kfree(buf_base);
  2901. return NULL;
  2902. }
  2903. void
  2904. bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base,
  2905. uint32_t num_sgles)
  2906. {
  2907. int i;
  2908. struct bfad_buf_info *buf_info = buf_base;
  2909. if (buf_base) {
  2910. for (i = 0; i < num_sgles; buf_info++, i++) {
  2911. if (buf_info->virt != NULL)
  2912. dma_free_coherent(&bfad->pcidev->dev,
  2913. buf_info->size, buf_info->virt,
  2914. buf_info->phys);
  2915. }
  2916. kfree(buf_base);
  2917. }
  2918. }
  2919. int
  2920. bfad_fcxp_bsg_send(struct bsg_job *job, struct bfad_fcxp *drv_fcxp,
  2921. bfa_bsg_fcpt_t *bsg_fcpt)
  2922. {
  2923. struct bfa_fcxp_s *hal_fcxp;
  2924. struct bfad_s *bfad = drv_fcxp->port->bfad;
  2925. unsigned long flags;
  2926. uint8_t lp_tag;
  2927. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2928. /* Allocate bfa_fcxp structure */
  2929. hal_fcxp = bfa_fcxp_req_rsp_alloc(drv_fcxp, &bfad->bfa,
  2930. drv_fcxp->num_req_sgles,
  2931. drv_fcxp->num_rsp_sgles,
  2932. bfad_fcxp_get_req_sgaddr_cb,
  2933. bfad_fcxp_get_req_sglen_cb,
  2934. bfad_fcxp_get_rsp_sgaddr_cb,
  2935. bfad_fcxp_get_rsp_sglen_cb, BFA_TRUE);
  2936. if (!hal_fcxp) {
  2937. bfa_trc(bfad, 0);
  2938. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2939. return BFA_STATUS_ENOMEM;
  2940. }
  2941. drv_fcxp->bfa_fcxp = hal_fcxp;
  2942. lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id);
  2943. bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag,
  2944. bsg_fcpt->cts, bsg_fcpt->cos,
  2945. job->request_payload.payload_len,
  2946. &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad,
  2947. job->reply_payload.payload_len, bsg_fcpt->tsecs);
  2948. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2949. return BFA_STATUS_OK;
  2950. }
  2951. int
  2952. bfad_im_bsg_els_ct_request(struct bsg_job *job)
  2953. {
  2954. struct bfa_bsg_data *bsg_data;
  2955. struct Scsi_Host *shost = fc_bsg_to_shost(job);
  2956. struct bfad_im_port_s *im_port = bfad_get_im_port(shost);
  2957. struct bfad_s *bfad = im_port->bfad;
  2958. bfa_bsg_fcpt_t *bsg_fcpt;
  2959. struct bfad_fcxp *drv_fcxp;
  2960. struct bfa_fcs_lport_s *fcs_port;
  2961. struct bfa_fcs_rport_s *fcs_rport;
  2962. struct fc_bsg_request *bsg_request = job->request;
  2963. struct fc_bsg_reply *bsg_reply = job->reply;
  2964. uint32_t command_type = bsg_request->msgcode;
  2965. unsigned long flags;
  2966. struct bfad_buf_info *rsp_buf_info;
  2967. void *req_kbuf = NULL, *rsp_kbuf = NULL;
  2968. int rc = -EINVAL;
  2969. job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */
  2970. bsg_reply->reply_payload_rcv_len = 0;
  2971. /* Get the payload passed in from userspace */
  2972. bsg_data = (struct bfa_bsg_data *) (((char *)bsg_request) +
  2973. sizeof(struct fc_bsg_request));
  2974. if (bsg_data == NULL)
  2975. goto out;
  2976. /*
  2977. * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
  2978. * buffer of size bsg_data->payload_len
  2979. */
  2980. bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL);
  2981. if (!bsg_fcpt) {
  2982. rc = -ENOMEM;
  2983. goto out;
  2984. }
  2985. if (copy_from_user((uint8_t *)bsg_fcpt,
  2986. (void *)(unsigned long)bsg_data->payload,
  2987. bsg_data->payload_len)) {
  2988. kfree(bsg_fcpt);
  2989. rc = -EIO;
  2990. goto out;
  2991. }
  2992. drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);
  2993. if (drv_fcxp == NULL) {
  2994. kfree(bsg_fcpt);
  2995. rc = -ENOMEM;
  2996. goto out;
  2997. }
  2998. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2999. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id,
  3000. bsg_fcpt->lpwwn);
  3001. if (fcs_port == NULL) {
  3002. bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN;
  3003. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3004. goto out_free_mem;
  3005. }
  3006. /* Check if the port is online before sending FC Passthru cmd */
  3007. if (!bfa_fcs_lport_is_online(fcs_port)) {
  3008. bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE;
  3009. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3010. goto out_free_mem;
  3011. }
  3012. drv_fcxp->port = fcs_port->bfad_port;
  3013. if (drv_fcxp->port->bfad == 0)
  3014. drv_fcxp->port->bfad = bfad;
  3015. /* Fetch the bfa_rport - if nexus needed */
  3016. if (command_type == FC_BSG_HST_ELS_NOLOGIN ||
  3017. command_type == FC_BSG_HST_CT) {
  3018. /* BSG HST commands: no nexus needed */
  3019. drv_fcxp->bfa_rport = NULL;
  3020. } else if (command_type == FC_BSG_RPT_ELS ||
  3021. command_type == FC_BSG_RPT_CT) {
  3022. /* BSG RPT commands: nexus needed */
  3023. fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port,
  3024. bsg_fcpt->dpwwn);
  3025. if (fcs_rport == NULL) {
  3026. bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN;
  3027. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3028. goto out_free_mem;
  3029. }
  3030. drv_fcxp->bfa_rport = fcs_rport->bfa_rport;
  3031. } else { /* Unknown BSG msgcode; return -EINVAL */
  3032. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3033. goto out_free_mem;
  3034. }
  3035. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3036. /* allocate memory for req / rsp buffers */
  3037. req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
  3038. if (!req_kbuf) {
  3039. printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n",
  3040. bfad->pci_name);
  3041. rc = -ENOMEM;
  3042. goto out_free_mem;
  3043. }
  3044. rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL);
  3045. if (!rsp_kbuf) {
  3046. printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n",
  3047. bfad->pci_name);
  3048. rc = -ENOMEM;
  3049. goto out_free_mem;
  3050. }
  3051. /* map req sg - copy the sg_list passed in to the linear buffer */
  3052. sg_copy_to_buffer(job->request_payload.sg_list,
  3053. job->request_payload.sg_cnt, req_kbuf,
  3054. job->request_payload.payload_len);
  3055. drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf,
  3056. job->request_payload.payload_len,
  3057. &drv_fcxp->num_req_sgles);
  3058. if (!drv_fcxp->reqbuf_info) {
  3059. printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n",
  3060. bfad->pci_name);
  3061. rc = -ENOMEM;
  3062. goto out_free_mem;
  3063. }
  3064. drv_fcxp->req_sge = (struct bfa_sge_s *)
  3065. (((uint8_t *)drv_fcxp->reqbuf_info) +
  3066. (sizeof(struct bfad_buf_info) *
  3067. drv_fcxp->num_req_sgles));
  3068. /* map rsp sg */
  3069. drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf,
  3070. job->reply_payload.payload_len,
  3071. &drv_fcxp->num_rsp_sgles);
  3072. if (!drv_fcxp->rspbuf_info) {
  3073. printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n",
  3074. bfad->pci_name);
  3075. rc = -ENOMEM;
  3076. goto out_free_mem;
  3077. }
  3078. rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info;
  3079. drv_fcxp->rsp_sge = (struct bfa_sge_s *)
  3080. (((uint8_t *)drv_fcxp->rspbuf_info) +
  3081. (sizeof(struct bfad_buf_info) *
  3082. drv_fcxp->num_rsp_sgles));
  3083. /* fcxp send */
  3084. init_completion(&drv_fcxp->comp);
  3085. rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt);
  3086. if (rc == BFA_STATUS_OK) {
  3087. wait_for_completion(&drv_fcxp->comp);
  3088. bsg_fcpt->status = drv_fcxp->req_status;
  3089. } else {
  3090. bsg_fcpt->status = rc;
  3091. goto out_free_mem;
  3092. }
  3093. /* fill the job->reply data */
  3094. if (drv_fcxp->req_status == BFA_STATUS_OK) {
  3095. job->reply_len = drv_fcxp->rsp_len;
  3096. bsg_reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
  3097. bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
  3098. } else {
  3099. bsg_reply->reply_payload_rcv_len =
  3100. sizeof(struct fc_bsg_ctels_reply);
  3101. job->reply_len = sizeof(uint32_t);
  3102. bsg_reply->reply_data.ctels_reply.status =
  3103. FC_CTELS_STATUS_REJECT;
  3104. }
  3105. /* Copy the response data to the reply_payload sg list */
  3106. sg_copy_from_buffer(job->reply_payload.sg_list,
  3107. job->reply_payload.sg_cnt,
  3108. (uint8_t *)rsp_buf_info->virt,
  3109. job->reply_payload.payload_len);
  3110. out_free_mem:
  3111. bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info,
  3112. drv_fcxp->num_rsp_sgles);
  3113. bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info,
  3114. drv_fcxp->num_req_sgles);
  3115. kfree(req_kbuf);
  3116. kfree(rsp_kbuf);
  3117. /* Need a copy to user op */
  3118. if (copy_to_user((void *)(unsigned long)bsg_data->payload,
  3119. (void *)bsg_fcpt, bsg_data->payload_len))
  3120. rc = -EIO;
  3121. kfree(bsg_fcpt);
  3122. kfree(drv_fcxp);
  3123. out:
  3124. bsg_reply->result = rc;
  3125. if (rc == BFA_STATUS_OK)
  3126. bsg_job_done(job, bsg_reply->result,
  3127. bsg_reply->reply_payload_rcv_len);
  3128. return rc;
  3129. }
  3130. int
  3131. bfad_im_bsg_request(struct bsg_job *job)
  3132. {
  3133. struct fc_bsg_request *bsg_request = job->request;
  3134. struct fc_bsg_reply *bsg_reply = job->reply;
  3135. uint32_t rc = BFA_STATUS_OK;
  3136. switch (bsg_request->msgcode) {
  3137. case FC_BSG_HST_VENDOR:
  3138. /* Process BSG HST Vendor requests */
  3139. rc = bfad_im_bsg_vendor_request(job);
  3140. break;
  3141. case FC_BSG_HST_ELS_NOLOGIN:
  3142. case FC_BSG_RPT_ELS:
  3143. case FC_BSG_HST_CT:
  3144. case FC_BSG_RPT_CT:
  3145. /* Process BSG ELS/CT commands */
  3146. rc = bfad_im_bsg_els_ct_request(job);
  3147. break;
  3148. default:
  3149. bsg_reply->result = rc = -EINVAL;
  3150. bsg_reply->reply_payload_rcv_len = 0;
  3151. break;
  3152. }
  3153. return rc;
  3154. }
  3155. int
  3156. bfad_im_bsg_timeout(struct bsg_job *job)
  3157. {
  3158. /* Don't complete the BSG job request - return -EAGAIN
  3159. * to reset bsg job timeout : for ELS/CT pass thru we
  3160. * already have timer to track the request.
  3161. */
  3162. return -EAGAIN;
  3163. }