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. strncpy(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. strncpy(iocmd->attr.port_symname.symname,
  269. port_attr.port_cfg.sym_name.symname,
  270. sizeof(port_attr.port_cfg.sym_name.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. struct timeval tv;
  1822. unsigned long flags;
  1823. do_gettimeofday(&tv);
  1824. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1825. if (v_cmd == IOCMD_FCPIM_PROFILE_ON)
  1826. iocmd->status = bfa_fcpim_profile_on(&bfad->bfa, tv.tv_sec);
  1827. else if (v_cmd == IOCMD_FCPIM_PROFILE_OFF)
  1828. iocmd->status = bfa_fcpim_profile_off(&bfad->bfa);
  1829. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1830. return 0;
  1831. }
  1832. static int
  1833. bfad_iocmd_itnim_get_ioprofile(struct bfad_s *bfad, void *cmd)
  1834. {
  1835. struct bfa_bsg_itnim_ioprofile_s *iocmd =
  1836. (struct bfa_bsg_itnim_ioprofile_s *)cmd;
  1837. struct bfa_fcs_lport_s *fcs_port;
  1838. struct bfa_fcs_itnim_s *itnim;
  1839. unsigned long flags;
  1840. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1841. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
  1842. iocmd->vf_id, iocmd->lpwwn);
  1843. if (!fcs_port)
  1844. iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
  1845. else {
  1846. itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
  1847. if (itnim == NULL)
  1848. iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
  1849. else
  1850. iocmd->status = bfa_itnim_get_ioprofile(
  1851. bfa_fcs_itnim_get_halitn(itnim),
  1852. &iocmd->ioprofile);
  1853. }
  1854. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1855. return 0;
  1856. }
  1857. int
  1858. bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)
  1859. {
  1860. struct bfa_bsg_fcport_stats_s *iocmd =
  1861. (struct bfa_bsg_fcport_stats_s *)cmd;
  1862. struct bfad_hal_comp fcomp;
  1863. unsigned long flags;
  1864. struct bfa_cb_pending_q_s cb_qe;
  1865. init_completion(&fcomp.comp);
  1866. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  1867. &fcomp, &iocmd->stats);
  1868. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1869. iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
  1870. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1871. if (iocmd->status != BFA_STATUS_OK) {
  1872. bfa_trc(bfad, iocmd->status);
  1873. goto out;
  1874. }
  1875. wait_for_completion(&fcomp.comp);
  1876. iocmd->status = fcomp.status;
  1877. out:
  1878. return 0;
  1879. }
  1880. int
  1881. bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)
  1882. {
  1883. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  1884. struct bfad_hal_comp fcomp;
  1885. unsigned long flags;
  1886. struct bfa_cb_pending_q_s cb_qe;
  1887. init_completion(&fcomp.comp);
  1888. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL);
  1889. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1890. iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
  1891. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1892. if (iocmd->status != BFA_STATUS_OK) {
  1893. bfa_trc(bfad, iocmd->status);
  1894. goto out;
  1895. }
  1896. wait_for_completion(&fcomp.comp);
  1897. iocmd->status = fcomp.status;
  1898. out:
  1899. return 0;
  1900. }
  1901. int
  1902. bfad_iocmd_boot_cfg(struct bfad_s *bfad, void *cmd)
  1903. {
  1904. struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
  1905. struct bfad_hal_comp fcomp;
  1906. unsigned long flags;
  1907. init_completion(&fcomp.comp);
  1908. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1909. iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
  1910. BFA_FLASH_PART_BOOT, bfad->bfa.ioc.port_id,
  1911. &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
  1912. bfad_hcb_comp, &fcomp);
  1913. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1914. if (iocmd->status != BFA_STATUS_OK)
  1915. goto out;
  1916. wait_for_completion(&fcomp.comp);
  1917. iocmd->status = fcomp.status;
  1918. out:
  1919. return 0;
  1920. }
  1921. int
  1922. bfad_iocmd_boot_query(struct bfad_s *bfad, void *cmd)
  1923. {
  1924. struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
  1925. struct bfad_hal_comp fcomp;
  1926. unsigned long flags;
  1927. init_completion(&fcomp.comp);
  1928. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1929. iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
  1930. BFA_FLASH_PART_BOOT, bfad->bfa.ioc.port_id,
  1931. &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
  1932. bfad_hcb_comp, &fcomp);
  1933. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1934. if (iocmd->status != BFA_STATUS_OK)
  1935. goto out;
  1936. wait_for_completion(&fcomp.comp);
  1937. iocmd->status = fcomp.status;
  1938. out:
  1939. return 0;
  1940. }
  1941. int
  1942. bfad_iocmd_preboot_query(struct bfad_s *bfad, void *cmd)
  1943. {
  1944. struct bfa_bsg_preboot_s *iocmd = (struct bfa_bsg_preboot_s *)cmd;
  1945. struct bfi_iocfc_cfgrsp_s *cfgrsp = bfad->bfa.iocfc.cfgrsp;
  1946. struct bfa_boot_pbc_s *pbcfg = &iocmd->cfg;
  1947. unsigned long flags;
  1948. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1949. pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
  1950. pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
  1951. pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
  1952. memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
  1953. iocmd->status = BFA_STATUS_OK;
  1954. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1955. return 0;
  1956. }
  1957. int
  1958. bfad_iocmd_ethboot_cfg(struct bfad_s *bfad, void *cmd)
  1959. {
  1960. struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
  1961. struct bfad_hal_comp fcomp;
  1962. unsigned long flags;
  1963. init_completion(&fcomp.comp);
  1964. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1965. iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
  1966. BFA_FLASH_PART_PXECFG,
  1967. bfad->bfa.ioc.port_id, &iocmd->cfg,
  1968. sizeof(struct bfa_ethboot_cfg_s), 0,
  1969. bfad_hcb_comp, &fcomp);
  1970. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1971. if (iocmd->status != BFA_STATUS_OK)
  1972. goto out;
  1973. wait_for_completion(&fcomp.comp);
  1974. iocmd->status = fcomp.status;
  1975. out:
  1976. return 0;
  1977. }
  1978. int
  1979. bfad_iocmd_ethboot_query(struct bfad_s *bfad, void *cmd)
  1980. {
  1981. struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
  1982. struct bfad_hal_comp fcomp;
  1983. unsigned long flags;
  1984. init_completion(&fcomp.comp);
  1985. spin_lock_irqsave(&bfad->bfad_lock, flags);
  1986. iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
  1987. BFA_FLASH_PART_PXECFG,
  1988. bfad->bfa.ioc.port_id, &iocmd->cfg,
  1989. sizeof(struct bfa_ethboot_cfg_s), 0,
  1990. bfad_hcb_comp, &fcomp);
  1991. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1992. if (iocmd->status != BFA_STATUS_OK)
  1993. goto out;
  1994. wait_for_completion(&fcomp.comp);
  1995. iocmd->status = fcomp.status;
  1996. out:
  1997. return 0;
  1998. }
  1999. int
  2000. bfad_iocmd_cfg_trunk(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  2001. {
  2002. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2003. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2004. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2005. unsigned long flags;
  2006. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2007. if (bfa_fcport_is_dport(&bfad->bfa)) {
  2008. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2009. return BFA_STATUS_DPORT_ERR;
  2010. }
  2011. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
  2012. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2013. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2014. else {
  2015. if (v_cmd == IOCMD_TRUNK_ENABLE) {
  2016. trunk->attr.state = BFA_TRUNK_OFFLINE;
  2017. bfa_fcport_disable(&bfad->bfa);
  2018. fcport->cfg.trunked = BFA_TRUE;
  2019. } else if (v_cmd == IOCMD_TRUNK_DISABLE) {
  2020. trunk->attr.state = BFA_TRUNK_DISABLED;
  2021. bfa_fcport_disable(&bfad->bfa);
  2022. fcport->cfg.trunked = BFA_FALSE;
  2023. }
  2024. if (!bfa_fcport_is_disabled(&bfad->bfa))
  2025. bfa_fcport_enable(&bfad->bfa);
  2026. iocmd->status = BFA_STATUS_OK;
  2027. }
  2028. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2029. return 0;
  2030. }
  2031. int
  2032. bfad_iocmd_trunk_get_attr(struct bfad_s *bfad, void *cmd)
  2033. {
  2034. struct bfa_bsg_trunk_attr_s *iocmd = (struct bfa_bsg_trunk_attr_s *)cmd;
  2035. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2036. struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
  2037. unsigned long flags;
  2038. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2039. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
  2040. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2041. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2042. else {
  2043. memcpy((void *)&iocmd->attr, (void *)&trunk->attr,
  2044. sizeof(struct bfa_trunk_attr_s));
  2045. iocmd->attr.port_id = bfa_lps_get_base_pid(&bfad->bfa);
  2046. iocmd->status = BFA_STATUS_OK;
  2047. }
  2048. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2049. return 0;
  2050. }
  2051. int
  2052. bfad_iocmd_qos(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  2053. {
  2054. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2055. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2056. unsigned long flags;
  2057. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2058. if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) {
  2059. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2060. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2061. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2062. else {
  2063. if (v_cmd == IOCMD_QOS_ENABLE)
  2064. fcport->cfg.qos_enabled = BFA_TRUE;
  2065. else if (v_cmd == IOCMD_QOS_DISABLE) {
  2066. fcport->cfg.qos_enabled = BFA_FALSE;
  2067. fcport->cfg.qos_bw.high = BFA_QOS_BW_HIGH;
  2068. fcport->cfg.qos_bw.med = BFA_QOS_BW_MED;
  2069. fcport->cfg.qos_bw.low = BFA_QOS_BW_LOW;
  2070. }
  2071. }
  2072. }
  2073. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2074. return 0;
  2075. }
  2076. int
  2077. bfad_iocmd_qos_get_attr(struct bfad_s *bfad, void *cmd)
  2078. {
  2079. struct bfa_bsg_qos_attr_s *iocmd = (struct bfa_bsg_qos_attr_s *)cmd;
  2080. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2081. unsigned long flags;
  2082. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2083. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2084. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2085. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2086. else {
  2087. iocmd->attr.state = fcport->qos_attr.state;
  2088. iocmd->attr.total_bb_cr =
  2089. be32_to_cpu(fcport->qos_attr.total_bb_cr);
  2090. iocmd->attr.qos_bw.high = fcport->cfg.qos_bw.high;
  2091. iocmd->attr.qos_bw.med = fcport->cfg.qos_bw.med;
  2092. iocmd->attr.qos_bw.low = fcport->cfg.qos_bw.low;
  2093. iocmd->attr.qos_bw_op = fcport->qos_attr.qos_bw_op;
  2094. iocmd->status = BFA_STATUS_OK;
  2095. }
  2096. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2097. return 0;
  2098. }
  2099. int
  2100. bfad_iocmd_qos_get_vc_attr(struct bfad_s *bfad, void *cmd)
  2101. {
  2102. struct bfa_bsg_qos_vc_attr_s *iocmd =
  2103. (struct bfa_bsg_qos_vc_attr_s *)cmd;
  2104. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2105. struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
  2106. unsigned long flags;
  2107. u32 i = 0;
  2108. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2109. iocmd->attr.total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count);
  2110. iocmd->attr.shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit);
  2111. iocmd->attr.elp_opmode_flags =
  2112. be32_to_cpu(bfa_vc_attr->elp_opmode_flags);
  2113. /* Individual VC info */
  2114. while (i < iocmd->attr.total_vc_count) {
  2115. iocmd->attr.vc_info[i].vc_credit =
  2116. bfa_vc_attr->vc_info[i].vc_credit;
  2117. iocmd->attr.vc_info[i].borrow_credit =
  2118. bfa_vc_attr->vc_info[i].borrow_credit;
  2119. iocmd->attr.vc_info[i].priority =
  2120. bfa_vc_attr->vc_info[i].priority;
  2121. i++;
  2122. }
  2123. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2124. iocmd->status = BFA_STATUS_OK;
  2125. return 0;
  2126. }
  2127. int
  2128. bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd)
  2129. {
  2130. struct bfa_bsg_fcport_stats_s *iocmd =
  2131. (struct bfa_bsg_fcport_stats_s *)cmd;
  2132. struct bfad_hal_comp fcomp;
  2133. unsigned long flags;
  2134. struct bfa_cb_pending_q_s cb_qe;
  2135. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2136. init_completion(&fcomp.comp);
  2137. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  2138. &fcomp, &iocmd->stats);
  2139. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2140. WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
  2141. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2142. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2143. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2144. else
  2145. iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
  2146. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2147. if (iocmd->status != BFA_STATUS_OK) {
  2148. bfa_trc(bfad, iocmd->status);
  2149. goto out;
  2150. }
  2151. wait_for_completion(&fcomp.comp);
  2152. iocmd->status = fcomp.status;
  2153. out:
  2154. return 0;
  2155. }
  2156. int
  2157. bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)
  2158. {
  2159. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
  2160. struct bfad_hal_comp fcomp;
  2161. unsigned long flags;
  2162. struct bfa_cb_pending_q_s cb_qe;
  2163. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
  2164. init_completion(&fcomp.comp);
  2165. bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
  2166. &fcomp, NULL);
  2167. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2168. WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
  2169. if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
  2170. (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
  2171. iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
  2172. else
  2173. iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
  2174. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2175. if (iocmd->status != BFA_STATUS_OK) {
  2176. bfa_trc(bfad, iocmd->status);
  2177. goto out;
  2178. }
  2179. wait_for_completion(&fcomp.comp);
  2180. iocmd->status = fcomp.status;
  2181. out:
  2182. return 0;
  2183. }
  2184. int
  2185. bfad_iocmd_vf_get_stats(struct bfad_s *bfad, void *cmd)
  2186. {
  2187. struct bfa_bsg_vf_stats_s *iocmd =
  2188. (struct bfa_bsg_vf_stats_s *)cmd;
  2189. struct bfa_fcs_fabric_s *fcs_vf;
  2190. unsigned long flags;
  2191. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2192. fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
  2193. if (fcs_vf == NULL) {
  2194. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2195. iocmd->status = BFA_STATUS_UNKNOWN_VFID;
  2196. goto out;
  2197. }
  2198. memcpy((void *)&iocmd->stats, (void *)&fcs_vf->stats,
  2199. sizeof(struct bfa_vf_stats_s));
  2200. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2201. iocmd->status = BFA_STATUS_OK;
  2202. out:
  2203. return 0;
  2204. }
  2205. int
  2206. bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd)
  2207. {
  2208. struct bfa_bsg_vf_reset_stats_s *iocmd =
  2209. (struct bfa_bsg_vf_reset_stats_s *)cmd;
  2210. struct bfa_fcs_fabric_s *fcs_vf;
  2211. unsigned long flags;
  2212. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2213. fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
  2214. if (fcs_vf == NULL) {
  2215. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2216. iocmd->status = BFA_STATUS_UNKNOWN_VFID;
  2217. goto out;
  2218. }
  2219. memset((void *)&fcs_vf->stats, 0, sizeof(struct bfa_vf_stats_s));
  2220. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2221. iocmd->status = BFA_STATUS_OK;
  2222. out:
  2223. return 0;
  2224. }
  2225. /* Function to reset the LUN SCAN mode */
  2226. static void
  2227. bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg)
  2228. {
  2229. struct bfad_im_port_s *pport_im = bfad->pport.im_port;
  2230. struct bfad_vport_s *vport = NULL;
  2231. /* Set the scsi device LUN SCAN flags for base port */
  2232. bfad_reset_sdev_bflags(pport_im, lunmask_cfg);
  2233. /* Set the scsi device LUN SCAN flags for the vports */
  2234. list_for_each_entry(vport, &bfad->vport_list, list_entry)
  2235. bfad_reset_sdev_bflags(vport->drv_port.im_port, lunmask_cfg);
  2236. }
  2237. int
  2238. bfad_iocmd_lunmask(struct bfad_s *bfad, void *pcmd, unsigned int v_cmd)
  2239. {
  2240. struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
  2241. unsigned long flags;
  2242. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2243. if (v_cmd == IOCMD_FCPIM_LUNMASK_ENABLE) {
  2244. iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_TRUE);
  2245. /* Set the LUN Scanning mode to be Sequential scan */
  2246. if (iocmd->status == BFA_STATUS_OK)
  2247. bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_TRUE);
  2248. } else if (v_cmd == IOCMD_FCPIM_LUNMASK_DISABLE) {
  2249. iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_FALSE);
  2250. /* Set the LUN Scanning mode to default REPORT_LUNS scan */
  2251. if (iocmd->status == BFA_STATUS_OK)
  2252. bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_FALSE);
  2253. } else if (v_cmd == IOCMD_FCPIM_LUNMASK_CLEAR)
  2254. iocmd->status = bfa_fcpim_lunmask_clear(&bfad->bfa);
  2255. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2256. return 0;
  2257. }
  2258. int
  2259. bfad_iocmd_fcpim_lunmask_query(struct bfad_s *bfad, void *cmd)
  2260. {
  2261. struct bfa_bsg_fcpim_lunmask_query_s *iocmd =
  2262. (struct bfa_bsg_fcpim_lunmask_query_s *)cmd;
  2263. struct bfa_lunmask_cfg_s *lun_mask = &iocmd->lun_mask;
  2264. unsigned long flags;
  2265. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2266. iocmd->status = bfa_fcpim_lunmask_query(&bfad->bfa, lun_mask);
  2267. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2268. return 0;
  2269. }
  2270. int
  2271. bfad_iocmd_fcpim_cfg_lunmask(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
  2272. {
  2273. struct bfa_bsg_fcpim_lunmask_s *iocmd =
  2274. (struct bfa_bsg_fcpim_lunmask_s *)cmd;
  2275. unsigned long flags;
  2276. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2277. if (v_cmd == IOCMD_FCPIM_LUNMASK_ADD)
  2278. iocmd->status = bfa_fcpim_lunmask_add(&bfad->bfa, iocmd->vf_id,
  2279. &iocmd->pwwn, iocmd->rpwwn, iocmd->lun);
  2280. else if (v_cmd == IOCMD_FCPIM_LUNMASK_DELETE)
  2281. iocmd->status = bfa_fcpim_lunmask_delete(&bfad->bfa,
  2282. iocmd->vf_id, &iocmd->pwwn,
  2283. iocmd->rpwwn, iocmd->lun);
  2284. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2285. return 0;
  2286. }
  2287. int
  2288. bfad_iocmd_fcpim_throttle_query(struct bfad_s *bfad, void *cmd)
  2289. {
  2290. struct bfa_bsg_fcpim_throttle_s *iocmd =
  2291. (struct bfa_bsg_fcpim_throttle_s *)cmd;
  2292. unsigned long flags;
  2293. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2294. iocmd->status = bfa_fcpim_throttle_get(&bfad->bfa,
  2295. (void *)&iocmd->throttle);
  2296. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2297. return 0;
  2298. }
  2299. int
  2300. bfad_iocmd_fcpim_throttle_set(struct bfad_s *bfad, void *cmd)
  2301. {
  2302. struct bfa_bsg_fcpim_throttle_s *iocmd =
  2303. (struct bfa_bsg_fcpim_throttle_s *)cmd;
  2304. unsigned long flags;
  2305. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2306. iocmd->status = bfa_fcpim_throttle_set(&bfad->bfa,
  2307. iocmd->throttle.cfg_value);
  2308. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2309. return 0;
  2310. }
  2311. int
  2312. bfad_iocmd_tfru_read(struct bfad_s *bfad, void *cmd)
  2313. {
  2314. struct bfa_bsg_tfru_s *iocmd =
  2315. (struct bfa_bsg_tfru_s *)cmd;
  2316. struct bfad_hal_comp fcomp;
  2317. unsigned long flags = 0;
  2318. init_completion(&fcomp.comp);
  2319. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2320. iocmd->status = bfa_tfru_read(BFA_FRU(&bfad->bfa),
  2321. &iocmd->data, iocmd->len, iocmd->offset,
  2322. bfad_hcb_comp, &fcomp);
  2323. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2324. if (iocmd->status == BFA_STATUS_OK) {
  2325. wait_for_completion(&fcomp.comp);
  2326. iocmd->status = fcomp.status;
  2327. }
  2328. return 0;
  2329. }
  2330. int
  2331. bfad_iocmd_tfru_write(struct bfad_s *bfad, void *cmd)
  2332. {
  2333. struct bfa_bsg_tfru_s *iocmd =
  2334. (struct bfa_bsg_tfru_s *)cmd;
  2335. struct bfad_hal_comp fcomp;
  2336. unsigned long flags = 0;
  2337. init_completion(&fcomp.comp);
  2338. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2339. iocmd->status = bfa_tfru_write(BFA_FRU(&bfad->bfa),
  2340. &iocmd->data, iocmd->len, iocmd->offset,
  2341. bfad_hcb_comp, &fcomp);
  2342. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2343. if (iocmd->status == BFA_STATUS_OK) {
  2344. wait_for_completion(&fcomp.comp);
  2345. iocmd->status = fcomp.status;
  2346. }
  2347. return 0;
  2348. }
  2349. int
  2350. bfad_iocmd_fruvpd_read(struct bfad_s *bfad, void *cmd)
  2351. {
  2352. struct bfa_bsg_fruvpd_s *iocmd =
  2353. (struct bfa_bsg_fruvpd_s *)cmd;
  2354. struct bfad_hal_comp fcomp;
  2355. unsigned long flags = 0;
  2356. init_completion(&fcomp.comp);
  2357. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2358. iocmd->status = bfa_fruvpd_read(BFA_FRU(&bfad->bfa),
  2359. &iocmd->data, iocmd->len, iocmd->offset,
  2360. bfad_hcb_comp, &fcomp);
  2361. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2362. if (iocmd->status == BFA_STATUS_OK) {
  2363. wait_for_completion(&fcomp.comp);
  2364. iocmd->status = fcomp.status;
  2365. }
  2366. return 0;
  2367. }
  2368. int
  2369. bfad_iocmd_fruvpd_update(struct bfad_s *bfad, void *cmd)
  2370. {
  2371. struct bfa_bsg_fruvpd_s *iocmd =
  2372. (struct bfa_bsg_fruvpd_s *)cmd;
  2373. struct bfad_hal_comp fcomp;
  2374. unsigned long flags = 0;
  2375. init_completion(&fcomp.comp);
  2376. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2377. iocmd->status = bfa_fruvpd_update(BFA_FRU(&bfad->bfa),
  2378. &iocmd->data, iocmd->len, iocmd->offset,
  2379. bfad_hcb_comp, &fcomp, iocmd->trfr_cmpl);
  2380. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2381. if (iocmd->status == BFA_STATUS_OK) {
  2382. wait_for_completion(&fcomp.comp);
  2383. iocmd->status = fcomp.status;
  2384. }
  2385. return 0;
  2386. }
  2387. int
  2388. bfad_iocmd_fruvpd_get_max_size(struct bfad_s *bfad, void *cmd)
  2389. {
  2390. struct bfa_bsg_fruvpd_max_size_s *iocmd =
  2391. (struct bfa_bsg_fruvpd_max_size_s *)cmd;
  2392. unsigned long flags = 0;
  2393. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2394. iocmd->status = bfa_fruvpd_get_max_size(BFA_FRU(&bfad->bfa),
  2395. &iocmd->max_size);
  2396. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2397. return 0;
  2398. }
  2399. static int
  2400. bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd,
  2401. unsigned int payload_len)
  2402. {
  2403. int rc = -EINVAL;
  2404. switch (cmd) {
  2405. case IOCMD_IOC_ENABLE:
  2406. rc = bfad_iocmd_ioc_enable(bfad, iocmd);
  2407. break;
  2408. case IOCMD_IOC_DISABLE:
  2409. rc = bfad_iocmd_ioc_disable(bfad, iocmd);
  2410. break;
  2411. case IOCMD_IOC_GET_INFO:
  2412. rc = bfad_iocmd_ioc_get_info(bfad, iocmd);
  2413. break;
  2414. case IOCMD_IOC_GET_ATTR:
  2415. rc = bfad_iocmd_ioc_get_attr(bfad, iocmd);
  2416. break;
  2417. case IOCMD_IOC_GET_STATS:
  2418. rc = bfad_iocmd_ioc_get_stats(bfad, iocmd);
  2419. break;
  2420. case IOCMD_IOC_GET_FWSTATS:
  2421. rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len);
  2422. break;
  2423. case IOCMD_IOC_RESET_STATS:
  2424. case IOCMD_IOC_RESET_FWSTATS:
  2425. rc = bfad_iocmd_ioc_reset_stats(bfad, iocmd, cmd);
  2426. break;
  2427. case IOCMD_IOC_SET_ADAPTER_NAME:
  2428. case IOCMD_IOC_SET_PORT_NAME:
  2429. rc = bfad_iocmd_ioc_set_name(bfad, iocmd, cmd);
  2430. break;
  2431. case IOCMD_IOCFC_GET_ATTR:
  2432. rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd);
  2433. break;
  2434. case IOCMD_IOCFC_SET_INTR:
  2435. rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd);
  2436. break;
  2437. case IOCMD_PORT_ENABLE:
  2438. rc = bfad_iocmd_port_enable(bfad, iocmd);
  2439. break;
  2440. case IOCMD_PORT_DISABLE:
  2441. rc = bfad_iocmd_port_disable(bfad, iocmd);
  2442. break;
  2443. case IOCMD_PORT_GET_ATTR:
  2444. rc = bfad_iocmd_port_get_attr(bfad, iocmd);
  2445. break;
  2446. case IOCMD_PORT_GET_STATS:
  2447. rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len);
  2448. break;
  2449. case IOCMD_PORT_RESET_STATS:
  2450. rc = bfad_iocmd_port_reset_stats(bfad, iocmd);
  2451. break;
  2452. case IOCMD_PORT_CFG_TOPO:
  2453. case IOCMD_PORT_CFG_SPEED:
  2454. case IOCMD_PORT_CFG_ALPA:
  2455. case IOCMD_PORT_CLR_ALPA:
  2456. rc = bfad_iocmd_set_port_cfg(bfad, iocmd, cmd);
  2457. break;
  2458. case IOCMD_PORT_CFG_MAXFRSZ:
  2459. rc = bfad_iocmd_port_cfg_maxfrsize(bfad, iocmd);
  2460. break;
  2461. case IOCMD_PORT_BBCR_ENABLE:
  2462. case IOCMD_PORT_BBCR_DISABLE:
  2463. rc = bfad_iocmd_port_cfg_bbcr(bfad, cmd, iocmd);
  2464. break;
  2465. case IOCMD_PORT_BBCR_GET_ATTR:
  2466. rc = bfad_iocmd_port_get_bbcr_attr(bfad, iocmd);
  2467. break;
  2468. case IOCMD_LPORT_GET_ATTR:
  2469. rc = bfad_iocmd_lport_get_attr(bfad, iocmd);
  2470. break;
  2471. case IOCMD_LPORT_GET_STATS:
  2472. rc = bfad_iocmd_lport_get_stats(bfad, iocmd);
  2473. break;
  2474. case IOCMD_LPORT_RESET_STATS:
  2475. rc = bfad_iocmd_lport_reset_stats(bfad, iocmd);
  2476. break;
  2477. case IOCMD_LPORT_GET_IOSTATS:
  2478. rc = bfad_iocmd_lport_get_iostats(bfad, iocmd);
  2479. break;
  2480. case IOCMD_LPORT_GET_RPORTS:
  2481. rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len);
  2482. break;
  2483. case IOCMD_RPORT_GET_ATTR:
  2484. rc = bfad_iocmd_rport_get_attr(bfad, iocmd);
  2485. break;
  2486. case IOCMD_RPORT_GET_ADDR:
  2487. rc = bfad_iocmd_rport_get_addr(bfad, iocmd);
  2488. break;
  2489. case IOCMD_RPORT_GET_STATS:
  2490. rc = bfad_iocmd_rport_get_stats(bfad, iocmd);
  2491. break;
  2492. case IOCMD_RPORT_RESET_STATS:
  2493. rc = bfad_iocmd_rport_clr_stats(bfad, iocmd);
  2494. break;
  2495. case IOCMD_RPORT_SET_SPEED:
  2496. rc = bfad_iocmd_rport_set_speed(bfad, iocmd);
  2497. break;
  2498. case IOCMD_VPORT_GET_ATTR:
  2499. rc = bfad_iocmd_vport_get_attr(bfad, iocmd);
  2500. break;
  2501. case IOCMD_VPORT_GET_STATS:
  2502. rc = bfad_iocmd_vport_get_stats(bfad, iocmd);
  2503. break;
  2504. case IOCMD_VPORT_RESET_STATS:
  2505. rc = bfad_iocmd_vport_clr_stats(bfad, iocmd);
  2506. break;
  2507. case IOCMD_FABRIC_GET_LPORTS:
  2508. rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len);
  2509. break;
  2510. case IOCMD_RATELIM_ENABLE:
  2511. case IOCMD_RATELIM_DISABLE:
  2512. rc = bfad_iocmd_ratelim(bfad, cmd, iocmd);
  2513. break;
  2514. case IOCMD_RATELIM_DEF_SPEED:
  2515. rc = bfad_iocmd_ratelim_speed(bfad, cmd, iocmd);
  2516. break;
  2517. case IOCMD_FCPIM_FAILOVER:
  2518. rc = bfad_iocmd_cfg_fcpim(bfad, iocmd);
  2519. break;
  2520. case IOCMD_FCPIM_MODSTATS:
  2521. rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd);
  2522. break;
  2523. case IOCMD_FCPIM_MODSTATSCLR:
  2524. rc = bfad_iocmd_fcpim_clr_modstats(bfad, iocmd);
  2525. break;
  2526. case IOCMD_FCPIM_DEL_ITN_STATS:
  2527. rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd);
  2528. break;
  2529. case IOCMD_ITNIM_GET_ATTR:
  2530. rc = bfad_iocmd_itnim_get_attr(bfad, iocmd);
  2531. break;
  2532. case IOCMD_ITNIM_GET_IOSTATS:
  2533. rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd);
  2534. break;
  2535. case IOCMD_ITNIM_RESET_STATS:
  2536. rc = bfad_iocmd_itnim_reset_stats(bfad, iocmd);
  2537. break;
  2538. case IOCMD_ITNIM_GET_ITNSTATS:
  2539. rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd);
  2540. break;
  2541. case IOCMD_FCPORT_ENABLE:
  2542. rc = bfad_iocmd_fcport_enable(bfad, iocmd);
  2543. break;
  2544. case IOCMD_FCPORT_DISABLE:
  2545. rc = bfad_iocmd_fcport_disable(bfad, iocmd);
  2546. break;
  2547. case IOCMD_IOC_PCIFN_CFG:
  2548. rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd);
  2549. break;
  2550. case IOCMD_IOC_FW_SIG_INV:
  2551. rc = bfad_iocmd_ioc_fw_sig_inv(bfad, iocmd);
  2552. break;
  2553. case IOCMD_PCIFN_CREATE:
  2554. rc = bfad_iocmd_pcifn_create(bfad, iocmd);
  2555. break;
  2556. case IOCMD_PCIFN_DELETE:
  2557. rc = bfad_iocmd_pcifn_delete(bfad, iocmd);
  2558. break;
  2559. case IOCMD_PCIFN_BW:
  2560. rc = bfad_iocmd_pcifn_bw(bfad, iocmd);
  2561. break;
  2562. case IOCMD_ADAPTER_CFG_MODE:
  2563. rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd);
  2564. break;
  2565. case IOCMD_PORT_CFG_MODE:
  2566. rc = bfad_iocmd_port_cfg_mode(bfad, iocmd);
  2567. break;
  2568. case IOCMD_FLASH_ENABLE_OPTROM:
  2569. case IOCMD_FLASH_DISABLE_OPTROM:
  2570. rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
  2571. break;
  2572. case IOCMD_FAA_QUERY:
  2573. rc = bfad_iocmd_faa_query(bfad, iocmd);
  2574. break;
  2575. case IOCMD_CEE_GET_ATTR:
  2576. rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len);
  2577. break;
  2578. case IOCMD_CEE_GET_STATS:
  2579. rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len);
  2580. break;
  2581. case IOCMD_CEE_RESET_STATS:
  2582. rc = bfad_iocmd_cee_reset_stats(bfad, iocmd);
  2583. break;
  2584. case IOCMD_SFP_MEDIA:
  2585. rc = bfad_iocmd_sfp_media(bfad, iocmd);
  2586. break;
  2587. case IOCMD_SFP_SPEED:
  2588. rc = bfad_iocmd_sfp_speed(bfad, iocmd);
  2589. break;
  2590. case IOCMD_FLASH_GET_ATTR:
  2591. rc = bfad_iocmd_flash_get_attr(bfad, iocmd);
  2592. break;
  2593. case IOCMD_FLASH_ERASE_PART:
  2594. rc = bfad_iocmd_flash_erase_part(bfad, iocmd);
  2595. break;
  2596. case IOCMD_FLASH_UPDATE_PART:
  2597. rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len);
  2598. break;
  2599. case IOCMD_FLASH_READ_PART:
  2600. rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len);
  2601. break;
  2602. case IOCMD_DIAG_TEMP:
  2603. rc = bfad_iocmd_diag_temp(bfad, iocmd);
  2604. break;
  2605. case IOCMD_DIAG_MEMTEST:
  2606. rc = bfad_iocmd_diag_memtest(bfad, iocmd);
  2607. break;
  2608. case IOCMD_DIAG_LOOPBACK:
  2609. rc = bfad_iocmd_diag_loopback(bfad, iocmd);
  2610. break;
  2611. case IOCMD_DIAG_FWPING:
  2612. rc = bfad_iocmd_diag_fwping(bfad, iocmd);
  2613. break;
  2614. case IOCMD_DIAG_QUEUETEST:
  2615. rc = bfad_iocmd_diag_queuetest(bfad, iocmd);
  2616. break;
  2617. case IOCMD_DIAG_SFP:
  2618. rc = bfad_iocmd_diag_sfp(bfad, iocmd);
  2619. break;
  2620. case IOCMD_DIAG_LED:
  2621. rc = bfad_iocmd_diag_led(bfad, iocmd);
  2622. break;
  2623. case IOCMD_DIAG_BEACON_LPORT:
  2624. rc = bfad_iocmd_diag_beacon_lport(bfad, iocmd);
  2625. break;
  2626. case IOCMD_DIAG_LB_STAT:
  2627. rc = bfad_iocmd_diag_lb_stat(bfad, iocmd);
  2628. break;
  2629. case IOCMD_DIAG_DPORT_ENABLE:
  2630. rc = bfad_iocmd_diag_dport_enable(bfad, iocmd);
  2631. break;
  2632. case IOCMD_DIAG_DPORT_DISABLE:
  2633. rc = bfad_iocmd_diag_dport_disable(bfad, iocmd);
  2634. break;
  2635. case IOCMD_DIAG_DPORT_SHOW:
  2636. rc = bfad_iocmd_diag_dport_show(bfad, iocmd);
  2637. break;
  2638. case IOCMD_DIAG_DPORT_START:
  2639. rc = bfad_iocmd_diag_dport_start(bfad, iocmd);
  2640. break;
  2641. case IOCMD_PHY_GET_ATTR:
  2642. rc = bfad_iocmd_phy_get_attr(bfad, iocmd);
  2643. break;
  2644. case IOCMD_PHY_GET_STATS:
  2645. rc = bfad_iocmd_phy_get_stats(bfad, iocmd);
  2646. break;
  2647. case IOCMD_PHY_UPDATE_FW:
  2648. rc = bfad_iocmd_phy_update(bfad, iocmd, payload_len);
  2649. break;
  2650. case IOCMD_PHY_READ_FW:
  2651. rc = bfad_iocmd_phy_read(bfad, iocmd, payload_len);
  2652. break;
  2653. case IOCMD_VHBA_QUERY:
  2654. rc = bfad_iocmd_vhba_query(bfad, iocmd);
  2655. break;
  2656. case IOCMD_DEBUG_PORTLOG:
  2657. rc = bfad_iocmd_porglog_get(bfad, iocmd);
  2658. break;
  2659. case IOCMD_DEBUG_FW_CORE:
  2660. rc = bfad_iocmd_debug_fw_core(bfad, iocmd, payload_len);
  2661. break;
  2662. case IOCMD_DEBUG_FW_STATE_CLR:
  2663. case IOCMD_DEBUG_PORTLOG_CLR:
  2664. case IOCMD_DEBUG_START_DTRC:
  2665. case IOCMD_DEBUG_STOP_DTRC:
  2666. rc = bfad_iocmd_debug_ctl(bfad, iocmd, cmd);
  2667. break;
  2668. case IOCMD_DEBUG_PORTLOG_CTL:
  2669. rc = bfad_iocmd_porglog_ctl(bfad, iocmd);
  2670. break;
  2671. case IOCMD_FCPIM_PROFILE_ON:
  2672. case IOCMD_FCPIM_PROFILE_OFF:
  2673. rc = bfad_iocmd_fcpim_cfg_profile(bfad, iocmd, cmd);
  2674. break;
  2675. case IOCMD_ITNIM_GET_IOPROFILE:
  2676. rc = bfad_iocmd_itnim_get_ioprofile(bfad, iocmd);
  2677. break;
  2678. case IOCMD_FCPORT_GET_STATS:
  2679. rc = bfad_iocmd_fcport_get_stats(bfad, iocmd);
  2680. break;
  2681. case IOCMD_FCPORT_RESET_STATS:
  2682. rc = bfad_iocmd_fcport_reset_stats(bfad, iocmd);
  2683. break;
  2684. case IOCMD_BOOT_CFG:
  2685. rc = bfad_iocmd_boot_cfg(bfad, iocmd);
  2686. break;
  2687. case IOCMD_BOOT_QUERY:
  2688. rc = bfad_iocmd_boot_query(bfad, iocmd);
  2689. break;
  2690. case IOCMD_PREBOOT_QUERY:
  2691. rc = bfad_iocmd_preboot_query(bfad, iocmd);
  2692. break;
  2693. case IOCMD_ETHBOOT_CFG:
  2694. rc = bfad_iocmd_ethboot_cfg(bfad, iocmd);
  2695. break;
  2696. case IOCMD_ETHBOOT_QUERY:
  2697. rc = bfad_iocmd_ethboot_query(bfad, iocmd);
  2698. break;
  2699. case IOCMD_TRUNK_ENABLE:
  2700. case IOCMD_TRUNK_DISABLE:
  2701. rc = bfad_iocmd_cfg_trunk(bfad, iocmd, cmd);
  2702. break;
  2703. case IOCMD_TRUNK_GET_ATTR:
  2704. rc = bfad_iocmd_trunk_get_attr(bfad, iocmd);
  2705. break;
  2706. case IOCMD_QOS_ENABLE:
  2707. case IOCMD_QOS_DISABLE:
  2708. rc = bfad_iocmd_qos(bfad, iocmd, cmd);
  2709. break;
  2710. case IOCMD_QOS_GET_ATTR:
  2711. rc = bfad_iocmd_qos_get_attr(bfad, iocmd);
  2712. break;
  2713. case IOCMD_QOS_GET_VC_ATTR:
  2714. rc = bfad_iocmd_qos_get_vc_attr(bfad, iocmd);
  2715. break;
  2716. case IOCMD_QOS_GET_STATS:
  2717. rc = bfad_iocmd_qos_get_stats(bfad, iocmd);
  2718. break;
  2719. case IOCMD_QOS_RESET_STATS:
  2720. rc = bfad_iocmd_qos_reset_stats(bfad, iocmd);
  2721. break;
  2722. case IOCMD_QOS_SET_BW:
  2723. rc = bfad_iocmd_qos_set_bw(bfad, iocmd);
  2724. break;
  2725. case IOCMD_VF_GET_STATS:
  2726. rc = bfad_iocmd_vf_get_stats(bfad, iocmd);
  2727. break;
  2728. case IOCMD_VF_RESET_STATS:
  2729. rc = bfad_iocmd_vf_clr_stats(bfad, iocmd);
  2730. break;
  2731. case IOCMD_FCPIM_LUNMASK_ENABLE:
  2732. case IOCMD_FCPIM_LUNMASK_DISABLE:
  2733. case IOCMD_FCPIM_LUNMASK_CLEAR:
  2734. rc = bfad_iocmd_lunmask(bfad, iocmd, cmd);
  2735. break;
  2736. case IOCMD_FCPIM_LUNMASK_QUERY:
  2737. rc = bfad_iocmd_fcpim_lunmask_query(bfad, iocmd);
  2738. break;
  2739. case IOCMD_FCPIM_LUNMASK_ADD:
  2740. case IOCMD_FCPIM_LUNMASK_DELETE:
  2741. rc = bfad_iocmd_fcpim_cfg_lunmask(bfad, iocmd, cmd);
  2742. break;
  2743. case IOCMD_FCPIM_THROTTLE_QUERY:
  2744. rc = bfad_iocmd_fcpim_throttle_query(bfad, iocmd);
  2745. break;
  2746. case IOCMD_FCPIM_THROTTLE_SET:
  2747. rc = bfad_iocmd_fcpim_throttle_set(bfad, iocmd);
  2748. break;
  2749. /* TFRU */
  2750. case IOCMD_TFRU_READ:
  2751. rc = bfad_iocmd_tfru_read(bfad, iocmd);
  2752. break;
  2753. case IOCMD_TFRU_WRITE:
  2754. rc = bfad_iocmd_tfru_write(bfad, iocmd);
  2755. break;
  2756. /* FRU */
  2757. case IOCMD_FRUVPD_READ:
  2758. rc = bfad_iocmd_fruvpd_read(bfad, iocmd);
  2759. break;
  2760. case IOCMD_FRUVPD_UPDATE:
  2761. rc = bfad_iocmd_fruvpd_update(bfad, iocmd);
  2762. break;
  2763. case IOCMD_FRUVPD_GET_MAX_SIZE:
  2764. rc = bfad_iocmd_fruvpd_get_max_size(bfad, iocmd);
  2765. break;
  2766. default:
  2767. rc = -EINVAL;
  2768. break;
  2769. }
  2770. return rc;
  2771. }
  2772. static int
  2773. bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
  2774. {
  2775. uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
  2776. struct bfad_im_port_s *im_port =
  2777. (struct bfad_im_port_s *) job->shost->hostdata[0];
  2778. struct bfad_s *bfad = im_port->bfad;
  2779. struct request_queue *request_q = job->req->q;
  2780. void *payload_kbuf;
  2781. int rc = -EINVAL;
  2782. /*
  2783. * Set the BSG device request_queue size to 256 to support
  2784. * payloads larger than 512*1024K bytes.
  2785. */
  2786. blk_queue_max_segments(request_q, 256);
  2787. /* Allocate a temp buffer to hold the passed in user space command */
  2788. payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
  2789. if (!payload_kbuf) {
  2790. rc = -ENOMEM;
  2791. goto out;
  2792. }
  2793. /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */
  2794. sg_copy_to_buffer(job->request_payload.sg_list,
  2795. job->request_payload.sg_cnt, payload_kbuf,
  2796. job->request_payload.payload_len);
  2797. /* Invoke IOCMD handler - to handle all the vendor command requests */
  2798. rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf,
  2799. job->request_payload.payload_len);
  2800. if (rc != BFA_STATUS_OK)
  2801. goto error;
  2802. /* Copy the response data to the job->reply_payload sg_list */
  2803. sg_copy_from_buffer(job->reply_payload.sg_list,
  2804. job->reply_payload.sg_cnt,
  2805. payload_kbuf,
  2806. job->reply_payload.payload_len);
  2807. /* free the command buffer */
  2808. kfree(payload_kbuf);
  2809. /* Fill the BSG job reply data */
  2810. job->reply_len = job->reply_payload.payload_len;
  2811. job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
  2812. job->reply->result = rc;
  2813. job->job_done(job);
  2814. return rc;
  2815. error:
  2816. /* free the command buffer */
  2817. kfree(payload_kbuf);
  2818. out:
  2819. job->reply->result = rc;
  2820. job->reply_len = sizeof(uint32_t);
  2821. job->reply->reply_payload_rcv_len = 0;
  2822. return rc;
  2823. }
  2824. /* FC passthru call backs */
  2825. u64
  2826. bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid)
  2827. {
  2828. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2829. struct bfa_sge_s *sge;
  2830. u64 addr;
  2831. sge = drv_fcxp->req_sge + sgeid;
  2832. addr = (u64)(size_t) sge->sg_addr;
  2833. return addr;
  2834. }
  2835. u32
  2836. bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid)
  2837. {
  2838. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2839. struct bfa_sge_s *sge;
  2840. sge = drv_fcxp->req_sge + sgeid;
  2841. return sge->sg_len;
  2842. }
  2843. u64
  2844. bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid)
  2845. {
  2846. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2847. struct bfa_sge_s *sge;
  2848. u64 addr;
  2849. sge = drv_fcxp->rsp_sge + sgeid;
  2850. addr = (u64)(size_t) sge->sg_addr;
  2851. return addr;
  2852. }
  2853. u32
  2854. bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid)
  2855. {
  2856. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2857. struct bfa_sge_s *sge;
  2858. sge = drv_fcxp->rsp_sge + sgeid;
  2859. return sge->sg_len;
  2860. }
  2861. void
  2862. bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
  2863. bfa_status_t req_status, u32 rsp_len, u32 resid_len,
  2864. struct fchs_s *rsp_fchs)
  2865. {
  2866. struct bfad_fcxp *drv_fcxp = bfad_fcxp;
  2867. drv_fcxp->req_status = req_status;
  2868. drv_fcxp->rsp_len = rsp_len;
  2869. /* bfa_fcxp will be automatically freed by BFA */
  2870. drv_fcxp->bfa_fcxp = NULL;
  2871. complete(&drv_fcxp->comp);
  2872. }
  2873. struct bfad_buf_info *
  2874. bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf,
  2875. uint32_t payload_len, uint32_t *num_sgles)
  2876. {
  2877. struct bfad_buf_info *buf_base, *buf_info;
  2878. struct bfa_sge_s *sg_table;
  2879. int sge_num = 1;
  2880. buf_base = kzalloc((sizeof(struct bfad_buf_info) +
  2881. sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL);
  2882. if (!buf_base)
  2883. return NULL;
  2884. sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) +
  2885. (sizeof(struct bfad_buf_info) * sge_num));
  2886. /* Allocate dma coherent memory */
  2887. buf_info = buf_base;
  2888. buf_info->size = payload_len;
  2889. buf_info->virt = dma_zalloc_coherent(&bfad->pcidev->dev,
  2890. buf_info->size, &buf_info->phys,
  2891. GFP_KERNEL);
  2892. if (!buf_info->virt)
  2893. goto out_free_mem;
  2894. /* copy the linear bsg buffer to buf_info */
  2895. memcpy(buf_info->virt, payload_kbuf, buf_info->size);
  2896. /*
  2897. * Setup SG table
  2898. */
  2899. sg_table->sg_len = buf_info->size;
  2900. sg_table->sg_addr = (void *)(size_t) buf_info->phys;
  2901. *num_sgles = sge_num;
  2902. return buf_base;
  2903. out_free_mem:
  2904. kfree(buf_base);
  2905. return NULL;
  2906. }
  2907. void
  2908. bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base,
  2909. uint32_t num_sgles)
  2910. {
  2911. int i;
  2912. struct bfad_buf_info *buf_info = buf_base;
  2913. if (buf_base) {
  2914. for (i = 0; i < num_sgles; buf_info++, i++) {
  2915. if (buf_info->virt != NULL)
  2916. dma_free_coherent(&bfad->pcidev->dev,
  2917. buf_info->size, buf_info->virt,
  2918. buf_info->phys);
  2919. }
  2920. kfree(buf_base);
  2921. }
  2922. }
  2923. int
  2924. bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp,
  2925. bfa_bsg_fcpt_t *bsg_fcpt)
  2926. {
  2927. struct bfa_fcxp_s *hal_fcxp;
  2928. struct bfad_s *bfad = drv_fcxp->port->bfad;
  2929. unsigned long flags;
  2930. uint8_t lp_tag;
  2931. spin_lock_irqsave(&bfad->bfad_lock, flags);
  2932. /* Allocate bfa_fcxp structure */
  2933. hal_fcxp = bfa_fcxp_req_rsp_alloc(drv_fcxp, &bfad->bfa,
  2934. drv_fcxp->num_req_sgles,
  2935. drv_fcxp->num_rsp_sgles,
  2936. bfad_fcxp_get_req_sgaddr_cb,
  2937. bfad_fcxp_get_req_sglen_cb,
  2938. bfad_fcxp_get_rsp_sgaddr_cb,
  2939. bfad_fcxp_get_rsp_sglen_cb, BFA_TRUE);
  2940. if (!hal_fcxp) {
  2941. bfa_trc(bfad, 0);
  2942. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2943. return BFA_STATUS_ENOMEM;
  2944. }
  2945. drv_fcxp->bfa_fcxp = hal_fcxp;
  2946. lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id);
  2947. bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag,
  2948. bsg_fcpt->cts, bsg_fcpt->cos,
  2949. job->request_payload.payload_len,
  2950. &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad,
  2951. job->reply_payload.payload_len, bsg_fcpt->tsecs);
  2952. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  2953. return BFA_STATUS_OK;
  2954. }
  2955. int
  2956. bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
  2957. {
  2958. struct bfa_bsg_data *bsg_data;
  2959. struct bfad_im_port_s *im_port =
  2960. (struct bfad_im_port_s *) job->shost->hostdata[0];
  2961. struct bfad_s *bfad = im_port->bfad;
  2962. bfa_bsg_fcpt_t *bsg_fcpt;
  2963. struct bfad_fcxp *drv_fcxp;
  2964. struct bfa_fcs_lport_s *fcs_port;
  2965. struct bfa_fcs_rport_s *fcs_rport;
  2966. uint32_t command_type = job->request->msgcode;
  2967. unsigned long flags;
  2968. struct bfad_buf_info *rsp_buf_info;
  2969. void *req_kbuf = NULL, *rsp_kbuf = NULL;
  2970. int rc = -EINVAL;
  2971. job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */
  2972. job->reply->reply_payload_rcv_len = 0;
  2973. /* Get the payload passed in from userspace */
  2974. bsg_data = (struct bfa_bsg_data *) (((char *)job->request) +
  2975. sizeof(struct fc_bsg_request));
  2976. if (bsg_data == NULL)
  2977. goto out;
  2978. /*
  2979. * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
  2980. * buffer of size bsg_data->payload_len
  2981. */
  2982. bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL);
  2983. if (!bsg_fcpt) {
  2984. rc = -ENOMEM;
  2985. goto out;
  2986. }
  2987. if (copy_from_user((uint8_t *)bsg_fcpt,
  2988. (void *)(unsigned long)bsg_data->payload,
  2989. bsg_data->payload_len)) {
  2990. kfree(bsg_fcpt);
  2991. rc = -EIO;
  2992. goto out;
  2993. }
  2994. drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);
  2995. if (drv_fcxp == NULL) {
  2996. kfree(bsg_fcpt);
  2997. rc = -ENOMEM;
  2998. goto out;
  2999. }
  3000. spin_lock_irqsave(&bfad->bfad_lock, flags);
  3001. fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id,
  3002. bsg_fcpt->lpwwn);
  3003. if (fcs_port == NULL) {
  3004. bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN;
  3005. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3006. goto out_free_mem;
  3007. }
  3008. /* Check if the port is online before sending FC Passthru cmd */
  3009. if (!bfa_fcs_lport_is_online(fcs_port)) {
  3010. bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE;
  3011. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3012. goto out_free_mem;
  3013. }
  3014. drv_fcxp->port = fcs_port->bfad_port;
  3015. if (drv_fcxp->port->bfad == 0)
  3016. drv_fcxp->port->bfad = bfad;
  3017. /* Fetch the bfa_rport - if nexus needed */
  3018. if (command_type == FC_BSG_HST_ELS_NOLOGIN ||
  3019. command_type == FC_BSG_HST_CT) {
  3020. /* BSG HST commands: no nexus needed */
  3021. drv_fcxp->bfa_rport = NULL;
  3022. } else if (command_type == FC_BSG_RPT_ELS ||
  3023. command_type == FC_BSG_RPT_CT) {
  3024. /* BSG RPT commands: nexus needed */
  3025. fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port,
  3026. bsg_fcpt->dpwwn);
  3027. if (fcs_rport == NULL) {
  3028. bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN;
  3029. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3030. goto out_free_mem;
  3031. }
  3032. drv_fcxp->bfa_rport = fcs_rport->bfa_rport;
  3033. } else { /* Unknown BSG msgcode; return -EINVAL */
  3034. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3035. goto out_free_mem;
  3036. }
  3037. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  3038. /* allocate memory for req / rsp buffers */
  3039. req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
  3040. if (!req_kbuf) {
  3041. printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n",
  3042. bfad->pci_name);
  3043. rc = -ENOMEM;
  3044. goto out_free_mem;
  3045. }
  3046. rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL);
  3047. if (!rsp_kbuf) {
  3048. printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n",
  3049. bfad->pci_name);
  3050. rc = -ENOMEM;
  3051. goto out_free_mem;
  3052. }
  3053. /* map req sg - copy the sg_list passed in to the linear buffer */
  3054. sg_copy_to_buffer(job->request_payload.sg_list,
  3055. job->request_payload.sg_cnt, req_kbuf,
  3056. job->request_payload.payload_len);
  3057. drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf,
  3058. job->request_payload.payload_len,
  3059. &drv_fcxp->num_req_sgles);
  3060. if (!drv_fcxp->reqbuf_info) {
  3061. printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n",
  3062. bfad->pci_name);
  3063. rc = -ENOMEM;
  3064. goto out_free_mem;
  3065. }
  3066. drv_fcxp->req_sge = (struct bfa_sge_s *)
  3067. (((uint8_t *)drv_fcxp->reqbuf_info) +
  3068. (sizeof(struct bfad_buf_info) *
  3069. drv_fcxp->num_req_sgles));
  3070. /* map rsp sg */
  3071. drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf,
  3072. job->reply_payload.payload_len,
  3073. &drv_fcxp->num_rsp_sgles);
  3074. if (!drv_fcxp->rspbuf_info) {
  3075. printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n",
  3076. bfad->pci_name);
  3077. rc = -ENOMEM;
  3078. goto out_free_mem;
  3079. }
  3080. rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info;
  3081. drv_fcxp->rsp_sge = (struct bfa_sge_s *)
  3082. (((uint8_t *)drv_fcxp->rspbuf_info) +
  3083. (sizeof(struct bfad_buf_info) *
  3084. drv_fcxp->num_rsp_sgles));
  3085. /* fcxp send */
  3086. init_completion(&drv_fcxp->comp);
  3087. rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt);
  3088. if (rc == BFA_STATUS_OK) {
  3089. wait_for_completion(&drv_fcxp->comp);
  3090. bsg_fcpt->status = drv_fcxp->req_status;
  3091. } else {
  3092. bsg_fcpt->status = rc;
  3093. goto out_free_mem;
  3094. }
  3095. /* fill the job->reply data */
  3096. if (drv_fcxp->req_status == BFA_STATUS_OK) {
  3097. job->reply_len = drv_fcxp->rsp_len;
  3098. job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
  3099. job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
  3100. } else {
  3101. job->reply->reply_payload_rcv_len =
  3102. sizeof(struct fc_bsg_ctels_reply);
  3103. job->reply_len = sizeof(uint32_t);
  3104. job->reply->reply_data.ctels_reply.status =
  3105. FC_CTELS_STATUS_REJECT;
  3106. }
  3107. /* Copy the response data to the reply_payload sg list */
  3108. sg_copy_from_buffer(job->reply_payload.sg_list,
  3109. job->reply_payload.sg_cnt,
  3110. (uint8_t *)rsp_buf_info->virt,
  3111. job->reply_payload.payload_len);
  3112. out_free_mem:
  3113. bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info,
  3114. drv_fcxp->num_rsp_sgles);
  3115. bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info,
  3116. drv_fcxp->num_req_sgles);
  3117. kfree(req_kbuf);
  3118. kfree(rsp_kbuf);
  3119. /* Need a copy to user op */
  3120. if (copy_to_user((void *)(unsigned long)bsg_data->payload,
  3121. (void *)bsg_fcpt, bsg_data->payload_len))
  3122. rc = -EIO;
  3123. kfree(bsg_fcpt);
  3124. kfree(drv_fcxp);
  3125. out:
  3126. job->reply->result = rc;
  3127. if (rc == BFA_STATUS_OK)
  3128. job->job_done(job);
  3129. return rc;
  3130. }
  3131. int
  3132. bfad_im_bsg_request(struct fc_bsg_job *job)
  3133. {
  3134. uint32_t rc = BFA_STATUS_OK;
  3135. switch (job->request->msgcode) {
  3136. case FC_BSG_HST_VENDOR:
  3137. /* Process BSG HST Vendor requests */
  3138. rc = bfad_im_bsg_vendor_request(job);
  3139. break;
  3140. case FC_BSG_HST_ELS_NOLOGIN:
  3141. case FC_BSG_RPT_ELS:
  3142. case FC_BSG_HST_CT:
  3143. case FC_BSG_RPT_CT:
  3144. /* Process BSG ELS/CT commands */
  3145. rc = bfad_im_bsg_els_ct_request(job);
  3146. break;
  3147. default:
  3148. job->reply->result = rc = -EINVAL;
  3149. job->reply->reply_payload_rcv_len = 0;
  3150. break;
  3151. }
  3152. return rc;
  3153. }
  3154. int
  3155. bfad_im_bsg_timeout(struct fc_bsg_job *job)
  3156. {
  3157. /* Don't complete the BSG job request - return -EAGAIN
  3158. * to reset bsg job timeout : for ELS/CT pass thru we
  3159. * already have timer to track the request.
  3160. */
  3161. return -EAGAIN;
  3162. }