1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545 |
- /*
- * This file is provided under a dual BSD/GPLv2 license. When using or
- * redistributing this file, you may do so under either license.
- *
- * GPL LICENSE SUMMARY
- *
- * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * The full GNU General Public License is included in this distribution
- * in the file called LICENSE.GPL.
- *
- * BSD LICENSE
- *
- * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "isci.h"
- #include "task.h"
- #include "request.h"
- #include "sata.h"
- #include "scu_completion_codes.h"
- #include "sas.h"
- /**
- * This method returns the sgl element pair for the specificed sgl_pair index.
- * @sci_req: This parameter specifies the IO request for which to retrieve
- * the Scatter-Gather List element pair.
- * @sgl_pair_index: This parameter specifies the index into the SGL element
- * pair to be retrieved.
- *
- * This method returns a pointer to an struct scu_sgl_element_pair.
- */
- static struct scu_sgl_element_pair *scic_sds_request_get_sgl_element_pair(
- struct scic_sds_request *sci_req,
- u32 sgl_pair_index
- ) {
- struct scu_task_context *task_context;
- task_context = (struct scu_task_context *)sci_req->task_context_buffer;
- if (sgl_pair_index == 0) {
- return &task_context->sgl_pair_ab;
- } else if (sgl_pair_index == 1) {
- return &task_context->sgl_pair_cd;
- }
- return &sci_req->sg_table[sgl_pair_index - 2];
- }
- /**
- * This function will build the SGL list for an IO request.
- * @sci_req: This parameter specifies the IO request for which to build
- * the Scatter-Gather List.
- *
- */
- void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
- {
- struct isci_request *isci_request = sci_req_to_ireq(sds_request);
- struct isci_host *isci_host = isci_request->isci_host;
- struct sas_task *task = isci_request_access_task(isci_request);
- struct scatterlist *sg = NULL;
- dma_addr_t dma_addr;
- u32 sg_idx = 0;
- struct scu_sgl_element_pair *scu_sg = NULL;
- struct scu_sgl_element_pair *prev_sg = NULL;
- if (task->num_scatter > 0) {
- sg = task->scatter;
- while (sg) {
- scu_sg = scic_sds_request_get_sgl_element_pair(
- sds_request,
- sg_idx);
- SCU_SGL_COPY(scu_sg->A, sg);
- sg = sg_next(sg);
- if (sg) {
- SCU_SGL_COPY(scu_sg->B, sg);
- sg = sg_next(sg);
- } else
- SCU_SGL_ZERO(scu_sg->B);
- if (prev_sg) {
- dma_addr =
- scic_io_request_get_dma_addr(
- sds_request,
- scu_sg);
- prev_sg->next_pair_upper =
- upper_32_bits(dma_addr);
- prev_sg->next_pair_lower =
- lower_32_bits(dma_addr);
- }
- prev_sg = scu_sg;
- sg_idx++;
- }
- } else { /* handle when no sg */
- scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
- sg_idx);
- dma_addr = dma_map_single(&isci_host->pdev->dev,
- task->scatter,
- task->total_xfer_len,
- task->data_dir);
- isci_request->zero_scatter_daddr = dma_addr;
- scu_sg->A.length = task->total_xfer_len;
- scu_sg->A.address_upper = upper_32_bits(dma_addr);
- scu_sg->A.address_lower = lower_32_bits(dma_addr);
- }
- if (scu_sg) {
- scu_sg->next_pair_upper = 0;
- scu_sg->next_pair_lower = 0;
- }
- }
- static void scic_sds_ssp_io_request_assign_buffers(struct scic_sds_request *sci_req)
- {
- if (sci_req->was_tag_assigned_by_user == false)
- sci_req->task_context_buffer = &sci_req->tc;
- }
- static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request *sci_req)
- {
- struct ssp_cmd_iu *cmd_iu;
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- struct sas_task *task = isci_request_access_task(ireq);
- cmd_iu = &sci_req->ssp.cmd;
- memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8);
- cmd_iu->add_cdb_len = 0;
- cmd_iu->_r_a = 0;
- cmd_iu->_r_b = 0;
- cmd_iu->en_fburst = 0; /* unsupported */
- cmd_iu->task_prio = task->ssp_task.task_prio;
- cmd_iu->task_attr = task->ssp_task.task_attr;
- cmd_iu->_r_c = 0;
- sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cdb,
- sizeof(task->ssp_task.cdb) / sizeof(u32));
- }
- static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request *sci_req)
- {
- struct ssp_task_iu *task_iu;
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- struct sas_task *task = isci_request_access_task(ireq);
- struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
- task_iu = &sci_req->ssp.tmf;
- memset(task_iu, 0, sizeof(struct ssp_task_iu));
- memcpy(task_iu->LUN, task->ssp_task.LUN, 8);
- task_iu->task_func = isci_tmf->tmf_code;
- task_iu->task_tag =
- (ireq->ttype == tmf_task) ?
- isci_tmf->io_tag :
- SCI_CONTROLLER_INVALID_IO_TAG;
- }
- /**
- * This method is will fill in the SCU Task Context for any type of SSP request.
- * @sci_req:
- * @task_context:
- *
- */
- static void scu_ssp_reqeust_construct_task_context(
- struct scic_sds_request *sds_request,
- struct scu_task_context *task_context)
- {
- dma_addr_t dma_addr;
- struct scic_sds_controller *controller;
- struct scic_sds_remote_device *target_device;
- struct scic_sds_port *target_port;
- controller = scic_sds_request_get_controller(sds_request);
- target_device = scic_sds_request_get_device(sds_request);
- target_port = scic_sds_request_get_port(sds_request);
- /* Fill in the TC with the its required data */
- task_context->abort = 0;
- task_context->priority = 0;
- task_context->initiator_request = 1;
- task_context->connection_rate = target_device->connection_rate;
- task_context->protocol_engine_index =
- scic_sds_controller_get_protocol_engine_group(controller);
- task_context->logical_port_index =
- scic_sds_port_get_index(target_port);
- task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
- task_context->valid = SCU_TASK_CONTEXT_VALID;
- task_context->context_type = SCU_TASK_CONTEXT_TYPE;
- task_context->remote_node_index =
- scic_sds_remote_device_get_index(sds_request->target_device);
- task_context->command_code = 0;
- task_context->link_layer_control = 0;
- task_context->do_not_dma_ssp_good_response = 1;
- task_context->strict_ordering = 0;
- task_context->control_frame = 0;
- task_context->timeout_enable = 0;
- task_context->block_guard_enable = 0;
- task_context->address_modifier = 0;
- /* task_context->type.ssp.tag = sci_req->io_tag; */
- task_context->task_phase = 0x01;
- if (sds_request->was_tag_assigned_by_user) {
- /*
- * Build the task context now since we have already read
- * the data
- */
- sds_request->post_context =
- (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
- (scic_sds_controller_get_protocol_engine_group(
- controller) <<
- SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
- (scic_sds_port_get_index(target_port) <<
- SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
- scic_sds_io_tag_get_index(sds_request->io_tag));
- } else {
- /*
- * Build the task context now since we have already read
- * the data
- *
- * I/O tag index is not assigned because we have to wait
- * until we get a TCi
- */
- sds_request->post_context =
- (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
- (scic_sds_controller_get_protocol_engine_group(
- owning_controller) <<
- SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
- (scic_sds_port_get_index(target_port) <<
- SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
- }
- /*
- * Copy the physical address for the command buffer to the
- * SCU Task Context
- */
- dma_addr = scic_io_request_get_dma_addr(sds_request,
- &sds_request->ssp.cmd);
- task_context->command_iu_upper = upper_32_bits(dma_addr);
- task_context->command_iu_lower = lower_32_bits(dma_addr);
- /*
- * Copy the physical address for the response buffer to the
- * SCU Task Context
- */
- dma_addr = scic_io_request_get_dma_addr(sds_request,
- &sds_request->ssp.rsp);
- task_context->response_iu_upper = upper_32_bits(dma_addr);
- task_context->response_iu_lower = lower_32_bits(dma_addr);
- }
- /**
- * This method is will fill in the SCU Task Context for a SSP IO request.
- * @sci_req:
- *
- */
- static void scu_ssp_io_request_construct_task_context(
- struct scic_sds_request *sci_req,
- enum dma_data_direction dir,
- u32 len)
- {
- struct scu_task_context *task_context;
- task_context = scic_sds_request_get_task_context(sci_req);
- scu_ssp_reqeust_construct_task_context(sci_req, task_context);
- task_context->ssp_command_iu_length =
- sizeof(struct ssp_cmd_iu) / sizeof(u32);
- task_context->type.ssp.frame_type = SSP_COMMAND;
- switch (dir) {
- case DMA_FROM_DEVICE:
- case DMA_NONE:
- default:
- task_context->task_type = SCU_TASK_TYPE_IOREAD;
- break;
- case DMA_TO_DEVICE:
- task_context->task_type = SCU_TASK_TYPE_IOWRITE;
- break;
- }
- task_context->transfer_length_bytes = len;
- if (task_context->transfer_length_bytes > 0)
- scic_sds_request_build_sgl(sci_req);
- }
- static void scic_sds_ssp_task_request_assign_buffers(struct scic_sds_request *sci_req)
- {
- if (sci_req->was_tag_assigned_by_user == false)
- sci_req->task_context_buffer = &sci_req->tc;
- }
- /**
- * This method will fill in the SCU Task Context for a SSP Task request. The
- * following important settings are utilized: -# priority ==
- * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
- * ahead of other task destined for the same Remote Node. -# task_type ==
- * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
- * (i.e. non-raw frame) is being utilized to perform task management. -#
- * control_frame == 1. This ensures that the proper endianess is set so
- * that the bytes are transmitted in the right order for a task frame.
- * @sci_req: This parameter specifies the task request object being
- * constructed.
- *
- */
- static void scu_ssp_task_request_construct_task_context(
- struct scic_sds_request *sci_req)
- {
- struct scu_task_context *task_context;
- task_context = scic_sds_request_get_task_context(sci_req);
- scu_ssp_reqeust_construct_task_context(sci_req, task_context);
- task_context->control_frame = 1;
- task_context->priority = SCU_TASK_PRIORITY_HIGH;
- task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
- task_context->transfer_length_bytes = 0;
- task_context->type.ssp.frame_type = SSP_TASK;
- task_context->ssp_command_iu_length =
- sizeof(struct ssp_task_iu) / sizeof(u32);
- }
- /**
- * This method constructs the SSP Command IU data for this ssp passthrough
- * comand request object.
- * @sci_req: This parameter specifies the request object for which the SSP
- * command information unit is being built.
- *
- * enum sci_status, returns invalid parameter is cdb > 16
- */
- /**
- * This method constructs the SATA request object.
- * @sci_req:
- * @sat_protocol:
- * @transfer_length:
- * @data_direction:
- * @copy_rx_frame:
- *
- * enum sci_status
- */
- static enum sci_status
- scic_io_request_construct_sata(struct scic_sds_request *sci_req,
- u32 len,
- enum dma_data_direction dir,
- bool copy)
- {
- enum sci_status status = SCI_SUCCESS;
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- struct sas_task *task = isci_request_access_task(ireq);
- /* check for management protocols */
- if (ireq->ttype == tmf_task) {
- struct isci_tmf *tmf = isci_request_access_tmf(ireq);
- if (tmf->tmf_code == isci_tmf_sata_srst_high ||
- tmf->tmf_code == isci_tmf_sata_srst_low)
- return scic_sds_stp_soft_reset_request_construct(sci_req);
- else {
- dev_err(scic_to_dev(sci_req->owning_controller),
- "%s: Request 0x%p received un-handled SAT "
- "management protocol 0x%x.\n",
- __func__, sci_req, tmf->tmf_code);
- return SCI_FAILURE;
- }
- }
- if (!sas_protocol_ata(task->task_proto)) {
- dev_err(scic_to_dev(sci_req->owning_controller),
- "%s: Non-ATA protocol in SATA path: 0x%x\n",
- __func__,
- task->task_proto);
- return SCI_FAILURE;
- }
- /* non data */
- if (task->data_dir == DMA_NONE)
- return scic_sds_stp_non_data_request_construct(sci_req);
- /* NCQ */
- if (task->ata_task.use_ncq)
- return scic_sds_stp_ncq_request_construct(sci_req, len, dir);
- /* DMA */
- if (task->ata_task.dma_xfer)
- return scic_sds_stp_udma_request_construct(sci_req, len, dir);
- else /* PIO */
- return scic_sds_stp_pio_request_construct(sci_req, copy);
- return status;
- }
- static enum sci_status scic_io_request_construct_basic_ssp(struct scic_sds_request *sci_req)
- {
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- struct sas_task *task = isci_request_access_task(ireq);
- sci_req->protocol = SCIC_SSP_PROTOCOL;
- scu_ssp_io_request_construct_task_context(sci_req,
- task->data_dir,
- task->total_xfer_len);
- scic_sds_io_request_build_ssp_command_iu(sci_req);
- sci_base_state_machine_change_state(
- &sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_CONSTRUCTED);
- return SCI_SUCCESS;
- }
- enum sci_status scic_task_request_construct_ssp(
- struct scic_sds_request *sci_req)
- {
- /* Construct the SSP Task SCU Task Context */
- scu_ssp_task_request_construct_task_context(sci_req);
- /* Fill in the SSP Task IU */
- scic_sds_task_request_build_ssp_task_iu(sci_req);
- sci_base_state_machine_change_state(&sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_CONSTRUCTED);
- return SCI_SUCCESS;
- }
- static enum sci_status scic_io_request_construct_basic_sata(struct scic_sds_request *sci_req)
- {
- enum sci_status status;
- struct scic_sds_stp_request *stp_req;
- bool copy = false;
- struct isci_request *isci_request = sci_req_to_ireq(sci_req);
- struct sas_task *task = isci_request_access_task(isci_request);
- stp_req = &sci_req->stp.req;
- sci_req->protocol = SCIC_STP_PROTOCOL;
- copy = (task->data_dir == DMA_NONE) ? false : true;
- status = scic_io_request_construct_sata(sci_req,
- task->total_xfer_len,
- task->data_dir,
- copy);
- if (status == SCI_SUCCESS)
- sci_base_state_machine_change_state(&sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_CONSTRUCTED);
- return status;
- }
- enum sci_status scic_task_request_construct_sata(struct scic_sds_request *sci_req)
- {
- enum sci_status status = SCI_SUCCESS;
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- /* check for management protocols */
- if (ireq->ttype == tmf_task) {
- struct isci_tmf *tmf = isci_request_access_tmf(ireq);
- if (tmf->tmf_code == isci_tmf_sata_srst_high ||
- tmf->tmf_code == isci_tmf_sata_srst_low) {
- status = scic_sds_stp_soft_reset_request_construct(sci_req);
- } else {
- dev_err(scic_to_dev(sci_req->owning_controller),
- "%s: Request 0x%p received un-handled SAT "
- "Protocol 0x%x.\n",
- __func__, sci_req, tmf->tmf_code);
- return SCI_FAILURE;
- }
- }
- if (status == SCI_SUCCESS)
- sci_base_state_machine_change_state(
- &sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_CONSTRUCTED);
- return status;
- }
- /**
- * sci_req_tx_bytes - bytes transferred when reply underruns request
- * @sci_req: request that was terminated early
- */
- #define SCU_TASK_CONTEXT_SRAM 0x200000
- static u32 sci_req_tx_bytes(struct scic_sds_request *sci_req)
- {
- struct scic_sds_controller *scic = sci_req->owning_controller;
- u32 ret_val = 0;
- if (readl(&scic->smu_registers->address_modifier) == 0) {
- void __iomem *scu_reg_base = scic->scu_registers;
- /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
- * BAR1 is the scu_registers
- * 0x20002C = 0x200000 + 0x2c
- * = start of task context SRAM + offset of (type.ssp.data_offset)
- * TCi is the io_tag of struct scic_sds_request
- */
- ret_val = readl(scu_reg_base +
- (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
- ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(sci_req->io_tag)));
- }
- return ret_val;
- }
- enum sci_status
- scic_sds_request_start(struct scic_sds_request *request)
- {
- if (request->device_sequence !=
- scic_sds_remote_device_get_sequence(request->target_device))
- return SCI_FAILURE;
- if (request->state_handlers->start_handler)
- return request->state_handlers->start_handler(request);
- dev_warn(scic_to_dev(request->owning_controller),
- "%s: SCIC IO Request requested to start while in wrong "
- "state %d\n",
- __func__,
- sci_base_state_machine_get_state(&request->state_machine));
- return SCI_FAILURE_INVALID_STATE;
- }
- enum sci_status
- scic_sds_io_request_terminate(struct scic_sds_request *request)
- {
- if (request->state_handlers->abort_handler)
- return request->state_handlers->abort_handler(request);
- dev_warn(scic_to_dev(request->owning_controller),
- "%s: SCIC IO Request requested to abort while in wrong "
- "state %d\n",
- __func__,
- sci_base_state_machine_get_state(&request->state_machine));
- return SCI_FAILURE_INVALID_STATE;
- }
- enum sci_status scic_sds_io_request_event_handler(
- struct scic_sds_request *request,
- u32 event_code)
- {
- if (request->state_handlers->event_handler)
- return request->state_handlers->event_handler(request, event_code);
- dev_warn(scic_to_dev(request->owning_controller),
- "%s: SCIC IO Request given event code notification %x while "
- "in wrong state %d\n",
- __func__,
- event_code,
- sci_base_state_machine_get_state(&request->state_machine));
- return SCI_FAILURE_INVALID_STATE;
- }
- /**
- *
- * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
- * operation is to be executed.
- * @frame_index: The frame index returned by the hardware for the reqeust
- * object.
- *
- * This method invokes the core state frame handler for the
- * SCIC_SDS_IO_REQUEST_T object. enum sci_status
- */
- enum sci_status scic_sds_io_request_frame_handler(
- struct scic_sds_request *request,
- u32 frame_index)
- {
- if (request->state_handlers->frame_handler)
- return request->state_handlers->frame_handler(request, frame_index);
- dev_warn(scic_to_dev(request->owning_controller),
- "%s: SCIC IO Request given unexpected frame %x while in "
- "state %d\n",
- __func__,
- frame_index,
- sci_base_state_machine_get_state(&request->state_machine));
- scic_sds_controller_release_frame(request->owning_controller, frame_index);
- return SCI_FAILURE_INVALID_STATE;
- }
- /*
- * This function copies response data for requests returning response data
- * instead of sense data.
- * @sci_req: This parameter specifies the request object for which to copy
- * the response data.
- */
- void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
- {
- void *resp_buf;
- u32 len;
- struct ssp_response_iu *ssp_response;
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
- ssp_response = &sci_req->ssp.rsp;
- resp_buf = &isci_tmf->resp.resp_iu;
- len = min_t(u32,
- SSP_RESP_IU_MAX_SIZE,
- be32_to_cpu(ssp_response->response_data_len));
- memcpy(resp_buf, ssp_response->resp_data, len);
- }
- /*
- * This method implements the action taken when a constructed
- * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
- * This method will, if necessary, allocate a TCi for the io request object and
- * then will, if necessary, copy the constructed TC data into the actual TC
- * buffer. If everything is successful the post context field is updated with
- * the TCi so the controller can post the request to the hardware. enum sci_status
- * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
- */
- static enum sci_status scic_sds_request_constructed_state_start_handler(
- struct scic_sds_request *request)
- {
- struct scu_task_context *task_context;
- if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
- request->io_tag =
- scic_controller_allocate_io_tag(request->owning_controller);
- }
- /* Record the IO Tag in the request */
- if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
- task_context = request->task_context_buffer;
- task_context->task_index = scic_sds_io_tag_get_index(request->io_tag);
- switch (task_context->protocol_type) {
- case SCU_TASK_CONTEXT_PROTOCOL_SMP:
- case SCU_TASK_CONTEXT_PROTOCOL_SSP:
- /* SSP/SMP Frame */
- task_context->type.ssp.tag = request->io_tag;
- task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
- break;
- case SCU_TASK_CONTEXT_PROTOCOL_STP:
- /*
- * STP/SATA Frame
- * task_context->type.stp.ncq_tag = request->ncq_tag; */
- break;
- case SCU_TASK_CONTEXT_PROTOCOL_NONE:
- /* / @todo When do we set no protocol type? */
- break;
- default:
- /* This should never happen since we build the IO requests */
- break;
- }
- /*
- * Check to see if we need to copy the task context buffer
- * or have been building into the task context buffer */
- if (request->was_tag_assigned_by_user == false) {
- scic_sds_controller_copy_task_context(
- request->owning_controller, request);
- }
- /* Add to the post_context the io tag value */
- request->post_context |= scic_sds_io_tag_get_index(request->io_tag);
- /* Everything is good go ahead and change state */
- sci_base_state_machine_change_state(&request->state_machine,
- SCI_BASE_REQUEST_STATE_STARTED);
- return SCI_SUCCESS;
- }
- return SCI_FAILURE_INSUFFICIENT_RESOURCES;
- }
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_terminate() request. Since the request
- * has not yet been posted to the hardware the request transitions to the
- * completed state. enum sci_status SCI_SUCCESS
- */
- static enum sci_status scic_sds_request_constructed_state_abort_handler(
- struct scic_sds_request *request)
- {
- /*
- * This request has been terminated by the user make sure that the correct
- * status code is returned */
- scic_sds_request_set_status(request,
- SCU_TASK_DONE_TASK_ABORT,
- SCI_FAILURE_IO_TERMINATED);
- sci_base_state_machine_change_state(&request->state_machine,
- SCI_BASE_REQUEST_STATE_COMPLETED);
- return SCI_SUCCESS;
- }
- /*
- * *****************************************************************************
- * * STARTED STATE HANDLERS
- * ***************************************************************************** */
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_terminate() request. Since the request
- * has been posted to the hardware the io request state is changed to the
- * aborting state. enum sci_status SCI_SUCCESS
- */
- enum sci_status scic_sds_request_started_state_abort_handler(
- struct scic_sds_request *request)
- {
- if (request->has_started_substate_machine)
- sci_base_state_machine_stop(&request->started_substate_machine);
- sci_base_state_machine_change_state(&request->state_machine,
- SCI_BASE_REQUEST_STATE_ABORTING);
- return SCI_SUCCESS;
- }
- /*
- * scic_sds_request_started_state_tc_completion_handler() - This method process
- * TC (task context) completions for normal IO request (i.e. Task/Abort
- * Completions of type 0). This method will update the
- * SCIC_SDS_IO_REQUEST_T::status field.
- * @sci_req: This parameter specifies the request for which a completion
- * occurred.
- * @completion_code: This parameter specifies the completion code received from
- * the SCU.
- *
- */
- static enum sci_status
- scic_sds_request_started_state_tc_completion_handler(struct scic_sds_request *sci_req,
- u32 completion_code)
- {
- u8 datapres;
- struct ssp_response_iu *resp_iu;
- /*
- * TODO: Any SDMA return code of other than 0 is bad
- * decode 0x003C0000 to determine SDMA status
- */
- switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
- scic_sds_request_set_status(sci_req,
- SCU_TASK_DONE_GOOD,
- SCI_SUCCESS);
- break;
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
- {
- /*
- * There are times when the SCU hardware will return an early
- * response because the io request specified more data than is
- * returned by the target device (mode pages, inquiry data,
- * etc.). We must check the response stats to see if this is
- * truly a failed request or a good request that just got
- * completed early.
- */
- struct ssp_response_iu *resp = &sci_req->ssp.rsp;
- ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
- sci_swab32_cpy(&sci_req->ssp.rsp,
- &sci_req->ssp.rsp,
- word_cnt);
- if (resp->status == 0) {
- scic_sds_request_set_status(
- sci_req,
- SCU_TASK_DONE_GOOD,
- SCI_SUCCESS_IO_DONE_EARLY);
- } else {
- scic_sds_request_set_status(
- sci_req,
- SCU_TASK_DONE_CHECK_RESPONSE,
- SCI_FAILURE_IO_RESPONSE_VALID);
- }
- }
- break;
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
- {
- ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
- sci_swab32_cpy(&sci_req->ssp.rsp,
- &sci_req->ssp.rsp,
- word_cnt);
- scic_sds_request_set_status(sci_req,
- SCU_TASK_DONE_CHECK_RESPONSE,
- SCI_FAILURE_IO_RESPONSE_VALID);
- break;
- }
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
- /*
- * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
- * guaranteed to be received before this completion status is
- * posted?
- */
- resp_iu = &sci_req->ssp.rsp;
- datapres = resp_iu->datapres;
- if ((datapres == 0x01) || (datapres == 0x02)) {
- scic_sds_request_set_status(
- sci_req,
- SCU_TASK_DONE_CHECK_RESPONSE,
- SCI_FAILURE_IO_RESPONSE_VALID);
- } else
- scic_sds_request_set_status(
- sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
- break;
- /* only stp device gets suspended. */
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
- if (sci_req->protocol == SCIC_STP_PROTOCOL) {
- scic_sds_request_set_status(
- sci_req,
- SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
- SCU_COMPLETION_TL_STATUS_SHIFT,
- SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
- } else {
- scic_sds_request_set_status(
- sci_req,
- SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
- SCU_COMPLETION_TL_STATUS_SHIFT,
- SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
- }
- break;
- /* both stp/ssp device gets suspended */
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
- scic_sds_request_set_status(
- sci_req,
- SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
- SCU_COMPLETION_TL_STATUS_SHIFT,
- SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
- break;
- /* neither ssp nor stp gets suspended. */
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
- case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
- default:
- scic_sds_request_set_status(
- sci_req,
- SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
- SCU_COMPLETION_TL_STATUS_SHIFT,
- SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
- break;
- }
- /*
- * TODO: This is probably wrong for ACK/NAK timeout conditions
- */
- /* In all cases we will treat this as the completion of the IO req. */
- sci_base_state_machine_change_state(
- &sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_COMPLETED);
- return SCI_SUCCESS;
- }
- enum sci_status
- scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code)
- {
- if (request->state_machine.current_state_id == SCI_BASE_REQUEST_STATE_STARTED &&
- request->has_started_substate_machine == false)
- return scic_sds_request_started_state_tc_completion_handler(request, completion_code);
- else if (request->state_handlers->tc_completion_handler)
- return request->state_handlers->tc_completion_handler(request, completion_code);
- dev_warn(scic_to_dev(request->owning_controller),
- "%s: SCIC IO Request given task completion notification %x "
- "while in wrong state %d\n",
- __func__,
- completion_code,
- sci_base_state_machine_get_state(&request->state_machine));
- return SCI_FAILURE_INVALID_STATE;
- }
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_frame_handler() request. This method
- * first determines the frame type received. If this is a response frame then
- * the response data is copied to the io request response buffer for processing
- * at completion time. If the frame type is not a response buffer an error is
- * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
- */
- static enum sci_status
- scic_sds_request_started_state_frame_handler(struct scic_sds_request *sci_req,
- u32 frame_index)
- {
- enum sci_status status;
- u32 *frame_header;
- struct ssp_frame_hdr ssp_hdr;
- ssize_t word_cnt;
- status = scic_sds_unsolicited_frame_control_get_header(
- &(scic_sds_request_get_controller(sci_req)->uf_control),
- frame_index,
- (void **)&frame_header);
- word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
- sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
- if (ssp_hdr.frame_type == SSP_RESPONSE) {
- struct ssp_response_iu *resp_iu;
- ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
- status = scic_sds_unsolicited_frame_control_get_buffer(
- &(scic_sds_request_get_controller(sci_req)->uf_control),
- frame_index,
- (void **)&resp_iu);
- sci_swab32_cpy(&sci_req->ssp.rsp,
- resp_iu, word_cnt);
- resp_iu = &sci_req->ssp.rsp;
- if ((resp_iu->datapres == 0x01) ||
- (resp_iu->datapres == 0x02)) {
- scic_sds_request_set_status(
- sci_req,
- SCU_TASK_DONE_CHECK_RESPONSE,
- SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
- } else
- scic_sds_request_set_status(
- sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
- } else {
- /* This was not a response frame why did it get forwarded? */
- dev_err(scic_to_dev(sci_req->owning_controller),
- "%s: SCIC IO Request 0x%p received unexpected "
- "frame %d type 0x%02x\n",
- __func__,
- sci_req,
- frame_index,
- ssp_hdr.frame_type);
- }
- /*
- * In any case we are done with this frame buffer return it to the
- * controller
- */
- scic_sds_controller_release_frame(
- sci_req->owning_controller, frame_index);
- return SCI_SUCCESS;
- }
- /*
- * *****************************************************************************
- * * COMPLETED STATE HANDLERS
- * ***************************************************************************** */
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_complete() request. This method frees up
- * any io request resources that have been allocated and transitions the
- * request to its final state. Consider stopping the state machine instead of
- * transitioning to the final state? enum sci_status SCI_SUCCESS
- */
- static enum sci_status scic_sds_request_completed_state_complete_handler(
- struct scic_sds_request *request)
- {
- if (request->was_tag_assigned_by_user != true) {
- scic_controller_free_io_tag(
- request->owning_controller, request->io_tag);
- }
- if (request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
- scic_sds_controller_release_frame(
- request->owning_controller, request->saved_rx_frame_index);
- }
- sci_base_state_machine_change_state(&request->state_machine,
- SCI_BASE_REQUEST_STATE_FINAL);
- return SCI_SUCCESS;
- }
- /*
- * *****************************************************************************
- * * ABORTING STATE HANDLERS
- * ***************************************************************************** */
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_terminate() request. This method is the
- * io request aborting state abort handlers. On receipt of a multiple
- * terminate requests the io request will transition to the completed state.
- * This should not happen in normal operation. enum sci_status SCI_SUCCESS
- */
- static enum sci_status scic_sds_request_aborting_state_abort_handler(
- struct scic_sds_request *request)
- {
- sci_base_state_machine_change_state(&request->state_machine,
- SCI_BASE_REQUEST_STATE_COMPLETED);
- return SCI_SUCCESS;
- }
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_task_completion() request. This method
- * decodes the completion type waiting for the abort task complete
- * notification. When the abort task complete is received the io request
- * transitions to the completed state. enum sci_status SCI_SUCCESS
- */
- static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
- struct scic_sds_request *sci_req,
- u32 completion_code)
- {
- switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
- case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
- case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
- scic_sds_request_set_status(
- sci_req, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
- );
- sci_base_state_machine_change_state(&sci_req->state_machine,
- SCI_BASE_REQUEST_STATE_COMPLETED);
- break;
- default:
- /*
- * Unless we get some strange error wait for the task abort to complete
- * TODO: Should there be a state change for this completion? */
- break;
- }
- return SCI_SUCCESS;
- }
- /*
- * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
- * object receives a scic_sds_request_frame_handler() request. This method
- * discards the unsolicited frame since we are waiting for the abort task
- * completion. enum sci_status SCI_SUCCESS
- */
- static enum sci_status scic_sds_request_aborting_state_frame_handler(
- struct scic_sds_request *sci_req,
- u32 frame_index)
- {
- /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
- scic_sds_controller_release_frame(
- sci_req->owning_controller, frame_index);
- return SCI_SUCCESS;
- }
- static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
- [SCI_BASE_REQUEST_STATE_INITIAL] = {
- },
- [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
- .start_handler = scic_sds_request_constructed_state_start_handler,
- .abort_handler = scic_sds_request_constructed_state_abort_handler,
- },
- [SCI_BASE_REQUEST_STATE_STARTED] = {
- .abort_handler = scic_sds_request_started_state_abort_handler,
- .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
- .frame_handler = scic_sds_request_started_state_frame_handler,
- },
- [SCI_BASE_REQUEST_STATE_COMPLETED] = {
- .complete_handler = scic_sds_request_completed_state_complete_handler,
- },
- [SCI_BASE_REQUEST_STATE_ABORTING] = {
- .abort_handler = scic_sds_request_aborting_state_abort_handler,
- .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
- .frame_handler = scic_sds_request_aborting_state_frame_handler,
- },
- [SCI_BASE_REQUEST_STATE_FINAL] = {
- },
- };
- /**
- * isci_request_process_response_iu() - This function sets the status and
- * response iu, in the task struct, from the request object for the upper
- * layer driver.
- * @sas_task: This parameter is the task struct from the upper layer driver.
- * @resp_iu: This parameter points to the response iu of the completed request.
- * @dev: This parameter specifies the linux device struct.
- *
- * none.
- */
- static void isci_request_process_response_iu(
- struct sas_task *task,
- struct ssp_response_iu *resp_iu,
- struct device *dev)
- {
- dev_dbg(dev,
- "%s: resp_iu = %p "
- "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
- "resp_iu->response_data_len = %x, "
- "resp_iu->sense_data_len = %x\nrepsonse data: ",
- __func__,
- resp_iu,
- resp_iu->status,
- resp_iu->datapres,
- resp_iu->response_data_len,
- resp_iu->sense_data_len);
- task->task_status.stat = resp_iu->status;
- /* libsas updates the task status fields based on the response iu. */
- sas_ssp_task_response(dev, task, resp_iu);
- }
- /**
- * isci_request_set_open_reject_status() - This function prepares the I/O
- * completion for OPEN_REJECT conditions.
- * @request: This parameter is the completed isci_request object.
- * @response_ptr: This parameter specifies the service response for the I/O.
- * @status_ptr: This parameter specifies the exec status for the I/O.
- * @complete_to_host_ptr: This parameter specifies the action to be taken by
- * the LLDD with respect to completing this request or forcing an abort
- * condition on the I/O.
- * @open_rej_reason: This parameter specifies the encoded reason for the
- * abandon-class reject.
- *
- * none.
- */
- static void isci_request_set_open_reject_status(
- struct isci_request *request,
- struct sas_task *task,
- enum service_response *response_ptr,
- enum exec_status *status_ptr,
- enum isci_completion_selection *complete_to_host_ptr,
- enum sas_open_rej_reason open_rej_reason)
- {
- /* Task in the target is done. */
- request->complete_in_target = true;
- *response_ptr = SAS_TASK_UNDELIVERED;
- *status_ptr = SAS_OPEN_REJECT;
- *complete_to_host_ptr = isci_perform_normal_io_completion;
- task->task_status.open_rej_reason = open_rej_reason;
- }
- /**
- * isci_request_handle_controller_specific_errors() - This function decodes
- * controller-specific I/O completion error conditions.
- * @request: This parameter is the completed isci_request object.
- * @response_ptr: This parameter specifies the service response for the I/O.
- * @status_ptr: This parameter specifies the exec status for the I/O.
- * @complete_to_host_ptr: This parameter specifies the action to be taken by
- * the LLDD with respect to completing this request or forcing an abort
- * condition on the I/O.
- *
- * none.
- */
- static void isci_request_handle_controller_specific_errors(
- struct isci_remote_device *isci_device,
- struct isci_request *request,
- struct sas_task *task,
- enum service_response *response_ptr,
- enum exec_status *status_ptr,
- enum isci_completion_selection *complete_to_host_ptr)
- {
- unsigned int cstatus;
- cstatus = request->sci.scu_status;
- dev_dbg(&request->isci_host->pdev->dev,
- "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
- "- controller status = 0x%x\n",
- __func__, request, cstatus);
- /* Decode the controller-specific errors; most
- * important is to recognize those conditions in which
- * the target may still have a task outstanding that
- * must be aborted.
- *
- * Note that there are SCU completion codes being
- * named in the decode below for which SCIC has already
- * done work to handle them in a way other than as
- * a controller-specific completion code; these are left
- * in the decode below for completeness sake.
- */
- switch (cstatus) {
- case SCU_TASK_DONE_DMASETUP_DIRERR:
- /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
- case SCU_TASK_DONE_XFERCNT_ERR:
- /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
- if (task->task_proto == SAS_PROTOCOL_SMP) {
- /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
- *response_ptr = SAS_TASK_COMPLETE;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- *status_ptr = SAS_DEVICE_UNKNOWN;
- else
- *status_ptr = SAS_ABORTED_TASK;
- request->complete_in_target = true;
- *complete_to_host_ptr =
- isci_perform_normal_io_completion;
- } else {
- /* Task in the target is not done. */
- *response_ptr = SAS_TASK_UNDELIVERED;
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- *status_ptr = SAS_DEVICE_UNKNOWN;
- else
- *status_ptr = SAM_STAT_TASK_ABORTED;
- request->complete_in_target = false;
- *complete_to_host_ptr =
- isci_perform_error_io_completion;
- }
- break;
- case SCU_TASK_DONE_CRC_ERR:
- case SCU_TASK_DONE_NAK_CMD_ERR:
- case SCU_TASK_DONE_EXCESS_DATA:
- case SCU_TASK_DONE_UNEXP_FIS:
- /* Also SCU_TASK_DONE_UNEXP_RESP: */
- case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
- case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
- case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
- /* These are conditions in which the target
- * has completed the task, so that no cleanup
- * is necessary.
- */
- *response_ptr = SAS_TASK_COMPLETE;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- *status_ptr = SAS_DEVICE_UNKNOWN;
- else
- *status_ptr = SAS_ABORTED_TASK;
- request->complete_in_target = true;
- *complete_to_host_ptr = isci_perform_normal_io_completion;
- break;
- /* Note that the only open reject completion codes seen here will be
- * abandon-class codes; all others are automatically retried in the SCU.
- */
- case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
- break;
- case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
- /* Note - the return of AB0 will change when
- * libsas implements detection of zone violations.
- */
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_RESV_AB0);
- break;
- case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_RESV_AB1);
- break;
- case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_RESV_AB2);
- break;
- case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_RESV_AB3);
- break;
- case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_BAD_DEST);
- break;
- case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_STP_NORES);
- break;
- case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_EPROTO);
- break;
- case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
- isci_request_set_open_reject_status(
- request, task, response_ptr, status_ptr,
- complete_to_host_ptr, SAS_OREJ_CONN_RATE);
- break;
- case SCU_TASK_DONE_LL_R_ERR:
- /* Also SCU_TASK_DONE_ACK_NAK_TO: */
- case SCU_TASK_DONE_LL_PERR:
- case SCU_TASK_DONE_LL_SY_TERM:
- /* Also SCU_TASK_DONE_NAK_ERR:*/
- case SCU_TASK_DONE_LL_LF_TERM:
- /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
- case SCU_TASK_DONE_LL_ABORT_ERR:
- case SCU_TASK_DONE_SEQ_INV_TYPE:
- /* Also SCU_TASK_DONE_UNEXP_XR: */
- case SCU_TASK_DONE_XR_IU_LEN_ERR:
- case SCU_TASK_DONE_INV_FIS_LEN:
- /* Also SCU_TASK_DONE_XR_WD_LEN: */
- case SCU_TASK_DONE_SDMA_ERR:
- case SCU_TASK_DONE_OFFSET_ERR:
- case SCU_TASK_DONE_MAX_PLD_ERR:
- case SCU_TASK_DONE_LF_ERR:
- case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
- case SCU_TASK_DONE_SMP_LL_RX_ERR:
- case SCU_TASK_DONE_UNEXP_DATA:
- case SCU_TASK_DONE_UNEXP_SDBFIS:
- case SCU_TASK_DONE_REG_ERR:
- case SCU_TASK_DONE_SDB_ERR:
- case SCU_TASK_DONE_TASK_ABORT:
- default:
- /* Task in the target is not done. */
- *response_ptr = SAS_TASK_UNDELIVERED;
- *status_ptr = SAM_STAT_TASK_ABORTED;
- request->complete_in_target = false;
- *complete_to_host_ptr = isci_perform_error_io_completion;
- break;
- }
- }
- /**
- * isci_task_save_for_upper_layer_completion() - This function saves the
- * request for later completion to the upper layer driver.
- * @host: This parameter is a pointer to the host on which the the request
- * should be queued (either as an error or success).
- * @request: This parameter is the completed request.
- * @response: This parameter is the response code for the completed task.
- * @status: This parameter is the status code for the completed task.
- *
- * none.
- */
- static void isci_task_save_for_upper_layer_completion(
- struct isci_host *host,
- struct isci_request *request,
- enum service_response response,
- enum exec_status status,
- enum isci_completion_selection task_notification_selection)
- {
- struct sas_task *task = isci_request_access_task(request);
- task_notification_selection
- = isci_task_set_completion_status(task, response, status,
- task_notification_selection);
- /* Tasks aborted specifically by a call to the lldd_abort_task
- * function should not be completed to the host in the regular path.
- */
- switch (task_notification_selection) {
- case isci_perform_normal_io_completion:
- /* Normal notification (task_done) */
- dev_dbg(&host->pdev->dev,
- "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
- __func__,
- task,
- task->task_status.resp, response,
- task->task_status.stat, status);
- /* Add to the completed list. */
- list_add(&request->completed_node,
- &host->requests_to_complete);
- /* Take the request off the device's pending request list. */
- list_del_init(&request->dev_node);
- break;
- case isci_perform_aborted_io_completion:
- /* No notification to libsas because this request is
- * already in the abort path.
- */
- dev_warn(&host->pdev->dev,
- "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
- __func__,
- task,
- task->task_status.resp, response,
- task->task_status.stat, status);
- /* Wake up whatever process was waiting for this
- * request to complete.
- */
- WARN_ON(request->io_request_completion == NULL);
- if (request->io_request_completion != NULL) {
- /* Signal whoever is waiting that this
- * request is complete.
- */
- complete(request->io_request_completion);
- }
- break;
- case isci_perform_error_io_completion:
- /* Use sas_task_abort */
- dev_warn(&host->pdev->dev,
- "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
- __func__,
- task,
- task->task_status.resp, response,
- task->task_status.stat, status);
- /* Add to the aborted list. */
- list_add(&request->completed_node,
- &host->requests_to_errorback);
- break;
- default:
- dev_warn(&host->pdev->dev,
- "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
- __func__,
- task,
- task->task_status.resp, response,
- task->task_status.stat, status);
- /* Add to the error to libsas list. */
- list_add(&request->completed_node,
- &host->requests_to_errorback);
- break;
- }
- }
- static void isci_request_io_request_complete(struct isci_host *isci_host,
- struct isci_request *request,
- enum sci_io_status completion_status)
- {
- struct sas_task *task = isci_request_access_task(request);
- struct ssp_response_iu *resp_iu;
- void *resp_buf;
- unsigned long task_flags;
- struct isci_remote_device *isci_device = request->isci_device;
- enum service_response response = SAS_TASK_UNDELIVERED;
- enum exec_status status = SAS_ABORTED_TASK;
- enum isci_request_status request_status;
- enum isci_completion_selection complete_to_host
- = isci_perform_normal_io_completion;
- dev_dbg(&isci_host->pdev->dev,
- "%s: request = %p, task = %p,\n"
- "task->data_dir = %d completion_status = 0x%x\n",
- __func__,
- request,
- task,
- task->data_dir,
- completion_status);
- spin_lock(&request->state_lock);
- request_status = isci_request_get_state(request);
- /* Decode the request status. Note that if the request has been
- * aborted by a task management function, we don't care
- * what the status is.
- */
- switch (request_status) {
- case aborted:
- /* "aborted" indicates that the request was aborted by a task
- * management function, since once a task management request is
- * perfomed by the device, the request only completes because
- * of the subsequent driver terminate.
- *
- * Aborted also means an external thread is explicitly managing
- * this request, so that we do not complete it up the stack.
- *
- * The target is still there (since the TMF was successful).
- */
- request->complete_in_target = true;
- response = SAS_TASK_COMPLETE;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping)
- || (isci_device->status == isci_stopped)
- )
- status = SAS_DEVICE_UNKNOWN;
- else
- status = SAS_ABORTED_TASK;
- complete_to_host = isci_perform_aborted_io_completion;
- /* This was an aborted request. */
- spin_unlock(&request->state_lock);
- break;
- case aborting:
- /* aborting means that the task management function tried and
- * failed to abort the request. We need to note the request
- * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
- * target as down.
- *
- * Aborting also means an external thread is explicitly managing
- * this request, so that we do not complete it up the stack.
- */
- request->complete_in_target = true;
- response = SAS_TASK_UNDELIVERED;
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- /* The device has been /is being stopped. Note that
- * we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- status = SAS_DEVICE_UNKNOWN;
- else
- status = SAS_PHY_DOWN;
- complete_to_host = isci_perform_aborted_io_completion;
- /* This was an aborted request. */
- spin_unlock(&request->state_lock);
- break;
- case terminating:
- /* This was an terminated request. This happens when
- * the I/O is being terminated because of an action on
- * the device (reset, tear down, etc.), and the I/O needs
- * to be completed up the stack.
- */
- request->complete_in_target = true;
- response = SAS_TASK_UNDELIVERED;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- status = SAS_DEVICE_UNKNOWN;
- else
- status = SAS_ABORTED_TASK;
- complete_to_host = isci_perform_aborted_io_completion;
- /* This was a terminated request. */
- spin_unlock(&request->state_lock);
- break;
- default:
- /* The request is done from an SCU HW perspective. */
- request->status = completed;
- spin_unlock(&request->state_lock);
- /* This is an active request being completed from the core. */
- switch (completion_status) {
- case SCI_IO_FAILURE_RESPONSE_VALID:
- dev_dbg(&isci_host->pdev->dev,
- "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
- __func__,
- request,
- task);
- if (sas_protocol_ata(task->task_proto)) {
- resp_buf = &request->sci.stp.rsp;
- isci_request_process_stp_response(task,
- resp_buf);
- } else if (SAS_PROTOCOL_SSP == task->task_proto) {
- /* crack the iu response buffer. */
- resp_iu = &request->sci.ssp.rsp;
- isci_request_process_response_iu(task, resp_iu,
- &isci_host->pdev->dev);
- } else if (SAS_PROTOCOL_SMP == task->task_proto) {
- dev_err(&isci_host->pdev->dev,
- "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
- "SAS_PROTOCOL_SMP protocol\n",
- __func__);
- } else
- dev_err(&isci_host->pdev->dev,
- "%s: unknown protocol\n", __func__);
- /* use the task status set in the task struct by the
- * isci_request_process_response_iu call.
- */
- request->complete_in_target = true;
- response = task->task_status.resp;
- status = task->task_status.stat;
- break;
- case SCI_IO_SUCCESS:
- case SCI_IO_SUCCESS_IO_DONE_EARLY:
- response = SAS_TASK_COMPLETE;
- status = SAM_STAT_GOOD;
- request->complete_in_target = true;
- if (task->task_proto == SAS_PROTOCOL_SMP) {
- void *rsp = &request->sci.smp.rsp;
- dev_dbg(&isci_host->pdev->dev,
- "%s: SMP protocol completion\n",
- __func__);
- sg_copy_from_buffer(
- &task->smp_task.smp_resp, 1,
- rsp, sizeof(struct smp_resp));
- } else if (completion_status
- == SCI_IO_SUCCESS_IO_DONE_EARLY) {
- /* This was an SSP / STP / SATA transfer.
- * There is a possibility that less data than
- * the maximum was transferred.
- */
- u32 transferred_length = sci_req_tx_bytes(&request->sci);
- task->task_status.residual
- = task->total_xfer_len - transferred_length;
- /* If there were residual bytes, call this an
- * underrun.
- */
- if (task->task_status.residual != 0)
- status = SAS_DATA_UNDERRUN;
- dev_dbg(&isci_host->pdev->dev,
- "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
- __func__,
- status);
- } else
- dev_dbg(&isci_host->pdev->dev,
- "%s: SCI_IO_SUCCESS\n",
- __func__);
- break;
- case SCI_IO_FAILURE_TERMINATED:
- dev_dbg(&isci_host->pdev->dev,
- "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
- __func__,
- request,
- task);
- /* The request was terminated explicitly. No handling
- * is needed in the SCSI error handler path.
- */
- request->complete_in_target = true;
- response = SAS_TASK_UNDELIVERED;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- status = SAS_DEVICE_UNKNOWN;
- else
- status = SAS_ABORTED_TASK;
- complete_to_host = isci_perform_normal_io_completion;
- break;
- case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
- isci_request_handle_controller_specific_errors(
- isci_device, request, task, &response, &status,
- &complete_to_host);
- break;
- case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
- /* This is a special case, in that the I/O completion
- * is telling us that the device needs a reset.
- * In order for the device reset condition to be
- * noticed, the I/O has to be handled in the error
- * handler. Set the reset flag and cause the
- * SCSI error thread to be scheduled.
- */
- spin_lock_irqsave(&task->task_state_lock, task_flags);
- task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
- spin_unlock_irqrestore(&task->task_state_lock, task_flags);
- /* Fail the I/O. */
- response = SAS_TASK_UNDELIVERED;
- status = SAM_STAT_TASK_ABORTED;
- complete_to_host = isci_perform_error_io_completion;
- request->complete_in_target = false;
- break;
- default:
- /* Catch any otherwise unhandled error codes here. */
- dev_warn(&isci_host->pdev->dev,
- "%s: invalid completion code: 0x%x - "
- "isci_request = %p\n",
- __func__, completion_status, request);
- response = SAS_TASK_UNDELIVERED;
- /* See if the device has been/is being stopped. Note
- * that we ignore the quiesce state, since we are
- * concerned about the actual device state.
- */
- if ((isci_device->status == isci_stopping) ||
- (isci_device->status == isci_stopped))
- status = SAS_DEVICE_UNKNOWN;
- else
- status = SAS_ABORTED_TASK;
- complete_to_host = isci_perform_error_io_completion;
- request->complete_in_target = false;
- break;
- }
- break;
- }
- isci_request_unmap_sgl(request, isci_host->pdev);
- /* Put the completed request on the correct list */
- isci_task_save_for_upper_layer_completion(isci_host, request, response,
- status, complete_to_host
- );
- /* complete the io request to the core. */
- scic_controller_complete_io(&isci_host->sci,
- &isci_device->sci,
- &request->sci);
- /* set terminated handle so it cannot be completed or
- * terminated again, and to cause any calls into abort
- * task to recognize the already completed case.
- */
- request->terminated = true;
- isci_host_can_dequeue(isci_host, 1);
- }
- /**
- * scic_sds_request_initial_state_enter() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
- * base request is constructed. Entry into the initial state sets all handlers
- * for the io request object to their default handlers. none
- */
- static void scic_sds_request_initial_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- SET_STATE_HANDLER(
- sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_INITIAL
- );
- }
- /**
- * scic_sds_request_constructed_state_enter() -
- * @object: The io request object that is to enter the constructed state.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
- * for the the constructed state. none
- */
- static void scic_sds_request_constructed_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- SET_STATE_HANDLER(
- sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_CONSTRUCTED
- );
- }
- /**
- * scic_sds_request_started_state_enter() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
- * SCSI Task request we must enter the started substate machine. none
- */
- static void scic_sds_request_started_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- SET_STATE_HANDLER(
- sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_STARTED
- );
- /*
- * Most of the request state machines have a started substate machine so
- * start its execution on the entry to the started state. */
- if (sci_req->has_started_substate_machine == true)
- sci_base_state_machine_start(&sci_req->started_substate_machine);
- }
- /**
- * scic_sds_request_started_state_exit() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
- * object.
- *
- * This method implements the actions taken when exiting the
- * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
- * to stop the started substate machine. none
- */
- static void scic_sds_request_started_state_exit(void *object)
- {
- struct scic_sds_request *sci_req = object;
- if (sci_req->has_started_substate_machine == true)
- sci_base_state_machine_stop(&sci_req->started_substate_machine);
- }
- /**
- * scic_sds_request_completed_state_enter() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
- * object.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
- * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
- * completion status and convert it to an enum sci_status to return in the
- * completion callback function. none
- */
- static void scic_sds_request_completed_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- struct scic_sds_controller *scic =
- scic_sds_request_get_controller(sci_req);
- struct isci_host *ihost = scic_to_ihost(scic);
- struct isci_request *ireq = sci_req_to_ireq(sci_req);
- SET_STATE_HANDLER(sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_COMPLETED);
- /* Tell the SCI_USER that the IO request is complete */
- if (sci_req->is_task_management_request == false)
- isci_request_io_request_complete(ihost, ireq,
- sci_req->sci_status);
- else
- isci_task_request_complete(ihost, ireq, sci_req->sci_status);
- }
- /**
- * scic_sds_request_aborting_state_enter() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
- * object.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_ABORTING state. none
- */
- static void scic_sds_request_aborting_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- /* Setting the abort bit in the Task Context is required by the silicon. */
- sci_req->task_context_buffer->abort = 1;
- SET_STATE_HANDLER(
- sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_ABORTING
- );
- }
- /**
- * scic_sds_request_final_state_enter() -
- * @object: This parameter specifies the base object for which the state
- * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
- *
- * This method implements the actions taken when entering the
- * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
- * state handlers in place. none
- */
- static void scic_sds_request_final_state_enter(void *object)
- {
- struct scic_sds_request *sci_req = object;
- SET_STATE_HANDLER(
- sci_req,
- scic_sds_request_state_handler_table,
- SCI_BASE_REQUEST_STATE_FINAL
- );
- }
- static const struct sci_base_state scic_sds_request_state_table[] = {
- [SCI_BASE_REQUEST_STATE_INITIAL] = {
- .enter_state = scic_sds_request_initial_state_enter,
- },
- [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
- .enter_state = scic_sds_request_constructed_state_enter,
- },
- [SCI_BASE_REQUEST_STATE_STARTED] = {
- .enter_state = scic_sds_request_started_state_enter,
- .exit_state = scic_sds_request_started_state_exit
- },
- [SCI_BASE_REQUEST_STATE_COMPLETED] = {
- .enter_state = scic_sds_request_completed_state_enter,
- },
- [SCI_BASE_REQUEST_STATE_ABORTING] = {
- .enter_state = scic_sds_request_aborting_state_enter,
- },
- [SCI_BASE_REQUEST_STATE_FINAL] = {
- .enter_state = scic_sds_request_final_state_enter,
- },
- };
- static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
- struct scic_sds_remote_device *sci_dev,
- u16 io_tag, struct scic_sds_request *sci_req)
- {
- sci_base_state_machine_construct(&sci_req->state_machine, sci_req,
- scic_sds_request_state_table, SCI_BASE_REQUEST_STATE_INITIAL);
- sci_base_state_machine_start(&sci_req->state_machine);
- sci_req->io_tag = io_tag;
- sci_req->owning_controller = scic;
- sci_req->target_device = sci_dev;
- sci_req->has_started_substate_machine = false;
- sci_req->protocol = SCIC_NO_PROTOCOL;
- sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
- sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
- sci_req->sci_status = SCI_SUCCESS;
- sci_req->scu_status = 0;
- sci_req->post_context = 0xFFFFFFFF;
- sci_req->is_task_management_request = false;
- if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
- sci_req->was_tag_assigned_by_user = false;
- sci_req->task_context_buffer = NULL;
- } else {
- sci_req->was_tag_assigned_by_user = true;
- sci_req->task_context_buffer =
- scic_sds_controller_get_task_context_buffer(scic, io_tag);
- }
- }
- static enum sci_status
- scic_io_request_construct(struct scic_sds_controller *scic,
- struct scic_sds_remote_device *sci_dev,
- u16 io_tag, struct scic_sds_request *sci_req)
- {
- struct domain_device *dev = sci_dev_to_domain(sci_dev);
- enum sci_status status = SCI_SUCCESS;
- /* Build the common part of the request */
- scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
- if (sci_dev->rnc.remote_node_index ==
- SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
- return SCI_FAILURE_INVALID_REMOTE_DEVICE;
- if (dev->dev_type == SAS_END_DEV)
- scic_sds_ssp_io_request_assign_buffers(sci_req);
- else if ((dev->dev_type == SATA_DEV) ||
- (dev->tproto & SAS_PROTOCOL_STP)) {
- scic_sds_stp_request_assign_buffers(sci_req);
- memset(&sci_req->stp.cmd, 0, sizeof(sci_req->stp.cmd));
- } else if (dev_is_expander(dev)) {
- scic_sds_smp_request_assign_buffers(sci_req);
- memset(&sci_req->smp.cmd, 0, sizeof(sci_req->smp.cmd));
- } else
- status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
- if (status == SCI_SUCCESS) {
- memset(sci_req->task_context_buffer, 0,
- offsetof(struct scu_task_context, sgl_pair_ab));
- }
- return status;
- }
- enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
- struct scic_sds_remote_device *sci_dev,
- u16 io_tag, struct scic_sds_request *sci_req)
- {
- struct domain_device *dev = sci_dev_to_domain(sci_dev);
- enum sci_status status = SCI_SUCCESS;
- /* Build the common part of the request */
- scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
- if (dev->dev_type == SAS_END_DEV) {
- scic_sds_ssp_task_request_assign_buffers(sci_req);
- sci_req->has_started_substate_machine = true;
- /* Construct the started sub-state machine. */
- sci_base_state_machine_construct(
- &sci_req->started_substate_machine,
- sci_req,
- scic_sds_io_request_started_task_mgmt_substate_table,
- SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
- );
- } else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
- scic_sds_stp_request_assign_buffers(sci_req);
- else
- status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
- if (status == SCI_SUCCESS) {
- sci_req->is_task_management_request = true;
- memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
- }
- return status;
- }
- static enum sci_status isci_request_ssp_request_construct(
- struct isci_request *request)
- {
- enum sci_status status;
- dev_dbg(&request->isci_host->pdev->dev,
- "%s: request = %p\n",
- __func__,
- request);
- status = scic_io_request_construct_basic_ssp(&request->sci);
- return status;
- }
- static enum sci_status isci_request_stp_request_construct(
- struct isci_request *request)
- {
- struct sas_task *task = isci_request_access_task(request);
- enum sci_status status;
- struct host_to_dev_fis *register_fis;
- dev_dbg(&request->isci_host->pdev->dev,
- "%s: request = %p\n",
- __func__,
- request);
- /* Get the host_to_dev_fis from the core and copy
- * the fis from the task into it.
- */
- register_fis = isci_sata_task_to_fis_copy(task);
- status = scic_io_request_construct_basic_sata(&request->sci);
- /* Set the ncq tag in the fis, from the queue
- * command in the task.
- */
- if (isci_sata_is_task_ncq(task)) {
- isci_sata_set_ncq_tag(
- register_fis,
- task
- );
- }
- return status;
- }
- /*
- * isci_smp_request_build() - This function builds the smp request.
- * @ireq: This parameter points to the isci_request allocated in the
- * request construct function.
- *
- * SCI_SUCCESS on successfull completion, or specific failure code.
- */
- static enum sci_status isci_smp_request_build(struct isci_request *ireq)
- {
- enum sci_status status = SCI_FAILURE;
- struct sas_task *task = isci_request_access_task(ireq);
- struct scic_sds_request *sci_req = &ireq->sci;
- dev_dbg(&ireq->isci_host->pdev->dev,
- "%s: request = %p\n", __func__, ireq);
- dev_dbg(&ireq->isci_host->pdev->dev,
- "%s: smp_req len = %d\n",
- __func__,
- task->smp_task.smp_req.length);
- /* copy the smp_command to the address; */
- sg_copy_to_buffer(&task->smp_task.smp_req, 1,
- &sci_req->smp.cmd,
- sizeof(struct smp_req));
- status = scic_io_request_construct_smp(sci_req);
- if (status != SCI_SUCCESS)
- dev_warn(&ireq->isci_host->pdev->dev,
- "%s: failed with status = %d\n",
- __func__,
- status);
- return status;
- }
- /**
- * isci_io_request_build() - This function builds the io request object.
- * @isci_host: This parameter specifies the ISCI host object
- * @request: This parameter points to the isci_request object allocated in the
- * request construct function.
- * @sci_device: This parameter is the handle for the sci core's remote device
- * object that is the destination for this request.
- *
- * SCI_SUCCESS on successfull completion, or specific failure code.
- */
- static enum sci_status isci_io_request_build(
- struct isci_host *isci_host,
- struct isci_request *request,
- struct isci_remote_device *isci_device)
- {
- enum sci_status status = SCI_SUCCESS;
- struct sas_task *task = isci_request_access_task(request);
- struct scic_sds_remote_device *sci_device = &isci_device->sci;
- dev_dbg(&isci_host->pdev->dev,
- "%s: isci_device = 0x%p; request = %p, "
- "num_scatter = %d\n",
- __func__,
- isci_device,
- request,
- task->num_scatter);
- /* map the sgl addresses, if present.
- * libata does the mapping for sata devices
- * before we get the request.
- */
- if (task->num_scatter &&
- !sas_protocol_ata(task->task_proto) &&
- !(SAS_PROTOCOL_SMP & task->task_proto)) {
- request->num_sg_entries = dma_map_sg(
- &isci_host->pdev->dev,
- task->scatter,
- task->num_scatter,
- task->data_dir
- );
- if (request->num_sg_entries == 0)
- return SCI_FAILURE_INSUFFICIENT_RESOURCES;
- }
- /* build the common request object. For now,
- * we will let the core allocate the IO tag.
- */
- status = scic_io_request_construct(&isci_host->sci, sci_device,
- SCI_CONTROLLER_INVALID_IO_TAG,
- &request->sci);
- if (status != SCI_SUCCESS) {
- dev_warn(&isci_host->pdev->dev,
- "%s: failed request construct\n",
- __func__);
- return SCI_FAILURE;
- }
- switch (task->task_proto) {
- case SAS_PROTOCOL_SMP:
- status = isci_smp_request_build(request);
- break;
- case SAS_PROTOCOL_SSP:
- status = isci_request_ssp_request_construct(request);
- break;
- case SAS_PROTOCOL_SATA:
- case SAS_PROTOCOL_STP:
- case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
- status = isci_request_stp_request_construct(request);
- break;
- default:
- dev_warn(&isci_host->pdev->dev,
- "%s: unknown protocol\n", __func__);
- return SCI_FAILURE;
- }
- return SCI_SUCCESS;
- }
- /**
- * isci_request_alloc_core() - This function gets the request object from the
- * isci_host dma cache.
- * @isci_host: This parameter specifies the ISCI host object
- * @isci_request: This parameter will contain the pointer to the new
- * isci_request object.
- * @isci_device: This parameter is the pointer to the isci remote device object
- * that is the destination for this request.
- * @gfp_flags: This parameter specifies the os allocation flags.
- *
- * SCI_SUCCESS on successfull completion, or specific failure code.
- */
- static int isci_request_alloc_core(
- struct isci_host *isci_host,
- struct isci_request **isci_request,
- struct isci_remote_device *isci_device,
- gfp_t gfp_flags)
- {
- int ret = 0;
- dma_addr_t handle;
- struct isci_request *request;
- /* get pointer to dma memory. This actually points
- * to both the isci_remote_device object and the
- * sci object. The isci object is at the beginning
- * of the memory allocated here.
- */
- request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
- if (!request) {
- dev_warn(&isci_host->pdev->dev,
- "%s: dma_pool_alloc returned NULL\n", __func__);
- return -ENOMEM;
- }
- /* initialize the request object. */
- spin_lock_init(&request->state_lock);
- request->request_daddr = handle;
- request->isci_host = isci_host;
- request->isci_device = isci_device;
- request->io_request_completion = NULL;
- request->terminated = false;
- request->num_sg_entries = 0;
- request->complete_in_target = false;
- INIT_LIST_HEAD(&request->completed_node);
- INIT_LIST_HEAD(&request->dev_node);
- *isci_request = request;
- isci_request_change_state(request, allocated);
- return ret;
- }
- static int isci_request_alloc_io(
- struct isci_host *isci_host,
- struct sas_task *task,
- struct isci_request **isci_request,
- struct isci_remote_device *isci_device,
- gfp_t gfp_flags)
- {
- int retval = isci_request_alloc_core(isci_host, isci_request,
- isci_device, gfp_flags);
- if (!retval) {
- (*isci_request)->ttype_ptr.io_task_ptr = task;
- (*isci_request)->ttype = io_task;
- task->lldd_task = *isci_request;
- }
- return retval;
- }
- /**
- * isci_request_alloc_tmf() - This function gets the request object from the
- * isci_host dma cache and initializes the relevant fields as a sas_task.
- * @isci_host: This parameter specifies the ISCI host object
- * @sas_task: This parameter is the task struct from the upper layer driver.
- * @isci_request: This parameter will contain the pointer to the new
- * isci_request object.
- * @isci_device: This parameter is the pointer to the isci remote device object
- * that is the destination for this request.
- * @gfp_flags: This parameter specifies the os allocation flags.
- *
- * SCI_SUCCESS on successfull completion, or specific failure code.
- */
- int isci_request_alloc_tmf(
- struct isci_host *isci_host,
- struct isci_tmf *isci_tmf,
- struct isci_request **isci_request,
- struct isci_remote_device *isci_device,
- gfp_t gfp_flags)
- {
- int retval = isci_request_alloc_core(isci_host, isci_request,
- isci_device, gfp_flags);
- if (!retval) {
- (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
- (*isci_request)->ttype = tmf_task;
- }
- return retval;
- }
- /**
- * isci_request_execute() - This function allocates the isci_request object,
- * all fills in some common fields.
- * @isci_host: This parameter specifies the ISCI host object
- * @sas_task: This parameter is the task struct from the upper layer driver.
- * @isci_request: This parameter will contain the pointer to the new
- * isci_request object.
- * @gfp_flags: This parameter specifies the os allocation flags.
- *
- * SCI_SUCCESS on successfull completion, or specific failure code.
- */
- int isci_request_execute(
- struct isci_host *isci_host,
- struct sas_task *task,
- struct isci_request **isci_request,
- gfp_t gfp_flags)
- {
- int ret = 0;
- struct scic_sds_remote_device *sci_device;
- enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
- struct isci_remote_device *isci_device;
- struct isci_request *request;
- unsigned long flags;
- isci_device = task->dev->lldd_dev;
- sci_device = &isci_device->sci;
- /* do common allocation and init of request object. */
- ret = isci_request_alloc_io(
- isci_host,
- task,
- &request,
- isci_device,
- gfp_flags
- );
- if (ret)
- goto out;
- status = isci_io_request_build(isci_host, request, isci_device);
- if (status != SCI_SUCCESS) {
- dev_warn(&isci_host->pdev->dev,
- "%s: request_construct failed - status = 0x%x\n",
- __func__,
- status);
- goto out;
- }
- spin_lock_irqsave(&isci_host->scic_lock, flags);
- /* send the request, let the core assign the IO TAG. */
- status = scic_controller_start_io(&isci_host->sci, sci_device,
- &request->sci,
- SCI_CONTROLLER_INVALID_IO_TAG);
- if (status != SCI_SUCCESS &&
- status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
- dev_warn(&isci_host->pdev->dev,
- "%s: failed request start (0x%x)\n",
- __func__, status);
- spin_unlock_irqrestore(&isci_host->scic_lock, flags);
- goto out;
- }
- /* Either I/O started OK, or the core has signaled that
- * the device needs a target reset.
- *
- * In either case, hold onto the I/O for later.
- *
- * Update it's status and add it to the list in the
- * remote device object.
- */
- isci_request_change_state(request, started);
- list_add(&request->dev_node, &isci_device->reqs_in_process);
- if (status == SCI_SUCCESS) {
- /* Save the tag for possible task mgmt later. */
- request->io_tag = request->sci.io_tag;
- } else {
- /* The request did not really start in the
- * hardware, so clear the request handle
- * here so no terminations will be done.
- */
- request->terminated = true;
- }
- spin_unlock_irqrestore(&isci_host->scic_lock, flags);
- if (status ==
- SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
- /* Signal libsas that we need the SCSI error
- * handler thread to work on this I/O and that
- * we want a device reset.
- */
- spin_lock_irqsave(&task->task_state_lock, flags);
- task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
- spin_unlock_irqrestore(&task->task_state_lock, flags);
- /* Cause this task to be scheduled in the SCSI error
- * handler thread.
- */
- isci_execpath_callback(isci_host, task,
- sas_task_abort);
- /* Change the status, since we are holding
- * the I/O until it is managed by the SCSI
- * error handler.
- */
- status = SCI_SUCCESS;
- }
- out:
- if (status != SCI_SUCCESS) {
- /* release dma memory on failure. */
- isci_request_free(isci_host, request);
- request = NULL;
- ret = SCI_FAILURE;
- }
- *isci_request = request;
- return ret;
- }
|