request.c 136 KB

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