request.c 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687
  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 scic_sds_request_start(struct scic_sds_request *sci_req)
  644. {
  645. struct scic_sds_controller *scic = sci_req->owning_controller;
  646. struct scu_task_context *task_context;
  647. enum sci_base_request_states state;
  648. if (sci_req->device_sequence !=
  649. scic_sds_remote_device_get_sequence(sci_req->target_device))
  650. return SCI_FAILURE;
  651. state = sci_req->state_machine.current_state_id;
  652. if (state != SCI_BASE_REQUEST_STATE_CONSTRUCTED) {
  653. dev_warn(scic_to_dev(scic),
  654. "%s: SCIC IO Request requested to start while in wrong "
  655. "state %d\n", __func__, state);
  656. return SCI_FAILURE_INVALID_STATE;
  657. }
  658. /* if necessary, allocate a TCi for the io request object and then will,
  659. * if necessary, copy the constructed TC data into the actual TC buffer.
  660. * If everything is successful the post context field is updated with
  661. * the TCi so the controller can post the request to the hardware.
  662. */
  663. if (sci_req->io_tag == SCI_CONTROLLER_INVALID_IO_TAG)
  664. sci_req->io_tag = scic_controller_allocate_io_tag(scic);
  665. /* Record the IO Tag in the request */
  666. if (sci_req->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
  667. task_context = sci_req->task_context_buffer;
  668. task_context->task_index = scic_sds_io_tag_get_index(sci_req->io_tag);
  669. switch (task_context->protocol_type) {
  670. case SCU_TASK_CONTEXT_PROTOCOL_SMP:
  671. case SCU_TASK_CONTEXT_PROTOCOL_SSP:
  672. /* SSP/SMP Frame */
  673. task_context->type.ssp.tag = sci_req->io_tag;
  674. task_context->type.ssp.target_port_transfer_tag =
  675. 0xFFFF;
  676. break;
  677. case SCU_TASK_CONTEXT_PROTOCOL_STP:
  678. /* STP/SATA Frame
  679. * task_context->type.stp.ncq_tag = sci_req->ncq_tag;
  680. */
  681. break;
  682. case SCU_TASK_CONTEXT_PROTOCOL_NONE:
  683. /* / @todo When do we set no protocol type? */
  684. break;
  685. default:
  686. /* This should never happen since we build the IO
  687. * requests */
  688. break;
  689. }
  690. /*
  691. * Check to see if we need to copy the task context buffer
  692. * or have been building into the task context buffer */
  693. if (sci_req->was_tag_assigned_by_user == false)
  694. scic_sds_controller_copy_task_context(scic, sci_req);
  695. /* Add to the post_context the io tag value */
  696. sci_req->post_context |= scic_sds_io_tag_get_index(sci_req->io_tag);
  697. /* Everything is good go ahead and change state */
  698. sci_base_state_machine_change_state(&sci_req->state_machine,
  699. SCI_BASE_REQUEST_STATE_STARTED);
  700. return SCI_SUCCESS;
  701. }
  702. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  703. }
  704. enum sci_status
  705. scic_sds_io_request_terminate(struct scic_sds_request *sci_req)
  706. {
  707. enum sci_base_request_states state;
  708. state = sci_req->state_machine.current_state_id;
  709. switch (state) {
  710. case SCI_BASE_REQUEST_STATE_CONSTRUCTED:
  711. scic_sds_request_set_status(sci_req,
  712. SCU_TASK_DONE_TASK_ABORT,
  713. SCI_FAILURE_IO_TERMINATED);
  714. sci_base_state_machine_change_state(&sci_req->state_machine,
  715. SCI_BASE_REQUEST_STATE_COMPLETED);
  716. return SCI_SUCCESS;
  717. case SCI_BASE_REQUEST_STATE_STARTED:
  718. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION:
  719. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE:
  720. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION:
  721. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE:
  722. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE:
  723. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE:
  724. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE:
  725. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE:
  726. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE:
  727. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE:
  728. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE:
  729. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE:
  730. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE:
  731. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE:
  732. sci_base_state_machine_change_state(&sci_req->state_machine,
  733. SCI_BASE_REQUEST_STATE_ABORTING);
  734. return SCI_SUCCESS;
  735. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE:
  736. sci_base_state_machine_change_state(&sci_req->state_machine,
  737. SCI_BASE_REQUEST_STATE_ABORTING);
  738. sci_base_state_machine_change_state(&sci_req->state_machine,
  739. SCI_BASE_REQUEST_STATE_COMPLETED);
  740. return SCI_SUCCESS;
  741. case SCI_BASE_REQUEST_STATE_ABORTING:
  742. sci_base_state_machine_change_state(&sci_req->state_machine,
  743. SCI_BASE_REQUEST_STATE_COMPLETED);
  744. return SCI_SUCCESS;
  745. case SCI_BASE_REQUEST_STATE_COMPLETED:
  746. default:
  747. dev_warn(scic_to_dev(sci_req->owning_controller),
  748. "%s: SCIC IO Request requested to abort while in wrong "
  749. "state %d\n",
  750. __func__,
  751. sci_base_state_machine_get_state(&sci_req->state_machine));
  752. break;
  753. }
  754. return SCI_FAILURE_INVALID_STATE;
  755. }
  756. enum sci_status scic_sds_request_complete(struct scic_sds_request *sci_req)
  757. {
  758. enum sci_base_request_states state;
  759. struct scic_sds_controller *scic = sci_req->owning_controller;
  760. state = sci_req->state_machine.current_state_id;
  761. if (WARN_ONCE(state != SCI_BASE_REQUEST_STATE_COMPLETED,
  762. "isci: request completion from wrong state (%d)\n", state))
  763. return SCI_FAILURE_INVALID_STATE;
  764. if (!sci_req->was_tag_assigned_by_user)
  765. scic_controller_free_io_tag(scic, sci_req->io_tag);
  766. if (sci_req->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX)
  767. scic_sds_controller_release_frame(scic,
  768. sci_req->saved_rx_frame_index);
  769. /* XXX can we just stop the machine and remove the 'final' state? */
  770. sci_base_state_machine_change_state(&sci_req->state_machine,
  771. SCI_BASE_REQUEST_STATE_FINAL);
  772. return SCI_SUCCESS;
  773. }
  774. enum sci_status scic_sds_io_request_event_handler(struct scic_sds_request *sci_req,
  775. u32 event_code)
  776. {
  777. enum sci_base_request_states state;
  778. struct scic_sds_controller *scic = sci_req->owning_controller;
  779. state = sci_req->state_machine.current_state_id;
  780. if (state != SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE) {
  781. dev_warn(scic_to_dev(scic), "%s: (%x) in wrong state %d\n",
  782. __func__, event_code, state);
  783. return SCI_FAILURE_INVALID_STATE;
  784. }
  785. switch (scu_get_event_specifier(event_code)) {
  786. case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
  787. /* We are waiting for data and the SCU has R_ERR the data frame.
  788. * Go back to waiting for the D2H Register FIS
  789. */
  790. sci_base_state_machine_change_state(&sci_req->state_machine,
  791. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  792. return SCI_SUCCESS;
  793. default:
  794. dev_err(scic_to_dev(scic),
  795. "%s: pio request unexpected event %#x\n",
  796. __func__, event_code);
  797. /* TODO Should we fail the PIO request when we get an
  798. * unexpected event?
  799. */
  800. return SCI_FAILURE;
  801. }
  802. }
  803. /*
  804. * This function copies response data for requests returning response data
  805. * instead of sense data.
  806. * @sci_req: This parameter specifies the request object for which to copy
  807. * the response data.
  808. */
  809. static void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
  810. {
  811. void *resp_buf;
  812. u32 len;
  813. struct ssp_response_iu *ssp_response;
  814. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  815. struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
  816. ssp_response = &sci_req->ssp.rsp;
  817. resp_buf = &isci_tmf->resp.resp_iu;
  818. len = min_t(u32,
  819. SSP_RESP_IU_MAX_SIZE,
  820. be32_to_cpu(ssp_response->response_data_len));
  821. memcpy(resp_buf, ssp_response->resp_data, len);
  822. }
  823. static enum sci_status request_started_state_tc_event(struct scic_sds_request *sci_req,
  824. u32 completion_code)
  825. {
  826. struct ssp_response_iu *resp_iu;
  827. u8 datapres;
  828. /* TODO: Any SDMA return code of other than 0 is bad decode 0x003C0000
  829. * to determine SDMA status
  830. */
  831. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  832. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  833. scic_sds_request_set_status(sci_req,
  834. SCU_TASK_DONE_GOOD,
  835. SCI_SUCCESS);
  836. break;
  837. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP): {
  838. /* There are times when the SCU hardware will return an early
  839. * response because the io request specified more data than is
  840. * returned by the target device (mode pages, inquiry data,
  841. * etc.). We must check the response stats to see if this is
  842. * truly a failed request or a good request that just got
  843. * completed early.
  844. */
  845. struct ssp_response_iu *resp = &sci_req->ssp.rsp;
  846. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  847. sci_swab32_cpy(&sci_req->ssp.rsp,
  848. &sci_req->ssp.rsp,
  849. word_cnt);
  850. if (resp->status == 0) {
  851. scic_sds_request_set_status(sci_req,
  852. SCU_TASK_DONE_GOOD,
  853. SCI_SUCCESS_IO_DONE_EARLY);
  854. } else {
  855. scic_sds_request_set_status(sci_req,
  856. SCU_TASK_DONE_CHECK_RESPONSE,
  857. SCI_FAILURE_IO_RESPONSE_VALID);
  858. }
  859. break;
  860. }
  861. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE): {
  862. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  863. sci_swab32_cpy(&sci_req->ssp.rsp,
  864. &sci_req->ssp.rsp,
  865. word_cnt);
  866. scic_sds_request_set_status(sci_req,
  867. SCU_TASK_DONE_CHECK_RESPONSE,
  868. SCI_FAILURE_IO_RESPONSE_VALID);
  869. break;
  870. }
  871. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
  872. /* TODO With TASK_DONE_RESP_LEN_ERR is the response frame
  873. * guaranteed to be received before this completion status is
  874. * posted?
  875. */
  876. resp_iu = &sci_req->ssp.rsp;
  877. datapres = resp_iu->datapres;
  878. if (datapres == 1 || datapres == 2) {
  879. scic_sds_request_set_status(sci_req,
  880. SCU_TASK_DONE_CHECK_RESPONSE,
  881. SCI_FAILURE_IO_RESPONSE_VALID);
  882. } else
  883. scic_sds_request_set_status(sci_req,
  884. SCU_TASK_DONE_GOOD,
  885. SCI_SUCCESS);
  886. break;
  887. /* only stp device gets suspended. */
  888. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
  889. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
  890. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
  891. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
  892. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
  893. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
  894. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
  895. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
  896. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
  897. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
  898. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
  899. if (sci_req->protocol == SCIC_STP_PROTOCOL) {
  900. scic_sds_request_set_status(sci_req,
  901. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  902. SCU_COMPLETION_TL_STATUS_SHIFT,
  903. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
  904. } else {
  905. scic_sds_request_set_status(sci_req,
  906. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  907. SCU_COMPLETION_TL_STATUS_SHIFT,
  908. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  909. }
  910. break;
  911. /* both stp/ssp device gets suspended */
  912. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
  913. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
  914. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
  915. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
  916. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
  917. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
  918. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
  919. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
  920. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
  921. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
  922. scic_sds_request_set_status(sci_req,
  923. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  924. SCU_COMPLETION_TL_STATUS_SHIFT,
  925. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
  926. break;
  927. /* neither ssp nor stp gets suspended. */
  928. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
  929. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
  930. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
  931. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
  932. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
  933. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
  934. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
  935. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
  936. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
  937. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
  938. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
  939. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
  940. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
  941. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
  942. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
  943. default:
  944. scic_sds_request_set_status(
  945. sci_req,
  946. SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
  947. SCU_COMPLETION_TL_STATUS_SHIFT,
  948. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  949. break;
  950. }
  951. /*
  952. * TODO: This is probably wrong for ACK/NAK timeout conditions
  953. */
  954. /* In all cases we will treat this as the completion of the IO req. */
  955. sci_base_state_machine_change_state(&sci_req->state_machine,
  956. SCI_BASE_REQUEST_STATE_COMPLETED);
  957. return SCI_SUCCESS;
  958. }
  959. static enum sci_status request_aborting_state_tc_event(struct scic_sds_request *sci_req,
  960. u32 completion_code)
  961. {
  962. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  963. case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
  964. case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
  965. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_TASK_ABORT,
  966. SCI_FAILURE_IO_TERMINATED);
  967. sci_base_state_machine_change_state(&sci_req->state_machine,
  968. SCI_BASE_REQUEST_STATE_COMPLETED);
  969. break;
  970. default:
  971. /* Unless we get some strange error wait for the task abort to complete
  972. * TODO: Should there be a state change for this completion?
  973. */
  974. break;
  975. }
  976. return SCI_SUCCESS;
  977. }
  978. static enum sci_status ssp_task_request_await_tc_event(struct scic_sds_request *sci_req,
  979. u32 completion_code)
  980. {
  981. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  982. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  983. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  984. SCI_SUCCESS);
  985. sci_base_state_machine_change_state(&sci_req->state_machine,
  986. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
  987. break;
  988. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
  989. /* Currently, the decision is to simply allow the task request
  990. * to timeout if the task IU wasn't received successfully.
  991. * There is a potential for receiving multiple task responses if
  992. * we decide to send the task IU again.
  993. */
  994. dev_warn(scic_to_dev(sci_req->owning_controller),
  995. "%s: TaskRequest:0x%p CompletionCode:%x - "
  996. "ACK/NAK timeout\n", __func__, sci_req,
  997. completion_code);
  998. sci_base_state_machine_change_state(&sci_req->state_machine,
  999. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
  1000. break;
  1001. default:
  1002. /* All other completion status cause the IO to be complete. If a NAK
  1003. * was received, then it is up to the user to retry the request.
  1004. */
  1005. scic_sds_request_set_status(sci_req,
  1006. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1007. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1008. sci_base_state_machine_change_state(&sci_req->state_machine,
  1009. SCI_BASE_REQUEST_STATE_COMPLETED);
  1010. break;
  1011. }
  1012. return SCI_SUCCESS;
  1013. }
  1014. static enum sci_status smp_request_await_response_tc_event(struct scic_sds_request *sci_req,
  1015. u32 completion_code)
  1016. {
  1017. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1018. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1019. /* In the AWAIT RESPONSE state, any TC completion is
  1020. * unexpected. but if the TC has success status, we
  1021. * complete the IO anyway.
  1022. */
  1023. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1024. SCI_SUCCESS);
  1025. sci_base_state_machine_change_state(&sci_req->state_machine,
  1026. SCI_BASE_REQUEST_STATE_COMPLETED);
  1027. break;
  1028. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
  1029. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
  1030. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
  1031. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
  1032. /* These status has been seen in a specific LSI
  1033. * expander, which sometimes is not able to send smp
  1034. * response within 2 ms. This causes our hardware break
  1035. * the connection and set TC completion with one of
  1036. * these SMP_XXX_XX_ERR status. For these type of error,
  1037. * we ask scic user to retry the request.
  1038. */
  1039. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR,
  1040. SCI_FAILURE_RETRY_REQUIRED);
  1041. sci_base_state_machine_change_state(&sci_req->state_machine,
  1042. SCI_BASE_REQUEST_STATE_COMPLETED);
  1043. break;
  1044. default:
  1045. /* All other completion status cause the IO to be complete. If a NAK
  1046. * was received, then it is up to the user to retry the request
  1047. */
  1048. scic_sds_request_set_status(sci_req,
  1049. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1050. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1051. sci_base_state_machine_change_state(&sci_req->state_machine,
  1052. SCI_BASE_REQUEST_STATE_COMPLETED);
  1053. break;
  1054. }
  1055. return SCI_SUCCESS;
  1056. }
  1057. static enum sci_status smp_request_await_tc_event(struct scic_sds_request *sci_req,
  1058. u32 completion_code)
  1059. {
  1060. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1061. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1062. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1063. SCI_SUCCESS);
  1064. sci_base_state_machine_change_state(&sci_req->state_machine,
  1065. SCI_BASE_REQUEST_STATE_COMPLETED);
  1066. break;
  1067. default:
  1068. /* All other completion status cause the IO to be
  1069. * complete. If a NAK was received, then it is up to
  1070. * the user to retry the request.
  1071. */
  1072. scic_sds_request_set_status(sci_req,
  1073. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1074. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1075. sci_base_state_machine_change_state(&sci_req->state_machine,
  1076. SCI_BASE_REQUEST_STATE_COMPLETED);
  1077. break;
  1078. }
  1079. return SCI_SUCCESS;
  1080. }
  1081. void scic_stp_io_request_set_ncq_tag(struct scic_sds_request *req,
  1082. u16 ncq_tag)
  1083. {
  1084. /**
  1085. * @note This could be made to return an error to the user if the user
  1086. * attempts to set the NCQ tag in the wrong state.
  1087. */
  1088. req->task_context_buffer->type.stp.ncq_tag = ncq_tag;
  1089. }
  1090. /**
  1091. *
  1092. * @sci_req:
  1093. *
  1094. * Get the next SGL element from the request. - Check on which SGL element pair
  1095. * we are working - if working on SLG pair element A - advance to element B -
  1096. * else - check to see if there are more SGL element pairs for this IO request
  1097. * - if there are more SGL element pairs - advance to the next pair and return
  1098. * element A struct scu_sgl_element*
  1099. */
  1100. static struct scu_sgl_element *scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request *stp_req)
  1101. {
  1102. struct scu_sgl_element *current_sgl;
  1103. struct scic_sds_request *sci_req = to_sci_req(stp_req);
  1104. struct scic_sds_request_pio_sgl *pio_sgl = &stp_req->type.pio.request_current;
  1105. if (pio_sgl->sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
  1106. if (pio_sgl->sgl_pair->B.address_lower == 0 &&
  1107. pio_sgl->sgl_pair->B.address_upper == 0) {
  1108. current_sgl = NULL;
  1109. } else {
  1110. pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_B;
  1111. current_sgl = &pio_sgl->sgl_pair->B;
  1112. }
  1113. } else {
  1114. if (pio_sgl->sgl_pair->next_pair_lower == 0 &&
  1115. pio_sgl->sgl_pair->next_pair_upper == 0) {
  1116. current_sgl = NULL;
  1117. } else {
  1118. u64 phys_addr;
  1119. phys_addr = pio_sgl->sgl_pair->next_pair_upper;
  1120. phys_addr <<= 32;
  1121. phys_addr |= pio_sgl->sgl_pair->next_pair_lower;
  1122. pio_sgl->sgl_pair = scic_request_get_virt_addr(sci_req, phys_addr);
  1123. pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_A;
  1124. current_sgl = &pio_sgl->sgl_pair->A;
  1125. }
  1126. }
  1127. return current_sgl;
  1128. }
  1129. static enum sci_status stp_request_non_data_await_h2d_tc_event(struct scic_sds_request *sci_req,
  1130. u32 completion_code)
  1131. {
  1132. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1133. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1134. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1135. SCI_SUCCESS);
  1136. sci_base_state_machine_change_state(&sci_req->state_machine,
  1137. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE);
  1138. break;
  1139. default:
  1140. /* All other completion status cause the IO to be
  1141. * complete. If a NAK was received, then it is up to
  1142. * the user to retry the request.
  1143. */
  1144. scic_sds_request_set_status(sci_req,
  1145. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1146. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1147. sci_base_state_machine_change_state(&sci_req->state_machine,
  1148. SCI_BASE_REQUEST_STATE_COMPLETED);
  1149. break;
  1150. }
  1151. return SCI_SUCCESS;
  1152. }
  1153. #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
  1154. /* transmit DATA_FIS from (current sgl + offset) for input
  1155. * parameter length. current sgl and offset is alreay stored in the IO request
  1156. */
  1157. static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
  1158. struct scic_sds_request *sci_req,
  1159. u32 length)
  1160. {
  1161. struct scic_sds_controller *scic = sci_req->owning_controller;
  1162. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1163. struct scu_task_context *task_context;
  1164. struct scu_sgl_element *current_sgl;
  1165. /* Recycle the TC and reconstruct it for sending out DATA FIS containing
  1166. * for the data from current_sgl+offset for the input length
  1167. */
  1168. task_context = scic_sds_controller_get_task_context_buffer(scic,
  1169. sci_req->io_tag);
  1170. if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
  1171. current_sgl = &stp_req->type.pio.request_current.sgl_pair->A;
  1172. else
  1173. current_sgl = &stp_req->type.pio.request_current.sgl_pair->B;
  1174. /* update the TC */
  1175. task_context->command_iu_upper = current_sgl->address_upper;
  1176. task_context->command_iu_lower = current_sgl->address_lower;
  1177. task_context->transfer_length_bytes = length;
  1178. task_context->type.stp.fis_type = FIS_DATA;
  1179. /* send the new TC out. */
  1180. return scic_controller_continue_io(sci_req);
  1181. }
  1182. static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request *sci_req)
  1183. {
  1184. struct scu_sgl_element *current_sgl;
  1185. u32 sgl_offset;
  1186. u32 remaining_bytes_in_current_sgl = 0;
  1187. enum sci_status status = SCI_SUCCESS;
  1188. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1189. sgl_offset = stp_req->type.pio.request_current.sgl_offset;
  1190. if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
  1191. current_sgl = &(stp_req->type.pio.request_current.sgl_pair->A);
  1192. remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->A.length - sgl_offset;
  1193. } else {
  1194. current_sgl = &(stp_req->type.pio.request_current.sgl_pair->B);
  1195. remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->B.length - sgl_offset;
  1196. }
  1197. if (stp_req->type.pio.pio_transfer_bytes > 0) {
  1198. if (stp_req->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
  1199. /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
  1200. status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, remaining_bytes_in_current_sgl);
  1201. if (status == SCI_SUCCESS) {
  1202. stp_req->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
  1203. /* update the current sgl, sgl_offset and save for future */
  1204. current_sgl = scic_sds_stp_request_pio_get_next_sgl(stp_req);
  1205. sgl_offset = 0;
  1206. }
  1207. } else if (stp_req->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
  1208. /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
  1209. scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, stp_req->type.pio.pio_transfer_bytes);
  1210. if (status == SCI_SUCCESS) {
  1211. /* Sgl offset will be adjusted and saved for future */
  1212. sgl_offset += stp_req->type.pio.pio_transfer_bytes;
  1213. current_sgl->address_lower += stp_req->type.pio.pio_transfer_bytes;
  1214. stp_req->type.pio.pio_transfer_bytes = 0;
  1215. }
  1216. }
  1217. }
  1218. if (status == SCI_SUCCESS) {
  1219. stp_req->type.pio.request_current.sgl_offset = sgl_offset;
  1220. }
  1221. return status;
  1222. }
  1223. /**
  1224. *
  1225. * @stp_request: The request that is used for the SGL processing.
  1226. * @data_buffer: The buffer of data to be copied.
  1227. * @length: The length of the data transfer.
  1228. *
  1229. * Copy the data from the buffer for the length specified to the IO reqeust SGL
  1230. * specified data region. enum sci_status
  1231. */
  1232. static enum sci_status
  1233. scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request *stp_req,
  1234. u8 *data_buf, u32 len)
  1235. {
  1236. struct scic_sds_request *sci_req;
  1237. struct isci_request *ireq;
  1238. u8 *src_addr;
  1239. int copy_len;
  1240. struct sas_task *task;
  1241. struct scatterlist *sg;
  1242. void *kaddr;
  1243. int total_len = len;
  1244. sci_req = to_sci_req(stp_req);
  1245. ireq = sci_req_to_ireq(sci_req);
  1246. task = isci_request_access_task(ireq);
  1247. src_addr = data_buf;
  1248. if (task->num_scatter > 0) {
  1249. sg = task->scatter;
  1250. while (total_len > 0) {
  1251. struct page *page = sg_page(sg);
  1252. copy_len = min_t(int, total_len, sg_dma_len(sg));
  1253. kaddr = kmap_atomic(page, KM_IRQ0);
  1254. memcpy(kaddr + sg->offset, src_addr, copy_len);
  1255. kunmap_atomic(kaddr, KM_IRQ0);
  1256. total_len -= copy_len;
  1257. src_addr += copy_len;
  1258. sg = sg_next(sg);
  1259. }
  1260. } else {
  1261. BUG_ON(task->total_xfer_len < total_len);
  1262. memcpy(task->scatter, src_addr, total_len);
  1263. }
  1264. return SCI_SUCCESS;
  1265. }
  1266. /**
  1267. *
  1268. * @sci_req: The PIO DATA IN request that is to receive the data.
  1269. * @data_buffer: The buffer to copy from.
  1270. *
  1271. * Copy the data buffer to the io request data region. enum sci_status
  1272. */
  1273. static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
  1274. struct scic_sds_stp_request *sci_req,
  1275. u8 *data_buffer)
  1276. {
  1277. enum sci_status status;
  1278. /*
  1279. * If there is less than 1K remaining in the transfer request
  1280. * copy just the data for the transfer */
  1281. if (sci_req->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
  1282. status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
  1283. sci_req, data_buffer, sci_req->type.pio.pio_transfer_bytes);
  1284. if (status == SCI_SUCCESS)
  1285. sci_req->type.pio.pio_transfer_bytes = 0;
  1286. } else {
  1287. /* We are transfering the whole frame so copy */
  1288. status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
  1289. sci_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
  1290. if (status == SCI_SUCCESS)
  1291. sci_req->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
  1292. }
  1293. return status;
  1294. }
  1295. static enum sci_status stp_request_pio_await_h2d_completion_tc_event(struct scic_sds_request *sci_req,
  1296. u32 completion_code)
  1297. {
  1298. enum sci_status status = SCI_SUCCESS;
  1299. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1300. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1301. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
  1302. sci_base_state_machine_change_state(&sci_req->state_machine,
  1303. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  1304. break;
  1305. default:
  1306. /* All other completion status cause the IO to be
  1307. * complete. If a NAK was received, then it is up to
  1308. * the user to retry the request.
  1309. */
  1310. scic_sds_request_set_status(sci_req,
  1311. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1312. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1313. sci_base_state_machine_change_state(&sci_req->state_machine,
  1314. SCI_BASE_REQUEST_STATE_COMPLETED);
  1315. break;
  1316. }
  1317. return status;
  1318. }
  1319. static enum sci_status pio_data_out_tx_done_tc_event(struct scic_sds_request *sci_req,
  1320. u32 completion_code)
  1321. {
  1322. enum sci_status status = SCI_SUCCESS;
  1323. bool all_frames_transferred = false;
  1324. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1325. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1326. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1327. /* Transmit data */
  1328. if (stp_req->type.pio.pio_transfer_bytes != 0) {
  1329. status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
  1330. if (status == SCI_SUCCESS) {
  1331. if (stp_req->type.pio.pio_transfer_bytes == 0)
  1332. all_frames_transferred = true;
  1333. }
  1334. } else if (stp_req->type.pio.pio_transfer_bytes == 0) {
  1335. /*
  1336. * this will happen if the all data is written at the
  1337. * first time after the pio setup fis is received
  1338. */
  1339. all_frames_transferred = true;
  1340. }
  1341. /* all data transferred. */
  1342. if (all_frames_transferred) {
  1343. /*
  1344. * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
  1345. * and wait for PIO_SETUP fis / or D2H REg fis. */
  1346. sci_base_state_machine_change_state(
  1347. &sci_req->state_machine,
  1348. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
  1349. );
  1350. }
  1351. break;
  1352. default:
  1353. /*
  1354. * All other completion status cause the IO to be complete. If a NAK
  1355. * was received, then it is up to the user to retry the request. */
  1356. scic_sds_request_set_status(
  1357. sci_req,
  1358. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1359. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
  1360. );
  1361. sci_base_state_machine_change_state(
  1362. &sci_req->state_machine,
  1363. SCI_BASE_REQUEST_STATE_COMPLETED
  1364. );
  1365. break;
  1366. }
  1367. return status;
  1368. }
  1369. static void scic_sds_stp_request_udma_complete_request(
  1370. struct scic_sds_request *request,
  1371. u32 scu_status,
  1372. enum sci_status sci_status)
  1373. {
  1374. scic_sds_request_set_status(request, scu_status, sci_status);
  1375. sci_base_state_machine_change_state(&request->state_machine,
  1376. SCI_BASE_REQUEST_STATE_COMPLETED);
  1377. }
  1378. static enum sci_status scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request *sci_req,
  1379. u32 frame_index)
  1380. {
  1381. struct scic_sds_controller *scic = sci_req->owning_controller;
  1382. struct dev_to_host_fis *frame_header;
  1383. enum sci_status status;
  1384. u32 *frame_buffer;
  1385. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1386. frame_index,
  1387. (void **)&frame_header);
  1388. if ((status == SCI_SUCCESS) &&
  1389. (frame_header->fis_type == FIS_REGD2H)) {
  1390. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1391. frame_index,
  1392. (void **)&frame_buffer);
  1393. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1394. frame_header,
  1395. frame_buffer);
  1396. }
  1397. scic_sds_controller_release_frame(scic, frame_index);
  1398. return status;
  1399. }
  1400. enum sci_status scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req,
  1401. u32 frame_index)
  1402. {
  1403. struct scic_sds_controller *scic = sci_req->owning_controller;
  1404. struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
  1405. enum sci_base_request_states state;
  1406. enum sci_status status;
  1407. ssize_t word_cnt;
  1408. state = sci_req->state_machine.current_state_id;
  1409. switch (state) {
  1410. case SCI_BASE_REQUEST_STATE_STARTED: {
  1411. struct ssp_frame_hdr ssp_hdr;
  1412. void *frame_header;
  1413. scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1414. frame_index,
  1415. &frame_header);
  1416. word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
  1417. sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
  1418. if (ssp_hdr.frame_type == SSP_RESPONSE) {
  1419. struct ssp_response_iu *resp_iu;
  1420. ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
  1421. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1422. frame_index,
  1423. (void **)&resp_iu);
  1424. sci_swab32_cpy(&sci_req->ssp.rsp, resp_iu, word_cnt);
  1425. resp_iu = &sci_req->ssp.rsp;
  1426. if (resp_iu->datapres == 0x01 ||
  1427. resp_iu->datapres == 0x02) {
  1428. scic_sds_request_set_status(sci_req,
  1429. SCU_TASK_DONE_CHECK_RESPONSE,
  1430. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1431. } else
  1432. scic_sds_request_set_status(sci_req,
  1433. SCU_TASK_DONE_GOOD,
  1434. SCI_SUCCESS);
  1435. } else {
  1436. /* not a response frame, why did it get forwarded? */
  1437. dev_err(scic_to_dev(scic),
  1438. "%s: SCIC IO Request 0x%p received unexpected "
  1439. "frame %d type 0x%02x\n", __func__, sci_req,
  1440. frame_index, ssp_hdr.frame_type);
  1441. }
  1442. /*
  1443. * In any case we are done with this frame buffer return it to the
  1444. * controller
  1445. */
  1446. scic_sds_controller_release_frame(scic, frame_index);
  1447. return SCI_SUCCESS;
  1448. }
  1449. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE:
  1450. scic_sds_io_request_copy_response(sci_req);
  1451. sci_base_state_machine_change_state(&sci_req->state_machine,
  1452. SCI_BASE_REQUEST_STATE_COMPLETED);
  1453. scic_sds_controller_release_frame(scic,frame_index);
  1454. return SCI_SUCCESS;
  1455. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE: {
  1456. struct smp_resp *rsp_hdr = &sci_req->smp.rsp;
  1457. void *frame_header;
  1458. scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1459. frame_index,
  1460. &frame_header);
  1461. /* byte swap the header. */
  1462. word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
  1463. sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
  1464. if (rsp_hdr->frame_type == SMP_RESPONSE) {
  1465. void *smp_resp;
  1466. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1467. frame_index,
  1468. &smp_resp);
  1469. word_cnt = (sizeof(struct smp_req) - SMP_RESP_HDR_SZ) /
  1470. sizeof(u32);
  1471. sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
  1472. smp_resp, word_cnt);
  1473. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1474. SCI_SUCCESS);
  1475. sci_base_state_machine_change_state(&sci_req->state_machine,
  1476. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION);
  1477. } else {
  1478. /* This was not a response frame why did it get forwarded? */
  1479. dev_err(scic_to_dev(scic),
  1480. "%s: SCIC SMP Request 0x%p received unexpected frame "
  1481. "%d type 0x%02x\n", __func__, sci_req,
  1482. frame_index, rsp_hdr->frame_type);
  1483. scic_sds_request_set_status(sci_req,
  1484. SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
  1485. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1486. sci_base_state_machine_change_state(&sci_req->state_machine,
  1487. SCI_BASE_REQUEST_STATE_COMPLETED);
  1488. }
  1489. scic_sds_controller_release_frame(scic, frame_index);
  1490. return SCI_SUCCESS;
  1491. }
  1492. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE:
  1493. return scic_sds_stp_request_udma_general_frame_handler(sci_req, frame_index);
  1494. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE:
  1495. /* Use the general frame handler to copy the resposne data */
  1496. status = scic_sds_stp_request_udma_general_frame_handler(sci_req, frame_index);
  1497. if (status != SCI_SUCCESS)
  1498. return status;
  1499. scic_sds_stp_request_udma_complete_request(sci_req,
  1500. SCU_TASK_DONE_CHECK_RESPONSE,
  1501. SCI_FAILURE_IO_RESPONSE_VALID);
  1502. return SCI_SUCCESS;
  1503. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE: {
  1504. struct dev_to_host_fis *frame_header;
  1505. u32 *frame_buffer;
  1506. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1507. frame_index,
  1508. (void **)&frame_header);
  1509. if (status != SCI_SUCCESS) {
  1510. dev_err(scic_to_dev(scic),
  1511. "%s: SCIC IO Request 0x%p could not get frame header "
  1512. "for frame index %d, status %x\n",
  1513. __func__, stp_req, frame_index, status);
  1514. return status;
  1515. }
  1516. switch (frame_header->fis_type) {
  1517. case FIS_REGD2H:
  1518. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1519. frame_index,
  1520. (void **)&frame_buffer);
  1521. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1522. frame_header,
  1523. frame_buffer);
  1524. /* The command has completed with error */
  1525. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_CHECK_RESPONSE,
  1526. SCI_FAILURE_IO_RESPONSE_VALID);
  1527. break;
  1528. default:
  1529. dev_warn(scic_to_dev(scic),
  1530. "%s: IO Request:0x%p Frame Id:%d protocol "
  1531. "violation occurred\n", __func__, stp_req,
  1532. frame_index);
  1533. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
  1534. SCI_FAILURE_PROTOCOL_VIOLATION);
  1535. break;
  1536. }
  1537. sci_base_state_machine_change_state(&sci_req->state_machine,
  1538. SCI_BASE_REQUEST_STATE_COMPLETED);
  1539. /* Frame has been decoded return it to the controller */
  1540. scic_sds_controller_release_frame(scic, frame_index);
  1541. return status;
  1542. }
  1543. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE: {
  1544. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  1545. struct sas_task *task = isci_request_access_task(ireq);
  1546. struct dev_to_host_fis *frame_header;
  1547. u32 *frame_buffer;
  1548. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1549. frame_index,
  1550. (void **)&frame_header);
  1551. if (status != SCI_SUCCESS) {
  1552. dev_err(scic_to_dev(scic),
  1553. "%s: SCIC IO Request 0x%p could not get frame header "
  1554. "for frame index %d, status %x\n",
  1555. __func__, stp_req, frame_index, status);
  1556. return status;
  1557. }
  1558. switch (frame_header->fis_type) {
  1559. case FIS_PIO_SETUP:
  1560. /* Get from the frame buffer the PIO Setup Data */
  1561. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1562. frame_index,
  1563. (void **)&frame_buffer);
  1564. /* Get the data from the PIO Setup The SCU Hardware returns
  1565. * first word in the frame_header and the rest of the data is in
  1566. * the frame buffer so we need to back up one dword
  1567. */
  1568. /* transfer_count: first 16bits in the 4th dword */
  1569. stp_req->type.pio.pio_transfer_bytes = frame_buffer[3] & 0xffff;
  1570. /* ending_status: 4th byte in the 3rd dword */
  1571. stp_req->type.pio.ending_status = (frame_buffer[2] >> 24) & 0xff;
  1572. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1573. frame_header,
  1574. frame_buffer);
  1575. sci_req->stp.rsp.status = stp_req->type.pio.ending_status;
  1576. /* The next state is dependent on whether the
  1577. * request was PIO Data-in or Data out
  1578. */
  1579. if (task->data_dir == DMA_FROM_DEVICE) {
  1580. sci_base_state_machine_change_state(&sci_req->state_machine,
  1581. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE);
  1582. } else if (task->data_dir == DMA_TO_DEVICE) {
  1583. /* Transmit data */
  1584. status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
  1585. if (status != SCI_SUCCESS)
  1586. break;
  1587. sci_base_state_machine_change_state(&sci_req->state_machine,
  1588. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE);
  1589. }
  1590. break;
  1591. case FIS_SETDEVBITS:
  1592. sci_base_state_machine_change_state(&sci_req->state_machine,
  1593. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  1594. break;
  1595. case FIS_REGD2H:
  1596. if (frame_header->status & ATA_BUSY) {
  1597. /* Now why is the drive sending a D2H Register FIS when
  1598. * it is still busy? Do nothing since we are still in
  1599. * the right state.
  1600. */
  1601. dev_dbg(scic_to_dev(scic),
  1602. "%s: SCIC PIO Request 0x%p received "
  1603. "D2H Register FIS with BSY status "
  1604. "0x%x\n", __func__, stp_req,
  1605. frame_header->status);
  1606. break;
  1607. }
  1608. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1609. frame_index,
  1610. (void **)&frame_buffer);
  1611. scic_sds_controller_copy_sata_response(&sci_req->stp.req,
  1612. frame_header,
  1613. frame_buffer);
  1614. scic_sds_request_set_status(sci_req,
  1615. SCU_TASK_DONE_CHECK_RESPONSE,
  1616. SCI_FAILURE_IO_RESPONSE_VALID);
  1617. sci_base_state_machine_change_state(&sci_req->state_machine,
  1618. SCI_BASE_REQUEST_STATE_COMPLETED);
  1619. break;
  1620. default:
  1621. /* FIXME: what do we do here? */
  1622. break;
  1623. }
  1624. /* Frame is decoded return it to the controller */
  1625. scic_sds_controller_release_frame(scic, frame_index);
  1626. return status;
  1627. }
  1628. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE: {
  1629. struct dev_to_host_fis *frame_header;
  1630. struct sata_fis_data *frame_buffer;
  1631. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1632. frame_index,
  1633. (void **)&frame_header);
  1634. if (status != SCI_SUCCESS) {
  1635. dev_err(scic_to_dev(scic),
  1636. "%s: SCIC IO Request 0x%p could not get frame header "
  1637. "for frame index %d, status %x\n",
  1638. __func__, stp_req, frame_index, status);
  1639. return status;
  1640. }
  1641. if (frame_header->fis_type != FIS_DATA) {
  1642. dev_err(scic_to_dev(scic),
  1643. "%s: SCIC PIO Request 0x%p received frame %d "
  1644. "with fis type 0x%02x when expecting a data "
  1645. "fis.\n", __func__, stp_req, frame_index,
  1646. frame_header->fis_type);
  1647. scic_sds_request_set_status(sci_req,
  1648. SCU_TASK_DONE_GOOD,
  1649. SCI_FAILURE_IO_REQUIRES_SCSI_ABORT);
  1650. sci_base_state_machine_change_state(&sci_req->state_machine,
  1651. SCI_BASE_REQUEST_STATE_COMPLETED);
  1652. /* Frame is decoded return it to the controller */
  1653. scic_sds_controller_release_frame(scic, frame_index);
  1654. return status;
  1655. }
  1656. if (stp_req->type.pio.request_current.sgl_pair == NULL) {
  1657. sci_req->saved_rx_frame_index = frame_index;
  1658. stp_req->type.pio.pio_transfer_bytes = 0;
  1659. } else {
  1660. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1661. frame_index,
  1662. (void **)&frame_buffer);
  1663. status = scic_sds_stp_request_pio_data_in_copy_data(stp_req,
  1664. (u8 *)frame_buffer);
  1665. /* Frame is decoded return it to the controller */
  1666. scic_sds_controller_release_frame(scic, frame_index);
  1667. }
  1668. /* Check for the end of the transfer, are there more
  1669. * bytes remaining for this data transfer
  1670. */
  1671. if (status != SCI_SUCCESS ||
  1672. stp_req->type.pio.pio_transfer_bytes != 0)
  1673. return status;
  1674. if ((stp_req->type.pio.ending_status & ATA_BUSY) == 0) {
  1675. scic_sds_request_set_status(sci_req,
  1676. SCU_TASK_DONE_CHECK_RESPONSE,
  1677. SCI_FAILURE_IO_RESPONSE_VALID);
  1678. sci_base_state_machine_change_state(&sci_req->state_machine,
  1679. SCI_BASE_REQUEST_STATE_COMPLETED);
  1680. } else {
  1681. sci_base_state_machine_change_state(&sci_req->state_machine,
  1682. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
  1683. }
  1684. return status;
  1685. }
  1686. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE: {
  1687. struct dev_to_host_fis *frame_header;
  1688. u32 *frame_buffer;
  1689. status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  1690. frame_index,
  1691. (void **)&frame_header);
  1692. if (status != SCI_SUCCESS) {
  1693. dev_err(scic_to_dev(scic),
  1694. "%s: SCIC IO Request 0x%p could not get frame header "
  1695. "for frame index %d, status %x\n",
  1696. __func__, stp_req, frame_index, status);
  1697. return status;
  1698. }
  1699. switch (frame_header->fis_type) {
  1700. case FIS_REGD2H:
  1701. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  1702. frame_index,
  1703. (void **)&frame_buffer);
  1704. scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
  1705. frame_header,
  1706. frame_buffer);
  1707. /* The command has completed with error */
  1708. scic_sds_request_set_status(sci_req,
  1709. SCU_TASK_DONE_CHECK_RESPONSE,
  1710. SCI_FAILURE_IO_RESPONSE_VALID);
  1711. break;
  1712. default:
  1713. dev_warn(scic_to_dev(scic),
  1714. "%s: IO Request:0x%p Frame Id:%d protocol "
  1715. "violation occurred\n", __func__, stp_req,
  1716. frame_index);
  1717. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
  1718. SCI_FAILURE_PROTOCOL_VIOLATION);
  1719. break;
  1720. }
  1721. sci_base_state_machine_change_state(&sci_req->state_machine,
  1722. SCI_BASE_REQUEST_STATE_COMPLETED);
  1723. /* Frame has been decoded return it to the controller */
  1724. scic_sds_controller_release_frame(scic, frame_index);
  1725. return status;
  1726. }
  1727. case SCI_BASE_REQUEST_STATE_ABORTING:
  1728. /* TODO: Is it even possible to get an unsolicited frame in the
  1729. * aborting state?
  1730. */
  1731. scic_sds_controller_release_frame(scic, frame_index);
  1732. return SCI_SUCCESS;
  1733. default:
  1734. dev_warn(scic_to_dev(scic),
  1735. "%s: SCIC IO Request given unexpected frame %x while in "
  1736. "state %d\n", __func__, frame_index, state);
  1737. scic_sds_controller_release_frame(scic, frame_index);
  1738. return SCI_FAILURE_INVALID_STATE;
  1739. }
  1740. }
  1741. static enum sci_status stp_request_udma_await_tc_event(struct scic_sds_request *sci_req,
  1742. u32 completion_code)
  1743. {
  1744. enum sci_status status = SCI_SUCCESS;
  1745. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1746. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1747. scic_sds_stp_request_udma_complete_request(sci_req,
  1748. SCU_TASK_DONE_GOOD,
  1749. SCI_SUCCESS);
  1750. break;
  1751. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
  1752. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
  1753. /* We must check ther response buffer to see if the D2H
  1754. * Register FIS was received before we got the TC
  1755. * completion.
  1756. */
  1757. if (sci_req->stp.rsp.fis_type == FIS_REGD2H) {
  1758. scic_sds_remote_device_suspend(sci_req->target_device,
  1759. SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
  1760. scic_sds_stp_request_udma_complete_request(sci_req,
  1761. SCU_TASK_DONE_CHECK_RESPONSE,
  1762. SCI_FAILURE_IO_RESPONSE_VALID);
  1763. } else {
  1764. /* If we have an error completion status for the
  1765. * TC then we can expect a D2H register FIS from
  1766. * the device so we must change state to wait
  1767. * for it
  1768. */
  1769. sci_base_state_machine_change_state(&sci_req->state_machine,
  1770. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE);
  1771. }
  1772. break;
  1773. /* TODO Check to see if any of these completion status need to
  1774. * wait for the device to host register fis.
  1775. */
  1776. /* TODO We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR
  1777. * - this comes only for B0
  1778. */
  1779. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
  1780. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
  1781. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
  1782. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
  1783. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
  1784. scic_sds_remote_device_suspend(sci_req->target_device,
  1785. SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
  1786. /* Fall through to the default case */
  1787. default:
  1788. /* All other completion status cause the IO to be complete. */
  1789. scic_sds_stp_request_udma_complete_request(sci_req,
  1790. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1791. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1792. break;
  1793. }
  1794. return status;
  1795. }
  1796. static enum sci_status stp_request_soft_reset_await_h2d_asserted_tc_event(struct scic_sds_request *sci_req,
  1797. u32 completion_code)
  1798. {
  1799. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1800. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1801. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1802. SCI_SUCCESS);
  1803. sci_base_state_machine_change_state(&sci_req->state_machine,
  1804. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE);
  1805. break;
  1806. default:
  1807. /*
  1808. * All other completion status cause the IO to be complete. If a NAK
  1809. * was received, then it is up to the user to retry the request. */
  1810. scic_sds_request_set_status(sci_req,
  1811. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1812. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1813. sci_base_state_machine_change_state(&sci_req->state_machine,
  1814. SCI_BASE_REQUEST_STATE_COMPLETED);
  1815. break;
  1816. }
  1817. return SCI_SUCCESS;
  1818. }
  1819. static enum sci_status stp_request_soft_reset_await_h2d_diagnostic_tc_event(
  1820. struct scic_sds_request *sci_req,
  1821. u32 completion_code)
  1822. {
  1823. switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
  1824. case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
  1825. scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
  1826. SCI_SUCCESS);
  1827. sci_base_state_machine_change_state(&sci_req->state_machine,
  1828. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE);
  1829. break;
  1830. default:
  1831. /* All other completion status cause the IO to be complete. If
  1832. * a NAK was received, then it is up to the user to retry the
  1833. * request.
  1834. */
  1835. scic_sds_request_set_status(sci_req,
  1836. SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
  1837. SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
  1838. sci_base_state_machine_change_state(&sci_req->state_machine,
  1839. SCI_BASE_REQUEST_STATE_COMPLETED);
  1840. break;
  1841. }
  1842. return SCI_SUCCESS;
  1843. }
  1844. enum sci_status
  1845. scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req, u32 completion_code)
  1846. {
  1847. enum sci_base_request_states state;
  1848. struct scic_sds_controller *scic = sci_req->owning_controller;
  1849. state = sci_req->state_machine.current_state_id;
  1850. switch (state) {
  1851. case SCI_BASE_REQUEST_STATE_STARTED:
  1852. return request_started_state_tc_event(sci_req, completion_code);
  1853. case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION:
  1854. return ssp_task_request_await_tc_event(sci_req, completion_code);
  1855. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE:
  1856. return smp_request_await_response_tc_event(sci_req, completion_code);
  1857. case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION:
  1858. return smp_request_await_tc_event(sci_req, completion_code);
  1859. case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE:
  1860. return stp_request_udma_await_tc_event(sci_req, completion_code);
  1861. case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE:
  1862. return stp_request_non_data_await_h2d_tc_event(sci_req, completion_code);
  1863. case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE:
  1864. return stp_request_pio_await_h2d_completion_tc_event(sci_req, completion_code);
  1865. case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE:
  1866. return pio_data_out_tx_done_tc_event(sci_req, completion_code);
  1867. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE:
  1868. return stp_request_soft_reset_await_h2d_asserted_tc_event(sci_req, completion_code);
  1869. case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE:
  1870. return stp_request_soft_reset_await_h2d_diagnostic_tc_event(sci_req, completion_code);
  1871. case SCI_BASE_REQUEST_STATE_ABORTING:
  1872. return request_aborting_state_tc_event(sci_req, completion_code);
  1873. default:
  1874. dev_warn(scic_to_dev(scic),
  1875. "%s: SCIC IO Request given task completion notification %x "
  1876. "while in wrong state %d\n", __func__, completion_code,
  1877. state);
  1878. return SCI_FAILURE_INVALID_STATE;
  1879. }
  1880. }
  1881. /**
  1882. * isci_request_process_response_iu() - This function sets the status and
  1883. * response iu, in the task struct, from the request object for the upper
  1884. * layer driver.
  1885. * @sas_task: This parameter is the task struct from the upper layer driver.
  1886. * @resp_iu: This parameter points to the response iu of the completed request.
  1887. * @dev: This parameter specifies the linux device struct.
  1888. *
  1889. * none.
  1890. */
  1891. static void isci_request_process_response_iu(
  1892. struct sas_task *task,
  1893. struct ssp_response_iu *resp_iu,
  1894. struct device *dev)
  1895. {
  1896. dev_dbg(dev,
  1897. "%s: resp_iu = %p "
  1898. "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
  1899. "resp_iu->response_data_len = %x, "
  1900. "resp_iu->sense_data_len = %x\nrepsonse data: ",
  1901. __func__,
  1902. resp_iu,
  1903. resp_iu->status,
  1904. resp_iu->datapres,
  1905. resp_iu->response_data_len,
  1906. resp_iu->sense_data_len);
  1907. task->task_status.stat = resp_iu->status;
  1908. /* libsas updates the task status fields based on the response iu. */
  1909. sas_ssp_task_response(dev, task, resp_iu);
  1910. }
  1911. /**
  1912. * isci_request_set_open_reject_status() - This function prepares the I/O
  1913. * completion for OPEN_REJECT conditions.
  1914. * @request: This parameter is the completed isci_request object.
  1915. * @response_ptr: This parameter specifies the service response for the I/O.
  1916. * @status_ptr: This parameter specifies the exec status for the I/O.
  1917. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  1918. * the LLDD with respect to completing this request or forcing an abort
  1919. * condition on the I/O.
  1920. * @open_rej_reason: This parameter specifies the encoded reason for the
  1921. * abandon-class reject.
  1922. *
  1923. * none.
  1924. */
  1925. static void isci_request_set_open_reject_status(
  1926. struct isci_request *request,
  1927. struct sas_task *task,
  1928. enum service_response *response_ptr,
  1929. enum exec_status *status_ptr,
  1930. enum isci_completion_selection *complete_to_host_ptr,
  1931. enum sas_open_rej_reason open_rej_reason)
  1932. {
  1933. /* Task in the target is done. */
  1934. request->complete_in_target = true;
  1935. *response_ptr = SAS_TASK_UNDELIVERED;
  1936. *status_ptr = SAS_OPEN_REJECT;
  1937. *complete_to_host_ptr = isci_perform_normal_io_completion;
  1938. task->task_status.open_rej_reason = open_rej_reason;
  1939. }
  1940. /**
  1941. * isci_request_handle_controller_specific_errors() - This function decodes
  1942. * controller-specific I/O completion error conditions.
  1943. * @request: This parameter is the completed isci_request object.
  1944. * @response_ptr: This parameter specifies the service response for the I/O.
  1945. * @status_ptr: This parameter specifies the exec status for the I/O.
  1946. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  1947. * the LLDD with respect to completing this request or forcing an abort
  1948. * condition on the I/O.
  1949. *
  1950. * none.
  1951. */
  1952. static void isci_request_handle_controller_specific_errors(
  1953. struct isci_remote_device *isci_device,
  1954. struct isci_request *request,
  1955. struct sas_task *task,
  1956. enum service_response *response_ptr,
  1957. enum exec_status *status_ptr,
  1958. enum isci_completion_selection *complete_to_host_ptr)
  1959. {
  1960. unsigned int cstatus;
  1961. cstatus = request->sci.scu_status;
  1962. dev_dbg(&request->isci_host->pdev->dev,
  1963. "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
  1964. "- controller status = 0x%x\n",
  1965. __func__, request, cstatus);
  1966. /* Decode the controller-specific errors; most
  1967. * important is to recognize those conditions in which
  1968. * the target may still have a task outstanding that
  1969. * must be aborted.
  1970. *
  1971. * Note that there are SCU completion codes being
  1972. * named in the decode below for which SCIC has already
  1973. * done work to handle them in a way other than as
  1974. * a controller-specific completion code; these are left
  1975. * in the decode below for completeness sake.
  1976. */
  1977. switch (cstatus) {
  1978. case SCU_TASK_DONE_DMASETUP_DIRERR:
  1979. /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
  1980. case SCU_TASK_DONE_XFERCNT_ERR:
  1981. /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
  1982. if (task->task_proto == SAS_PROTOCOL_SMP) {
  1983. /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
  1984. *response_ptr = SAS_TASK_COMPLETE;
  1985. /* See if the device has been/is being stopped. Note
  1986. * that we ignore the quiesce state, since we are
  1987. * concerned about the actual device state.
  1988. */
  1989. if ((isci_device->status == isci_stopping) ||
  1990. (isci_device->status == isci_stopped))
  1991. *status_ptr = SAS_DEVICE_UNKNOWN;
  1992. else
  1993. *status_ptr = SAS_ABORTED_TASK;
  1994. request->complete_in_target = true;
  1995. *complete_to_host_ptr =
  1996. isci_perform_normal_io_completion;
  1997. } else {
  1998. /* Task in the target is not done. */
  1999. *response_ptr = SAS_TASK_UNDELIVERED;
  2000. if ((isci_device->status == isci_stopping) ||
  2001. (isci_device->status == isci_stopped))
  2002. *status_ptr = SAS_DEVICE_UNKNOWN;
  2003. else
  2004. *status_ptr = SAM_STAT_TASK_ABORTED;
  2005. request->complete_in_target = false;
  2006. *complete_to_host_ptr =
  2007. isci_perform_error_io_completion;
  2008. }
  2009. break;
  2010. case SCU_TASK_DONE_CRC_ERR:
  2011. case SCU_TASK_DONE_NAK_CMD_ERR:
  2012. case SCU_TASK_DONE_EXCESS_DATA:
  2013. case SCU_TASK_DONE_UNEXP_FIS:
  2014. /* Also SCU_TASK_DONE_UNEXP_RESP: */
  2015. case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
  2016. case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
  2017. case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
  2018. /* These are conditions in which the target
  2019. * has completed the task, so that no cleanup
  2020. * is necessary.
  2021. */
  2022. *response_ptr = SAS_TASK_COMPLETE;
  2023. /* See if the device has been/is being stopped. Note
  2024. * that we ignore the quiesce state, since we are
  2025. * concerned about the actual device state.
  2026. */
  2027. if ((isci_device->status == isci_stopping) ||
  2028. (isci_device->status == isci_stopped))
  2029. *status_ptr = SAS_DEVICE_UNKNOWN;
  2030. else
  2031. *status_ptr = SAS_ABORTED_TASK;
  2032. request->complete_in_target = true;
  2033. *complete_to_host_ptr = isci_perform_normal_io_completion;
  2034. break;
  2035. /* Note that the only open reject completion codes seen here will be
  2036. * abandon-class codes; all others are automatically retried in the SCU.
  2037. */
  2038. case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
  2039. isci_request_set_open_reject_status(
  2040. request, task, response_ptr, status_ptr,
  2041. complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
  2042. break;
  2043. case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
  2044. /* Note - the return of AB0 will change when
  2045. * libsas implements detection of zone violations.
  2046. */
  2047. isci_request_set_open_reject_status(
  2048. request, task, response_ptr, status_ptr,
  2049. complete_to_host_ptr, SAS_OREJ_RESV_AB0);
  2050. break;
  2051. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
  2052. isci_request_set_open_reject_status(
  2053. request, task, response_ptr, status_ptr,
  2054. complete_to_host_ptr, SAS_OREJ_RESV_AB1);
  2055. break;
  2056. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
  2057. isci_request_set_open_reject_status(
  2058. request, task, response_ptr, status_ptr,
  2059. complete_to_host_ptr, SAS_OREJ_RESV_AB2);
  2060. break;
  2061. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
  2062. isci_request_set_open_reject_status(
  2063. request, task, response_ptr, status_ptr,
  2064. complete_to_host_ptr, SAS_OREJ_RESV_AB3);
  2065. break;
  2066. case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
  2067. isci_request_set_open_reject_status(
  2068. request, task, response_ptr, status_ptr,
  2069. complete_to_host_ptr, SAS_OREJ_BAD_DEST);
  2070. break;
  2071. case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
  2072. isci_request_set_open_reject_status(
  2073. request, task, response_ptr, status_ptr,
  2074. complete_to_host_ptr, SAS_OREJ_STP_NORES);
  2075. break;
  2076. case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
  2077. isci_request_set_open_reject_status(
  2078. request, task, response_ptr, status_ptr,
  2079. complete_to_host_ptr, SAS_OREJ_EPROTO);
  2080. break;
  2081. case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
  2082. isci_request_set_open_reject_status(
  2083. request, task, response_ptr, status_ptr,
  2084. complete_to_host_ptr, SAS_OREJ_CONN_RATE);
  2085. break;
  2086. case SCU_TASK_DONE_LL_R_ERR:
  2087. /* Also SCU_TASK_DONE_ACK_NAK_TO: */
  2088. case SCU_TASK_DONE_LL_PERR:
  2089. case SCU_TASK_DONE_LL_SY_TERM:
  2090. /* Also SCU_TASK_DONE_NAK_ERR:*/
  2091. case SCU_TASK_DONE_LL_LF_TERM:
  2092. /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
  2093. case SCU_TASK_DONE_LL_ABORT_ERR:
  2094. case SCU_TASK_DONE_SEQ_INV_TYPE:
  2095. /* Also SCU_TASK_DONE_UNEXP_XR: */
  2096. case SCU_TASK_DONE_XR_IU_LEN_ERR:
  2097. case SCU_TASK_DONE_INV_FIS_LEN:
  2098. /* Also SCU_TASK_DONE_XR_WD_LEN: */
  2099. case SCU_TASK_DONE_SDMA_ERR:
  2100. case SCU_TASK_DONE_OFFSET_ERR:
  2101. case SCU_TASK_DONE_MAX_PLD_ERR:
  2102. case SCU_TASK_DONE_LF_ERR:
  2103. case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
  2104. case SCU_TASK_DONE_SMP_LL_RX_ERR:
  2105. case SCU_TASK_DONE_UNEXP_DATA:
  2106. case SCU_TASK_DONE_UNEXP_SDBFIS:
  2107. case SCU_TASK_DONE_REG_ERR:
  2108. case SCU_TASK_DONE_SDB_ERR:
  2109. case SCU_TASK_DONE_TASK_ABORT:
  2110. default:
  2111. /* Task in the target is not done. */
  2112. *response_ptr = SAS_TASK_UNDELIVERED;
  2113. *status_ptr = SAM_STAT_TASK_ABORTED;
  2114. request->complete_in_target = false;
  2115. *complete_to_host_ptr = isci_perform_error_io_completion;
  2116. break;
  2117. }
  2118. }
  2119. /**
  2120. * isci_task_save_for_upper_layer_completion() - This function saves the
  2121. * request for later completion to the upper layer driver.
  2122. * @host: This parameter is a pointer to the host on which the the request
  2123. * should be queued (either as an error or success).
  2124. * @request: This parameter is the completed request.
  2125. * @response: This parameter is the response code for the completed task.
  2126. * @status: This parameter is the status code for the completed task.
  2127. *
  2128. * none.
  2129. */
  2130. static void isci_task_save_for_upper_layer_completion(
  2131. struct isci_host *host,
  2132. struct isci_request *request,
  2133. enum service_response response,
  2134. enum exec_status status,
  2135. enum isci_completion_selection task_notification_selection)
  2136. {
  2137. struct sas_task *task = isci_request_access_task(request);
  2138. task_notification_selection
  2139. = isci_task_set_completion_status(task, response, status,
  2140. task_notification_selection);
  2141. /* Tasks aborted specifically by a call to the lldd_abort_task
  2142. * function should not be completed to the host in the regular path.
  2143. */
  2144. switch (task_notification_selection) {
  2145. case isci_perform_normal_io_completion:
  2146. /* Normal notification (task_done) */
  2147. dev_dbg(&host->pdev->dev,
  2148. "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
  2149. __func__,
  2150. task,
  2151. task->task_status.resp, response,
  2152. task->task_status.stat, status);
  2153. /* Add to the completed list. */
  2154. list_add(&request->completed_node,
  2155. &host->requests_to_complete);
  2156. /* Take the request off the device's pending request list. */
  2157. list_del_init(&request->dev_node);
  2158. break;
  2159. case isci_perform_aborted_io_completion:
  2160. /* No notification to libsas because this request is
  2161. * already in the abort path.
  2162. */
  2163. dev_warn(&host->pdev->dev,
  2164. "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
  2165. __func__,
  2166. task,
  2167. task->task_status.resp, response,
  2168. task->task_status.stat, status);
  2169. /* Wake up whatever process was waiting for this
  2170. * request to complete.
  2171. */
  2172. WARN_ON(request->io_request_completion == NULL);
  2173. if (request->io_request_completion != NULL) {
  2174. /* Signal whoever is waiting that this
  2175. * request is complete.
  2176. */
  2177. complete(request->io_request_completion);
  2178. }
  2179. break;
  2180. case isci_perform_error_io_completion:
  2181. /* Use sas_task_abort */
  2182. dev_warn(&host->pdev->dev,
  2183. "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
  2184. __func__,
  2185. task,
  2186. task->task_status.resp, response,
  2187. task->task_status.stat, status);
  2188. /* Add to the aborted list. */
  2189. list_add(&request->completed_node,
  2190. &host->requests_to_errorback);
  2191. break;
  2192. default:
  2193. dev_warn(&host->pdev->dev,
  2194. "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
  2195. __func__,
  2196. task,
  2197. task->task_status.resp, response,
  2198. task->task_status.stat, status);
  2199. /* Add to the error to libsas list. */
  2200. list_add(&request->completed_node,
  2201. &host->requests_to_errorback);
  2202. break;
  2203. }
  2204. }
  2205. static void isci_request_io_request_complete(struct isci_host *isci_host,
  2206. struct isci_request *request,
  2207. enum sci_io_status completion_status)
  2208. {
  2209. struct sas_task *task = isci_request_access_task(request);
  2210. struct ssp_response_iu *resp_iu;
  2211. void *resp_buf;
  2212. unsigned long task_flags;
  2213. struct isci_remote_device *isci_device = request->isci_device;
  2214. enum service_response response = SAS_TASK_UNDELIVERED;
  2215. enum exec_status status = SAS_ABORTED_TASK;
  2216. enum isci_request_status request_status;
  2217. enum isci_completion_selection complete_to_host
  2218. = isci_perform_normal_io_completion;
  2219. dev_dbg(&isci_host->pdev->dev,
  2220. "%s: request = %p, task = %p,\n"
  2221. "task->data_dir = %d completion_status = 0x%x\n",
  2222. __func__,
  2223. request,
  2224. task,
  2225. task->data_dir,
  2226. completion_status);
  2227. spin_lock(&request->state_lock);
  2228. request_status = isci_request_get_state(request);
  2229. /* Decode the request status. Note that if the request has been
  2230. * aborted by a task management function, we don't care
  2231. * what the status is.
  2232. */
  2233. switch (request_status) {
  2234. case aborted:
  2235. /* "aborted" indicates that the request was aborted by a task
  2236. * management function, since once a task management request is
  2237. * perfomed by the device, the request only completes because
  2238. * of the subsequent driver terminate.
  2239. *
  2240. * Aborted also means an external thread is explicitly managing
  2241. * this request, so that we do not complete it up the stack.
  2242. *
  2243. * The target is still there (since the TMF was successful).
  2244. */
  2245. request->complete_in_target = true;
  2246. response = SAS_TASK_COMPLETE;
  2247. /* See if the device has been/is being stopped. Note
  2248. * that we ignore the quiesce state, since we are
  2249. * concerned about the actual device state.
  2250. */
  2251. if ((isci_device->status == isci_stopping)
  2252. || (isci_device->status == isci_stopped)
  2253. )
  2254. status = SAS_DEVICE_UNKNOWN;
  2255. else
  2256. status = SAS_ABORTED_TASK;
  2257. complete_to_host = isci_perform_aborted_io_completion;
  2258. /* This was an aborted request. */
  2259. spin_unlock(&request->state_lock);
  2260. break;
  2261. case aborting:
  2262. /* aborting means that the task management function tried and
  2263. * failed to abort the request. We need to note the request
  2264. * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
  2265. * target as down.
  2266. *
  2267. * Aborting also means an external thread is explicitly managing
  2268. * this request, so that we do not complete it up the stack.
  2269. */
  2270. request->complete_in_target = true;
  2271. response = SAS_TASK_UNDELIVERED;
  2272. if ((isci_device->status == isci_stopping) ||
  2273. (isci_device->status == isci_stopped))
  2274. /* The device has been /is being stopped. Note that
  2275. * we ignore the quiesce state, since we are
  2276. * concerned about the actual device state.
  2277. */
  2278. status = SAS_DEVICE_UNKNOWN;
  2279. else
  2280. status = SAS_PHY_DOWN;
  2281. complete_to_host = isci_perform_aborted_io_completion;
  2282. /* This was an aborted request. */
  2283. spin_unlock(&request->state_lock);
  2284. break;
  2285. case terminating:
  2286. /* This was an terminated request. This happens when
  2287. * the I/O is being terminated because of an action on
  2288. * the device (reset, tear down, etc.), and the I/O needs
  2289. * to be completed up the stack.
  2290. */
  2291. request->complete_in_target = true;
  2292. response = SAS_TASK_UNDELIVERED;
  2293. /* See if the device has been/is being stopped. Note
  2294. * that we ignore the quiesce state, since we are
  2295. * concerned about the actual device state.
  2296. */
  2297. if ((isci_device->status == isci_stopping) ||
  2298. (isci_device->status == isci_stopped))
  2299. status = SAS_DEVICE_UNKNOWN;
  2300. else
  2301. status = SAS_ABORTED_TASK;
  2302. complete_to_host = isci_perform_aborted_io_completion;
  2303. /* This was a terminated request. */
  2304. spin_unlock(&request->state_lock);
  2305. break;
  2306. default:
  2307. /* The request is done from an SCU HW perspective. */
  2308. request->status = completed;
  2309. spin_unlock(&request->state_lock);
  2310. /* This is an active request being completed from the core. */
  2311. switch (completion_status) {
  2312. case SCI_IO_FAILURE_RESPONSE_VALID:
  2313. dev_dbg(&isci_host->pdev->dev,
  2314. "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
  2315. __func__,
  2316. request,
  2317. task);
  2318. if (sas_protocol_ata(task->task_proto)) {
  2319. resp_buf = &request->sci.stp.rsp;
  2320. isci_request_process_stp_response(task,
  2321. resp_buf);
  2322. } else if (SAS_PROTOCOL_SSP == task->task_proto) {
  2323. /* crack the iu response buffer. */
  2324. resp_iu = &request->sci.ssp.rsp;
  2325. isci_request_process_response_iu(task, resp_iu,
  2326. &isci_host->pdev->dev);
  2327. } else if (SAS_PROTOCOL_SMP == task->task_proto) {
  2328. dev_err(&isci_host->pdev->dev,
  2329. "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
  2330. "SAS_PROTOCOL_SMP protocol\n",
  2331. __func__);
  2332. } else
  2333. dev_err(&isci_host->pdev->dev,
  2334. "%s: unknown protocol\n", __func__);
  2335. /* use the task status set in the task struct by the
  2336. * isci_request_process_response_iu call.
  2337. */
  2338. request->complete_in_target = true;
  2339. response = task->task_status.resp;
  2340. status = task->task_status.stat;
  2341. break;
  2342. case SCI_IO_SUCCESS:
  2343. case SCI_IO_SUCCESS_IO_DONE_EARLY:
  2344. response = SAS_TASK_COMPLETE;
  2345. status = SAM_STAT_GOOD;
  2346. request->complete_in_target = true;
  2347. if (task->task_proto == SAS_PROTOCOL_SMP) {
  2348. void *rsp = &request->sci.smp.rsp;
  2349. dev_dbg(&isci_host->pdev->dev,
  2350. "%s: SMP protocol completion\n",
  2351. __func__);
  2352. sg_copy_from_buffer(
  2353. &task->smp_task.smp_resp, 1,
  2354. rsp, sizeof(struct smp_resp));
  2355. } else if (completion_status
  2356. == SCI_IO_SUCCESS_IO_DONE_EARLY) {
  2357. /* This was an SSP / STP / SATA transfer.
  2358. * There is a possibility that less data than
  2359. * the maximum was transferred.
  2360. */
  2361. u32 transferred_length = sci_req_tx_bytes(&request->sci);
  2362. task->task_status.residual
  2363. = task->total_xfer_len - transferred_length;
  2364. /* If there were residual bytes, call this an
  2365. * underrun.
  2366. */
  2367. if (task->task_status.residual != 0)
  2368. status = SAS_DATA_UNDERRUN;
  2369. dev_dbg(&isci_host->pdev->dev,
  2370. "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
  2371. __func__,
  2372. status);
  2373. } else
  2374. dev_dbg(&isci_host->pdev->dev,
  2375. "%s: SCI_IO_SUCCESS\n",
  2376. __func__);
  2377. break;
  2378. case SCI_IO_FAILURE_TERMINATED:
  2379. dev_dbg(&isci_host->pdev->dev,
  2380. "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
  2381. __func__,
  2382. request,
  2383. task);
  2384. /* The request was terminated explicitly. No handling
  2385. * is needed in the SCSI error handler path.
  2386. */
  2387. request->complete_in_target = true;
  2388. response = SAS_TASK_UNDELIVERED;
  2389. /* See if the device has been/is being stopped. Note
  2390. * that we ignore the quiesce state, since we are
  2391. * concerned about the actual device state.
  2392. */
  2393. if ((isci_device->status == isci_stopping) ||
  2394. (isci_device->status == isci_stopped))
  2395. status = SAS_DEVICE_UNKNOWN;
  2396. else
  2397. status = SAS_ABORTED_TASK;
  2398. complete_to_host = isci_perform_normal_io_completion;
  2399. break;
  2400. case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
  2401. isci_request_handle_controller_specific_errors(
  2402. isci_device, request, task, &response, &status,
  2403. &complete_to_host);
  2404. break;
  2405. case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
  2406. /* This is a special case, in that the I/O completion
  2407. * is telling us that the device needs a reset.
  2408. * In order for the device reset condition to be
  2409. * noticed, the I/O has to be handled in the error
  2410. * handler. Set the reset flag and cause the
  2411. * SCSI error thread to be scheduled.
  2412. */
  2413. spin_lock_irqsave(&task->task_state_lock, task_flags);
  2414. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  2415. spin_unlock_irqrestore(&task->task_state_lock, task_flags);
  2416. /* Fail the I/O. */
  2417. response = SAS_TASK_UNDELIVERED;
  2418. status = SAM_STAT_TASK_ABORTED;
  2419. complete_to_host = isci_perform_error_io_completion;
  2420. request->complete_in_target = false;
  2421. break;
  2422. default:
  2423. /* Catch any otherwise unhandled error codes here. */
  2424. dev_warn(&isci_host->pdev->dev,
  2425. "%s: invalid completion code: 0x%x - "
  2426. "isci_request = %p\n",
  2427. __func__, completion_status, request);
  2428. response = SAS_TASK_UNDELIVERED;
  2429. /* See if the device has been/is being stopped. Note
  2430. * that we ignore the quiesce state, since we are
  2431. * concerned about the actual device state.
  2432. */
  2433. if ((isci_device->status == isci_stopping) ||
  2434. (isci_device->status == isci_stopped))
  2435. status = SAS_DEVICE_UNKNOWN;
  2436. else
  2437. status = SAS_ABORTED_TASK;
  2438. complete_to_host = isci_perform_error_io_completion;
  2439. request->complete_in_target = false;
  2440. break;
  2441. }
  2442. break;
  2443. }
  2444. isci_request_unmap_sgl(request, isci_host->pdev);
  2445. /* Put the completed request on the correct list */
  2446. isci_task_save_for_upper_layer_completion(isci_host, request, response,
  2447. status, complete_to_host
  2448. );
  2449. /* complete the io request to the core. */
  2450. scic_controller_complete_io(&isci_host->sci,
  2451. &isci_device->sci,
  2452. &request->sci);
  2453. /* set terminated handle so it cannot be completed or
  2454. * terminated again, and to cause any calls into abort
  2455. * task to recognize the already completed case.
  2456. */
  2457. request->terminated = true;
  2458. isci_host_can_dequeue(isci_host, 1);
  2459. }
  2460. static void scic_sds_request_started_state_enter(struct sci_base_state_machine *sm)
  2461. {
  2462. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2463. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  2464. struct domain_device *dev = sci_dev_to_domain(sci_req->target_device);
  2465. struct sas_task *task;
  2466. /* XXX as hch said always creating an internal sas_task for tmf
  2467. * requests would simplify the driver
  2468. */
  2469. task = ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL;
  2470. /* all unaccelerated request types (non ssp or ncq) handled with
  2471. * substates
  2472. */
  2473. if (!task && dev->dev_type == SAS_END_DEV) {
  2474. sci_base_state_machine_change_state(sm,
  2475. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION);
  2476. } else if (!task &&
  2477. (isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_high ||
  2478. isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_low)) {
  2479. sci_base_state_machine_change_state(sm,
  2480. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE);
  2481. } else if (task && task->task_proto == SAS_PROTOCOL_SMP) {
  2482. sci_base_state_machine_change_state(sm,
  2483. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE);
  2484. } else if (task && sas_protocol_ata(task->task_proto) &&
  2485. !task->ata_task.use_ncq) {
  2486. u32 state;
  2487. if (task->data_dir == DMA_NONE)
  2488. state = SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE;
  2489. else if (task->ata_task.dma_xfer)
  2490. state = SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE;
  2491. else /* PIO */
  2492. state = SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE;
  2493. sci_base_state_machine_change_state(sm, state);
  2494. }
  2495. }
  2496. static void scic_sds_request_completed_state_enter(struct sci_base_state_machine *sm)
  2497. {
  2498. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2499. struct scic_sds_controller *scic = sci_req->owning_controller;
  2500. struct isci_host *ihost = scic_to_ihost(scic);
  2501. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  2502. /* Tell the SCI_USER that the IO request is complete */
  2503. if (sci_req->is_task_management_request == false)
  2504. isci_request_io_request_complete(ihost, ireq,
  2505. sci_req->sci_status);
  2506. else
  2507. isci_task_request_complete(ihost, ireq, sci_req->sci_status);
  2508. }
  2509. static void scic_sds_request_aborting_state_enter(struct sci_base_state_machine *sm)
  2510. {
  2511. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2512. /* Setting the abort bit in the Task Context is required by the silicon. */
  2513. sci_req->task_context_buffer->abort = 1;
  2514. }
  2515. static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(struct sci_base_state_machine *sm)
  2516. {
  2517. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2518. scic_sds_remote_device_set_working_request(sci_req->target_device,
  2519. sci_req);
  2520. }
  2521. static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(struct sci_base_state_machine *sm)
  2522. {
  2523. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2524. scic_sds_remote_device_set_working_request(sci_req->target_device,
  2525. sci_req);
  2526. }
  2527. static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(struct sci_base_state_machine *sm)
  2528. {
  2529. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2530. scic_sds_remote_device_set_working_request(sci_req->target_device,
  2531. sci_req);
  2532. }
  2533. static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(struct sci_base_state_machine *sm)
  2534. {
  2535. struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), state_machine);
  2536. struct scu_task_context *task_context;
  2537. struct host_to_dev_fis *h2d_fis;
  2538. enum sci_status status;
  2539. /* Clear the SRST bit */
  2540. h2d_fis = &sci_req->stp.cmd;
  2541. h2d_fis->control = 0;
  2542. /* Clear the TC control bit */
  2543. task_context = scic_sds_controller_get_task_context_buffer(
  2544. sci_req->owning_controller, sci_req->io_tag);
  2545. task_context->control_frame = 0;
  2546. status = scic_controller_continue_io(sci_req);
  2547. WARN_ONCE(status != SCI_SUCCESS, "isci: continue io failure\n");
  2548. }
  2549. static const struct sci_base_state scic_sds_request_state_table[] = {
  2550. [SCI_BASE_REQUEST_STATE_INITIAL] = { },
  2551. [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = { },
  2552. [SCI_BASE_REQUEST_STATE_STARTED] = {
  2553. .enter_state = scic_sds_request_started_state_enter,
  2554. },
  2555. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  2556. .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
  2557. },
  2558. [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = { },
  2559. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
  2560. .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
  2561. },
  2562. [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = { },
  2563. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = { },
  2564. [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = { },
  2565. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = { },
  2566. [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = { },
  2567. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
  2568. .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
  2569. },
  2570. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
  2571. .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
  2572. },
  2573. [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = { },
  2574. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = { },
  2575. [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = { },
  2576. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = { },
  2577. [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = { },
  2578. [SCI_BASE_REQUEST_STATE_COMPLETED] = {
  2579. .enter_state = scic_sds_request_completed_state_enter,
  2580. },
  2581. [SCI_BASE_REQUEST_STATE_ABORTING] = {
  2582. .enter_state = scic_sds_request_aborting_state_enter,
  2583. },
  2584. [SCI_BASE_REQUEST_STATE_FINAL] = { },
  2585. };
  2586. static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
  2587. struct scic_sds_remote_device *sci_dev,
  2588. u16 io_tag, struct scic_sds_request *sci_req)
  2589. {
  2590. sci_base_state_machine_construct(&sci_req->state_machine,
  2591. scic_sds_request_state_table,
  2592. SCI_BASE_REQUEST_STATE_INITIAL);
  2593. sci_base_state_machine_start(&sci_req->state_machine);
  2594. sci_req->io_tag = io_tag;
  2595. sci_req->owning_controller = scic;
  2596. sci_req->target_device = sci_dev;
  2597. sci_req->protocol = SCIC_NO_PROTOCOL;
  2598. sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
  2599. sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
  2600. sci_req->sci_status = SCI_SUCCESS;
  2601. sci_req->scu_status = 0;
  2602. sci_req->post_context = 0xFFFFFFFF;
  2603. sci_req->is_task_management_request = false;
  2604. if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
  2605. sci_req->was_tag_assigned_by_user = false;
  2606. sci_req->task_context_buffer = &sci_req->tc;
  2607. } else {
  2608. sci_req->was_tag_assigned_by_user = true;
  2609. sci_req->task_context_buffer =
  2610. scic_sds_controller_get_task_context_buffer(scic, io_tag);
  2611. }
  2612. }
  2613. static enum sci_status
  2614. scic_io_request_construct(struct scic_sds_controller *scic,
  2615. struct scic_sds_remote_device *sci_dev,
  2616. u16 io_tag, struct scic_sds_request *sci_req)
  2617. {
  2618. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  2619. enum sci_status status = SCI_SUCCESS;
  2620. /* Build the common part of the request */
  2621. scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
  2622. if (sci_dev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
  2623. return SCI_FAILURE_INVALID_REMOTE_DEVICE;
  2624. if (dev->dev_type == SAS_END_DEV)
  2625. /* pass */;
  2626. else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
  2627. memset(&sci_req->stp.cmd, 0, sizeof(sci_req->stp.cmd));
  2628. else if (dev_is_expander(dev))
  2629. memset(&sci_req->smp.cmd, 0, sizeof(sci_req->smp.cmd));
  2630. else
  2631. return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  2632. memset(sci_req->task_context_buffer, 0,
  2633. offsetof(struct scu_task_context, sgl_pair_ab));
  2634. return status;
  2635. }
  2636. enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
  2637. struct scic_sds_remote_device *sci_dev,
  2638. u16 io_tag, struct scic_sds_request *sci_req)
  2639. {
  2640. struct domain_device *dev = sci_dev_to_domain(sci_dev);
  2641. enum sci_status status = SCI_SUCCESS;
  2642. /* Build the common part of the request */
  2643. scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
  2644. if (dev->dev_type == SAS_END_DEV ||
  2645. dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
  2646. sci_req->is_task_management_request = true;
  2647. memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
  2648. } else
  2649. status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  2650. return status;
  2651. }
  2652. static enum sci_status isci_request_ssp_request_construct(
  2653. struct isci_request *request)
  2654. {
  2655. enum sci_status status;
  2656. dev_dbg(&request->isci_host->pdev->dev,
  2657. "%s: request = %p\n",
  2658. __func__,
  2659. request);
  2660. status = scic_io_request_construct_basic_ssp(&request->sci);
  2661. return status;
  2662. }
  2663. static enum sci_status isci_request_stp_request_construct(
  2664. struct isci_request *request)
  2665. {
  2666. struct sas_task *task = isci_request_access_task(request);
  2667. enum sci_status status;
  2668. struct host_to_dev_fis *register_fis;
  2669. dev_dbg(&request->isci_host->pdev->dev,
  2670. "%s: request = %p\n",
  2671. __func__,
  2672. request);
  2673. /* Get the host_to_dev_fis from the core and copy
  2674. * the fis from the task into it.
  2675. */
  2676. register_fis = isci_sata_task_to_fis_copy(task);
  2677. status = scic_io_request_construct_basic_sata(&request->sci);
  2678. /* Set the ncq tag in the fis, from the queue
  2679. * command in the task.
  2680. */
  2681. if (isci_sata_is_task_ncq(task)) {
  2682. isci_sata_set_ncq_tag(
  2683. register_fis,
  2684. task
  2685. );
  2686. }
  2687. return status;
  2688. }
  2689. /*
  2690. * This function will fill in the SCU Task Context for a SMP request. The
  2691. * following important settings are utilized: -# task_type ==
  2692. * SCU_TASK_TYPE_SMP. This simply indicates that a normal request type
  2693. * (i.e. non-raw frame) is being utilized to perform task management. -#
  2694. * control_frame == 1. This ensures that the proper endianess is set so
  2695. * that the bytes are transmitted in the right order for a smp request frame.
  2696. * @sci_req: This parameter specifies the smp request object being
  2697. * constructed.
  2698. *
  2699. */
  2700. static void
  2701. scu_smp_request_construct_task_context(struct scic_sds_request *sci_req,
  2702. struct smp_req *smp_req)
  2703. {
  2704. dma_addr_t dma_addr;
  2705. struct scic_sds_controller *scic;
  2706. struct scic_sds_remote_device *sci_dev;
  2707. struct scic_sds_port *sci_port;
  2708. struct scu_task_context *task_context;
  2709. ssize_t word_cnt = sizeof(struct smp_req) / sizeof(u32);
  2710. /* byte swap the smp request. */
  2711. sci_swab32_cpy(&sci_req->smp.cmd, smp_req,
  2712. word_cnt);
  2713. task_context = scic_sds_request_get_task_context(sci_req);
  2714. scic = scic_sds_request_get_controller(sci_req);
  2715. sci_dev = scic_sds_request_get_device(sci_req);
  2716. sci_port = scic_sds_request_get_port(sci_req);
  2717. /*
  2718. * Fill in the TC with the its required data
  2719. * 00h
  2720. */
  2721. task_context->priority = 0;
  2722. task_context->initiator_request = 1;
  2723. task_context->connection_rate = sci_dev->connection_rate;
  2724. task_context->protocol_engine_index =
  2725. scic_sds_controller_get_protocol_engine_group(scic);
  2726. task_context->logical_port_index = scic_sds_port_get_index(sci_port);
  2727. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
  2728. task_context->abort = 0;
  2729. task_context->valid = SCU_TASK_CONTEXT_VALID;
  2730. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  2731. /* 04h */
  2732. task_context->remote_node_index = sci_dev->rnc.remote_node_index;
  2733. task_context->command_code = 0;
  2734. task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
  2735. /* 08h */
  2736. task_context->link_layer_control = 0;
  2737. task_context->do_not_dma_ssp_good_response = 1;
  2738. task_context->strict_ordering = 0;
  2739. task_context->control_frame = 1;
  2740. task_context->timeout_enable = 0;
  2741. task_context->block_guard_enable = 0;
  2742. /* 0ch */
  2743. task_context->address_modifier = 0;
  2744. /* 10h */
  2745. task_context->ssp_command_iu_length = smp_req->req_len;
  2746. /* 14h */
  2747. task_context->transfer_length_bytes = 0;
  2748. /*
  2749. * 18h ~ 30h, protocol specific
  2750. * since commandIU has been build by framework at this point, we just
  2751. * copy the frist DWord from command IU to this location. */
  2752. memcpy(&task_context->type.smp, &sci_req->smp.cmd, sizeof(u32));
  2753. /*
  2754. * 40h
  2755. * "For SMP you could program it to zero. We would prefer that way
  2756. * so that done code will be consistent." - Venki
  2757. */
  2758. task_context->task_phase = 0;
  2759. if (sci_req->was_tag_assigned_by_user) {
  2760. /*
  2761. * Build the task context now since we have already read
  2762. * the data
  2763. */
  2764. sci_req->post_context =
  2765. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  2766. (scic_sds_controller_get_protocol_engine_group(scic) <<
  2767. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  2768. (scic_sds_port_get_index(sci_port) <<
  2769. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
  2770. scic_sds_io_tag_get_index(sci_req->io_tag));
  2771. } else {
  2772. /*
  2773. * Build the task context now since we have already read
  2774. * the data.
  2775. * I/O tag index is not assigned because we have to wait
  2776. * until we get a TCi.
  2777. */
  2778. sci_req->post_context =
  2779. (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  2780. (scic_sds_controller_get_protocol_engine_group(scic) <<
  2781. SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
  2782. (scic_sds_port_get_index(sci_port) <<
  2783. SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
  2784. }
  2785. /*
  2786. * Copy the physical address for the command buffer to the SCU Task
  2787. * Context command buffer should not contain command header.
  2788. */
  2789. dma_addr = scic_io_request_get_dma_addr(sci_req,
  2790. ((char *) &sci_req->smp.cmd) +
  2791. sizeof(u32));
  2792. task_context->command_iu_upper = upper_32_bits(dma_addr);
  2793. task_context->command_iu_lower = lower_32_bits(dma_addr);
  2794. /* SMP response comes as UF, so no need to set response IU address. */
  2795. task_context->response_iu_upper = 0;
  2796. task_context->response_iu_lower = 0;
  2797. }
  2798. static enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req)
  2799. {
  2800. struct smp_req *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL);
  2801. if (!smp_req)
  2802. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  2803. sci_req->protocol = SCIC_SMP_PROTOCOL;
  2804. /* Construct the SMP SCU Task Context */
  2805. memcpy(smp_req, &sci_req->smp.cmd, sizeof(*smp_req));
  2806. /*
  2807. * Look at the SMP requests' header fields; for certain SAS 1.x SMP
  2808. * functions under SAS 2.0, a zero request length really indicates
  2809. * a non-zero default length. */
  2810. if (smp_req->req_len == 0) {
  2811. switch (smp_req->func) {
  2812. case SMP_DISCOVER:
  2813. case SMP_REPORT_PHY_ERR_LOG:
  2814. case SMP_REPORT_PHY_SATA:
  2815. case SMP_REPORT_ROUTE_INFO:
  2816. smp_req->req_len = 2;
  2817. break;
  2818. case SMP_CONF_ROUTE_INFO:
  2819. case SMP_PHY_CONTROL:
  2820. case SMP_PHY_TEST_FUNCTION:
  2821. smp_req->req_len = 9;
  2822. break;
  2823. /* Default - zero is a valid default for 2.0. */
  2824. }
  2825. }
  2826. scu_smp_request_construct_task_context(sci_req, smp_req);
  2827. sci_base_state_machine_change_state(&sci_req->state_machine,
  2828. SCI_BASE_REQUEST_STATE_CONSTRUCTED);
  2829. kfree(smp_req);
  2830. return SCI_SUCCESS;
  2831. }
  2832. /*
  2833. * isci_smp_request_build() - This function builds the smp request.
  2834. * @ireq: This parameter points to the isci_request allocated in the
  2835. * request construct function.
  2836. *
  2837. * SCI_SUCCESS on successfull completion, or specific failure code.
  2838. */
  2839. static enum sci_status isci_smp_request_build(struct isci_request *ireq)
  2840. {
  2841. enum sci_status status = SCI_FAILURE;
  2842. struct sas_task *task = isci_request_access_task(ireq);
  2843. struct scic_sds_request *sci_req = &ireq->sci;
  2844. dev_dbg(&ireq->isci_host->pdev->dev,
  2845. "%s: request = %p\n", __func__, ireq);
  2846. dev_dbg(&ireq->isci_host->pdev->dev,
  2847. "%s: smp_req len = %d\n",
  2848. __func__,
  2849. task->smp_task.smp_req.length);
  2850. /* copy the smp_command to the address; */
  2851. sg_copy_to_buffer(&task->smp_task.smp_req, 1,
  2852. &sci_req->smp.cmd,
  2853. sizeof(struct smp_req));
  2854. status = scic_io_request_construct_smp(sci_req);
  2855. if (status != SCI_SUCCESS)
  2856. dev_warn(&ireq->isci_host->pdev->dev,
  2857. "%s: failed with status = %d\n",
  2858. __func__,
  2859. status);
  2860. return status;
  2861. }
  2862. /**
  2863. * isci_io_request_build() - This function builds the io request object.
  2864. * @isci_host: This parameter specifies the ISCI host object
  2865. * @request: This parameter points to the isci_request object allocated in the
  2866. * request construct function.
  2867. * @sci_device: This parameter is the handle for the sci core's remote device
  2868. * object that is the destination for this request.
  2869. *
  2870. * SCI_SUCCESS on successfull completion, or specific failure code.
  2871. */
  2872. static enum sci_status isci_io_request_build(
  2873. struct isci_host *isci_host,
  2874. struct isci_request *request,
  2875. struct isci_remote_device *isci_device)
  2876. {
  2877. enum sci_status status = SCI_SUCCESS;
  2878. struct sas_task *task = isci_request_access_task(request);
  2879. struct scic_sds_remote_device *sci_device = &isci_device->sci;
  2880. dev_dbg(&isci_host->pdev->dev,
  2881. "%s: isci_device = 0x%p; request = %p, "
  2882. "num_scatter = %d\n",
  2883. __func__,
  2884. isci_device,
  2885. request,
  2886. task->num_scatter);
  2887. /* map the sgl addresses, if present.
  2888. * libata does the mapping for sata devices
  2889. * before we get the request.
  2890. */
  2891. if (task->num_scatter &&
  2892. !sas_protocol_ata(task->task_proto) &&
  2893. !(SAS_PROTOCOL_SMP & task->task_proto)) {
  2894. request->num_sg_entries = dma_map_sg(
  2895. &isci_host->pdev->dev,
  2896. task->scatter,
  2897. task->num_scatter,
  2898. task->data_dir
  2899. );
  2900. if (request->num_sg_entries == 0)
  2901. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  2902. }
  2903. /* build the common request object. For now,
  2904. * we will let the core allocate the IO tag.
  2905. */
  2906. status = scic_io_request_construct(&isci_host->sci, sci_device,
  2907. SCI_CONTROLLER_INVALID_IO_TAG,
  2908. &request->sci);
  2909. if (status != SCI_SUCCESS) {
  2910. dev_warn(&isci_host->pdev->dev,
  2911. "%s: failed request construct\n",
  2912. __func__);
  2913. return SCI_FAILURE;
  2914. }
  2915. switch (task->task_proto) {
  2916. case SAS_PROTOCOL_SMP:
  2917. status = isci_smp_request_build(request);
  2918. break;
  2919. case SAS_PROTOCOL_SSP:
  2920. status = isci_request_ssp_request_construct(request);
  2921. break;
  2922. case SAS_PROTOCOL_SATA:
  2923. case SAS_PROTOCOL_STP:
  2924. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  2925. status = isci_request_stp_request_construct(request);
  2926. break;
  2927. default:
  2928. dev_warn(&isci_host->pdev->dev,
  2929. "%s: unknown protocol\n", __func__);
  2930. return SCI_FAILURE;
  2931. }
  2932. return SCI_SUCCESS;
  2933. }
  2934. /**
  2935. * isci_request_alloc_core() - This function gets the request object from the
  2936. * isci_host dma cache.
  2937. * @isci_host: This parameter specifies the ISCI host object
  2938. * @isci_request: This parameter will contain the pointer to the new
  2939. * isci_request object.
  2940. * @isci_device: This parameter is the pointer to the isci remote device object
  2941. * that is the destination for this request.
  2942. * @gfp_flags: This parameter specifies the os allocation flags.
  2943. *
  2944. * SCI_SUCCESS on successfull completion, or specific failure code.
  2945. */
  2946. static int isci_request_alloc_core(
  2947. struct isci_host *isci_host,
  2948. struct isci_request **isci_request,
  2949. struct isci_remote_device *isci_device,
  2950. gfp_t gfp_flags)
  2951. {
  2952. int ret = 0;
  2953. dma_addr_t handle;
  2954. struct isci_request *request;
  2955. /* get pointer to dma memory. This actually points
  2956. * to both the isci_remote_device object and the
  2957. * sci object. The isci object is at the beginning
  2958. * of the memory allocated here.
  2959. */
  2960. request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
  2961. if (!request) {
  2962. dev_warn(&isci_host->pdev->dev,
  2963. "%s: dma_pool_alloc returned NULL\n", __func__);
  2964. return -ENOMEM;
  2965. }
  2966. /* initialize the request object. */
  2967. spin_lock_init(&request->state_lock);
  2968. request->request_daddr = handle;
  2969. request->isci_host = isci_host;
  2970. request->isci_device = isci_device;
  2971. request->io_request_completion = NULL;
  2972. request->terminated = false;
  2973. request->num_sg_entries = 0;
  2974. request->complete_in_target = false;
  2975. INIT_LIST_HEAD(&request->completed_node);
  2976. INIT_LIST_HEAD(&request->dev_node);
  2977. *isci_request = request;
  2978. isci_request_change_state(request, allocated);
  2979. return ret;
  2980. }
  2981. static int isci_request_alloc_io(
  2982. struct isci_host *isci_host,
  2983. struct sas_task *task,
  2984. struct isci_request **isci_request,
  2985. struct isci_remote_device *isci_device,
  2986. gfp_t gfp_flags)
  2987. {
  2988. int retval = isci_request_alloc_core(isci_host, isci_request,
  2989. isci_device, gfp_flags);
  2990. if (!retval) {
  2991. (*isci_request)->ttype_ptr.io_task_ptr = task;
  2992. (*isci_request)->ttype = io_task;
  2993. task->lldd_task = *isci_request;
  2994. }
  2995. return retval;
  2996. }
  2997. /**
  2998. * isci_request_alloc_tmf() - This function gets the request object from the
  2999. * isci_host dma cache and initializes the relevant fields as a sas_task.
  3000. * @isci_host: This parameter specifies the ISCI host object
  3001. * @sas_task: This parameter is the task struct from the upper layer driver.
  3002. * @isci_request: This parameter will contain the pointer to the new
  3003. * isci_request object.
  3004. * @isci_device: This parameter is the pointer to the isci remote device object
  3005. * that is the destination for this request.
  3006. * @gfp_flags: This parameter specifies the os allocation flags.
  3007. *
  3008. * SCI_SUCCESS on successfull completion, or specific failure code.
  3009. */
  3010. int isci_request_alloc_tmf(
  3011. struct isci_host *isci_host,
  3012. struct isci_tmf *isci_tmf,
  3013. struct isci_request **isci_request,
  3014. struct isci_remote_device *isci_device,
  3015. gfp_t gfp_flags)
  3016. {
  3017. int retval = isci_request_alloc_core(isci_host, isci_request,
  3018. isci_device, gfp_flags);
  3019. if (!retval) {
  3020. (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
  3021. (*isci_request)->ttype = tmf_task;
  3022. }
  3023. return retval;
  3024. }
  3025. /**
  3026. * isci_request_execute() - This function allocates the isci_request object,
  3027. * all fills in some common fields.
  3028. * @isci_host: This parameter specifies the ISCI host object
  3029. * @sas_task: This parameter is the task struct from the upper layer driver.
  3030. * @isci_request: This parameter will contain the pointer to the new
  3031. * isci_request object.
  3032. * @gfp_flags: This parameter specifies the os allocation flags.
  3033. *
  3034. * SCI_SUCCESS on successfull completion, or specific failure code.
  3035. */
  3036. int isci_request_execute(
  3037. struct isci_host *isci_host,
  3038. struct sas_task *task,
  3039. struct isci_request **isci_request,
  3040. gfp_t gfp_flags)
  3041. {
  3042. int ret = 0;
  3043. struct scic_sds_remote_device *sci_device;
  3044. enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  3045. struct isci_remote_device *isci_device;
  3046. struct isci_request *request;
  3047. unsigned long flags;
  3048. isci_device = task->dev->lldd_dev;
  3049. sci_device = &isci_device->sci;
  3050. /* do common allocation and init of request object. */
  3051. ret = isci_request_alloc_io(
  3052. isci_host,
  3053. task,
  3054. &request,
  3055. isci_device,
  3056. gfp_flags
  3057. );
  3058. if (ret)
  3059. goto out;
  3060. status = isci_io_request_build(isci_host, request, isci_device);
  3061. if (status != SCI_SUCCESS) {
  3062. dev_warn(&isci_host->pdev->dev,
  3063. "%s: request_construct failed - status = 0x%x\n",
  3064. __func__,
  3065. status);
  3066. goto out;
  3067. }
  3068. spin_lock_irqsave(&isci_host->scic_lock, flags);
  3069. /* send the request, let the core assign the IO TAG. */
  3070. status = scic_controller_start_io(&isci_host->sci, sci_device,
  3071. &request->sci,
  3072. SCI_CONTROLLER_INVALID_IO_TAG);
  3073. if (status != SCI_SUCCESS &&
  3074. status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  3075. dev_warn(&isci_host->pdev->dev,
  3076. "%s: failed request start (0x%x)\n",
  3077. __func__, status);
  3078. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  3079. goto out;
  3080. }
  3081. /* Either I/O started OK, or the core has signaled that
  3082. * the device needs a target reset.
  3083. *
  3084. * In either case, hold onto the I/O for later.
  3085. *
  3086. * Update it's status and add it to the list in the
  3087. * remote device object.
  3088. */
  3089. isci_request_change_state(request, started);
  3090. list_add(&request->dev_node, &isci_device->reqs_in_process);
  3091. if (status == SCI_SUCCESS) {
  3092. /* Save the tag for possible task mgmt later. */
  3093. request->io_tag = request->sci.io_tag;
  3094. } else {
  3095. /* The request did not really start in the
  3096. * hardware, so clear the request handle
  3097. * here so no terminations will be done.
  3098. */
  3099. request->terminated = true;
  3100. }
  3101. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  3102. if (status ==
  3103. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  3104. /* Signal libsas that we need the SCSI error
  3105. * handler thread to work on this I/O and that
  3106. * we want a device reset.
  3107. */
  3108. spin_lock_irqsave(&task->task_state_lock, flags);
  3109. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  3110. spin_unlock_irqrestore(&task->task_state_lock, flags);
  3111. /* Cause this task to be scheduled in the SCSI error
  3112. * handler thread.
  3113. */
  3114. isci_execpath_callback(isci_host, task,
  3115. sas_task_abort);
  3116. /* Change the status, since we are holding
  3117. * the I/O until it is managed by the SCSI
  3118. * error handler.
  3119. */
  3120. status = SCI_SUCCESS;
  3121. }
  3122. out:
  3123. if (status != SCI_SUCCESS) {
  3124. /* release dma memory on failure. */
  3125. isci_request_free(isci_host, request);
  3126. request = NULL;
  3127. ret = SCI_FAILURE;
  3128. }
  3129. *isci_request = request;
  3130. return ret;
  3131. }