request.c 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "task.h"
  57. #include "request.h"
  58. #include "sata.h"
  59. #include "scu_completion_codes.h"
  60. #include "scu_event_codes.h"
  61. #include "sas.h"
  62. /**
  63. * This method returns the sgl element pair for the specificed sgl_pair index.
  64. * @sci_req: This parameter specifies the IO request for which to retrieve
  65. * the Scatter-Gather List element pair.
  66. * @sgl_pair_index: This parameter specifies the index into the SGL element
  67. * pair to be retrieved.
  68. *
  69. * This method returns a pointer to an struct scu_sgl_element_pair.
  70. */
  71. static struct scu_sgl_element_pair *scic_sds_request_get_sgl_element_pair(
  72. struct scic_sds_request *sci_req,
  73. u32 sgl_pair_index
  74. ) {
  75. struct scu_task_context *task_context;
  76. task_context = (struct scu_task_context *)sci_req->task_context_buffer;
  77. if (sgl_pair_index == 0) {
  78. return &task_context->sgl_pair_ab;
  79. } else if (sgl_pair_index == 1) {
  80. return &task_context->sgl_pair_cd;
  81. }
  82. return &sci_req->sg_table[sgl_pair_index - 2];
  83. }
  84. /**
  85. * This function will build the SGL list for an IO request.
  86. * @sci_req: This parameter specifies the IO request for which to build
  87. * the Scatter-Gather List.
  88. *
  89. */
  90. static void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
  91. {
  92. struct isci_request *isci_request = sci_req_to_ireq(sds_request);
  93. struct isci_host *isci_host = isci_request->isci_host;
  94. struct sas_task *task = isci_request_access_task(isci_request);
  95. struct scatterlist *sg = NULL;
  96. dma_addr_t dma_addr;
  97. u32 sg_idx = 0;
  98. struct scu_sgl_element_pair *scu_sg = NULL;
  99. struct scu_sgl_element_pair *prev_sg = NULL;
  100. if (task->num_scatter > 0) {
  101. sg = task->scatter;
  102. while (sg) {
  103. scu_sg = scic_sds_request_get_sgl_element_pair(
  104. sds_request,
  105. sg_idx);
  106. SCU_SGL_COPY(scu_sg->A, sg);
  107. sg = sg_next(sg);
  108. if (sg) {
  109. SCU_SGL_COPY(scu_sg->B, sg);
  110. sg = sg_next(sg);
  111. } else
  112. SCU_SGL_ZERO(scu_sg->B);
  113. if (prev_sg) {
  114. dma_addr =
  115. scic_io_request_get_dma_addr(
  116. sds_request,
  117. scu_sg);
  118. prev_sg->next_pair_upper =
  119. upper_32_bits(dma_addr);
  120. prev_sg->next_pair_lower =
  121. lower_32_bits(dma_addr);
  122. }
  123. prev_sg = scu_sg;
  124. sg_idx++;
  125. }
  126. } else { /* handle when no sg */
  127. scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
  128. sg_idx);
  129. dma_addr = dma_map_single(&isci_host->pdev->dev,
  130. task->scatter,
  131. task->total_xfer_len,
  132. task->data_dir);
  133. isci_request->zero_scatter_daddr = dma_addr;
  134. scu_sg->A.length = task->total_xfer_len;
  135. scu_sg->A.address_upper = upper_32_bits(dma_addr);
  136. scu_sg->A.address_lower = lower_32_bits(dma_addr);
  137. }
  138. if (scu_sg) {
  139. scu_sg->next_pair_upper = 0;
  140. scu_sg->next_pair_lower = 0;
  141. }
  142. }
  143. static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request *sci_req)
  144. {
  145. struct ssp_cmd_iu *cmd_iu;
  146. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  147. struct sas_task *task = isci_request_access_task(ireq);
  148. cmd_iu = &sci_req->ssp.cmd;
  149. memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8);
  150. cmd_iu->add_cdb_len = 0;
  151. cmd_iu->_r_a = 0;
  152. cmd_iu->_r_b = 0;
  153. cmd_iu->en_fburst = 0; /* unsupported */
  154. cmd_iu->task_prio = task->ssp_task.task_prio;
  155. cmd_iu->task_attr = task->ssp_task.task_attr;
  156. cmd_iu->_r_c = 0;
  157. sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cdb,
  158. sizeof(task->ssp_task.cdb) / sizeof(u32));
  159. }
  160. static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request *sci_req)
  161. {
  162. struct ssp_task_iu *task_iu;
  163. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  164. struct sas_task *task = isci_request_access_task(ireq);
  165. struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
  166. task_iu = &sci_req->ssp.tmf;
  167. memset(task_iu, 0, sizeof(struct ssp_task_iu));
  168. memcpy(task_iu->LUN, task->ssp_task.LUN, 8);
  169. task_iu->task_func = isci_tmf->tmf_code;
  170. task_iu->task_tag =
  171. (ireq->ttype == tmf_task) ?
  172. isci_tmf->io_tag :
  173. SCI_CONTROLLER_INVALID_IO_TAG;
  174. }
  175. /**
  176. * This method is will fill in the SCU Task Context for any type of SSP request.
  177. * @sci_req:
  178. * @task_context:
  179. *
  180. */
  181. static void scu_ssp_reqeust_construct_task_context(
  182. struct scic_sds_request *sds_request,
  183. struct scu_task_context *task_context)
  184. {
  185. dma_addr_t dma_addr;
  186. struct scic_sds_controller *controller;
  187. struct scic_sds_remote_device *target_device;
  188. struct scic_sds_port *target_port;
  189. controller = scic_sds_request_get_controller(sds_request);
  190. target_device = scic_sds_request_get_device(sds_request);
  191. target_port = scic_sds_request_get_port(sds_request);
  192. /* Fill in the TC with the its required data */
  193. task_context->abort = 0;
  194. task_context->priority = 0;
  195. task_context->initiator_request = 1;
  196. task_context->connection_rate = target_device->connection_rate;
  197. task_context->protocol_engine_index =
  198. scic_sds_controller_get_protocol_engine_group(controller);
  199. task_context->logical_port_index =
  200. scic_sds_port_get_index(target_port);
  201. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  202. task_context->valid = SCU_TASK_CONTEXT_VALID;
  203. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  204. task_context->remote_node_index =
  205. scic_sds_remote_device_get_index(sds_request->target_device);
  206. task_context->command_code = 0;
  207. task_context->link_layer_control = 0;
  208. task_context->do_not_dma_ssp_good_response = 1;
  209. task_context->strict_ordering = 0;
  210. task_context->control_frame = 0;
  211. task_context->timeout_enable = 0;
  212. task_context->block_guard_enable = 0;
  213. task_context->address_modifier = 0;
  214. /* task_context->type.ssp.tag = sci_req->io_tag; */
  215. task_context->task_phase = 0x01;
  216. if (sds_request->was_tag_assigned_by_user) {
  217. /*
  218. * Build the task context now since we have already read
  219. * the data
  220. */
  221. sds_request->post_context =
  222. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  223. (scic_sds_controller_get_protocol_engine_group(
  224. controller) <<
  225. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  226. (scic_sds_port_get_index(target_port) <<
  227. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
  228. scic_sds_io_tag_get_index(sds_request->io_tag));
  229. } else {
  230. /*
  231. * Build the task context now since we have already read
  232. * the data
  233. *
  234. * I/O tag index is not assigned because we have to wait
  235. * until we get a TCi
  236. */
  237. sds_request->post_context =
  238. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  239. (scic_sds_controller_get_protocol_engine_group(
  240. owning_controller) <<
  241. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  242. (scic_sds_port_get_index(target_port) <<
  243. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
  244. }
  245. /*
  246. * Copy the physical address for the command buffer to the
  247. * SCU Task Context
  248. */
  249. dma_addr = scic_io_request_get_dma_addr(sds_request,
  250. &sds_request->ssp.cmd);
  251. task_context->command_iu_upper = upper_32_bits(dma_addr);
  252. task_context->command_iu_lower = lower_32_bits(dma_addr);
  253. /*
  254. * Copy the physical address for the response buffer to the
  255. * SCU Task Context
  256. */
  257. dma_addr = scic_io_request_get_dma_addr(sds_request,
  258. &sds_request->ssp.rsp);
  259. task_context->response_iu_upper = upper_32_bits(dma_addr);
  260. task_context->response_iu_lower = lower_32_bits(dma_addr);
  261. }
  262. /**
  263. * This method is will fill in the SCU Task Context for a SSP IO request.
  264. * @sci_req:
  265. *
  266. */
  267. static void scu_ssp_io_request_construct_task_context(
  268. struct scic_sds_request *sci_req,
  269. enum dma_data_direction dir,
  270. u32 len)
  271. {
  272. struct scu_task_context *task_context;
  273. task_context = scic_sds_request_get_task_context(sci_req);
  274. scu_ssp_reqeust_construct_task_context(sci_req, task_context);
  275. task_context->ssp_command_iu_length =
  276. sizeof(struct ssp_cmd_iu) / sizeof(u32);
  277. task_context->type.ssp.frame_type = SSP_COMMAND;
  278. switch (dir) {
  279. case DMA_FROM_DEVICE:
  280. case DMA_NONE:
  281. default:
  282. task_context->task_type = SCU_TASK_TYPE_IOREAD;
  283. break;
  284. case DMA_TO_DEVICE:
  285. task_context->task_type = SCU_TASK_TYPE_IOWRITE;
  286. break;
  287. }
  288. task_context->transfer_length_bytes = len;
  289. if (task_context->transfer_length_bytes > 0)
  290. scic_sds_request_build_sgl(sci_req);
  291. }
  292. /**
  293. * This method will fill in the SCU Task Context for a SSP Task request. The
  294. * following important settings are utilized: -# priority ==
  295. * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
  296. * ahead of other task destined for the same Remote Node. -# task_type ==
  297. * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
  298. * (i.e. non-raw frame) is being utilized to perform task management. -#
  299. * control_frame == 1. This ensures that the proper endianess is set so
  300. * that the bytes are transmitted in the right order for a task frame.
  301. * @sci_req: This parameter specifies the task request object being
  302. * constructed.
  303. *
  304. */
  305. static void scu_ssp_task_request_construct_task_context(
  306. struct scic_sds_request *sci_req)
  307. {
  308. struct scu_task_context *task_context;
  309. task_context = scic_sds_request_get_task_context(sci_req);
  310. scu_ssp_reqeust_construct_task_context(sci_req, task_context);
  311. task_context->control_frame = 1;
  312. task_context->priority = SCU_TASK_PRIORITY_HIGH;
  313. task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
  314. task_context->transfer_length_bytes = 0;
  315. task_context->type.ssp.frame_type = SSP_TASK;
  316. task_context->ssp_command_iu_length =
  317. sizeof(struct ssp_task_iu) / sizeof(u32);
  318. }
  319. /**
  320. * This method is will fill in the SCU Task Context for any type of SATA
  321. * request. This is called from the various SATA constructors.
  322. * @sci_req: The general IO request object which is to be used in
  323. * constructing the SCU task context.
  324. * @task_context: The buffer pointer for the SCU task context which is being
  325. * constructed.
  326. *
  327. * The general io request construction is complete. The buffer assignment for
  328. * the command buffer is complete. none Revisit task context construction to
  329. * determine what is common for SSP/SMP/STP task context structures.
  330. */
  331. static void scu_sata_reqeust_construct_task_context(
  332. struct scic_sds_request *sci_req,
  333. struct scu_task_context *task_context)
  334. {
  335. dma_addr_t dma_addr;
  336. struct scic_sds_controller *controller;
  337. struct scic_sds_remote_device *target_device;
  338. struct scic_sds_port *target_port;
  339. controller = scic_sds_request_get_controller(sci_req);
  340. target_device = scic_sds_request_get_device(sci_req);
  341. target_port = scic_sds_request_get_port(sci_req);
  342. /* Fill in the TC with the its required data */
  343. task_context->abort = 0;
  344. task_context->priority = SCU_TASK_PRIORITY_NORMAL;
  345. task_context->initiator_request = 1;
  346. task_context->connection_rate = target_device->connection_rate;
  347. task_context->protocol_engine_index =
  348. scic_sds_controller_get_protocol_engine_group(controller);
  349. task_context->logical_port_index =
  350. scic_sds_port_get_index(target_port);
  351. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
  352. task_context->valid = SCU_TASK_CONTEXT_VALID;
  353. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  354. task_context->remote_node_index =
  355. scic_sds_remote_device_get_index(sci_req->target_device);
  356. task_context->command_code = 0;
  357. task_context->link_layer_control = 0;
  358. task_context->do_not_dma_ssp_good_response = 1;
  359. task_context->strict_ordering = 0;
  360. task_context->control_frame = 0;
  361. task_context->timeout_enable = 0;
  362. task_context->block_guard_enable = 0;
  363. task_context->address_modifier = 0;
  364. task_context->task_phase = 0x01;
  365. task_context->ssp_command_iu_length =
  366. (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32);
  367. /* Set the first word of the H2D REG FIS */
  368. task_context->type.words[0] = *(u32 *)&sci_req->stp.cmd;
  369. if (sci_req->was_tag_assigned_by_user) {
  370. /*
  371. * Build the task context now since we have already read
  372. * the data
  373. */
  374. sci_req->post_context =
  375. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  376. (scic_sds_controller_get_protocol_engine_group(
  377. controller) <<
  378. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  379. (scic_sds_port_get_index(target_port) <<
  380. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
  381. scic_sds_io_tag_get_index(sci_req->io_tag));
  382. } else {
  383. /*
  384. * Build the task context now since we have already read
  385. * the data.
  386. * I/O tag index is not assigned because we have to wait
  387. * until we get a TCi.
  388. */
  389. sci_req->post_context =
  390. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  391. (scic_sds_controller_get_protocol_engine_group(
  392. controller) <<
  393. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  394. (scic_sds_port_get_index(target_port) <<
  395. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
  396. }
  397. /*
  398. * Copy the physical address for the command buffer to the SCU Task
  399. * Context. We must offset the command buffer by 4 bytes because the
  400. * first 4 bytes are transfered in the body of the TC.
  401. */
  402. dma_addr = scic_io_request_get_dma_addr(sci_req,
  403. ((char *) &sci_req->stp.cmd) +
  404. sizeof(u32));
  405. task_context->command_iu_upper = upper_32_bits(dma_addr);
  406. task_context->command_iu_lower = lower_32_bits(dma_addr);
  407. /* SATA Requests do not have a response buffer */
  408. task_context->response_iu_upper = 0;
  409. task_context->response_iu_lower = 0;
  410. }
  411. /**
  412. * scu_stp_raw_request_construct_task_context -
  413. * @sci_req: This parameter specifies the STP request object for which to
  414. * construct a RAW command frame task context.
  415. * @task_context: This parameter specifies the SCU specific task context buffer
  416. * to construct.
  417. *
  418. * This method performs the operations common to all SATA/STP requests
  419. * utilizing the raw frame method. none
  420. */
  421. static void scu_stp_raw_request_construct_task_context(struct scic_sds_stp_request *stp_req,
  422. struct scu_task_context *task_context)
  423. {
  424. struct scic_sds_request *sci_req = to_sci_req(stp_req);
  425. scu_sata_reqeust_construct_task_context(sci_req, task_context);
  426. task_context->control_frame = 0;
  427. task_context->priority = SCU_TASK_PRIORITY_NORMAL;
  428. task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
  429. task_context->type.stp.fis_type = FIS_REGH2D;
  430. task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32);
  431. }
  432. static enum sci_status
  433. scic_sds_stp_pio_request_construct(struct scic_sds_request *sci_req,
  434. bool copy_rx_frame)
  435. {
  436. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  437. struct scic_sds_stp_pio_request *pio = &stp_req->type.pio;
  438. scu_stp_raw_request_construct_task_context(stp_req,
  439. sci_req->task_context_buffer);
  440. pio->current_transfer_bytes = 0;
  441. pio->ending_error = 0;
  442. pio->ending_status = 0;
  443. pio->request_current.sgl_offset = 0;
  444. pio->request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
  445. if (copy_rx_frame) {
  446. scic_sds_request_build_sgl(sci_req);
  447. /* Since the IO request copy of the TC contains the same data as
  448. * the actual TC this pointer is vaild for either.
  449. */
  450. pio->request_current.sgl_pair = &sci_req->task_context_buffer->sgl_pair_ab;
  451. } else {
  452. /* The user does not want the data copied to the SGL buffer location */
  453. pio->request_current.sgl_pair = NULL;
  454. }
  455. return SCI_SUCCESS;
  456. }
  457. /**
  458. *
  459. * @sci_req: This parameter specifies the request to be constructed as an
  460. * optimized request.
  461. * @optimized_task_type: This parameter specifies whether the request is to be
  462. * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
  463. * value of 1 indicates NCQ.
  464. *
  465. * This method will perform request construction common to all types of STP
  466. * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
  467. * returns an indication as to whether the construction was successful.
  468. */
  469. static void scic_sds_stp_optimized_request_construct(struct scic_sds_request *sci_req,
  470. u8 optimized_task_type,
  471. u32 len,
  472. enum dma_data_direction dir)
  473. {
  474. struct scu_task_context *task_context = sci_req->task_context_buffer;
  475. /* Build the STP task context structure */
  476. scu_sata_reqeust_construct_task_context(sci_req, task_context);
  477. /* Copy over the SGL elements */
  478. scic_sds_request_build_sgl(sci_req);
  479. /* Copy over the number of bytes to be transfered */
  480. task_context->transfer_length_bytes = len;
  481. if (dir == DMA_TO_DEVICE) {
  482. /*
  483. * The difference between the DMA IN and DMA OUT request task type
  484. * values are consistent with the difference between FPDMA READ
  485. * and FPDMA WRITE values. Add the supplied task type parameter
  486. * to this difference to set the task type properly for this
  487. * DATA OUT (WRITE) case. */
  488. task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
  489. - SCU_TASK_TYPE_DMA_IN);
  490. } else {
  491. /*
  492. * For the DATA IN (READ) case, simply save the supplied
  493. * optimized task type. */
  494. task_context->task_type = optimized_task_type;
  495. }
  496. }
  497. static enum sci_status
  498. scic_io_request_construct_sata(struct scic_sds_request *sci_req,
  499. u32 len,
  500. enum dma_data_direction dir,
  501. bool copy)
  502. {
  503. enum sci_status status = SCI_SUCCESS;
  504. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  505. struct sas_task *task = isci_request_access_task(ireq);
  506. /* check for management protocols */
  507. if (ireq->ttype == tmf_task) {
  508. struct isci_tmf *tmf = isci_request_access_tmf(ireq);
  509. if (tmf->tmf_code == isci_tmf_sata_srst_high ||
  510. tmf->tmf_code == isci_tmf_sata_srst_low) {
  511. scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
  512. sci_req->task_context_buffer);
  513. return SCI_SUCCESS;
  514. } else {
  515. dev_err(scic_to_dev(sci_req->owning_controller),
  516. "%s: Request 0x%p received un-handled SAT "
  517. "management protocol 0x%x.\n",
  518. __func__, sci_req, tmf->tmf_code);
  519. return SCI_FAILURE;
  520. }
  521. }
  522. if (!sas_protocol_ata(task->task_proto)) {
  523. dev_err(scic_to_dev(sci_req->owning_controller),
  524. "%s: Non-ATA protocol in SATA path: 0x%x\n",
  525. __func__,
  526. task->task_proto);
  527. return SCI_FAILURE;
  528. }
  529. /* non data */
  530. if (task->data_dir == DMA_NONE) {
  531. scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
  532. sci_req->task_context_buffer);
  533. return SCI_SUCCESS;
  534. }
  535. /* NCQ */
  536. if (task->ata_task.use_ncq) {
  537. scic_sds_stp_optimized_request_construct(sci_req,
  538. SCU_TASK_TYPE_FPDMAQ_READ,
  539. len, dir);
  540. return SCI_SUCCESS;
  541. }
  542. /* DMA */
  543. if (task->ata_task.dma_xfer) {
  544. scic_sds_stp_optimized_request_construct(sci_req,
  545. SCU_TASK_TYPE_DMA_IN,
  546. len, dir);
  547. return SCI_SUCCESS;
  548. } else /* PIO */
  549. return scic_sds_stp_pio_request_construct(sci_req, copy);
  550. return status;
  551. }
  552. static enum sci_status scic_io_request_construct_basic_ssp(struct scic_sds_request *sci_req)
  553. {
  554. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  555. struct sas_task *task = isci_request_access_task(ireq);
  556. sci_req->protocol = SCIC_SSP_PROTOCOL;
  557. scu_ssp_io_request_construct_task_context(sci_req,
  558. task->data_dir,
  559. task->total_xfer_len);
  560. scic_sds_io_request_build_ssp_command_iu(sci_req);
  561. sci_base_state_machine_change_state(&sci_req->state_machine,
  562. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  563. return SCI_SUCCESS;
  564. }
  565. enum sci_status scic_task_request_construct_ssp(
  566. struct scic_sds_request *sci_req)
  567. {
  568. /* Construct the SSP Task SCU Task Context */
  569. scu_ssp_task_request_construct_task_context(sci_req);
  570. /* Fill in the SSP Task IU */
  571. scic_sds_task_request_build_ssp_task_iu(sci_req);
  572. sci_base_state_machine_change_state(&sci_req->state_machine,
  573. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  574. return SCI_SUCCESS;
  575. }
  576. static enum sci_status scic_io_request_construct_basic_sata(struct scic_sds_request *sci_req)
  577. {
  578. enum sci_status status;
  579. struct scic_sds_stp_request *stp_req;
  580. bool copy = false;
  581. struct isci_request *isci_request = sci_req_to_ireq(sci_req);
  582. struct sas_task *task = isci_request_access_task(isci_request);
  583. stp_req = &sci_req->stp.req;
  584. sci_req->protocol = SCIC_STP_PROTOCOL;
  585. copy = (task->data_dir == DMA_NONE) ? false : true;
  586. status = scic_io_request_construct_sata(sci_req,
  587. task->total_xfer_len,
  588. task->data_dir,
  589. copy);
  590. if (status == SCI_SUCCESS)
  591. sci_base_state_machine_change_state(&sci_req->state_machine,
  592. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  593. return status;
  594. }
  595. enum sci_status scic_task_request_construct_sata(struct scic_sds_request *sci_req)
  596. {
  597. enum sci_status status = SCI_SUCCESS;
  598. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  599. /* check for management protocols */
  600. if (ireq->ttype == tmf_task) {
  601. struct isci_tmf *tmf = isci_request_access_tmf(ireq);
  602. if (tmf->tmf_code == isci_tmf_sata_srst_high ||
  603. tmf->tmf_code == isci_tmf_sata_srst_low) {
  604. scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
  605. sci_req->task_context_buffer);
  606. } else {
  607. dev_err(scic_to_dev(sci_req->owning_controller),
  608. "%s: Request 0x%p received un-handled SAT "
  609. "Protocol 0x%x.\n",
  610. __func__, sci_req, tmf->tmf_code);
  611. return SCI_FAILURE;
  612. }
  613. }
  614. if (status != SCI_SUCCESS)
  615. return status;
  616. sci_base_state_machine_change_state(&sci_req->state_machine,
  617. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  618. return status;
  619. }
  620. /**
  621. * sci_req_tx_bytes - bytes transferred when reply underruns request
  622. * @sci_req: request that was terminated early
  623. */
  624. #define SCU_TASK_CONTEXT_SRAM 0x200000
  625. static u32 sci_req_tx_bytes(struct scic_sds_request *sci_req)
  626. {
  627. struct scic_sds_controller *scic = sci_req->owning_controller;
  628. u32 ret_val = 0;
  629. if (readl(&scic->smu_registers->address_modifier) == 0) {
  630. void __iomem *scu_reg_base = scic->scu_registers;
  631. /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
  632. * BAR1 is the scu_registers
  633. * 0x20002C = 0x200000 + 0x2c
  634. * = start of task context SRAM + offset of (type.ssp.data_offset)
  635. * TCi is the io_tag of struct scic_sds_request
  636. */
  637. ret_val = readl(scu_reg_base +
  638. (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
  639. ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(sci_req->io_tag)));
  640. }
  641. return ret_val;
  642. }
  643. enum sci_status
  644. scic_sds_request_start(struct scic_sds_request *request)
  645. {
  646. if (request->device_sequence !=
  647. scic_sds_remote_device_get_sequence(request->target_device))
  648. return SCI_FAILURE;
  649. if (request->state_handlers->start_handler)
  650. return request->state_handlers->start_handler(request);
  651. dev_warn(scic_to_dev(request->owning_controller),
  652. "%s: SCIC IO Request requested to start while in wrong "
  653. "state %d\n",
  654. __func__,
  655. sci_base_state_machine_get_state(&request->state_machine));
  656. return SCI_FAILURE_INVALID_STATE;
  657. }
  658. enum sci_status
  659. scic_sds_io_request_terminate(struct scic_sds_request *sci_req)
  660. {
  661. enum sci_base_request_states state;
  662. state = sci_req->state_machine.current_state_id;
  663. switch (state) {
  664. case SCI_BASE_REQUEST_STATE_CONSTRUCTED:
  665. scic_sds_request_set_status(sci_req,
  666. SCU_TASK_DONE_TASK_ABORT,
  667. SCI_FAILURE_IO_TERMINATED);
  668. sci_base_state_machine_change_state(&sci_req->state_machine,
  669. SCI_BASE_REQUEST_STATE_COMPLETED);
  670. return SCI_SUCCESS;
  671. case SCI_BASE_REQUEST_STATE_STARTED:
  672. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION:
  673. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE:
  674. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION:
  675. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE:
  676. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE:
  677. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE:
  678. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE:
  679. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE:
  680. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE:
  681. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE:
  682. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE:
  683. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE:
  684. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE:
  685. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE:
  686. sci_base_state_machine_change_state(&sci_req->state_machine,
  687. SCI_BASE_REQUEST_STATE_ABORTING);
  688. return SCI_SUCCESS;
  689. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE:
  690. sci_base_state_machine_change_state(&sci_req->state_machine,
  691. SCI_BASE_REQUEST_STATE_ABORTING);
  692. sci_base_state_machine_change_state(&sci_req->state_machine,
  693. SCI_BASE_REQUEST_STATE_COMPLETED);
  694. return SCI_SUCCESS;
  695. case SCI_BASE_REQUEST_STATE_ABORTING:
  696. sci_base_state_machine_change_state(&sci_req->state_machine,
  697. SCI_BASE_REQUEST_STATE_COMPLETED);
  698. return SCI_SUCCESS;
  699. case SCI_BASE_REQUEST_STATE_COMPLETED:
  700. default:
  701. dev_warn(scic_to_dev(sci_req->owning_controller),
  702. "%s: SCIC IO Request requested to abort while in wrong "
  703. "state %d\n",
  704. __func__,
  705. sci_base_state_machine_get_state(&sci_req->state_machine));
  706. break;
  707. }
  708. return SCI_FAILURE_INVALID_STATE;
  709. }
  710. enum sci_status scic_sds_io_request_event_handler(
  711. struct scic_sds_request *request,
  712. u32 event_code)
  713. {
  714. if (request->state_handlers->event_handler)
  715. return request->state_handlers->event_handler(request, event_code);
  716. dev_warn(scic_to_dev(request->owning_controller),
  717. "%s: SCIC IO Request given event code notification %x while "
  718. "in wrong state %d\n",
  719. __func__,
  720. event_code,
  721. sci_base_state_machine_get_state(&request->state_machine));
  722. return SCI_FAILURE_INVALID_STATE;
  723. }
  724. /**
  725. *
  726. * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
  727. * operation is to be executed.
  728. * @frame_index: The frame index returned by the hardware for the reqeust
  729. * object.
  730. *
  731. * This method invokes the core state frame handler for the
  732. * SCIC_SDS_IO_REQUEST_T object. enum sci_status
  733. */
  734. enum sci_status scic_sds_io_request_frame_handler(
  735. struct scic_sds_request *request,
  736. u32 frame_index)
  737. {
  738. if (request->state_handlers->frame_handler)
  739. return request->state_handlers->frame_handler(request, frame_index);
  740. dev_warn(scic_to_dev(request->owning_controller),
  741. "%s: SCIC IO Request given unexpected frame %x while in "
  742. "state %d\n",
  743. __func__,
  744. frame_index,
  745. sci_base_state_machine_get_state(&request->state_machine));
  746. scic_sds_controller_release_frame(request->owning_controller, frame_index);
  747. return SCI_FAILURE_INVALID_STATE;
  748. }
  749. /*
  750. * This function copies response data for requests returning response data
  751. * instead of sense data.
  752. * @sci_req: This parameter specifies the request object for which to copy
  753. * the response data.
  754. */
  755. static void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
  756. {
  757. void *resp_buf;
  758. u32 len;
  759. struct ssp_response_iu *ssp_response;
  760. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  761. struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
  762. ssp_response = &sci_req->ssp.rsp;
  763. resp_buf = &isci_tmf->resp.resp_iu;
  764. len = min_t(u32,
  765. SSP_RESP_IU_MAX_SIZE,
  766. be32_to_cpu(ssp_response->response_data_len));
  767. memcpy(resp_buf, ssp_response->resp_data, len);
  768. }
  769. /*
  770. * This method implements the action taken when a constructed
  771. * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
  772. * This method will, if necessary, allocate a TCi for the io request object and
  773. * then will, if necessary, copy the constructed TC data into the actual TC
  774. * buffer. If everything is successful the post context field is updated with
  775. * the TCi so the controller can post the request to the hardware. enum sci_status
  776. * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
  777. */
  778. static enum sci_status scic_sds_request_constructed_state_start_handler(
  779. struct scic_sds_request *request)
  780. {
  781. struct scu_task_context *task_context;
  782. if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
  783. request->io_tag =
  784. scic_controller_allocate_io_tag(request->owning_controller);
  785. }
  786. /* Record the IO Tag in the request */
  787. if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
  788. task_context = request->task_context_buffer;
  789. task_context->task_index = scic_sds_io_tag_get_index(request->io_tag);
  790. switch (task_context->protocol_type) {
  791. case SCU_TASK_CONTEXT_PROTOCOL_SMP:
  792. case SCU_TASK_CONTEXT_PROTOCOL_SSP:
  793. /* SSP/SMP Frame */
  794. task_context->type.ssp.tag = request->io_tag;
  795. task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
  796. break;
  797. case SCU_TASK_CONTEXT_PROTOCOL_STP:
  798. /*
  799. * STP/SATA Frame
  800. * task_context->type.stp.ncq_tag = request->ncq_tag; */
  801. break;
  802. case SCU_TASK_CONTEXT_PROTOCOL_NONE:
  803. /* / @todo When do we set no protocol type? */
  804. break;
  805. default:
  806. /* This should never happen since we build the IO requests */
  807. break;
  808. }
  809. /*
  810. * Check to see if we need to copy the task context buffer
  811. * or have been building into the task context buffer */
  812. if (request->was_tag_assigned_by_user == false) {
  813. scic_sds_controller_copy_task_context(
  814. request->owning_controller, request);
  815. }
  816. /* Add to the post_context the io tag value */
  817. request->post_context |= scic_sds_io_tag_get_index(request->io_tag);
  818. /* Everything is good go ahead and change state */
  819. sci_base_state_machine_change_state(&request->state_machine,
  820. SCI_BASE_REQUEST_STATE_STARTED);
  821. return SCI_SUCCESS;
  822. }
  823. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  824. }
  825. /*
  826. * scic_sds_request_started_state_tc_completion_handler() - This method process
  827. * TC (task context) completions for normal IO request (i.e. Task/Abort
  828. * Completions of type 0). This method will update the
  829. * SCIC_SDS_IO_REQUEST_T::status field.
  830. * @sci_req: This parameter specifies the request for which a completion
  831. * occurred.
  832. * @completion_code: This parameter specifies the completion code received from
  833. * the SCU.
  834. *
  835. */
  836. static enum sci_status
  837. scic_sds_request_started_state_tc_completion_handler(struct scic_sds_request *sci_req,
  838. u32 completion_code)
  839. {
  840. u8 datapres;
  841. struct ssp_response_iu *resp_iu;
  842. /*
  843. * TODO: Any SDMA return code of other than 0 is bad
  844. * decode 0x003C0000 to determine SDMA status
  845. */
  846. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  847. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  848. scic_sds_request_set_status(sci_req,
  849. SCU_TASK_DONE_GOOD,
  850. SCI_SUCCESS);
  851. break;
  852. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
  853. {
  854. /*
  855. * There are times when the SCU hardware will return an early
  856. * response because the io request specified more data than is
  857. * returned by the target device (mode pages, inquiry data,
  858. * etc.). We must check the response stats to see if this is
  859. * truly a failed request or a good request that just got
  860. * completed early.
  861. */
  862. struct ssp_response_iu *resp = &sci_req->ssp.rsp;
  863. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  864. sci_swab32_cpy(&sci_req->ssp.rsp,
  865. &sci_req->ssp.rsp,
  866. word_cnt);
  867. if (resp->status == 0) {
  868. scic_sds_request_set_status(
  869. sci_req,
  870. SCU_TASK_DONE_GOOD,
  871. SCI_SUCCESS_IO_DONE_EARLY);
  872. } else {
  873. scic_sds_request_set_status(
  874. sci_req,
  875. SCU_TASK_DONE_CHECK_RESPONSE,
  876. SCI_FAILURE_IO_RESPONSE_VALID);
  877. }
  878. }
  879. break;
  880. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
  881. {
  882. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  883. sci_swab32_cpy(&sci_req->ssp.rsp,
  884. &sci_req->ssp.rsp,
  885. word_cnt);
  886. scic_sds_request_set_status(sci_req,
  887. SCU_TASK_DONE_CHECK_RESPONSE,
  888. SCI_FAILURE_IO_RESPONSE_VALID);
  889. break;
  890. }
  891. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
  892. /*
  893. * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
  894. * guaranteed to be received before this completion status is
  895. * posted?
  896. */
  897. resp_iu = &sci_req->ssp.rsp;
  898. datapres = resp_iu->datapres;
  899. if ((datapres == 0x01) || (datapres == 0x02)) {
  900. scic_sds_request_set_status(
  901. sci_req,
  902. SCU_TASK_DONE_CHECK_RESPONSE,
  903. SCI_FAILURE_IO_RESPONSE_VALID);
  904. } else
  905. scic_sds_request_set_status(
  906. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
  907. break;
  908. /* only stp device gets suspended. */
  909. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
  910. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
  911. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
  912. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
  913. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
  914. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
  915. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
  916. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
  917. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
  918. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
  919. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
  920. if (sci_req->protocol == SCIC_STP_PROTOCOL) {
  921. scic_sds_request_set_status(
  922. sci_req,
  923. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  924. SCU_COMPLETION_TL_STATUS_SHIFT,
  925. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
  926. } else {
  927. scic_sds_request_set_status(
  928. sci_req,
  929. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  930. SCU_COMPLETION_TL_STATUS_SHIFT,
  931. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  932. }
  933. break;
  934. /* both stp/ssp device gets suspended */
  935. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
  936. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
  937. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
  938. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
  939. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
  940. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
  941. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
  942. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
  943. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
  944. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
  945. scic_sds_request_set_status(
  946. sci_req,
  947. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  948. SCU_COMPLETION_TL_STATUS_SHIFT,
  949. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
  950. break;
  951. /* neither ssp nor stp gets suspended. */
  952. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
  953. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
  954. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
  955. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
  956. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
  957. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
  958. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
  959. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
  960. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
  961. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
  962. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
  963. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
  964. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
  965. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
  966. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
  967. default:
  968. scic_sds_request_set_status(
  969. sci_req,
  970. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  971. SCU_COMPLETION_TL_STATUS_SHIFT,
  972. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  973. break;
  974. }
  975. /*
  976. * TODO: This is probably wrong for ACK/NAK timeout conditions
  977. */
  978. /* In all cases we will treat this as the completion of the IO req. */
  979. sci_base_state_machine_change_state(&sci_req->state_machine,
  980. SCI_BASE_REQUEST_STATE_COMPLETED);
  981. return SCI_SUCCESS;
  982. }
  983. enum sci_status
  984. scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code)
  985. {
  986. if (request->state_handlers->tc_completion_handler)
  987. return request->state_handlers->tc_completion_handler(request, completion_code);
  988. dev_warn(scic_to_dev(request->owning_controller),
  989. "%s: SCIC IO Request given task completion notification %x "
  990. "while in wrong state %d\n",
  991. __func__,
  992. completion_code,
  993. sci_base_state_machine_get_state(&request->state_machine));
  994. return SCI_FAILURE_INVALID_STATE;
  995. }
  996. /*
  997. * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
  998. * object receives a scic_sds_request_frame_handler() request. This method
  999. * first determines the frame type received. If this is a response frame then
  1000. * the response data is copied to the io request response buffer for processing
  1001. * at completion time. If the frame type is not a response buffer an error is
  1002. * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
  1003. */
  1004. static enum sci_status
  1005. scic_sds_request_started_state_frame_handler(struct scic_sds_request *sci_req,
  1006. u32 frame_index)
  1007. {
  1008. enum sci_status status;
  1009. u32 *frame_header;
  1010. struct ssp_frame_hdr ssp_hdr;
  1011. ssize_t word_cnt;
  1012. status = scic_sds_unsolicited_frame_control_get_header(
  1013. &(scic_sds_request_get_controller(sci_req)->uf_control),
  1014. frame_index,
  1015. (void **)&frame_header);
  1016. word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
  1017. sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
  1018. if (ssp_hdr.frame_type == SSP_RESPONSE) {
  1019. struct ssp_response_iu *resp_iu;
  1020. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  1021. status = scic_sds_unsolicited_frame_control_get_buffer(
  1022. &(scic_sds_request_get_controller(sci_req)->uf_control),
  1023. frame_index,
  1024. (void **)&resp_iu);
  1025. sci_swab32_cpy(&sci_req->ssp.rsp,
  1026. resp_iu, word_cnt);
  1027. resp_iu = &sci_req->ssp.rsp;
  1028. if ((resp_iu->datapres == 0x01) ||
  1029. (resp_iu->datapres == 0x02)) {
  1030. scic_sds_request_set_status(
  1031. sci_req,
  1032. SCU_TASK_DONE_CHECK_RESPONSE,
  1033. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1034. } else
  1035. scic_sds_request_set_status(
  1036. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
  1037. } else {
  1038. /* This was not a response frame why did it get forwarded? */
  1039. dev_err(scic_to_dev(sci_req->owning_controller),
  1040. "%s: SCIC IO Request 0x%p received unexpected "
  1041. "frame %d type 0x%02x\n",
  1042. __func__,
  1043. sci_req,
  1044. frame_index,
  1045. ssp_hdr.frame_type);
  1046. }
  1047. /*
  1048. * In any case we are done with this frame buffer return it to the
  1049. * controller
  1050. */
  1051. scic_sds_controller_release_frame(
  1052. sci_req->owning_controller, frame_index);
  1053. return SCI_SUCCESS;
  1054. }
  1055. /*
  1056. * *****************************************************************************
  1057. * * COMPLETED STATE HANDLERS
  1058. * ***************************************************************************** */
  1059. /*
  1060. * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
  1061. * object receives a scic_sds_request_complete() request. This method frees up
  1062. * any io request resources that have been allocated and transitions the
  1063. * request to its final state. Consider stopping the state machine instead of
  1064. * transitioning to the final state? enum sci_status SCI_SUCCESS
  1065. */
  1066. static enum sci_status scic_sds_request_completed_state_complete_handler(
  1067. struct scic_sds_request *request)
  1068. {
  1069. if (request->was_tag_assigned_by_user != true) {
  1070. scic_controller_free_io_tag(
  1071. request->owning_controller, request->io_tag);
  1072. }
  1073. if (request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
  1074. scic_sds_controller_release_frame(
  1075. request->owning_controller, request->saved_rx_frame_index);
  1076. }
  1077. sci_base_state_machine_change_state(&request->state_machine,
  1078. SCI_BASE_REQUEST_STATE_FINAL);
  1079. return SCI_SUCCESS;
  1080. }
  1081. /*
  1082. * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
  1083. * object receives a scic_sds_request_task_completion() request. This method
  1084. * decodes the completion type waiting for the abort task complete
  1085. * notification. When the abort task complete is received the io request
  1086. * transitions to the completed state. enum sci_status SCI_SUCCESS
  1087. */
  1088. static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
  1089. struct scic_sds_request *sci_req,
  1090. u32 completion_code)
  1091. {
  1092. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1093. case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
  1094. case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
  1095. scic_sds_request_set_status(
  1096. sci_req, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
  1097. );
  1098. sci_base_state_machine_change_state(&sci_req->state_machine,
  1099. SCI_BASE_REQUEST_STATE_COMPLETED);
  1100. break;
  1101. default:
  1102. /*
  1103. * Unless we get some strange error wait for the task abort to complete
  1104. * TODO: Should there be a state change for this completion? */
  1105. break;
  1106. }
  1107. return SCI_SUCCESS;
  1108. }
  1109. /*
  1110. * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
  1111. * object receives a scic_sds_request_frame_handler() request. This method
  1112. * discards the unsolicited frame since we are waiting for the abort task
  1113. * completion. enum sci_status SCI_SUCCESS
  1114. */
  1115. static enum sci_status scic_sds_request_aborting_state_frame_handler(
  1116. struct scic_sds_request *sci_req,
  1117. u32 frame_index)
  1118. {
  1119. /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
  1120. scic_sds_controller_release_frame(
  1121. sci_req->owning_controller, frame_index);
  1122. return SCI_SUCCESS;
  1123. }
  1124. /**
  1125. * This method processes the completions transport layer (TL) status to
  1126. * determine if the RAW task management frame was sent successfully. If the
  1127. * raw frame was sent successfully, then the state for the task request
  1128. * transitions to waiting for a response frame.
  1129. * @sci_req: This parameter specifies the request for which the TC
  1130. * completion was received.
  1131. * @completion_code: This parameter indicates the completion status information
  1132. * for the TC.
  1133. *
  1134. * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
  1135. * this method always returns success.
  1136. */
  1137. static enum sci_status scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
  1138. struct scic_sds_request *sci_req,
  1139. u32 completion_code)
  1140. {
  1141. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1142. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1143. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1144. SCI_SUCCESS);
  1145. sci_base_state_machine_change_state(&sci_req->state_machine,
  1146. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
  1147. break;
  1148. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
  1149. /*
  1150. * Currently, the decision is to simply allow the task request to
  1151. * timeout if the task IU wasn't received successfully.
  1152. * There is a potential for receiving multiple task responses if we
  1153. * decide to send the task IU again. */
  1154. dev_warn(scic_to_dev(sci_req->owning_controller),
  1155. "%s: TaskRequest:0x%p CompletionCode:%x - "
  1156. "ACK/NAK timeout\n",
  1157. __func__,
  1158. sci_req,
  1159. completion_code);
  1160. sci_base_state_machine_change_state(&sci_req->state_machine,
  1161. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
  1162. break;
  1163. default:
  1164. /*
  1165. * All other completion status cause the IO to be complete. If a NAK
  1166. * was received, then it is up to the user to retry the request. */
  1167. scic_sds_request_set_status(
  1168. sci_req,
  1169. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1170. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1171. );
  1172. sci_base_state_machine_change_state(&sci_req->state_machine,
  1173. SCI_BASE_REQUEST_STATE_COMPLETED);
  1174. break;
  1175. }
  1176. return SCI_SUCCESS;
  1177. }
  1178. /**
  1179. * This method processes an unsolicited frame while the task mgmt request is
  1180. * waiting for a response frame. It will copy the response data, release
  1181. * the unsolicited frame, and transition the request to the
  1182. * SCI_BASE_REQUEST_STATE_COMPLETED state.
  1183. * @sci_req: This parameter specifies the request for which the
  1184. * unsolicited frame was received.
  1185. * @frame_index: This parameter indicates the unsolicited frame index that
  1186. * should contain the response.
  1187. *
  1188. * This method returns an indication of whether the TC response frame was
  1189. * handled successfully or not. SCI_SUCCESS Currently this value is always
  1190. * returned and indicates successful processing of the TC response. Should
  1191. * probably update to check frame type and make sure it is a response frame.
  1192. */
  1193. static enum sci_status scic_sds_ssp_task_request_await_tc_response_frame_handler(
  1194. struct scic_sds_request *request,
  1195. u32 frame_index)
  1196. {
  1197. scic_sds_io_request_copy_response(request);
  1198. sci_base_state_machine_change_state(&request->state_machine,
  1199. SCI_BASE_REQUEST_STATE_COMPLETED);
  1200. scic_sds_controller_release_frame(request->owning_controller,
  1201. frame_index);
  1202. return SCI_SUCCESS;
  1203. }
  1204. /**
  1205. * This method processes an abnormal TC completion while the SMP request is
  1206. * waiting for a response frame. It decides what happened to the IO based
  1207. * on TC completion status.
  1208. * @sci_req: This parameter specifies the request for which the TC
  1209. * completion was received.
  1210. * @completion_code: This parameter indicates the completion status information
  1211. * for the TC.
  1212. *
  1213. * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
  1214. * this method always returns success.
  1215. */
  1216. static enum sci_status scic_sds_smp_request_await_response_tc_completion_handler(
  1217. struct scic_sds_request *sci_req,
  1218. u32 completion_code)
  1219. {
  1220. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1221. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1222. /*
  1223. * In the AWAIT RESPONSE state, any TC completion is unexpected.
  1224. * but if the TC has success status, we complete the IO anyway. */
  1225. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1226. SCI_SUCCESS);
  1227. sci_base_state_machine_change_state(&sci_req->state_machine,
  1228. SCI_BASE_REQUEST_STATE_COMPLETED);
  1229. break;
  1230. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
  1231. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
  1232. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
  1233. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
  1234. /*
  1235. * These status has been seen in a specific LSI expander, which sometimes
  1236. * is not able to send smp response within 2 ms. This causes our hardware
  1237. * break the connection and set TC completion with one of these SMP_XXX_XX_ERR
  1238. * status. For these type of error, we ask scic user to retry the request. */
  1239. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR,
  1240. SCI_FAILURE_RETRY_REQUIRED);
  1241. sci_base_state_machine_change_state(&sci_req->state_machine,
  1242. SCI_BASE_REQUEST_STATE_COMPLETED);
  1243. break;
  1244. default:
  1245. /*
  1246. * All other completion status cause the IO to be complete. If a NAK
  1247. * was received, then it is up to the user to retry the request. */
  1248. scic_sds_request_set_status(
  1249. sci_req,
  1250. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1251. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1252. );
  1253. sci_base_state_machine_change_state(&sci_req->state_machine,
  1254. SCI_BASE_REQUEST_STATE_COMPLETED);
  1255. break;
  1256. }
  1257. return SCI_SUCCESS;
  1258. }
  1259. /*
  1260. * This function processes an unsolicited frame while the SMP request is waiting
  1261. * for a response frame. It will copy the response data, release the
  1262. * unsolicited frame, and transition the request to the
  1263. * SCI_BASE_REQUEST_STATE_COMPLETED state.
  1264. * @sci_req: This parameter specifies the request for which the
  1265. * unsolicited frame was received.
  1266. * @frame_index: This parameter indicates the unsolicited frame index that
  1267. * should contain the response.
  1268. *
  1269. * This function returns an indication of whether the response frame was handled
  1270. * successfully or not. SCI_SUCCESS Currently this value is always returned and
  1271. * indicates successful processing of the TC response.
  1272. */
  1273. static enum sci_status
  1274. scic_sds_smp_request_await_response_frame_handler(struct scic_sds_request *sci_req,
  1275. u32 frame_index)
  1276. {
  1277. enum sci_status status;
  1278. void *frame_header;
  1279. struct smp_resp *rsp_hdr = &sci_req->smp.rsp;
  1280. ssize_t word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
  1281. status = scic_sds_unsolicited_frame_control_get_header(
  1282. &(scic_sds_request_get_controller(sci_req)->uf_control),
  1283. frame_index,
  1284. &frame_header);
  1285. /* byte swap the header. */
  1286. sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
  1287. if (rsp_hdr->frame_type == SMP_RESPONSE) {
  1288. void *smp_resp;
  1289. status = scic_sds_unsolicited_frame_control_get_buffer(
  1290. &(scic_sds_request_get_controller(sci_req)->uf_control),
  1291. frame_index,
  1292. &smp_resp);
  1293. word_cnt = (sizeof(struct smp_req) - SMP_RESP_HDR_SZ) /
  1294. sizeof(u32);
  1295. sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
  1296. smp_resp, word_cnt);
  1297. scic_sds_request_set_status(
  1298. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
  1299. sci_base_state_machine_change_state(&sci_req->state_machine,
  1300. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION);
  1301. } else {
  1302. /* This was not a response frame why did it get forwarded? */
  1303. dev_err(scic_to_dev(sci_req->owning_controller),
  1304. "%s: SCIC SMP Request 0x%p received unexpected frame "
  1305. "%d type 0x%02x\n",
  1306. __func__,
  1307. sci_req,
  1308. frame_index,
  1309. rsp_hdr->frame_type);
  1310. scic_sds_request_set_status(
  1311. sci_req,
  1312. SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
  1313. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1314. sci_base_state_machine_change_state(&sci_req->state_machine,
  1315. SCI_BASE_REQUEST_STATE_COMPLETED);
  1316. }
  1317. scic_sds_controller_release_frame(sci_req->owning_controller,
  1318. frame_index);
  1319. return SCI_SUCCESS;
  1320. }
  1321. /**
  1322. * This method processes the completions transport layer (TL) status to
  1323. * determine if the SMP request was sent successfully. If the SMP request
  1324. * was sent successfully, then the state for the SMP request transits to
  1325. * waiting for a response frame.
  1326. * @sci_req: This parameter specifies the request for which the TC
  1327. * completion was received.
  1328. * @completion_code: This parameter indicates the completion status information
  1329. * for the TC.
  1330. *
  1331. * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
  1332. * this method always returns success.
  1333. */
  1334. static enum sci_status scic_sds_smp_request_await_tc_completion_tc_completion_handler(
  1335. struct scic_sds_request *sci_req,
  1336. u32 completion_code)
  1337. {
  1338. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1339. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1340. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1341. SCI_SUCCESS);
  1342. sci_base_state_machine_change_state(&sci_req->state_machine,
  1343. SCI_BASE_REQUEST_STATE_COMPLETED);
  1344. break;
  1345. default:
  1346. /*
  1347. * All other completion status cause the IO to be complete. If a NAK
  1348. * was received, then it is up to the user to retry the request. */
  1349. scic_sds_request_set_status(
  1350. sci_req,
  1351. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1352. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1353. );
  1354. sci_base_state_machine_change_state(
  1355. &sci_req->state_machine,
  1356. SCI_BASE_REQUEST_STATE_COMPLETED);
  1357. break;
  1358. }
  1359. return SCI_SUCCESS;
  1360. }
  1361. void scic_stp_io_request_set_ncq_tag(struct scic_sds_request *req,
  1362. u16 ncq_tag)
  1363. {
  1364. /**
  1365. * @note This could be made to return an error to the user if the user
  1366. * attempts to set the NCQ tag in the wrong state.
  1367. */
  1368. req->task_context_buffer->type.stp.ncq_tag = ncq_tag;
  1369. }
  1370. /**
  1371. *
  1372. * @sci_req:
  1373. *
  1374. * Get the next SGL element from the request. - Check on which SGL element pair
  1375. * we are working - if working on SLG pair element A - advance to element B -
  1376. * else - check to see if there are more SGL element pairs for this IO request
  1377. * - if there are more SGL element pairs - advance to the next pair and return
  1378. * element A struct scu_sgl_element*
  1379. */
  1380. static struct scu_sgl_element *scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request *stp_req)
  1381. {
  1382. struct scu_sgl_element *current_sgl;
  1383. struct scic_sds_request *sci_req = to_sci_req(stp_req);
  1384. struct scic_sds_request_pio_sgl *pio_sgl = &stp_req->type.pio.request_current;
  1385. if (pio_sgl->sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
  1386. if (pio_sgl->sgl_pair->B.address_lower == 0 &&
  1387. pio_sgl->sgl_pair->B.address_upper == 0) {
  1388. current_sgl = NULL;
  1389. } else {
  1390. pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_B;
  1391. current_sgl = &pio_sgl->sgl_pair->B;
  1392. }
  1393. } else {
  1394. if (pio_sgl->sgl_pair->next_pair_lower == 0 &&
  1395. pio_sgl->sgl_pair->next_pair_upper == 0) {
  1396. current_sgl = NULL;
  1397. } else {
  1398. u64 phys_addr;
  1399. phys_addr = pio_sgl->sgl_pair->next_pair_upper;
  1400. phys_addr <<= 32;
  1401. phys_addr |= pio_sgl->sgl_pair->next_pair_lower;
  1402. pio_sgl->sgl_pair = scic_request_get_virt_addr(sci_req, phys_addr);
  1403. pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_A;
  1404. current_sgl = &pio_sgl->sgl_pair->A;
  1405. }
  1406. }
  1407. return current_sgl;
  1408. }
  1409. /**
  1410. *
  1411. * @sci_req:
  1412. * @completion_code:
  1413. *
  1414. * This method processes a TC completion. The expected TC completion is for
  1415. * the transmission of the H2D register FIS containing the SATA/STP non-data
  1416. * request. This method always successfully processes the TC completion.
  1417. * SCI_SUCCESS This value is always returned.
  1418. */
  1419. static enum sci_status scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
  1420. struct scic_sds_request *sci_req,
  1421. u32 completion_code)
  1422. {
  1423. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1424. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1425. scic_sds_request_set_status(
  1426. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
  1427. );
  1428. sci_base_state_machine_change_state(
  1429. &sci_req->state_machine,
  1430. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
  1431. );
  1432. break;
  1433. default:
  1434. /*
  1435. * All other completion status cause the IO to be complete. If a NAK
  1436. * was received, then it is up to the user to retry the request. */
  1437. scic_sds_request_set_status(
  1438. sci_req,
  1439. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1440. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1441. );
  1442. sci_base_state_machine_change_state(
  1443. &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
  1444. break;
  1445. }
  1446. return SCI_SUCCESS;
  1447. }
  1448. /**
  1449. *
  1450. * @request: This parameter specifies the request for which a frame has been
  1451. * received.
  1452. * @frame_index: This parameter specifies the index of the frame that has been
  1453. * received.
  1454. *
  1455. * This method processes frames received from the target while waiting for a
  1456. * device to host register FIS. If a non-register FIS is received during this
  1457. * time, it is treated as a protocol violation from an IO perspective. Indicate
  1458. * if the received frame was processed successfully.
  1459. */
  1460. static enum sci_status scic_sds_stp_request_non_data_await_d2h_frame_handler(
  1461. struct scic_sds_request *sci_req,
  1462. u32 frame_index)
  1463. {
  1464. enum sci_status status;
  1465. struct dev_to_host_fis *frame_header;
  1466. u32 *frame_buffer;
  1467. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1468. struct scic_sds_controller *scic = sci_req->owning_controller;
  1469. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1470. frame_index,
  1471. (void **)&frame_header);
  1472. if (status != SCI_SUCCESS) {
  1473. dev_err(scic_to_dev(sci_req->owning_controller),
  1474. "%s: SCIC IO Request 0x%p could not get frame header "
  1475. "for frame index %d, status %x\n",
  1476. __func__, stp_req, frame_index, status);
  1477. return status;
  1478. }
  1479. switch (frame_header->fis_type) {
  1480. case FIS_REGD2H:
  1481. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1482. frame_index,
  1483. (void **)&frame_buffer);
  1484. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1485. frame_header,
  1486. frame_buffer);
  1487. /* The command has completed with error */
  1488. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_CHECK_RESPONSE,
  1489. SCI_FAILURE_IO_RESPONSE_VALID);
  1490. break;
  1491. default:
  1492. dev_warn(scic_to_dev(scic),
  1493. "%s: IO Request:0x%p Frame Id:%d protocol "
  1494. "violation occurred\n", __func__, stp_req,
  1495. frame_index);
  1496. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
  1497. SCI_FAILURE_PROTOCOL_VIOLATION);
  1498. break;
  1499. }
  1500. sci_base_state_machine_change_state(&sci_req->state_machine,
  1501. SCI_BASE_REQUEST_STATE_COMPLETED);
  1502. /* Frame has been decoded return it to the controller */
  1503. scic_sds_controller_release_frame(scic, frame_index);
  1504. return status;
  1505. }
  1506. #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
  1507. /* transmit DATA_FIS from (current sgl + offset) for input
  1508. * parameter length. current sgl and offset is alreay stored in the IO request
  1509. */
  1510. static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
  1511. struct scic_sds_request *sci_req,
  1512. u32 length)
  1513. {
  1514. struct scic_sds_controller *scic = sci_req->owning_controller;
  1515. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1516. struct scu_task_context *task_context;
  1517. struct scu_sgl_element *current_sgl;
  1518. /* Recycle the TC and reconstruct it for sending out DATA FIS containing
  1519. * for the data from current_sgl+offset for the input length
  1520. */
  1521. task_context = scic_sds_controller_get_task_context_buffer(scic,
  1522. sci_req->io_tag);
  1523. if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
  1524. current_sgl = &stp_req->type.pio.request_current.sgl_pair->A;
  1525. else
  1526. current_sgl = &stp_req->type.pio.request_current.sgl_pair->B;
  1527. /* update the TC */
  1528. task_context->command_iu_upper = current_sgl->address_upper;
  1529. task_context->command_iu_lower = current_sgl->address_lower;
  1530. task_context->transfer_length_bytes = length;
  1531. task_context->type.stp.fis_type = FIS_DATA;
  1532. /* send the new TC out. */
  1533. return scic_controller_continue_io(sci_req);
  1534. }
  1535. static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request *sci_req)
  1536. {
  1537. struct scu_sgl_element *current_sgl;
  1538. u32 sgl_offset;
  1539. u32 remaining_bytes_in_current_sgl = 0;
  1540. enum sci_status status = SCI_SUCCESS;
  1541. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1542. sgl_offset = stp_req->type.pio.request_current.sgl_offset;
  1543. if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
  1544. current_sgl = &(stp_req->type.pio.request_current.sgl_pair->A);
  1545. remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->A.length - sgl_offset;
  1546. } else {
  1547. current_sgl = &(stp_req->type.pio.request_current.sgl_pair->B);
  1548. remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->B.length - sgl_offset;
  1549. }
  1550. if (stp_req->type.pio.pio_transfer_bytes > 0) {
  1551. if (stp_req->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
  1552. /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
  1553. status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, remaining_bytes_in_current_sgl);
  1554. if (status == SCI_SUCCESS) {
  1555. stp_req->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
  1556. /* update the current sgl, sgl_offset and save for future */
  1557. current_sgl = scic_sds_stp_request_pio_get_next_sgl(stp_req);
  1558. sgl_offset = 0;
  1559. }
  1560. } else if (stp_req->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
  1561. /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
  1562. scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, stp_req->type.pio.pio_transfer_bytes);
  1563. if (status == SCI_SUCCESS) {
  1564. /* Sgl offset will be adjusted and saved for future */
  1565. sgl_offset += stp_req->type.pio.pio_transfer_bytes;
  1566. current_sgl->address_lower += stp_req->type.pio.pio_transfer_bytes;
  1567. stp_req->type.pio.pio_transfer_bytes = 0;
  1568. }
  1569. }
  1570. }
  1571. if (status == SCI_SUCCESS) {
  1572. stp_req->type.pio.request_current.sgl_offset = sgl_offset;
  1573. }
  1574. return status;
  1575. }
  1576. /**
  1577. *
  1578. * @stp_request: The request that is used for the SGL processing.
  1579. * @data_buffer: The buffer of data to be copied.
  1580. * @length: The length of the data transfer.
  1581. *
  1582. * Copy the data from the buffer for the length specified to the IO reqeust SGL
  1583. * specified data region. enum sci_status
  1584. */
  1585. static enum sci_status
  1586. scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request *stp_req,
  1587. u8 *data_buf, u32 len)
  1588. {
  1589. struct scic_sds_request *sci_req;
  1590. struct isci_request *ireq;
  1591. u8 *src_addr;
  1592. int copy_len;
  1593. struct sas_task *task;
  1594. struct scatterlist *sg;
  1595. void *kaddr;
  1596. int total_len = len;
  1597. sci_req = to_sci_req(stp_req);
  1598. ireq = sci_req_to_ireq(sci_req);
  1599. task = isci_request_access_task(ireq);
  1600. src_addr = data_buf;
  1601. if (task->num_scatter > 0) {
  1602. sg = task->scatter;
  1603. while (total_len > 0) {
  1604. struct page *page = sg_page(sg);
  1605. copy_len = min_t(int, total_len, sg_dma_len(sg));
  1606. kaddr = kmap_atomic(page, KM_IRQ0);
  1607. memcpy(kaddr + sg->offset, src_addr, copy_len);
  1608. kunmap_atomic(kaddr, KM_IRQ0);
  1609. total_len -= copy_len;
  1610. src_addr += copy_len;
  1611. sg = sg_next(sg);
  1612. }
  1613. } else {
  1614. BUG_ON(task->total_xfer_len < total_len);
  1615. memcpy(task->scatter, src_addr, total_len);
  1616. }
  1617. return SCI_SUCCESS;
  1618. }
  1619. /**
  1620. *
  1621. * @sci_req: The PIO DATA IN request that is to receive the data.
  1622. * @data_buffer: The buffer to copy from.
  1623. *
  1624. * Copy the data buffer to the io request data region. enum sci_status
  1625. */
  1626. static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
  1627. struct scic_sds_stp_request *sci_req,
  1628. u8 *data_buffer)
  1629. {
  1630. enum sci_status status;
  1631. /*
  1632. * If there is less than 1K remaining in the transfer request
  1633. * copy just the data for the transfer */
  1634. if (sci_req->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
  1635. status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
  1636. sci_req, data_buffer, sci_req->type.pio.pio_transfer_bytes);
  1637. if (status == SCI_SUCCESS)
  1638. sci_req->type.pio.pio_transfer_bytes = 0;
  1639. } else {
  1640. /* We are transfering the whole frame so copy */
  1641. status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
  1642. sci_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
  1643. if (status == SCI_SUCCESS)
  1644. sci_req->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
  1645. }
  1646. return status;
  1647. }
  1648. /**
  1649. *
  1650. * @sci_req:
  1651. * @completion_code:
  1652. *
  1653. * enum sci_status
  1654. */
  1655. static enum sci_status scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
  1656. struct scic_sds_request *sci_req,
  1657. u32 completion_code)
  1658. {
  1659. enum sci_status status = SCI_SUCCESS;
  1660. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1661. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1662. scic_sds_request_set_status(
  1663. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
  1664. );
  1665. sci_base_state_machine_change_state(
  1666. &sci_req->state_machine,
  1667. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
  1668. );
  1669. break;
  1670. default:
  1671. /*
  1672. * All other completion status cause the IO to be complete. If a NAK
  1673. * was received, then it is up to the user to retry the request. */
  1674. scic_sds_request_set_status(
  1675. sci_req,
  1676. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1677. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1678. );
  1679. sci_base_state_machine_change_state(
  1680. &sci_req->state_machine,
  1681. SCI_BASE_REQUEST_STATE_COMPLETED
  1682. );
  1683. break;
  1684. }
  1685. return status;
  1686. }
  1687. static enum sci_status scic_sds_stp_request_pio_await_frame_frame_handler(struct scic_sds_request *sci_req,
  1688. u32 frame_index)
  1689. {
  1690. struct scic_sds_controller *scic = sci_req->owning_controller;
  1691. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1692. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  1693. struct sas_task *task = isci_request_access_task(ireq);
  1694. struct dev_to_host_fis *frame_header;
  1695. enum sci_status status;
  1696. u32 *frame_buffer;
  1697. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1698. frame_index,
  1699. (void **)&frame_header);
  1700. if (status != SCI_SUCCESS) {
  1701. dev_err(scic_to_dev(scic),
  1702. "%s: SCIC IO Request 0x%p could not get frame header "
  1703. "for frame index %d, status %x\n",
  1704. __func__, stp_req, frame_index, status);
  1705. return status;
  1706. }
  1707. switch (frame_header->fis_type) {
  1708. case FIS_PIO_SETUP:
  1709. /* Get from the frame buffer the PIO Setup Data */
  1710. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1711. frame_index,
  1712. (void **)&frame_buffer);
  1713. /* Get the data from the PIO Setup The SCU Hardware returns
  1714. * first word in the frame_header and the rest of the data is in
  1715. * the frame buffer so we need to back up one dword
  1716. */
  1717. /* transfer_count: first 16bits in the 4th dword */
  1718. stp_req->type.pio.pio_transfer_bytes = frame_buffer[3] & 0xffff;
  1719. /* ending_status: 4th byte in the 3rd dword */
  1720. stp_req->type.pio.ending_status = (frame_buffer[2] >> 24) & 0xff;
  1721. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1722. frame_header,
  1723. frame_buffer);
  1724. sci_req->stp.rsp.status = stp_req->type.pio.ending_status;
  1725. /* The next state is dependent on whether the
  1726. * request was PIO Data-in or Data out
  1727. */
  1728. if (task->data_dir == DMA_FROM_DEVICE) {
  1729. sci_base_state_machine_change_state(&sci_req->state_machine,
  1730. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE);
  1731. } else if (task->data_dir == DMA_TO_DEVICE) {
  1732. /* Transmit data */
  1733. status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
  1734. if (status != SCI_SUCCESS)
  1735. break;
  1736. sci_base_state_machine_change_state(&sci_req->state_machine,
  1737. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE);
  1738. }
  1739. break;
  1740. case FIS_SETDEVBITS:
  1741. sci_base_state_machine_change_state(&sci_req->state_machine,
  1742. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  1743. break;
  1744. case FIS_REGD2H:
  1745. if (frame_header->status & ATA_BUSY) {
  1746. /* Now why is the drive sending a D2H Register FIS when
  1747. * it is still busy? Do nothing since we are still in
  1748. * the right state.
  1749. */
  1750. dev_dbg(scic_to_dev(scic),
  1751. "%s: SCIC PIO Request 0x%p received "
  1752. "D2H Register FIS with BSY status "
  1753. "0x%x\n", __func__, stp_req,
  1754. frame_header->status);
  1755. break;
  1756. }
  1757. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1758. frame_index,
  1759. (void **)&frame_buffer);
  1760. scic_sds_controller_copy_sata_response(&sci_req->stp.req,
  1761. frame_header,
  1762. frame_buffer);
  1763. scic_sds_request_set_status(sci_req,
  1764. SCU_TASK_DONE_CHECK_RESPONSE,
  1765. SCI_FAILURE_IO_RESPONSE_VALID);
  1766. sci_base_state_machine_change_state(&sci_req->state_machine,
  1767. SCI_BASE_REQUEST_STATE_COMPLETED);
  1768. break;
  1769. default:
  1770. /* FIXME: what do we do here? */
  1771. break;
  1772. }
  1773. /* Frame is decoded return it to the controller */
  1774. scic_sds_controller_release_frame(scic, frame_index);
  1775. return status;
  1776. }
  1777. static enum sci_status scic_sds_stp_request_pio_data_in_await_data_frame_handler(struct scic_sds_request *sci_req,
  1778. u32 frame_index)
  1779. {
  1780. enum sci_status status;
  1781. struct dev_to_host_fis *frame_header;
  1782. struct sata_fis_data *frame_buffer;
  1783. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1784. struct scic_sds_controller *scic = sci_req->owning_controller;
  1785. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1786. frame_index,
  1787. (void **)&frame_header);
  1788. if (status != SCI_SUCCESS) {
  1789. dev_err(scic_to_dev(scic),
  1790. "%s: SCIC IO Request 0x%p could not get frame header "
  1791. "for frame index %d, status %x\n",
  1792. __func__, stp_req, frame_index, status);
  1793. return status;
  1794. }
  1795. if (frame_header->fis_type == FIS_DATA) {
  1796. if (stp_req->type.pio.request_current.sgl_pair == NULL) {
  1797. sci_req->saved_rx_frame_index = frame_index;
  1798. stp_req->type.pio.pio_transfer_bytes = 0;
  1799. } else {
  1800. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1801. frame_index,
  1802. (void **)&frame_buffer);
  1803. status = scic_sds_stp_request_pio_data_in_copy_data(stp_req,
  1804. (u8 *)frame_buffer);
  1805. /* Frame is decoded return it to the controller */
  1806. scic_sds_controller_release_frame(scic, frame_index);
  1807. }
  1808. /* Check for the end of the transfer, are there more
  1809. * bytes remaining for this data transfer
  1810. */
  1811. if (status != SCI_SUCCESS ||
  1812. stp_req->type.pio.pio_transfer_bytes != 0)
  1813. return status;
  1814. if ((stp_req->type.pio.ending_status & ATA_BUSY) == 0) {
  1815. scic_sds_request_set_status(sci_req,
  1816. SCU_TASK_DONE_CHECK_RESPONSE,
  1817. SCI_FAILURE_IO_RESPONSE_VALID);
  1818. sci_base_state_machine_change_state(&sci_req->state_machine,
  1819. SCI_BASE_REQUEST_STATE_COMPLETED);
  1820. } else {
  1821. sci_base_state_machine_change_state(&sci_req->state_machine,
  1822. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  1823. }
  1824. } else {
  1825. dev_err(scic_to_dev(scic),
  1826. "%s: SCIC PIO Request 0x%p received frame %d "
  1827. "with fis type 0x%02x when expecting a data "
  1828. "fis.\n", __func__, stp_req, frame_index,
  1829. frame_header->fis_type);
  1830. scic_sds_request_set_status(sci_req,
  1831. SCU_TASK_DONE_GOOD,
  1832. SCI_FAILURE_IO_REQUIRES_SCSI_ABORT);
  1833. sci_base_state_machine_change_state(&sci_req->state_machine,
  1834. SCI_BASE_REQUEST_STATE_COMPLETED);
  1835. /* Frame is decoded return it to the controller */
  1836. scic_sds_controller_release_frame(scic, frame_index);
  1837. }
  1838. return status;
  1839. }
  1840. /**
  1841. *
  1842. * @sci_req:
  1843. * @completion_code:
  1844. *
  1845. * enum sci_status
  1846. */
  1847. static enum sci_status scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
  1848. struct scic_sds_request *sci_req,
  1849. u32 completion_code)
  1850. {
  1851. enum sci_status status = SCI_SUCCESS;
  1852. bool all_frames_transferred = false;
  1853. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1854. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1855. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1856. /* Transmit data */
  1857. if (stp_req->type.pio.pio_transfer_bytes != 0) {
  1858. status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
  1859. if (status == SCI_SUCCESS) {
  1860. if (stp_req->type.pio.pio_transfer_bytes == 0)
  1861. all_frames_transferred = true;
  1862. }
  1863. } else if (stp_req->type.pio.pio_transfer_bytes == 0) {
  1864. /*
  1865. * this will happen if the all data is written at the
  1866. * first time after the pio setup fis is received
  1867. */
  1868. all_frames_transferred = true;
  1869. }
  1870. /* all data transferred. */
  1871. if (all_frames_transferred) {
  1872. /*
  1873. * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
  1874. * and wait for PIO_SETUP fis / or D2H REg fis. */
  1875. sci_base_state_machine_change_state(
  1876. &sci_req->state_machine,
  1877. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
  1878. );
  1879. }
  1880. break;
  1881. default:
  1882. /*
  1883. * All other completion status cause the IO to be complete. If a NAK
  1884. * was received, then it is up to the user to retry the request. */
  1885. scic_sds_request_set_status(
  1886. sci_req,
  1887. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1888. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1889. );
  1890. sci_base_state_machine_change_state(
  1891. &sci_req->state_machine,
  1892. SCI_BASE_REQUEST_STATE_COMPLETED
  1893. );
  1894. break;
  1895. }
  1896. return status;
  1897. }
  1898. /**
  1899. *
  1900. * @request: This is the request which is receiving the event.
  1901. * @event_code: This is the event code that the request on which the request is
  1902. * expected to take action.
  1903. *
  1904. * This method will handle any link layer events while waiting for the data
  1905. * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
  1906. */
  1907. static enum sci_status scic_sds_stp_request_pio_data_in_await_data_event_handler(
  1908. struct scic_sds_request *request,
  1909. u32 event_code)
  1910. {
  1911. enum sci_status status;
  1912. switch (scu_get_event_specifier(event_code)) {
  1913. case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
  1914. /*
  1915. * We are waiting for data and the SCU has R_ERR the data frame.
  1916. * Go back to waiting for the D2H Register FIS */
  1917. sci_base_state_machine_change_state(
  1918. &request->state_machine,
  1919. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
  1920. );
  1921. status = SCI_SUCCESS;
  1922. break;
  1923. default:
  1924. dev_err(scic_to_dev(request->owning_controller),
  1925. "%s: SCIC PIO Request 0x%p received unexpected "
  1926. "event 0x%08x\n",
  1927. __func__, request, event_code);
  1928. /* / @todo Should we fail the PIO request when we get an unexpected event? */
  1929. status = SCI_FAILURE;
  1930. break;
  1931. }
  1932. return status;
  1933. }
  1934. static void scic_sds_stp_request_udma_complete_request(
  1935. struct scic_sds_request *request,
  1936. u32 scu_status,
  1937. enum sci_status sci_status)
  1938. {
  1939. scic_sds_request_set_status(request, scu_status, sci_status);
  1940. sci_base_state_machine_change_state(&request->state_machine,
  1941. SCI_BASE_REQUEST_STATE_COMPLETED);
  1942. }
  1943. static enum sci_status scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request *sci_req,
  1944. u32 frame_index)
  1945. {
  1946. struct scic_sds_controller *scic = sci_req->owning_controller;
  1947. struct dev_to_host_fis *frame_header;
  1948. enum sci_status status;
  1949. u32 *frame_buffer;
  1950. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1951. frame_index,
  1952. (void **)&frame_header);
  1953. if ((status == SCI_SUCCESS) &&
  1954. (frame_header->fis_type == FIS_REGD2H)) {
  1955. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1956. frame_index,
  1957. (void **)&frame_buffer);
  1958. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1959. frame_header,
  1960. frame_buffer);
  1961. }
  1962. scic_sds_controller_release_frame(scic, frame_index);
  1963. return status;
  1964. }
  1965. static enum sci_status scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
  1966. struct scic_sds_request *sci_req,
  1967. u32 completion_code)
  1968. {
  1969. enum sci_status status = SCI_SUCCESS;
  1970. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1971. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1972. scic_sds_stp_request_udma_complete_request(sci_req,
  1973. SCU_TASK_DONE_GOOD,
  1974. SCI_SUCCESS);
  1975. break;
  1976. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
  1977. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
  1978. /*
  1979. * We must check ther response buffer to see if the D2H Register FIS was
  1980. * received before we got the TC completion. */
  1981. if (sci_req->stp.rsp.fis_type == FIS_REGD2H) {
  1982. scic_sds_remote_device_suspend(sci_req->target_device,
  1983. SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
  1984. scic_sds_stp_request_udma_complete_request(sci_req,
  1985. SCU_TASK_DONE_CHECK_RESPONSE,
  1986. SCI_FAILURE_IO_RESPONSE_VALID);
  1987. } else {
  1988. /*
  1989. * If we have an error completion status for the TC then we can expect a
  1990. * D2H register FIS from the device so we must change state to wait for it */
  1991. sci_base_state_machine_change_state(&sci_req->state_machine,
  1992. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE);
  1993. }
  1994. break;
  1995. /*
  1996. * / @todo Check to see if any of these completion status need to wait for
  1997. * / the device to host register fis. */
  1998. /* / @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0 */
  1999. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
  2000. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
  2001. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
  2002. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
  2003. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
  2004. scic_sds_remote_device_suspend(sci_req->target_device,
  2005. SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
  2006. /* Fall through to the default case */
  2007. default:
  2008. /* All other completion status cause the IO to be complete. */
  2009. scic_sds_stp_request_udma_complete_request(sci_req,
  2010. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  2011. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  2012. break;
  2013. }
  2014. return status;
  2015. }
  2016. static enum sci_status scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
  2017. struct scic_sds_request *sci_req,
  2018. u32 frame_index)
  2019. {
  2020. enum sci_status status;
  2021. /* Use the general frame handler to copy the resposne data */
  2022. status = scic_sds_stp_request_udma_general_frame_handler(sci_req, frame_index);
  2023. if (status != SCI_SUCCESS)
  2024. return status;
  2025. scic_sds_stp_request_udma_complete_request(sci_req,
  2026. SCU_TASK_DONE_CHECK_RESPONSE,
  2027. SCI_FAILURE_IO_RESPONSE_VALID);
  2028. return status;
  2029. }
  2030. enum sci_status scic_sds_stp_udma_request_construct(struct scic_sds_request *sci_req,
  2031. u32 len,
  2032. enum dma_data_direction dir)
  2033. {
  2034. return SCI_SUCCESS;
  2035. }
  2036. /**
  2037. *
  2038. * @sci_req:
  2039. * @completion_code:
  2040. *
  2041. * This method processes a TC completion. The expected TC completion is for
  2042. * the transmission of the H2D register FIS containing the SATA/STP non-data
  2043. * request. This method always successfully processes the TC completion.
  2044. * SCI_SUCCESS This value is always returned.
  2045. */
  2046. static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
  2047. struct scic_sds_request *sci_req,
  2048. u32 completion_code)
  2049. {
  2050. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  2051. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  2052. scic_sds_request_set_status(
  2053. sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
  2054. );
  2055. sci_base_state_machine_change_state(
  2056. &sci_req->state_machine,
  2057. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
  2058. );
  2059. break;
  2060. default:
  2061. /*
  2062. * All other completion status cause the IO to be complete. If a NAK
  2063. * was received, then it is up to the user to retry the request. */
  2064. scic_sds_request_set_status(
  2065. sci_req,
  2066. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  2067. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  2068. );
  2069. sci_base_state_machine_change_state(
  2070. &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
  2071. break;
  2072. }
  2073. return SCI_SUCCESS;
  2074. }
  2075. /**
  2076. *
  2077. * @sci_req:
  2078. * @completion_code:
  2079. *
  2080. * This method processes a TC completion. The expected TC completion is for
  2081. * the transmission of the H2D register FIS containing the SATA/STP non-data
  2082. * request. This method always successfully processes the TC completion.
  2083. * SCI_SUCCESS This value is always returned.
  2084. */
  2085. static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
  2086. struct scic_sds_request *sci_req,
  2087. u32 completion_code)
  2088. {
  2089. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  2090. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  2091. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  2092. SCI_SUCCESS);
  2093. sci_base_state_machine_change_state(&sci_req->state_machine,
  2094. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE);
  2095. break;
  2096. default:
  2097. /*
  2098. * All other completion status cause the IO to be complete. If a NAK
  2099. * was received, then it is up to the user to retry the request. */
  2100. scic_sds_request_set_status(
  2101. sci_req,
  2102. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  2103. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  2104. );
  2105. sci_base_state_machine_change_state(&sci_req->state_machine,
  2106. SCI_BASE_REQUEST_STATE_COMPLETED);
  2107. break;
  2108. }
  2109. return SCI_SUCCESS;
  2110. }
  2111. /**
  2112. *
  2113. * @request: This parameter specifies the request for which a frame has been
  2114. * received.
  2115. * @frame_index: This parameter specifies the index of the frame that has been
  2116. * received.
  2117. *
  2118. * This method processes frames received from the target while waiting for a
  2119. * device to host register FIS. If a non-register FIS is received during this
  2120. * time, it is treated as a protocol violation from an IO perspective. Indicate
  2121. * if the received frame was processed successfully.
  2122. */
  2123. static enum sci_status scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
  2124. struct scic_sds_request *sci_req,
  2125. u32 frame_index)
  2126. {
  2127. enum sci_status status;
  2128. struct dev_to_host_fis *frame_header;
  2129. u32 *frame_buffer;
  2130. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  2131. struct scic_sds_controller *scic = sci_req->owning_controller;
  2132. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  2133. frame_index,
  2134. (void **)&frame_header);
  2135. if (status != SCI_SUCCESS) {
  2136. dev_err(scic_to_dev(scic),
  2137. "%s: SCIC IO Request 0x%p could not get frame header "
  2138. "for frame index %d, status %x\n",
  2139. __func__, stp_req, frame_index, status);
  2140. return status;
  2141. }
  2142. switch (frame_header->fis_type) {
  2143. case FIS_REGD2H:
  2144. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  2145. frame_index,
  2146. (void **)&frame_buffer);
  2147. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  2148. frame_header,
  2149. frame_buffer);
  2150. /* The command has completed with error */
  2151. scic_sds_request_set_status(sci_req,
  2152. SCU_TASK_DONE_CHECK_RESPONSE,
  2153. SCI_FAILURE_IO_RESPONSE_VALID);
  2154. break;
  2155. default:
  2156. dev_warn(scic_to_dev(scic),
  2157. "%s: IO Request:0x%p Frame Id:%d protocol "
  2158. "violation occurred\n", __func__, stp_req,
  2159. frame_index);
  2160. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
  2161. SCI_FAILURE_PROTOCOL_VIOLATION);
  2162. break;
  2163. }
  2164. sci_base_state_machine_change_state(&sci_req->state_machine,
  2165. SCI_BASE_REQUEST_STATE_COMPLETED);
  2166. /* Frame has been decoded return it to the controller */
  2167. scic_sds_controller_release_frame(scic, frame_index);
  2168. return status;
  2169. }
  2170. static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
  2171. [SCI_BASE_REQUEST_STATE_INITIAL] = { },
  2172. [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
  2173. .start_handler = scic_sds_request_constructed_state_start_handler,
  2174. },
  2175. [SCI_BASE_REQUEST_STATE_STARTED] = {
  2176. .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
  2177. .frame_handler = scic_sds_request_started_state_frame_handler,
  2178. },
  2179. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
  2180. .tc_completion_handler = scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
  2181. },
  2182. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
  2183. .frame_handler = scic_sds_ssp_task_request_await_tc_response_frame_handler,
  2184. },
  2185. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
  2186. .tc_completion_handler = scic_sds_smp_request_await_response_tc_completion_handler,
  2187. .frame_handler = scic_sds_smp_request_await_response_frame_handler,
  2188. },
  2189. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
  2190. .tc_completion_handler = scic_sds_smp_request_await_tc_completion_tc_completion_handler,
  2191. },
  2192. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
  2193. .tc_completion_handler = scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler,
  2194. .frame_handler = scic_sds_stp_request_udma_general_frame_handler,
  2195. },
  2196. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
  2197. .frame_handler = scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler,
  2198. },
  2199. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  2200. .tc_completion_handler = scic_sds_stp_request_non_data_await_h2d_tc_completion_handler,
  2201. },
  2202. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
  2203. .frame_handler = scic_sds_stp_request_non_data_await_d2h_frame_handler,
  2204. },
  2205. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  2206. .tc_completion_handler = scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler,
  2207. },
  2208. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
  2209. .frame_handler = scic_sds_stp_request_pio_await_frame_frame_handler
  2210. },
  2211. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
  2212. .event_handler = scic_sds_stp_request_pio_data_in_await_data_event_handler,
  2213. .frame_handler = scic_sds_stp_request_pio_data_in_await_data_frame_handler
  2214. },
  2215. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
  2216. .tc_completion_handler = scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler,
  2217. },
  2218. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
  2219. .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler,
  2220. },
  2221. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
  2222. .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler,
  2223. },
  2224. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
  2225. .frame_handler = scic_sds_stp_request_soft_reset_await_d2h_frame_handler,
  2226. },
  2227. [SCI_BASE_REQUEST_STATE_COMPLETED] = {
  2228. .complete_handler = scic_sds_request_completed_state_complete_handler,
  2229. },
  2230. [SCI_BASE_REQUEST_STATE_ABORTING] = {
  2231. .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
  2232. .frame_handler = scic_sds_request_aborting_state_frame_handler,
  2233. },
  2234. [SCI_BASE_REQUEST_STATE_FINAL] = { },
  2235. };
  2236. /**
  2237. * isci_request_process_response_iu() - This function sets the status and
  2238. * response iu, in the task struct, from the request object for the upper
  2239. * layer driver.
  2240. * @sas_task: This parameter is the task struct from the upper layer driver.
  2241. * @resp_iu: This parameter points to the response iu of the completed request.
  2242. * @dev: This parameter specifies the linux device struct.
  2243. *
  2244. * none.
  2245. */
  2246. static void isci_request_process_response_iu(
  2247. struct sas_task *task,
  2248. struct ssp_response_iu *resp_iu,
  2249. struct device *dev)
  2250. {
  2251. dev_dbg(dev,
  2252. "%s: resp_iu = %p "
  2253. "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
  2254. "resp_iu->response_data_len = %x, "
  2255. "resp_iu->sense_data_len = %x\nrepsonse data: ",
  2256. __func__,
  2257. resp_iu,
  2258. resp_iu->status,
  2259. resp_iu->datapres,
  2260. resp_iu->response_data_len,
  2261. resp_iu->sense_data_len);
  2262. task->task_status.stat = resp_iu->status;
  2263. /* libsas updates the task status fields based on the response iu. */
  2264. sas_ssp_task_response(dev, task, resp_iu);
  2265. }
  2266. /**
  2267. * isci_request_set_open_reject_status() - This function prepares the I/O
  2268. * completion for OPEN_REJECT conditions.
  2269. * @request: This parameter is the completed isci_request object.
  2270. * @response_ptr: This parameter specifies the service response for the I/O.
  2271. * @status_ptr: This parameter specifies the exec status for the I/O.
  2272. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  2273. * the LLDD with respect to completing this request or forcing an abort
  2274. * condition on the I/O.
  2275. * @open_rej_reason: This parameter specifies the encoded reason for the
  2276. * abandon-class reject.
  2277. *
  2278. * none.
  2279. */
  2280. static void isci_request_set_open_reject_status(
  2281. struct isci_request *request,
  2282. struct sas_task *task,
  2283. enum service_response *response_ptr,
  2284. enum exec_status *status_ptr,
  2285. enum isci_completion_selection *complete_to_host_ptr,
  2286. enum sas_open_rej_reason open_rej_reason)
  2287. {
  2288. /* Task in the target is done. */
  2289. request->complete_in_target = true;
  2290. *response_ptr = SAS_TASK_UNDELIVERED;
  2291. *status_ptr = SAS_OPEN_REJECT;
  2292. *complete_to_host_ptr = isci_perform_normal_io_completion;
  2293. task->task_status.open_rej_reason = open_rej_reason;
  2294. }
  2295. /**
  2296. * isci_request_handle_controller_specific_errors() - This function decodes
  2297. * controller-specific I/O completion error conditions.
  2298. * @request: This parameter is the completed isci_request object.
  2299. * @response_ptr: This parameter specifies the service response for the I/O.
  2300. * @status_ptr: This parameter specifies the exec status for the I/O.
  2301. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  2302. * the LLDD with respect to completing this request or forcing an abort
  2303. * condition on the I/O.
  2304. *
  2305. * none.
  2306. */
  2307. static void isci_request_handle_controller_specific_errors(
  2308. struct isci_remote_device *isci_device,
  2309. struct isci_request *request,
  2310. struct sas_task *task,
  2311. enum service_response *response_ptr,
  2312. enum exec_status *status_ptr,
  2313. enum isci_completion_selection *complete_to_host_ptr)
  2314. {
  2315. unsigned int cstatus;
  2316. cstatus = request->sci.scu_status;
  2317. dev_dbg(&request->isci_host->pdev->dev,
  2318. "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
  2319. "- controller status = 0x%x\n",
  2320. __func__, request, cstatus);
  2321. /* Decode the controller-specific errors; most
  2322. * important is to recognize those conditions in which
  2323. * the target may still have a task outstanding that
  2324. * must be aborted.
  2325. *
  2326. * Note that there are SCU completion codes being
  2327. * named in the decode below for which SCIC has already
  2328. * done work to handle them in a way other than as
  2329. * a controller-specific completion code; these are left
  2330. * in the decode below for completeness sake.
  2331. */
  2332. switch (cstatus) {
  2333. case SCU_TASK_DONE_DMASETUP_DIRERR:
  2334. /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
  2335. case SCU_TASK_DONE_XFERCNT_ERR:
  2336. /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
  2337. if (task->task_proto == SAS_PROTOCOL_SMP) {
  2338. /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
  2339. *response_ptr = SAS_TASK_COMPLETE;
  2340. /* See if the device has been/is being stopped. Note
  2341. * that we ignore the quiesce state, since we are
  2342. * concerned about the actual device state.
  2343. */
  2344. if ((isci_device->status == isci_stopping) ||
  2345. (isci_device->status == isci_stopped))
  2346. *status_ptr = SAS_DEVICE_UNKNOWN;
  2347. else
  2348. *status_ptr = SAS_ABORTED_TASK;
  2349. request->complete_in_target = true;
  2350. *complete_to_host_ptr =
  2351. isci_perform_normal_io_completion;
  2352. } else {
  2353. /* Task in the target is not done. */
  2354. *response_ptr = SAS_TASK_UNDELIVERED;
  2355. if ((isci_device->status == isci_stopping) ||
  2356. (isci_device->status == isci_stopped))
  2357. *status_ptr = SAS_DEVICE_UNKNOWN;
  2358. else
  2359. *status_ptr = SAM_STAT_TASK_ABORTED;
  2360. request->complete_in_target = false;
  2361. *complete_to_host_ptr =
  2362. isci_perform_error_io_completion;
  2363. }
  2364. break;
  2365. case SCU_TASK_DONE_CRC_ERR:
  2366. case SCU_TASK_DONE_NAK_CMD_ERR:
  2367. case SCU_TASK_DONE_EXCESS_DATA:
  2368. case SCU_TASK_DONE_UNEXP_FIS:
  2369. /* Also SCU_TASK_DONE_UNEXP_RESP: */
  2370. case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
  2371. case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
  2372. case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
  2373. /* These are conditions in which the target
  2374. * has completed the task, so that no cleanup
  2375. * is necessary.
  2376. */
  2377. *response_ptr = SAS_TASK_COMPLETE;
  2378. /* See if the device has been/is being stopped. Note
  2379. * that we ignore the quiesce state, since we are
  2380. * concerned about the actual device state.
  2381. */
  2382. if ((isci_device->status == isci_stopping) ||
  2383. (isci_device->status == isci_stopped))
  2384. *status_ptr = SAS_DEVICE_UNKNOWN;
  2385. else
  2386. *status_ptr = SAS_ABORTED_TASK;
  2387. request->complete_in_target = true;
  2388. *complete_to_host_ptr = isci_perform_normal_io_completion;
  2389. break;
  2390. /* Note that the only open reject completion codes seen here will be
  2391. * abandon-class codes; all others are automatically retried in the SCU.
  2392. */
  2393. case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
  2394. isci_request_set_open_reject_status(
  2395. request, task, response_ptr, status_ptr,
  2396. complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
  2397. break;
  2398. case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
  2399. /* Note - the return of AB0 will change when
  2400. * libsas implements detection of zone violations.
  2401. */
  2402. isci_request_set_open_reject_status(
  2403. request, task, response_ptr, status_ptr,
  2404. complete_to_host_ptr, SAS_OREJ_RESV_AB0);
  2405. break;
  2406. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
  2407. isci_request_set_open_reject_status(
  2408. request, task, response_ptr, status_ptr,
  2409. complete_to_host_ptr, SAS_OREJ_RESV_AB1);
  2410. break;
  2411. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
  2412. isci_request_set_open_reject_status(
  2413. request, task, response_ptr, status_ptr,
  2414. complete_to_host_ptr, SAS_OREJ_RESV_AB2);
  2415. break;
  2416. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
  2417. isci_request_set_open_reject_status(
  2418. request, task, response_ptr, status_ptr,
  2419. complete_to_host_ptr, SAS_OREJ_RESV_AB3);
  2420. break;
  2421. case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
  2422. isci_request_set_open_reject_status(
  2423. request, task, response_ptr, status_ptr,
  2424. complete_to_host_ptr, SAS_OREJ_BAD_DEST);
  2425. break;
  2426. case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
  2427. isci_request_set_open_reject_status(
  2428. request, task, response_ptr, status_ptr,
  2429. complete_to_host_ptr, SAS_OREJ_STP_NORES);
  2430. break;
  2431. case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
  2432. isci_request_set_open_reject_status(
  2433. request, task, response_ptr, status_ptr,
  2434. complete_to_host_ptr, SAS_OREJ_EPROTO);
  2435. break;
  2436. case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
  2437. isci_request_set_open_reject_status(
  2438. request, task, response_ptr, status_ptr,
  2439. complete_to_host_ptr, SAS_OREJ_CONN_RATE);
  2440. break;
  2441. case SCU_TASK_DONE_LL_R_ERR:
  2442. /* Also SCU_TASK_DONE_ACK_NAK_TO: */
  2443. case SCU_TASK_DONE_LL_PERR:
  2444. case SCU_TASK_DONE_LL_SY_TERM:
  2445. /* Also SCU_TASK_DONE_NAK_ERR:*/
  2446. case SCU_TASK_DONE_LL_LF_TERM:
  2447. /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
  2448. case SCU_TASK_DONE_LL_ABORT_ERR:
  2449. case SCU_TASK_DONE_SEQ_INV_TYPE:
  2450. /* Also SCU_TASK_DONE_UNEXP_XR: */
  2451. case SCU_TASK_DONE_XR_IU_LEN_ERR:
  2452. case SCU_TASK_DONE_INV_FIS_LEN:
  2453. /* Also SCU_TASK_DONE_XR_WD_LEN: */
  2454. case SCU_TASK_DONE_SDMA_ERR:
  2455. case SCU_TASK_DONE_OFFSET_ERR:
  2456. case SCU_TASK_DONE_MAX_PLD_ERR:
  2457. case SCU_TASK_DONE_LF_ERR:
  2458. case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
  2459. case SCU_TASK_DONE_SMP_LL_RX_ERR:
  2460. case SCU_TASK_DONE_UNEXP_DATA:
  2461. case SCU_TASK_DONE_UNEXP_SDBFIS:
  2462. case SCU_TASK_DONE_REG_ERR:
  2463. case SCU_TASK_DONE_SDB_ERR:
  2464. case SCU_TASK_DONE_TASK_ABORT:
  2465. default:
  2466. /* Task in the target is not done. */
  2467. *response_ptr = SAS_TASK_UNDELIVERED;
  2468. *status_ptr = SAM_STAT_TASK_ABORTED;
  2469. request->complete_in_target = false;
  2470. *complete_to_host_ptr = isci_perform_error_io_completion;
  2471. break;
  2472. }
  2473. }
  2474. /**
  2475. * isci_task_save_for_upper_layer_completion() - This function saves the
  2476. * request for later completion to the upper layer driver.
  2477. * @host: This parameter is a pointer to the host on which the the request
  2478. * should be queued (either as an error or success).
  2479. * @request: This parameter is the completed request.
  2480. * @response: This parameter is the response code for the completed task.
  2481. * @status: This parameter is the status code for the completed task.
  2482. *
  2483. * none.
  2484. */
  2485. static void isci_task_save_for_upper_layer_completion(
  2486. struct isci_host *host,
  2487. struct isci_request *request,
  2488. enum service_response response,
  2489. enum exec_status status,
  2490. enum isci_completion_selection task_notification_selection)
  2491. {
  2492. struct sas_task *task = isci_request_access_task(request);
  2493. task_notification_selection
  2494. = isci_task_set_completion_status(task, response, status,
  2495. task_notification_selection);
  2496. /* Tasks aborted specifically by a call to the lldd_abort_task
  2497. * function should not be completed to the host in the regular path.
  2498. */
  2499. switch (task_notification_selection) {
  2500. case isci_perform_normal_io_completion:
  2501. /* Normal notification (task_done) */
  2502. dev_dbg(&host->pdev->dev,
  2503. "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
  2504. __func__,
  2505. task,
  2506. task->task_status.resp, response,
  2507. task->task_status.stat, status);
  2508. /* Add to the completed list. */
  2509. list_add(&request->completed_node,
  2510. &host->requests_to_complete);
  2511. /* Take the request off the device's pending request list. */
  2512. list_del_init(&request->dev_node);
  2513. break;
  2514. case isci_perform_aborted_io_completion:
  2515. /* No notification to libsas because this request is
  2516. * already in the abort path.
  2517. */
  2518. dev_warn(&host->pdev->dev,
  2519. "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
  2520. __func__,
  2521. task,
  2522. task->task_status.resp, response,
  2523. task->task_status.stat, status);
  2524. /* Wake up whatever process was waiting for this
  2525. * request to complete.
  2526. */
  2527. WARN_ON(request->io_request_completion == NULL);
  2528. if (request->io_request_completion != NULL) {
  2529. /* Signal whoever is waiting that this
  2530. * request is complete.
  2531. */
  2532. complete(request->io_request_completion);
  2533. }
  2534. break;
  2535. case isci_perform_error_io_completion:
  2536. /* Use sas_task_abort */
  2537. dev_warn(&host->pdev->dev,
  2538. "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
  2539. __func__,
  2540. task,
  2541. task->task_status.resp, response,
  2542. task->task_status.stat, status);
  2543. /* Add to the aborted list. */
  2544. list_add(&request->completed_node,
  2545. &host->requests_to_errorback);
  2546. break;
  2547. default:
  2548. dev_warn(&host->pdev->dev,
  2549. "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
  2550. __func__,
  2551. task,
  2552. task->task_status.resp, response,
  2553. task->task_status.stat, status);
  2554. /* Add to the error to libsas list. */
  2555. list_add(&request->completed_node,
  2556. &host->requests_to_errorback);
  2557. break;
  2558. }
  2559. }
  2560. static void isci_request_io_request_complete(struct isci_host *isci_host,
  2561. struct isci_request *request,
  2562. enum sci_io_status completion_status)
  2563. {
  2564. struct sas_task *task = isci_request_access_task(request);
  2565. struct ssp_response_iu *resp_iu;
  2566. void *resp_buf;
  2567. unsigned long task_flags;
  2568. struct isci_remote_device *isci_device = request->isci_device;
  2569. enum service_response response = SAS_TASK_UNDELIVERED;
  2570. enum exec_status status = SAS_ABORTED_TASK;
  2571. enum isci_request_status request_status;
  2572. enum isci_completion_selection complete_to_host
  2573. = isci_perform_normal_io_completion;
  2574. dev_dbg(&isci_host->pdev->dev,
  2575. "%s: request = %p, task = %p,\n"
  2576. "task->data_dir = %d completion_status = 0x%x\n",
  2577. __func__,
  2578. request,
  2579. task,
  2580. task->data_dir,
  2581. completion_status);
  2582. spin_lock(&request->state_lock);
  2583. request_status = isci_request_get_state(request);
  2584. /* Decode the request status. Note that if the request has been
  2585. * aborted by a task management function, we don't care
  2586. * what the status is.
  2587. */
  2588. switch (request_status) {
  2589. case aborted:
  2590. /* "aborted" indicates that the request was aborted by a task
  2591. * management function, since once a task management request is
  2592. * perfomed by the device, the request only completes because
  2593. * of the subsequent driver terminate.
  2594. *
  2595. * Aborted also means an external thread is explicitly managing
  2596. * this request, so that we do not complete it up the stack.
  2597. *
  2598. * The target is still there (since the TMF was successful).
  2599. */
  2600. request->complete_in_target = true;
  2601. response = SAS_TASK_COMPLETE;
  2602. /* See if the device has been/is being stopped. Note
  2603. * that we ignore the quiesce state, since we are
  2604. * concerned about the actual device state.
  2605. */
  2606. if ((isci_device->status == isci_stopping)
  2607. || (isci_device->status == isci_stopped)
  2608. )
  2609. status = SAS_DEVICE_UNKNOWN;
  2610. else
  2611. status = SAS_ABORTED_TASK;
  2612. complete_to_host = isci_perform_aborted_io_completion;
  2613. /* This was an aborted request. */
  2614. spin_unlock(&request->state_lock);
  2615. break;
  2616. case aborting:
  2617. /* aborting means that the task management function tried and
  2618. * failed to abort the request. We need to note the request
  2619. * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
  2620. * target as down.
  2621. *
  2622. * Aborting also means an external thread is explicitly managing
  2623. * this request, so that we do not complete it up the stack.
  2624. */
  2625. request->complete_in_target = true;
  2626. response = SAS_TASK_UNDELIVERED;
  2627. if ((isci_device->status == isci_stopping) ||
  2628. (isci_device->status == isci_stopped))
  2629. /* The device has been /is being stopped. Note that
  2630. * we ignore the quiesce state, since we are
  2631. * concerned about the actual device state.
  2632. */
  2633. status = SAS_DEVICE_UNKNOWN;
  2634. else
  2635. status = SAS_PHY_DOWN;
  2636. complete_to_host = isci_perform_aborted_io_completion;
  2637. /* This was an aborted request. */
  2638. spin_unlock(&request->state_lock);
  2639. break;
  2640. case terminating:
  2641. /* This was an terminated request. This happens when
  2642. * the I/O is being terminated because of an action on
  2643. * the device (reset, tear down, etc.), and the I/O needs
  2644. * to be completed up the stack.
  2645. */
  2646. request->complete_in_target = true;
  2647. response = SAS_TASK_UNDELIVERED;
  2648. /* See if the device has been/is being stopped. Note
  2649. * that we ignore the quiesce state, since we are
  2650. * concerned about the actual device state.
  2651. */
  2652. if ((isci_device->status == isci_stopping) ||
  2653. (isci_device->status == isci_stopped))
  2654. status = SAS_DEVICE_UNKNOWN;
  2655. else
  2656. status = SAS_ABORTED_TASK;
  2657. complete_to_host = isci_perform_aborted_io_completion;
  2658. /* This was a terminated request. */
  2659. spin_unlock(&request->state_lock);
  2660. break;
  2661. default:
  2662. /* The request is done from an SCU HW perspective. */
  2663. request->status = completed;
  2664. spin_unlock(&request->state_lock);
  2665. /* This is an active request being completed from the core. */
  2666. switch (completion_status) {
  2667. case SCI_IO_FAILURE_RESPONSE_VALID:
  2668. dev_dbg(&isci_host->pdev->dev,
  2669. "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
  2670. __func__,
  2671. request,
  2672. task);
  2673. if (sas_protocol_ata(task->task_proto)) {
  2674. resp_buf = &request->sci.stp.rsp;
  2675. isci_request_process_stp_response(task,
  2676. resp_buf);
  2677. } else if (SAS_PROTOCOL_SSP == task->task_proto) {
  2678. /* crack the iu response buffer. */
  2679. resp_iu = &request->sci.ssp.rsp;
  2680. isci_request_process_response_iu(task, resp_iu,
  2681. &isci_host->pdev->dev);
  2682. } else if (SAS_PROTOCOL_SMP == task->task_proto) {
  2683. dev_err(&isci_host->pdev->dev,
  2684. "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
  2685. "SAS_PROTOCOL_SMP protocol\n",
  2686. __func__);
  2687. } else
  2688. dev_err(&isci_host->pdev->dev,
  2689. "%s: unknown protocol\n", __func__);
  2690. /* use the task status set in the task struct by the
  2691. * isci_request_process_response_iu call.
  2692. */
  2693. request->complete_in_target = true;
  2694. response = task->task_status.resp;
  2695. status = task->task_status.stat;
  2696. break;
  2697. case SCI_IO_SUCCESS:
  2698. case SCI_IO_SUCCESS_IO_DONE_EARLY:
  2699. response = SAS_TASK_COMPLETE;
  2700. status = SAM_STAT_GOOD;
  2701. request->complete_in_target = true;
  2702. if (task->task_proto == SAS_PROTOCOL_SMP) {
  2703. void *rsp = &request->sci.smp.rsp;
  2704. dev_dbg(&isci_host->pdev->dev,
  2705. "%s: SMP protocol completion\n",
  2706. __func__);
  2707. sg_copy_from_buffer(
  2708. &task->smp_task.smp_resp, 1,
  2709. rsp, sizeof(struct smp_resp));
  2710. } else if (completion_status
  2711. == SCI_IO_SUCCESS_IO_DONE_EARLY) {
  2712. /* This was an SSP / STP / SATA transfer.
  2713. * There is a possibility that less data than
  2714. * the maximum was transferred.
  2715. */
  2716. u32 transferred_length = sci_req_tx_bytes(&request->sci);
  2717. task->task_status.residual
  2718. = task->total_xfer_len - transferred_length;
  2719. /* If there were residual bytes, call this an
  2720. * underrun.
  2721. */
  2722. if (task->task_status.residual != 0)
  2723. status = SAS_DATA_UNDERRUN;
  2724. dev_dbg(&isci_host->pdev->dev,
  2725. "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
  2726. __func__,
  2727. status);
  2728. } else
  2729. dev_dbg(&isci_host->pdev->dev,
  2730. "%s: SCI_IO_SUCCESS\n",
  2731. __func__);
  2732. break;
  2733. case SCI_IO_FAILURE_TERMINATED:
  2734. dev_dbg(&isci_host->pdev->dev,
  2735. "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
  2736. __func__,
  2737. request,
  2738. task);
  2739. /* The request was terminated explicitly. No handling
  2740. * is needed in the SCSI error handler path.
  2741. */
  2742. request->complete_in_target = true;
  2743. response = SAS_TASK_UNDELIVERED;
  2744. /* See if the device has been/is being stopped. Note
  2745. * that we ignore the quiesce state, since we are
  2746. * concerned about the actual device state.
  2747. */
  2748. if ((isci_device->status == isci_stopping) ||
  2749. (isci_device->status == isci_stopped))
  2750. status = SAS_DEVICE_UNKNOWN;
  2751. else
  2752. status = SAS_ABORTED_TASK;
  2753. complete_to_host = isci_perform_normal_io_completion;
  2754. break;
  2755. case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
  2756. isci_request_handle_controller_specific_errors(
  2757. isci_device, request, task, &response, &status,
  2758. &complete_to_host);
  2759. break;
  2760. case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
  2761. /* This is a special case, in that the I/O completion
  2762. * is telling us that the device needs a reset.
  2763. * In order for the device reset condition to be
  2764. * noticed, the I/O has to be handled in the error
  2765. * handler. Set the reset flag and cause the
  2766. * SCSI error thread to be scheduled.
  2767. */
  2768. spin_lock_irqsave(&task->task_state_lock, task_flags);
  2769. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  2770. spin_unlock_irqrestore(&task->task_state_lock, task_flags);
  2771. /* Fail the I/O. */
  2772. response = SAS_TASK_UNDELIVERED;
  2773. status = SAM_STAT_TASK_ABORTED;
  2774. complete_to_host = isci_perform_error_io_completion;
  2775. request->complete_in_target = false;
  2776. break;
  2777. default:
  2778. /* Catch any otherwise unhandled error codes here. */
  2779. dev_warn(&isci_host->pdev->dev,
  2780. "%s: invalid completion code: 0x%x - "
  2781. "isci_request = %p\n",
  2782. __func__, completion_status, request);
  2783. response = SAS_TASK_UNDELIVERED;
  2784. /* See if the device has been/is being stopped. Note
  2785. * that we ignore the quiesce state, since we are
  2786. * concerned about the actual device state.
  2787. */
  2788. if ((isci_device->status == isci_stopping) ||
  2789. (isci_device->status == isci_stopped))
  2790. status = SAS_DEVICE_UNKNOWN;
  2791. else
  2792. status = SAS_ABORTED_TASK;
  2793. complete_to_host = isci_perform_error_io_completion;
  2794. request->complete_in_target = false;
  2795. break;
  2796. }
  2797. break;
  2798. }
  2799. isci_request_unmap_sgl(request, isci_host->pdev);
  2800. /* Put the completed request on the correct list */
  2801. isci_task_save_for_upper_layer_completion(isci_host, request, response,
  2802. status, complete_to_host
  2803. );
  2804. /* complete the io request to the core. */
  2805. scic_controller_complete_io(&isci_host->sci,
  2806. &isci_device->sci,
  2807. &request->sci);
  2808. /* set terminated handle so it cannot be completed or
  2809. * terminated again, and to cause any calls into abort
  2810. * task to recognize the already completed case.
  2811. */
  2812. request->terminated = true;
  2813. isci_host_can_dequeue(isci_host, 1);
  2814. }
  2815. /**
  2816. * scic_sds_request_initial_state_enter() -
  2817. * @object: This parameter specifies the base object for which the state
  2818. * transition is occurring.
  2819. *
  2820. * This method implements the actions taken when entering the
  2821. * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
  2822. * base request is constructed. Entry into the initial state sets all handlers
  2823. * for the io request object to their default handlers. none
  2824. */
  2825. static void scic_sds_request_initial_state_enter(void *object)
  2826. {
  2827. struct scic_sds_request *sci_req = object;
  2828. SET_STATE_HANDLER(
  2829. sci_req,
  2830. scic_sds_request_state_handler_table,
  2831. SCI_BASE_REQUEST_STATE_INITIAL
  2832. );
  2833. }
  2834. /**
  2835. * scic_sds_request_constructed_state_enter() -
  2836. * @object: The io request object that is to enter the constructed state.
  2837. *
  2838. * This method implements the actions taken when entering the
  2839. * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
  2840. * for the the constructed state. none
  2841. */
  2842. static void scic_sds_request_constructed_state_enter(void *object)
  2843. {
  2844. struct scic_sds_request *sci_req = object;
  2845. SET_STATE_HANDLER(
  2846. sci_req,
  2847. scic_sds_request_state_handler_table,
  2848. SCI_BASE_REQUEST_STATE_CONSTRUCTED
  2849. );
  2850. }
  2851. static void scic_sds_request_started_state_enter(void *object)
  2852. {
  2853. struct scic_sds_request *sci_req = object;
  2854. struct sci_base_state_machine *sm = &sci_req->state_machine;
  2855. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  2856. struct domain_device *dev = sci_dev_to_domain(sci_req->target_device);
  2857. struct sas_task *task;
  2858. /* XXX as hch said always creating an internal sas_task for tmf
  2859. * requests would simplify the driver
  2860. */
  2861. task = ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL;
  2862. SET_STATE_HANDLER(
  2863. sci_req,
  2864. scic_sds_request_state_handler_table,
  2865. SCI_BASE_REQUEST_STATE_STARTED
  2866. );
  2867. /* all unaccelerated request types (non ssp or ncq) handled with
  2868. * substates
  2869. */
  2870. if (!task && dev->dev_type == SAS_END_DEV) {
  2871. sci_base_state_machine_change_state(sm,
  2872. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION);
  2873. } else if (!task &&
  2874. (isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_high ||
  2875. isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_low)) {
  2876. sci_base_state_machine_change_state(sm,
  2877. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE);
  2878. } else if (task && task->task_proto == SAS_PROTOCOL_SMP) {
  2879. sci_base_state_machine_change_state(sm,
  2880. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE);
  2881. } else if (task && sas_protocol_ata(task->task_proto) &&
  2882. !task->ata_task.use_ncq) {
  2883. u32 state;
  2884. if (task->data_dir == DMA_NONE)
  2885. state = SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE;
  2886. else if (task->ata_task.dma_xfer)
  2887. state = SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE;
  2888. else /* PIO */
  2889. state = SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE;
  2890. sci_base_state_machine_change_state(sm, state);
  2891. }
  2892. }
  2893. /**
  2894. * scic_sds_request_completed_state_enter() -
  2895. * @object: This parameter specifies the base object for which the state
  2896. * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
  2897. * object.
  2898. *
  2899. * This method implements the actions taken when entering the
  2900. * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
  2901. * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
  2902. * completion status and convert it to an enum sci_status to return in the
  2903. * completion callback function. none
  2904. */
  2905. static void scic_sds_request_completed_state_enter(void *object)
  2906. {
  2907. struct scic_sds_request *sci_req = object;
  2908. struct scic_sds_controller *scic =
  2909. scic_sds_request_get_controller(sci_req);
  2910. struct isci_host *ihost = scic_to_ihost(scic);
  2911. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  2912. SET_STATE_HANDLER(sci_req,
  2913. scic_sds_request_state_handler_table,
  2914. SCI_BASE_REQUEST_STATE_COMPLETED);
  2915. /* Tell the SCI_USER that the IO request is complete */
  2916. if (sci_req->is_task_management_request == false)
  2917. isci_request_io_request_complete(ihost, ireq,
  2918. sci_req->sci_status);
  2919. else
  2920. isci_task_request_complete(ihost, ireq, sci_req->sci_status);
  2921. }
  2922. /**
  2923. * scic_sds_request_aborting_state_enter() -
  2924. * @object: This parameter specifies the base object for which the state
  2925. * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
  2926. * object.
  2927. *
  2928. * This method implements the actions taken when entering the
  2929. * SCI_BASE_REQUEST_STATE_ABORTING state. none
  2930. */
  2931. static void scic_sds_request_aborting_state_enter(void *object)
  2932. {
  2933. struct scic_sds_request *sci_req = object;
  2934. /* Setting the abort bit in the Task Context is required by the silicon. */
  2935. sci_req->task_context_buffer->abort = 1;
  2936. SET_STATE_HANDLER(
  2937. sci_req,
  2938. scic_sds_request_state_handler_table,
  2939. SCI_BASE_REQUEST_STATE_ABORTING
  2940. );
  2941. }
  2942. /**
  2943. * scic_sds_request_final_state_enter() -
  2944. * @object: This parameter specifies the base object for which the state
  2945. * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
  2946. *
  2947. * This method implements the actions taken when entering the
  2948. * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
  2949. * state handlers in place. none
  2950. */
  2951. static void scic_sds_request_final_state_enter(void *object)
  2952. {
  2953. struct scic_sds_request *sci_req = object;
  2954. SET_STATE_HANDLER(
  2955. sci_req,
  2956. scic_sds_request_state_handler_table,
  2957. SCI_BASE_REQUEST_STATE_FINAL
  2958. );
  2959. }
  2960. static void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
  2961. void *object)
  2962. {
  2963. struct scic_sds_request *sci_req = object;
  2964. SET_STATE_HANDLER(
  2965. sci_req,
  2966. scic_sds_request_state_handler_table,
  2967. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
  2968. );
  2969. }
  2970. static void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
  2971. void *object)
  2972. {
  2973. struct scic_sds_request *sci_req = object;
  2974. SET_STATE_HANDLER(
  2975. sci_req,
  2976. scic_sds_request_state_handler_table,
  2977. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
  2978. );
  2979. }
  2980. static void scic_sds_smp_request_started_await_response_substate_enter(void *object)
  2981. {
  2982. struct scic_sds_request *sci_req = object;
  2983. SET_STATE_HANDLER(
  2984. sci_req,
  2985. scic_sds_request_state_handler_table,
  2986. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
  2987. );
  2988. }
  2989. static void scic_sds_smp_request_started_await_tc_completion_substate_enter(void *object)
  2990. {
  2991. struct scic_sds_request *sci_req = object;
  2992. SET_STATE_HANDLER(
  2993. sci_req,
  2994. scic_sds_request_state_handler_table,
  2995. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION
  2996. );
  2997. }
  2998. static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
  2999. void *object)
  3000. {
  3001. struct scic_sds_request *sci_req = object;
  3002. SET_STATE_HANDLER(
  3003. sci_req,
  3004. scic_sds_request_state_handler_table,
  3005. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
  3006. );
  3007. scic_sds_remote_device_set_working_request(
  3008. sci_req->target_device, sci_req
  3009. );
  3010. }
  3011. static void scic_sds_stp_request_started_non_data_await_d2h_enter(void *object)
  3012. {
  3013. struct scic_sds_request *sci_req = object;
  3014. SET_STATE_HANDLER(
  3015. sci_req,
  3016. scic_sds_request_state_handler_table,
  3017. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
  3018. );
  3019. }
  3020. static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
  3021. void *object)
  3022. {
  3023. struct scic_sds_request *sci_req = object;
  3024. SET_STATE_HANDLER(
  3025. sci_req,
  3026. scic_sds_request_state_handler_table,
  3027. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
  3028. );
  3029. scic_sds_remote_device_set_working_request(
  3030. sci_req->target_device, sci_req);
  3031. }
  3032. static void scic_sds_stp_request_started_pio_await_frame_enter(void *object)
  3033. {
  3034. struct scic_sds_request *sci_req = object;
  3035. SET_STATE_HANDLER(
  3036. sci_req,
  3037. scic_sds_request_state_handler_table,
  3038. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
  3039. );
  3040. }
  3041. static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
  3042. void *object)
  3043. {
  3044. struct scic_sds_request *sci_req = object;
  3045. SET_STATE_HANDLER(
  3046. sci_req,
  3047. scic_sds_request_state_handler_table,
  3048. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
  3049. );
  3050. }
  3051. static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
  3052. void *object)
  3053. {
  3054. struct scic_sds_request *sci_req = object;
  3055. SET_STATE_HANDLER(
  3056. sci_req,
  3057. scic_sds_request_state_handler_table,
  3058. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
  3059. );
  3060. }
  3061. static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
  3062. void *object)
  3063. {
  3064. struct scic_sds_request *sci_req = object;
  3065. SET_STATE_HANDLER(
  3066. sci_req,
  3067. scic_sds_request_state_handler_table,
  3068. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
  3069. );
  3070. }
  3071. /**
  3072. *
  3073. *
  3074. * This state is entered when there is an TC completion failure. The hardware
  3075. * received an unexpected condition while processing the IO request and now
  3076. * will UF the D2H register FIS to complete the IO.
  3077. */
  3078. static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
  3079. void *object)
  3080. {
  3081. struct scic_sds_request *sci_req = object;
  3082. SET_STATE_HANDLER(
  3083. sci_req,
  3084. scic_sds_request_state_handler_table,
  3085. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
  3086. );
  3087. }
  3088. static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
  3089. void *object)
  3090. {
  3091. struct scic_sds_request *sci_req = object;
  3092. SET_STATE_HANDLER(
  3093. sci_req,
  3094. scic_sds_request_state_handler_table,
  3095. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
  3096. );
  3097. scic_sds_remote_device_set_working_request(
  3098. sci_req->target_device, sci_req
  3099. );
  3100. }
  3101. static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
  3102. void *object)
  3103. {
  3104. struct scic_sds_request *sci_req = object;
  3105. struct scu_task_context *task_context;
  3106. struct host_to_dev_fis *h2d_fis;
  3107. enum sci_status status;
  3108. /* Clear the SRST bit */
  3109. h2d_fis = &sci_req->stp.cmd;
  3110. h2d_fis->control = 0;
  3111. /* Clear the TC control bit */
  3112. task_context = scic_sds_controller_get_task_context_buffer(
  3113. sci_req->owning_controller, sci_req->io_tag);
  3114. task_context->control_frame = 0;
  3115. status = scic_controller_continue_io(sci_req);
  3116. if (status == SCI_SUCCESS) {
  3117. SET_STATE_HANDLER(
  3118. sci_req,
  3119. scic_sds_request_state_handler_table,
  3120. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
  3121. );
  3122. }
  3123. }
  3124. static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
  3125. void *object)
  3126. {
  3127. struct scic_sds_request *sci_req = object;
  3128. SET_STATE_HANDLER(
  3129. sci_req,
  3130. scic_sds_request_state_handler_table,
  3131. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
  3132. );
  3133. }
  3134. static const struct sci_base_state scic_sds_request_state_table[] = {
  3135. [SCI_BASE_REQUEST_STATE_INITIAL] = {
  3136. .enter_state = scic_sds_request_initial_state_enter,
  3137. },
  3138. [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
  3139. .enter_state = scic_sds_request_constructed_state_enter,
  3140. },
  3141. [SCI_BASE_REQUEST_STATE_STARTED] = {
  3142. .enter_state = scic_sds_request_started_state_enter,
  3143. },
  3144. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  3145. .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
  3146. },
  3147. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
  3148. .enter_state = scic_sds_stp_request_started_non_data_await_d2h_enter,
  3149. },
  3150. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  3151. .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
  3152. },
  3153. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
  3154. .enter_state = scic_sds_stp_request_started_pio_await_frame_enter,
  3155. },
  3156. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
  3157. .enter_state = scic_sds_stp_request_started_pio_data_in_await_data_enter,
  3158. },
  3159. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
  3160. .enter_state = scic_sds_stp_request_started_pio_data_out_transmit_data_enter,
  3161. },
  3162. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
  3163. .enter_state = scic_sds_stp_request_started_udma_await_tc_completion_enter,
  3164. },
  3165. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
  3166. .enter_state = scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter,
  3167. },
  3168. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
  3169. .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
  3170. },
  3171. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
  3172. .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
  3173. },
  3174. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
  3175. .enter_state = scic_sds_stp_request_started_soft_reset_await_d2h_response_enter,
  3176. },
  3177. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
  3178. .enter_state = scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter,
  3179. },
  3180. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
  3181. .enter_state = scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter,
  3182. },
  3183. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
  3184. .enter_state = scic_sds_smp_request_started_await_response_substate_enter,
  3185. },
  3186. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
  3187. .enter_state = scic_sds_smp_request_started_await_tc_completion_substate_enter,
  3188. },
  3189. [SCI_BASE_REQUEST_STATE_COMPLETED] = {
  3190. .enter_state = scic_sds_request_completed_state_enter,
  3191. },
  3192. [SCI_BASE_REQUEST_STATE_ABORTING] = {
  3193. .enter_state = scic_sds_request_aborting_state_enter,
  3194. },
  3195. [SCI_BASE_REQUEST_STATE_FINAL] = {
  3196. .enter_state = scic_sds_request_final_state_enter,
  3197. },
  3198. };
  3199. static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
  3200. struct scic_sds_remote_device *sci_dev,
  3201. u16 io_tag, struct scic_sds_request *sci_req)
  3202. {
  3203. sci_base_state_machine_construct(&sci_req->state_machine, sci_req,
  3204. scic_sds_request_state_table, SCI_BASE_REQUEST_STATE_INITIAL);
  3205. sci_base_state_machine_start(&sci_req->state_machine);
  3206. sci_req->io_tag = io_tag;
  3207. sci_req->owning_controller = scic;
  3208. sci_req->target_device = sci_dev;
  3209. sci_req->protocol = SCIC_NO_PROTOCOL;
  3210. sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
  3211. sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
  3212. sci_req->sci_status = SCI_SUCCESS;
  3213. sci_req->scu_status = 0;
  3214. sci_req->post_context = 0xFFFFFFFF;
  3215. sci_req->is_task_management_request = false;
  3216. if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
  3217. sci_req->was_tag_assigned_by_user = false;
  3218. sci_req->task_context_buffer = &sci_req->tc;
  3219. } else {
  3220. sci_req->was_tag_assigned_by_user = true;
  3221. sci_req->task_context_buffer =
  3222. scic_sds_controller_get_task_context_buffer(scic, io_tag);
  3223. }
  3224. }
  3225. static enum sci_status
  3226. scic_io_request_construct(struct scic_sds_controller *scic,
  3227. struct scic_sds_remote_device *sci_dev,
  3228. u16 io_tag, struct scic_sds_request *sci_req)
  3229. {
  3230. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  3231. enum sci_status status = SCI_SUCCESS;
  3232. /* Build the common part of the request */
  3233. scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
  3234. if (sci_dev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
  3235. return SCI_FAILURE_INVALID_REMOTE_DEVICE;
  3236. if (dev->dev_type == SAS_END_DEV)
  3237. /* pass */;
  3238. else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
  3239. memset(&sci_req->stp.cmd, 0, sizeof(sci_req->stp.cmd));
  3240. else if (dev_is_expander(dev))
  3241. memset(&sci_req->smp.cmd, 0, sizeof(sci_req->smp.cmd));
  3242. else
  3243. return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  3244. memset(sci_req->task_context_buffer, 0,
  3245. offsetof(struct scu_task_context, sgl_pair_ab));
  3246. return status;
  3247. }
  3248. enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
  3249. struct scic_sds_remote_device *sci_dev,
  3250. u16 io_tag, struct scic_sds_request *sci_req)
  3251. {
  3252. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  3253. enum sci_status status = SCI_SUCCESS;
  3254. /* Build the common part of the request */
  3255. scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
  3256. if (dev->dev_type == SAS_END_DEV ||
  3257. dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  3258. sci_req->is_task_management_request = true;
  3259. memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
  3260. } else
  3261. status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  3262. return status;
  3263. }
  3264. static enum sci_status isci_request_ssp_request_construct(
  3265. struct isci_request *request)
  3266. {
  3267. enum sci_status status;
  3268. dev_dbg(&request->isci_host->pdev->dev,
  3269. "%s: request = %p\n",
  3270. __func__,
  3271. request);
  3272. status = scic_io_request_construct_basic_ssp(&request->sci);
  3273. return status;
  3274. }
  3275. static enum sci_status isci_request_stp_request_construct(
  3276. struct isci_request *request)
  3277. {
  3278. struct sas_task *task = isci_request_access_task(request);
  3279. enum sci_status status;
  3280. struct host_to_dev_fis *register_fis;
  3281. dev_dbg(&request->isci_host->pdev->dev,
  3282. "%s: request = %p\n",
  3283. __func__,
  3284. request);
  3285. /* Get the host_to_dev_fis from the core and copy
  3286. * the fis from the task into it.
  3287. */
  3288. register_fis = isci_sata_task_to_fis_copy(task);
  3289. status = scic_io_request_construct_basic_sata(&request->sci);
  3290. /* Set the ncq tag in the fis, from the queue
  3291. * command in the task.
  3292. */
  3293. if (isci_sata_is_task_ncq(task)) {
  3294. isci_sata_set_ncq_tag(
  3295. register_fis,
  3296. task
  3297. );
  3298. }
  3299. return status;
  3300. }
  3301. /*
  3302. * This function will fill in the SCU Task Context for a SMP request. The
  3303. * following important settings are utilized: -# task_type ==
  3304. * SCU_TASK_TYPE_SMP. This simply indicates that a normal request type
  3305. * (i.e. non-raw frame) is being utilized to perform task management. -#
  3306. * control_frame == 1. This ensures that the proper endianess is set so
  3307. * that the bytes are transmitted in the right order for a smp request frame.
  3308. * @sci_req: This parameter specifies the smp request object being
  3309. * constructed.
  3310. *
  3311. */
  3312. static void
  3313. scu_smp_request_construct_task_context(struct scic_sds_request *sci_req,
  3314. struct smp_req *smp_req)
  3315. {
  3316. dma_addr_t dma_addr;
  3317. struct scic_sds_controller *scic;
  3318. struct scic_sds_remote_device *sci_dev;
  3319. struct scic_sds_port *sci_port;
  3320. struct scu_task_context *task_context;
  3321. ssize_t word_cnt = sizeof(struct smp_req) / sizeof(u32);
  3322. /* byte swap the smp request. */
  3323. sci_swab32_cpy(&sci_req->smp.cmd, smp_req,
  3324. word_cnt);
  3325. task_context = scic_sds_request_get_task_context(sci_req);
  3326. scic = scic_sds_request_get_controller(sci_req);
  3327. sci_dev = scic_sds_request_get_device(sci_req);
  3328. sci_port = scic_sds_request_get_port(sci_req);
  3329. /*
  3330. * Fill in the TC with the its required data
  3331. * 00h
  3332. */
  3333. task_context->priority = 0;
  3334. task_context->initiator_request = 1;
  3335. task_context->connection_rate = sci_dev->connection_rate;
  3336. task_context->protocol_engine_index =
  3337. scic_sds_controller_get_protocol_engine_group(scic);
  3338. task_context->logical_port_index = scic_sds_port_get_index(sci_port);
  3339. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
  3340. task_context->abort = 0;
  3341. task_context->valid = SCU_TASK_CONTEXT_VALID;
  3342. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  3343. /* 04h */
  3344. task_context->remote_node_index = sci_dev->rnc.remote_node_index;
  3345. task_context->command_code = 0;
  3346. task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
  3347. /* 08h */
  3348. task_context->link_layer_control = 0;
  3349. task_context->do_not_dma_ssp_good_response = 1;
  3350. task_context->strict_ordering = 0;
  3351. task_context->control_frame = 1;
  3352. task_context->timeout_enable = 0;
  3353. task_context->block_guard_enable = 0;
  3354. /* 0ch */
  3355. task_context->address_modifier = 0;
  3356. /* 10h */
  3357. task_context->ssp_command_iu_length = smp_req->req_len;
  3358. /* 14h */
  3359. task_context->transfer_length_bytes = 0;
  3360. /*
  3361. * 18h ~ 30h, protocol specific
  3362. * since commandIU has been build by framework at this point, we just
  3363. * copy the frist DWord from command IU to this location. */
  3364. memcpy(&task_context->type.smp, &sci_req->smp.cmd, sizeof(u32));
  3365. /*
  3366. * 40h
  3367. * "For SMP you could program it to zero. We would prefer that way
  3368. * so that done code will be consistent." - Venki
  3369. */
  3370. task_context->task_phase = 0;
  3371. if (sci_req->was_tag_assigned_by_user) {
  3372. /*
  3373. * Build the task context now since we have already read
  3374. * the data
  3375. */
  3376. sci_req->post_context =
  3377. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  3378. (scic_sds_controller_get_protocol_engine_group(scic) <<
  3379. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  3380. (scic_sds_port_get_index(sci_port) <<
  3381. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
  3382. scic_sds_io_tag_get_index(sci_req->io_tag));
  3383. } else {
  3384. /*
  3385. * Build the task context now since we have already read
  3386. * the data.
  3387. * I/O tag index is not assigned because we have to wait
  3388. * until we get a TCi.
  3389. */
  3390. sci_req->post_context =
  3391. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  3392. (scic_sds_controller_get_protocol_engine_group(scic) <<
  3393. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  3394. (scic_sds_port_get_index(sci_port) <<
  3395. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
  3396. }
  3397. /*
  3398. * Copy the physical address for the command buffer to the SCU Task
  3399. * Context command buffer should not contain command header.
  3400. */
  3401. dma_addr = scic_io_request_get_dma_addr(sci_req,
  3402. ((char *) &sci_req->smp.cmd) +
  3403. sizeof(u32));
  3404. task_context->command_iu_upper = upper_32_bits(dma_addr);
  3405. task_context->command_iu_lower = lower_32_bits(dma_addr);
  3406. /* SMP response comes as UF, so no need to set response IU address. */
  3407. task_context->response_iu_upper = 0;
  3408. task_context->response_iu_lower = 0;
  3409. }
  3410. static enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req)
  3411. {
  3412. struct smp_req *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL);
  3413. if (!smp_req)
  3414. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  3415. sci_req->protocol = SCIC_SMP_PROTOCOL;
  3416. /* Construct the SMP SCU Task Context */
  3417. memcpy(smp_req, &sci_req->smp.cmd, sizeof(*smp_req));
  3418. /*
  3419. * Look at the SMP requests' header fields; for certain SAS 1.x SMP
  3420. * functions under SAS 2.0, a zero request length really indicates
  3421. * a non-zero default length. */
  3422. if (smp_req->req_len == 0) {
  3423. switch (smp_req->func) {
  3424. case SMP_DISCOVER:
  3425. case SMP_REPORT_PHY_ERR_LOG:
  3426. case SMP_REPORT_PHY_SATA:
  3427. case SMP_REPORT_ROUTE_INFO:
  3428. smp_req->req_len = 2;
  3429. break;
  3430. case SMP_CONF_ROUTE_INFO:
  3431. case SMP_PHY_CONTROL:
  3432. case SMP_PHY_TEST_FUNCTION:
  3433. smp_req->req_len = 9;
  3434. break;
  3435. /* Default - zero is a valid default for 2.0. */
  3436. }
  3437. }
  3438. scu_smp_request_construct_task_context(sci_req, smp_req);
  3439. sci_base_state_machine_change_state(&sci_req->state_machine,
  3440. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  3441. kfree(smp_req);
  3442. return SCI_SUCCESS;
  3443. }
  3444. /*
  3445. * isci_smp_request_build() - This function builds the smp request.
  3446. * @ireq: This parameter points to the isci_request allocated in the
  3447. * request construct function.
  3448. *
  3449. * SCI_SUCCESS on successfull completion, or specific failure code.
  3450. */
  3451. static enum sci_status isci_smp_request_build(struct isci_request *ireq)
  3452. {
  3453. enum sci_status status = SCI_FAILURE;
  3454. struct sas_task *task = isci_request_access_task(ireq);
  3455. struct scic_sds_request *sci_req = &ireq->sci;
  3456. dev_dbg(&ireq->isci_host->pdev->dev,
  3457. "%s: request = %p\n", __func__, ireq);
  3458. dev_dbg(&ireq->isci_host->pdev->dev,
  3459. "%s: smp_req len = %d\n",
  3460. __func__,
  3461. task->smp_task.smp_req.length);
  3462. /* copy the smp_command to the address; */
  3463. sg_copy_to_buffer(&task->smp_task.smp_req, 1,
  3464. &sci_req->smp.cmd,
  3465. sizeof(struct smp_req));
  3466. status = scic_io_request_construct_smp(sci_req);
  3467. if (status != SCI_SUCCESS)
  3468. dev_warn(&ireq->isci_host->pdev->dev,
  3469. "%s: failed with status = %d\n",
  3470. __func__,
  3471. status);
  3472. return status;
  3473. }
  3474. /**
  3475. * isci_io_request_build() - This function builds the io request object.
  3476. * @isci_host: This parameter specifies the ISCI host object
  3477. * @request: This parameter points to the isci_request object allocated in the
  3478. * request construct function.
  3479. * @sci_device: This parameter is the handle for the sci core's remote device
  3480. * object that is the destination for this request.
  3481. *
  3482. * SCI_SUCCESS on successfull completion, or specific failure code.
  3483. */
  3484. static enum sci_status isci_io_request_build(
  3485. struct isci_host *isci_host,
  3486. struct isci_request *request,
  3487. struct isci_remote_device *isci_device)
  3488. {
  3489. enum sci_status status = SCI_SUCCESS;
  3490. struct sas_task *task = isci_request_access_task(request);
  3491. struct scic_sds_remote_device *sci_device = &isci_device->sci;
  3492. dev_dbg(&isci_host->pdev->dev,
  3493. "%s: isci_device = 0x%p; request = %p, "
  3494. "num_scatter = %d\n",
  3495. __func__,
  3496. isci_device,
  3497. request,
  3498. task->num_scatter);
  3499. /* map the sgl addresses, if present.
  3500. * libata does the mapping for sata devices
  3501. * before we get the request.
  3502. */
  3503. if (task->num_scatter &&
  3504. !sas_protocol_ata(task->task_proto) &&
  3505. !(SAS_PROTOCOL_SMP & task->task_proto)) {
  3506. request->num_sg_entries = dma_map_sg(
  3507. &isci_host->pdev->dev,
  3508. task->scatter,
  3509. task->num_scatter,
  3510. task->data_dir
  3511. );
  3512. if (request->num_sg_entries == 0)
  3513. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  3514. }
  3515. /* build the common request object. For now,
  3516. * we will let the core allocate the IO tag.
  3517. */
  3518. status = scic_io_request_construct(&isci_host->sci, sci_device,
  3519. SCI_CONTROLLER_INVALID_IO_TAG,
  3520. &request->sci);
  3521. if (status != SCI_SUCCESS) {
  3522. dev_warn(&isci_host->pdev->dev,
  3523. "%s: failed request construct\n",
  3524. __func__);
  3525. return SCI_FAILURE;
  3526. }
  3527. switch (task->task_proto) {
  3528. case SAS_PROTOCOL_SMP:
  3529. status = isci_smp_request_build(request);
  3530. break;
  3531. case SAS_PROTOCOL_SSP:
  3532. status = isci_request_ssp_request_construct(request);
  3533. break;
  3534. case SAS_PROTOCOL_SATA:
  3535. case SAS_PROTOCOL_STP:
  3536. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  3537. status = isci_request_stp_request_construct(request);
  3538. break;
  3539. default:
  3540. dev_warn(&isci_host->pdev->dev,
  3541. "%s: unknown protocol\n", __func__);
  3542. return SCI_FAILURE;
  3543. }
  3544. return SCI_SUCCESS;
  3545. }
  3546. /**
  3547. * isci_request_alloc_core() - This function gets the request object from the
  3548. * isci_host dma cache.
  3549. * @isci_host: This parameter specifies the ISCI host object
  3550. * @isci_request: This parameter will contain the pointer to the new
  3551. * isci_request object.
  3552. * @isci_device: This parameter is the pointer to the isci remote device object
  3553. * that is the destination for this request.
  3554. * @gfp_flags: This parameter specifies the os allocation flags.
  3555. *
  3556. * SCI_SUCCESS on successfull completion, or specific failure code.
  3557. */
  3558. static int isci_request_alloc_core(
  3559. struct isci_host *isci_host,
  3560. struct isci_request **isci_request,
  3561. struct isci_remote_device *isci_device,
  3562. gfp_t gfp_flags)
  3563. {
  3564. int ret = 0;
  3565. dma_addr_t handle;
  3566. struct isci_request *request;
  3567. /* get pointer to dma memory. This actually points
  3568. * to both the isci_remote_device object and the
  3569. * sci object. The isci object is at the beginning
  3570. * of the memory allocated here.
  3571. */
  3572. request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
  3573. if (!request) {
  3574. dev_warn(&isci_host->pdev->dev,
  3575. "%s: dma_pool_alloc returned NULL\n", __func__);
  3576. return -ENOMEM;
  3577. }
  3578. /* initialize the request object. */
  3579. spin_lock_init(&request->state_lock);
  3580. request->request_daddr = handle;
  3581. request->isci_host = isci_host;
  3582. request->isci_device = isci_device;
  3583. request->io_request_completion = NULL;
  3584. request->terminated = false;
  3585. request->num_sg_entries = 0;
  3586. request->complete_in_target = false;
  3587. INIT_LIST_HEAD(&request->completed_node);
  3588. INIT_LIST_HEAD(&request->dev_node);
  3589. *isci_request = request;
  3590. isci_request_change_state(request, allocated);
  3591. return ret;
  3592. }
  3593. static int isci_request_alloc_io(
  3594. struct isci_host *isci_host,
  3595. struct sas_task *task,
  3596. struct isci_request **isci_request,
  3597. struct isci_remote_device *isci_device,
  3598. gfp_t gfp_flags)
  3599. {
  3600. int retval = isci_request_alloc_core(isci_host, isci_request,
  3601. isci_device, gfp_flags);
  3602. if (!retval) {
  3603. (*isci_request)->ttype_ptr.io_task_ptr = task;
  3604. (*isci_request)->ttype = io_task;
  3605. task->lldd_task = *isci_request;
  3606. }
  3607. return retval;
  3608. }
  3609. /**
  3610. * isci_request_alloc_tmf() - This function gets the request object from the
  3611. * isci_host dma cache and initializes the relevant fields as a sas_task.
  3612. * @isci_host: This parameter specifies the ISCI host object
  3613. * @sas_task: This parameter is the task struct from the upper layer driver.
  3614. * @isci_request: This parameter will contain the pointer to the new
  3615. * isci_request object.
  3616. * @isci_device: This parameter is the pointer to the isci remote device object
  3617. * that is the destination for this request.
  3618. * @gfp_flags: This parameter specifies the os allocation flags.
  3619. *
  3620. * SCI_SUCCESS on successfull completion, or specific failure code.
  3621. */
  3622. int isci_request_alloc_tmf(
  3623. struct isci_host *isci_host,
  3624. struct isci_tmf *isci_tmf,
  3625. struct isci_request **isci_request,
  3626. struct isci_remote_device *isci_device,
  3627. gfp_t gfp_flags)
  3628. {
  3629. int retval = isci_request_alloc_core(isci_host, isci_request,
  3630. isci_device, gfp_flags);
  3631. if (!retval) {
  3632. (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
  3633. (*isci_request)->ttype = tmf_task;
  3634. }
  3635. return retval;
  3636. }
  3637. /**
  3638. * isci_request_execute() - This function allocates the isci_request object,
  3639. * all fills in some common fields.
  3640. * @isci_host: This parameter specifies the ISCI host object
  3641. * @sas_task: This parameter is the task struct from the upper layer driver.
  3642. * @isci_request: This parameter will contain the pointer to the new
  3643. * isci_request object.
  3644. * @gfp_flags: This parameter specifies the os allocation flags.
  3645. *
  3646. * SCI_SUCCESS on successfull completion, or specific failure code.
  3647. */
  3648. int isci_request_execute(
  3649. struct isci_host *isci_host,
  3650. struct sas_task *task,
  3651. struct isci_request **isci_request,
  3652. gfp_t gfp_flags)
  3653. {
  3654. int ret = 0;
  3655. struct scic_sds_remote_device *sci_device;
  3656. enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  3657. struct isci_remote_device *isci_device;
  3658. struct isci_request *request;
  3659. unsigned long flags;
  3660. isci_device = task->dev->lldd_dev;
  3661. sci_device = &isci_device->sci;
  3662. /* do common allocation and init of request object. */
  3663. ret = isci_request_alloc_io(
  3664. isci_host,
  3665. task,
  3666. &request,
  3667. isci_device,
  3668. gfp_flags
  3669. );
  3670. if (ret)
  3671. goto out;
  3672. status = isci_io_request_build(isci_host, request, isci_device);
  3673. if (status != SCI_SUCCESS) {
  3674. dev_warn(&isci_host->pdev->dev,
  3675. "%s: request_construct failed - status = 0x%x\n",
  3676. __func__,
  3677. status);
  3678. goto out;
  3679. }
  3680. spin_lock_irqsave(&isci_host->scic_lock, flags);
  3681. /* send the request, let the core assign the IO TAG. */
  3682. status = scic_controller_start_io(&isci_host->sci, sci_device,
  3683. &request->sci,
  3684. SCI_CONTROLLER_INVALID_IO_TAG);
  3685. if (status != SCI_SUCCESS &&
  3686. status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  3687. dev_warn(&isci_host->pdev->dev,
  3688. "%s: failed request start (0x%x)\n",
  3689. __func__, status);
  3690. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  3691. goto out;
  3692. }
  3693. /* Either I/O started OK, or the core has signaled that
  3694. * the device needs a target reset.
  3695. *
  3696. * In either case, hold onto the I/O for later.
  3697. *
  3698. * Update it's status and add it to the list in the
  3699. * remote device object.
  3700. */
  3701. isci_request_change_state(request, started);
  3702. list_add(&request->dev_node, &isci_device->reqs_in_process);
  3703. if (status == SCI_SUCCESS) {
  3704. /* Save the tag for possible task mgmt later. */
  3705. request->io_tag = request->sci.io_tag;
  3706. } else {
  3707. /* The request did not really start in the
  3708. * hardware, so clear the request handle
  3709. * here so no terminations will be done.
  3710. */
  3711. request->terminated = true;
  3712. }
  3713. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  3714. if (status ==
  3715. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  3716. /* Signal libsas that we need the SCSI error
  3717. * handler thread to work on this I/O and that
  3718. * we want a device reset.
  3719. */
  3720. spin_lock_irqsave(&task->task_state_lock, flags);
  3721. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  3722. spin_unlock_irqrestore(&task->task_state_lock, flags);
  3723. /* Cause this task to be scheduled in the SCSI error
  3724. * handler thread.
  3725. */
  3726. isci_execpath_callback(isci_host, task,
  3727. sas_task_abort);
  3728. /* Change the status, since we are holding
  3729. * the I/O until it is managed by the SCSI
  3730. * error handler.
  3731. */
  3732. status = SCI_SUCCESS;
  3733. }
  3734. out:
  3735. if (status != SCI_SUCCESS) {
  3736. /* release dma memory on failure. */
  3737. isci_request_free(isci_host, request);
  3738. request = NULL;
  3739. ret = SCI_FAILURE;
  3740. }
  3741. *isci_request = request;
  3742. return ret;
  3743. }