bfad_bsg.c 96 KB

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