request.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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 "scic_remote_device.h"
  57. #include "scic_io_request.h"
  58. #include "scic_task_request.h"
  59. #include "scic_port.h"
  60. #include "task.h"
  61. #include "request.h"
  62. #include "sata.h"
  63. #include "scu_completion_codes.h"
  64. static enum sci_status isci_request_ssp_request_construct(
  65. struct isci_request *request)
  66. {
  67. enum sci_status status;
  68. dev_dbg(&request->isci_host->pdev->dev,
  69. "%s: request = %p\n",
  70. __func__,
  71. request);
  72. status = scic_io_request_construct_basic_ssp(
  73. request->sci_request_handle
  74. );
  75. return status;
  76. }
  77. static enum sci_status isci_request_stp_request_construct(
  78. struct isci_request *request)
  79. {
  80. struct sas_task *task = isci_request_access_task(request);
  81. enum sci_status status;
  82. struct host_to_dev_fis *register_fis;
  83. dev_dbg(&request->isci_host->pdev->dev,
  84. "%s: request = %p\n",
  85. __func__,
  86. request);
  87. /* Get the host_to_dev_fis from the core and copy
  88. * the fis from the task into it.
  89. */
  90. register_fis = isci_sata_task_to_fis_copy(task);
  91. status = scic_io_request_construct_basic_sata(
  92. request->sci_request_handle
  93. );
  94. /* Set the ncq tag in the fis, from the queue
  95. * command in the task.
  96. */
  97. if (isci_sata_is_task_ncq(task)) {
  98. isci_sata_set_ncq_tag(
  99. register_fis,
  100. task
  101. );
  102. }
  103. return status;
  104. }
  105. /**
  106. * isci_smp_request_build() - This function builds the smp request object.
  107. * @isci_host: This parameter specifies the ISCI host object
  108. * @request: This parameter points to the isci_request object allocated in the
  109. * request construct function.
  110. * @sci_device: This parameter is the handle for the sci core's remote device
  111. * object that is the destination for this request.
  112. *
  113. * SCI_SUCCESS on successfull completion, or specific failure code.
  114. */
  115. static enum sci_status isci_smp_request_build(
  116. struct isci_request *request)
  117. {
  118. enum sci_status status = SCI_FAILURE;
  119. struct sas_task *task = isci_request_access_task(request);
  120. void *command_iu_address =
  121. scic_io_request_get_command_iu_address(
  122. request->sci_request_handle
  123. );
  124. dev_dbg(&request->isci_host->pdev->dev,
  125. "%s: request = %p\n",
  126. __func__,
  127. request);
  128. dev_dbg(&request->isci_host->pdev->dev,
  129. "%s: smp_req len = %d\n",
  130. __func__,
  131. task->smp_task.smp_req.length);
  132. /* copy the smp_command to the address; */
  133. sg_copy_to_buffer(&task->smp_task.smp_req, 1,
  134. (char *)command_iu_address,
  135. sizeof(struct smp_request)
  136. );
  137. status = scic_io_request_construct_smp(request->sci_request_handle);
  138. if (status != SCI_SUCCESS)
  139. dev_warn(&request->isci_host->pdev->dev,
  140. "%s: scic_io_request_construct_smp failed with "
  141. "status = %d\n",
  142. __func__,
  143. status);
  144. return status;
  145. }
  146. /**
  147. * isci_io_request_build() - This function builds the io request object.
  148. * @isci_host: This parameter specifies the ISCI host object
  149. * @request: This parameter points to the isci_request object allocated in the
  150. * request construct function.
  151. * @sci_device: This parameter is the handle for the sci core's remote device
  152. * object that is the destination for this request.
  153. *
  154. * SCI_SUCCESS on successfull completion, or specific failure code.
  155. */
  156. static enum sci_status isci_io_request_build(
  157. struct isci_host *isci_host,
  158. struct isci_request *request,
  159. struct isci_remote_device *isci_device)
  160. {
  161. struct smp_discover_response_protocols dev_protocols;
  162. enum sci_status status = SCI_SUCCESS;
  163. struct sas_task *task = isci_request_access_task(request);
  164. struct scic_sds_remote_device *sci_device =
  165. isci_device->sci_device_handle;
  166. dev_dbg(&isci_host->pdev->dev,
  167. "%s: isci_device = 0x%p; request = %p, "
  168. "num_scatter = %d\n",
  169. __func__,
  170. isci_device,
  171. request,
  172. task->num_scatter);
  173. /* map the sgl addresses, if present.
  174. * libata does the mapping for sata devices
  175. * before we get the request.
  176. */
  177. if (task->num_scatter &&
  178. !sas_protocol_ata(task->task_proto) &&
  179. !(SAS_PROTOCOL_SMP & task->task_proto)) {
  180. request->num_sg_entries = dma_map_sg(
  181. &isci_host->pdev->dev,
  182. task->scatter,
  183. task->num_scatter,
  184. task->data_dir
  185. );
  186. if (request->num_sg_entries == 0)
  187. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  188. }
  189. /* build the common request object. For now,
  190. * we will let the core allocate the IO tag.
  191. */
  192. status = scic_io_request_construct(
  193. isci_host->core_controller,
  194. sci_device,
  195. SCI_CONTROLLER_INVALID_IO_TAG,
  196. request,
  197. request->sci_request_mem_ptr,
  198. (struct scic_sds_request **)&request->sci_request_handle
  199. );
  200. if (status != SCI_SUCCESS) {
  201. dev_warn(&isci_host->pdev->dev,
  202. "%s: failed request construct\n",
  203. __func__);
  204. return SCI_FAILURE;
  205. }
  206. sci_object_set_association(request->sci_request_handle, request);
  207. /* Determine protocol and call the appropriate basic constructor */
  208. scic_remote_device_get_protocols(sci_device, &dev_protocols);
  209. if (dev_protocols.u.bits.attached_ssp_target)
  210. status = isci_request_ssp_request_construct(request);
  211. else if (dev_protocols.u.bits.attached_stp_target)
  212. status = isci_request_stp_request_construct(request);
  213. else if (dev_protocols.u.bits.attached_smp_target)
  214. status = isci_smp_request_build(request);
  215. else {
  216. dev_warn(&isci_host->pdev->dev,
  217. "%s: unknown protocol\n", __func__);
  218. return SCI_FAILURE;
  219. }
  220. return SCI_SUCCESS;
  221. }
  222. /**
  223. * isci_request_alloc_core() - This function gets the request object from the
  224. * isci_host dma cache.
  225. * @isci_host: This parameter specifies the ISCI host object
  226. * @isci_request: This parameter will contain the pointer to the new
  227. * isci_request object.
  228. * @isci_device: This parameter is the pointer to the isci remote device object
  229. * that is the destination for this request.
  230. * @gfp_flags: This parameter specifies the os allocation flags.
  231. *
  232. * SCI_SUCCESS on successfull completion, or specific failure code.
  233. */
  234. static int isci_request_alloc_core(
  235. struct isci_host *isci_host,
  236. struct isci_request **isci_request,
  237. struct isci_remote_device *isci_device,
  238. gfp_t gfp_flags)
  239. {
  240. int ret = 0;
  241. dma_addr_t handle;
  242. struct isci_request *request;
  243. /* get pointer to dma memory. This actually points
  244. * to both the isci_remote_device object and the
  245. * sci object. The isci object is at the beginning
  246. * of the memory allocated here.
  247. */
  248. request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
  249. if (!request) {
  250. dev_warn(&isci_host->pdev->dev,
  251. "%s: dma_pool_alloc returned NULL\n", __func__);
  252. return -ENOMEM;
  253. }
  254. /* initialize the request object. */
  255. spin_lock_init(&request->state_lock);
  256. request->sci_request_mem_ptr = ((u8 *)request) +
  257. sizeof(struct isci_request);
  258. request->request_daddr = handle;
  259. request->isci_host = isci_host;
  260. request->isci_device = isci_device;
  261. request->io_request_completion = NULL;
  262. request->request_alloc_size = isci_host->dma_pool_alloc_size;
  263. request->num_sg_entries = 0;
  264. request->complete_in_target = false;
  265. INIT_LIST_HEAD(&request->completed_node);
  266. INIT_LIST_HEAD(&request->dev_node);
  267. *isci_request = request;
  268. isci_request_change_state(request, allocated);
  269. return ret;
  270. }
  271. static int isci_request_alloc_io(
  272. struct isci_host *isci_host,
  273. struct sas_task *task,
  274. struct isci_request **isci_request,
  275. struct isci_remote_device *isci_device,
  276. gfp_t gfp_flags)
  277. {
  278. int retval = isci_request_alloc_core(isci_host, isci_request,
  279. isci_device, gfp_flags);
  280. if (!retval) {
  281. (*isci_request)->ttype_ptr.io_task_ptr = task;
  282. (*isci_request)->ttype = io_task;
  283. task->lldd_task = *isci_request;
  284. }
  285. return retval;
  286. }
  287. /**
  288. * isci_request_alloc_tmf() - This function gets the request object from the
  289. * isci_host dma cache and initializes the relevant fields as a sas_task.
  290. * @isci_host: This parameter specifies the ISCI host object
  291. * @sas_task: This parameter is the task struct from the upper layer driver.
  292. * @isci_request: This parameter will contain the pointer to the new
  293. * isci_request object.
  294. * @isci_device: This parameter is the pointer to the isci remote device object
  295. * that is the destination for this request.
  296. * @gfp_flags: This parameter specifies the os allocation flags.
  297. *
  298. * SCI_SUCCESS on successfull completion, or specific failure code.
  299. */
  300. int isci_request_alloc_tmf(
  301. struct isci_host *isci_host,
  302. struct isci_tmf *isci_tmf,
  303. struct isci_request **isci_request,
  304. struct isci_remote_device *isci_device,
  305. gfp_t gfp_flags)
  306. {
  307. int retval = isci_request_alloc_core(isci_host, isci_request,
  308. isci_device, gfp_flags);
  309. if (!retval) {
  310. (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
  311. (*isci_request)->ttype = tmf_task;
  312. }
  313. return retval;
  314. }
  315. /**
  316. * isci_request_signal_device_reset() - This function will set the "device
  317. * needs target reset" flag in the given sas_tasks' task_state_flags, and
  318. * then cause the task to be added into the SCSI error handler queue which
  319. * will eventually be escalated to a target reset.
  320. *
  321. *
  322. */
  323. static void isci_request_signal_device_reset(
  324. struct isci_request *isci_request)
  325. {
  326. unsigned long flags;
  327. struct sas_task *task = isci_request_access_task(isci_request);
  328. dev_dbg(&isci_request->isci_host->pdev->dev,
  329. "%s: request=%p, task=%p\n", __func__, isci_request, task);
  330. spin_lock_irqsave(&task->task_state_lock, flags);
  331. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  332. spin_unlock_irqrestore(&task->task_state_lock, flags);
  333. /* Cause this task to be scheduled in the SCSI error handler
  334. * thread.
  335. */
  336. sas_task_abort(task);
  337. }
  338. /**
  339. * isci_request_execute() - This function allocates the isci_request object,
  340. * all fills in some common fields.
  341. * @isci_host: This parameter specifies the ISCI host object
  342. * @sas_task: This parameter is the task struct from the upper layer driver.
  343. * @isci_request: This parameter will contain the pointer to the new
  344. * isci_request object.
  345. * @gfp_flags: This parameter specifies the os allocation flags.
  346. *
  347. * SCI_SUCCESS on successfull completion, or specific failure code.
  348. */
  349. int isci_request_execute(
  350. struct isci_host *isci_host,
  351. struct sas_task *task,
  352. struct isci_request **isci_request,
  353. gfp_t gfp_flags)
  354. {
  355. int ret = 0;
  356. struct scic_sds_remote_device *sci_device;
  357. enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
  358. struct isci_remote_device *isci_device;
  359. struct isci_request *request;
  360. unsigned long flags;
  361. isci_device = isci_dev_from_domain_dev(task->dev);
  362. sci_device = isci_device->sci_device_handle;
  363. /* do common allocation and init of request object. */
  364. ret = isci_request_alloc_io(
  365. isci_host,
  366. task,
  367. &request,
  368. isci_device,
  369. gfp_flags
  370. );
  371. if (ret)
  372. goto out;
  373. status = isci_io_request_build(isci_host, request, isci_device);
  374. if (status == SCI_SUCCESS) {
  375. spin_lock_irqsave(&isci_host->scic_lock, flags);
  376. /* send the request, let the core assign the IO TAG. */
  377. status = scic_controller_start_io(
  378. isci_host->core_controller,
  379. sci_device,
  380. request->sci_request_handle,
  381. SCI_CONTROLLER_INVALID_IO_TAG
  382. );
  383. if (status == SCI_SUCCESS ||
  384. status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  385. /* Either I/O started OK, or the core has signaled that
  386. * the device needs a target reset.
  387. *
  388. * In either case, hold onto the I/O for later.
  389. *
  390. * Update it's status and add it to the list in the
  391. * remote device object.
  392. */
  393. isci_request_change_state(request, started);
  394. list_add(&request->dev_node,
  395. &isci_device->reqs_in_process);
  396. if (status ==
  397. SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
  398. /* Signal libsas that we need the SCSI error
  399. * handler thread to work on this I/O and that
  400. * we want a device reset.
  401. */
  402. isci_request_signal_device_reset(request);
  403. /* Change the status, since we are holding
  404. * the I/O until it is managed by the SCSI
  405. * error handler.
  406. */
  407. status = SCI_SUCCESS;
  408. }
  409. } else
  410. dev_warn(&isci_host->pdev->dev,
  411. "%s: failed request start\n",
  412. __func__);
  413. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  414. } else
  415. dev_warn(&isci_host->pdev->dev,
  416. "%s: request_construct failed - status = 0x%x\n",
  417. __func__,
  418. status);
  419. out:
  420. if (status != SCI_SUCCESS) {
  421. /* release dma memory on failure. */
  422. isci_request_free(isci_host, request);
  423. request = NULL;
  424. ret = SCI_FAILURE;
  425. }
  426. *isci_request = request;
  427. return ret;
  428. }
  429. /**
  430. * isci_request_process_response_iu() - This function sets the status and
  431. * response iu, in the task struct, from the request object for the upper
  432. * layer driver.
  433. * @sas_task: This parameter is the task struct from the upper layer driver.
  434. * @resp_iu: This parameter points to the response iu of the completed request.
  435. * @dev: This parameter specifies the linux device struct.
  436. *
  437. * none.
  438. */
  439. static void isci_request_process_response_iu(
  440. struct sas_task *task,
  441. struct ssp_response_iu *resp_iu,
  442. struct device *dev)
  443. {
  444. dev_dbg(dev,
  445. "%s: resp_iu = %p "
  446. "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
  447. "resp_iu->response_data_len = %x, "
  448. "resp_iu->sense_data_len = %x\nrepsonse data: ",
  449. __func__,
  450. resp_iu,
  451. resp_iu->status,
  452. resp_iu->datapres,
  453. resp_iu->response_data_len,
  454. resp_iu->sense_data_len);
  455. task->task_status.stat = resp_iu->status;
  456. /* libsas updates the task status fields based on the response iu. */
  457. sas_ssp_task_response(dev, task, resp_iu);
  458. }
  459. /**
  460. * isci_request_set_open_reject_status() - This function prepares the I/O
  461. * completion for OPEN_REJECT conditions.
  462. * @request: This parameter is the completed isci_request object.
  463. * @response_ptr: This parameter specifies the service response for the I/O.
  464. * @status_ptr: This parameter specifies the exec status for the I/O.
  465. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  466. * the LLDD with respect to completing this request or forcing an abort
  467. * condition on the I/O.
  468. * @open_rej_reason: This parameter specifies the encoded reason for the
  469. * abandon-class reject.
  470. *
  471. * none.
  472. */
  473. static void isci_request_set_open_reject_status(
  474. struct isci_request *request,
  475. struct sas_task *task,
  476. enum service_response *response_ptr,
  477. enum exec_status *status_ptr,
  478. enum isci_completion_selection *complete_to_host_ptr,
  479. enum sas_open_rej_reason open_rej_reason)
  480. {
  481. /* Task in the target is done. */
  482. request->complete_in_target = true;
  483. *response_ptr = SAS_TASK_UNDELIVERED;
  484. *status_ptr = SAS_OPEN_REJECT;
  485. *complete_to_host_ptr = isci_perform_normal_io_completion;
  486. task->task_status.open_rej_reason = open_rej_reason;
  487. }
  488. /**
  489. * isci_request_handle_controller_specific_errors() - This function decodes
  490. * controller-specific I/O completion error conditions.
  491. * @request: This parameter is the completed isci_request object.
  492. * @response_ptr: This parameter specifies the service response for the I/O.
  493. * @status_ptr: This parameter specifies the exec status for the I/O.
  494. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  495. * the LLDD with respect to completing this request or forcing an abort
  496. * condition on the I/O.
  497. *
  498. * none.
  499. */
  500. static void isci_request_handle_controller_specific_errors(
  501. struct isci_remote_device *isci_device,
  502. struct isci_request *request,
  503. struct sas_task *task,
  504. enum service_response *response_ptr,
  505. enum exec_status *status_ptr,
  506. enum isci_completion_selection *complete_to_host_ptr)
  507. {
  508. unsigned int cstatus;
  509. cstatus = scic_request_get_controller_status(
  510. request->sci_request_handle
  511. );
  512. dev_dbg(&request->isci_host->pdev->dev,
  513. "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
  514. "- controller status = 0x%x\n",
  515. __func__, request, cstatus);
  516. /* Decode the controller-specific errors; most
  517. * important is to recognize those conditions in which
  518. * the target may still have a task outstanding that
  519. * must be aborted.
  520. *
  521. * Note that there are SCU completion codes being
  522. * named in the decode below for which SCIC has already
  523. * done work to handle them in a way other than as
  524. * a controller-specific completion code; these are left
  525. * in the decode below for completeness sake.
  526. */
  527. switch (cstatus) {
  528. case SCU_TASK_DONE_DMASETUP_DIRERR:
  529. /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
  530. case SCU_TASK_DONE_XFERCNT_ERR:
  531. /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
  532. if (task->task_proto == SAS_PROTOCOL_SMP) {
  533. /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
  534. *response_ptr = SAS_TASK_COMPLETE;
  535. /* See if the device has been/is being stopped. Note
  536. * that we ignore the quiesce state, since we are
  537. * concerned about the actual device state.
  538. */
  539. if ((isci_device->status == isci_stopping) ||
  540. (isci_device->status == isci_stopped))
  541. *status_ptr = SAS_DEVICE_UNKNOWN;
  542. else
  543. *status_ptr = SAS_ABORTED_TASK;
  544. request->complete_in_target = true;
  545. *complete_to_host_ptr =
  546. isci_perform_normal_io_completion;
  547. } else {
  548. /* Task in the target is not done. */
  549. *response_ptr = SAS_TASK_UNDELIVERED;
  550. if ((isci_device->status == isci_stopping) ||
  551. (isci_device->status == isci_stopped))
  552. *status_ptr = SAS_DEVICE_UNKNOWN;
  553. else
  554. *status_ptr = SAM_STAT_TASK_ABORTED;
  555. request->complete_in_target = false;
  556. *complete_to_host_ptr =
  557. isci_perform_error_io_completion;
  558. }
  559. break;
  560. case SCU_TASK_DONE_CRC_ERR:
  561. case SCU_TASK_DONE_NAK_CMD_ERR:
  562. case SCU_TASK_DONE_EXCESS_DATA:
  563. case SCU_TASK_DONE_UNEXP_FIS:
  564. /* Also SCU_TASK_DONE_UNEXP_RESP: */
  565. case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
  566. case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
  567. case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
  568. /* These are conditions in which the target
  569. * has completed the task, so that no cleanup
  570. * is necessary.
  571. */
  572. *response_ptr = SAS_TASK_COMPLETE;
  573. /* See if the device has been/is being stopped. Note
  574. * that we ignore the quiesce state, since we are
  575. * concerned about the actual device state.
  576. */
  577. if ((isci_device->status == isci_stopping) ||
  578. (isci_device->status == isci_stopped))
  579. *status_ptr = SAS_DEVICE_UNKNOWN;
  580. else
  581. *status_ptr = SAS_ABORTED_TASK;
  582. request->complete_in_target = true;
  583. *complete_to_host_ptr = isci_perform_normal_io_completion;
  584. break;
  585. /* Note that the only open reject completion codes seen here will be
  586. * abandon-class codes; all others are automatically retried in the SCU.
  587. */
  588. case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
  589. isci_request_set_open_reject_status(
  590. request, task, response_ptr, status_ptr,
  591. complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
  592. break;
  593. case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
  594. /* Note - the return of AB0 will change when
  595. * libsas implements detection of zone violations.
  596. */
  597. isci_request_set_open_reject_status(
  598. request, task, response_ptr, status_ptr,
  599. complete_to_host_ptr, SAS_OREJ_RESV_AB0);
  600. break;
  601. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
  602. isci_request_set_open_reject_status(
  603. request, task, response_ptr, status_ptr,
  604. complete_to_host_ptr, SAS_OREJ_RESV_AB1);
  605. break;
  606. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
  607. isci_request_set_open_reject_status(
  608. request, task, response_ptr, status_ptr,
  609. complete_to_host_ptr, SAS_OREJ_RESV_AB2);
  610. break;
  611. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
  612. isci_request_set_open_reject_status(
  613. request, task, response_ptr, status_ptr,
  614. complete_to_host_ptr, SAS_OREJ_RESV_AB3);
  615. break;
  616. case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
  617. isci_request_set_open_reject_status(
  618. request, task, response_ptr, status_ptr,
  619. complete_to_host_ptr, SAS_OREJ_BAD_DEST);
  620. break;
  621. case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
  622. isci_request_set_open_reject_status(
  623. request, task, response_ptr, status_ptr,
  624. complete_to_host_ptr, SAS_OREJ_STP_NORES);
  625. break;
  626. case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
  627. isci_request_set_open_reject_status(
  628. request, task, response_ptr, status_ptr,
  629. complete_to_host_ptr, SAS_OREJ_EPROTO);
  630. break;
  631. case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
  632. isci_request_set_open_reject_status(
  633. request, task, response_ptr, status_ptr,
  634. complete_to_host_ptr, SAS_OREJ_CONN_RATE);
  635. break;
  636. case SCU_TASK_DONE_LL_R_ERR:
  637. /* Also SCU_TASK_DONE_ACK_NAK_TO: */
  638. case SCU_TASK_DONE_LL_PERR:
  639. case SCU_TASK_DONE_LL_SY_TERM:
  640. /* Also SCU_TASK_DONE_NAK_ERR:*/
  641. case SCU_TASK_DONE_LL_LF_TERM:
  642. /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
  643. case SCU_TASK_DONE_LL_ABORT_ERR:
  644. case SCU_TASK_DONE_SEQ_INV_TYPE:
  645. /* Also SCU_TASK_DONE_UNEXP_XR: */
  646. case SCU_TASK_DONE_XR_IU_LEN_ERR:
  647. case SCU_TASK_DONE_INV_FIS_LEN:
  648. /* Also SCU_TASK_DONE_XR_WD_LEN: */
  649. case SCU_TASK_DONE_SDMA_ERR:
  650. case SCU_TASK_DONE_OFFSET_ERR:
  651. case SCU_TASK_DONE_MAX_PLD_ERR:
  652. case SCU_TASK_DONE_LF_ERR:
  653. case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
  654. case SCU_TASK_DONE_SMP_LL_RX_ERR:
  655. case SCU_TASK_DONE_UNEXP_DATA:
  656. case SCU_TASK_DONE_UNEXP_SDBFIS:
  657. case SCU_TASK_DONE_REG_ERR:
  658. case SCU_TASK_DONE_SDB_ERR:
  659. case SCU_TASK_DONE_TASK_ABORT:
  660. default:
  661. /* Task in the target is not done. */
  662. *response_ptr = SAS_TASK_UNDELIVERED;
  663. *status_ptr = SAM_STAT_TASK_ABORTED;
  664. request->complete_in_target = false;
  665. *complete_to_host_ptr = isci_perform_error_io_completion;
  666. break;
  667. }
  668. }
  669. /**
  670. * isci_task_save_for_upper_layer_completion() - This function saves the
  671. * request for later completion to the upper layer driver.
  672. * @host: This parameter is a pointer to the host on which the the request
  673. * should be queued (either as an error or success).
  674. * @request: This parameter is the completed request.
  675. * @response: This parameter is the response code for the completed task.
  676. * @status: This parameter is the status code for the completed task.
  677. *
  678. * none.
  679. */
  680. static void isci_task_save_for_upper_layer_completion(
  681. struct isci_host *host,
  682. struct isci_request *request,
  683. enum service_response response,
  684. enum exec_status status,
  685. enum isci_completion_selection task_notification_selection)
  686. {
  687. struct sas_task *task = isci_request_access_task(request);
  688. isci_task_set_completion_status(task, response, status,
  689. task_notification_selection);
  690. /* Tasks aborted specifically by a call to the lldd_abort_task
  691. * function should not be completed to the host in the regular path.
  692. */
  693. switch (task_notification_selection) {
  694. case isci_perform_normal_io_completion:
  695. /* Normal notification (task_done) */
  696. dev_dbg(&host->pdev->dev,
  697. "%s: Normal - task = %p, response=%d, status=%d\n",
  698. __func__,
  699. task,
  700. response,
  701. status);
  702. /* Add to the completed list. */
  703. list_add(&request->completed_node,
  704. &host->requests_to_complete);
  705. break;
  706. case isci_perform_aborted_io_completion:
  707. /*
  708. * No notification because this request is already
  709. * in the abort path.
  710. */
  711. dev_warn(&host->pdev->dev,
  712. "%s: Aborted - task = %p, response=%d, status=%d\n",
  713. __func__,
  714. task,
  715. response,
  716. status);
  717. break;
  718. case isci_perform_error_io_completion:
  719. /* Use sas_task_abort */
  720. dev_warn(&host->pdev->dev,
  721. "%s: Error - task = %p, response=%d, status=%d\n",
  722. __func__,
  723. task,
  724. response,
  725. status);
  726. /* Add to the aborted list. */
  727. list_add(&request->completed_node,
  728. &host->requests_to_abort);
  729. break;
  730. default:
  731. dev_warn(&host->pdev->dev,
  732. "%s: Unknown - task = %p, response=%d, status=%d\n",
  733. __func__,
  734. task,
  735. response,
  736. status);
  737. /* Add to the aborted list. */
  738. list_add(&request->completed_node,
  739. &host->requests_to_abort);
  740. break;
  741. }
  742. }
  743. /**
  744. * isci_request_io_request_complete() - This function is called by the sci core
  745. * when an io request completes.
  746. * @isci_host: This parameter specifies the ISCI host object
  747. * @request: This parameter is the completed isci_request object.
  748. * @completion_status: This parameter specifies the completion status from the
  749. * sci core.
  750. *
  751. * none.
  752. */
  753. void isci_request_io_request_complete(
  754. struct isci_host *isci_host,
  755. struct isci_request *request,
  756. enum sci_io_status completion_status)
  757. {
  758. struct sas_task *task = isci_request_access_task(request);
  759. struct ssp_response_iu *resp_iu;
  760. void *resp_buf;
  761. unsigned long task_flags;
  762. unsigned long state_flags;
  763. struct completion *io_request_completion;
  764. struct isci_remote_device *isci_device = request->isci_device;
  765. enum service_response response = SAS_TASK_UNDELIVERED;
  766. enum exec_status status = SAS_ABORTED_TASK;
  767. enum isci_request_status request_status;
  768. enum isci_completion_selection complete_to_host
  769. = isci_perform_normal_io_completion;
  770. dev_dbg(&isci_host->pdev->dev,
  771. "%s: request = %p, task = %p,\n"
  772. "task->data_dir = %d completion_status = 0x%x\n",
  773. __func__,
  774. request,
  775. task,
  776. task->data_dir,
  777. completion_status);
  778. spin_lock_irqsave(&request->state_lock, state_flags);
  779. request_status = isci_request_get_state(request);
  780. spin_unlock_irqrestore(&request->state_lock, state_flags);
  781. /* Decode the request status. Note that if the request has been
  782. * aborted by a task management function, we don't care
  783. * what the status is.
  784. */
  785. switch (request_status) {
  786. case aborted:
  787. /* "aborted" indicates that the request was aborted by a task
  788. * management function, since once a task management request is
  789. * perfomed by the device, the request only completes because
  790. * of the subsequent driver terminate.
  791. *
  792. * Aborted also means an external thread is explicitly managing
  793. * this request, so that we do not complete it up the stack.
  794. *
  795. * The target is still there (since the TMF was successful).
  796. */
  797. request->complete_in_target = true;
  798. response = SAS_TASK_COMPLETE;
  799. /* See if the device has been/is being stopped. Note
  800. * that we ignore the quiesce state, since we are
  801. * concerned about the actual device state.
  802. */
  803. if ((isci_device->status == isci_stopping)
  804. || (isci_device->status == isci_stopped)
  805. )
  806. status = SAS_DEVICE_UNKNOWN;
  807. else
  808. status = SAS_ABORTED_TASK;
  809. complete_to_host = isci_perform_aborted_io_completion;
  810. /* This was an aborted request. */
  811. break;
  812. case aborting:
  813. /* aborting means that the task management function tried and
  814. * failed to abort the request. We need to note the request
  815. * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
  816. * target as down.
  817. *
  818. * Aborting also means an external thread is explicitly managing
  819. * this request, so that we do not complete it up the stack.
  820. */
  821. request->complete_in_target = true;
  822. response = SAS_TASK_UNDELIVERED;
  823. if ((isci_device->status == isci_stopping) ||
  824. (isci_device->status == isci_stopped))
  825. /* The device has been /is being stopped. Note that
  826. * we ignore the quiesce state, since we are
  827. * concerned about the actual device state.
  828. */
  829. status = SAS_DEVICE_UNKNOWN;
  830. else
  831. status = SAS_PHY_DOWN;
  832. complete_to_host = isci_perform_aborted_io_completion;
  833. /* This was an aborted request. */
  834. break;
  835. case terminating:
  836. /* This was an terminated request. This happens when
  837. * the I/O is being terminated because of an action on
  838. * the device (reset, tear down, etc.), and the I/O needs
  839. * to be completed up the stack.
  840. */
  841. request->complete_in_target = true;
  842. response = SAS_TASK_UNDELIVERED;
  843. /* See if the device has been/is being stopped. Note
  844. * that we ignore the quiesce state, since we are
  845. * concerned about the actual device state.
  846. */
  847. if ((isci_device->status == isci_stopping) ||
  848. (isci_device->status == isci_stopped))
  849. status = SAS_DEVICE_UNKNOWN;
  850. else
  851. status = SAS_ABORTED_TASK;
  852. complete_to_host = isci_perform_normal_io_completion;
  853. /* This was a terminated request. */
  854. break;
  855. default:
  856. /* This is an active request being completed from the core. */
  857. switch (completion_status) {
  858. case SCI_IO_FAILURE_RESPONSE_VALID:
  859. dev_dbg(&isci_host->pdev->dev,
  860. "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
  861. __func__,
  862. request,
  863. task);
  864. if (sas_protocol_ata(task->task_proto)) {
  865. resp_buf
  866. = scic_stp_io_request_get_d2h_reg_address(
  867. request->sci_request_handle
  868. );
  869. isci_request_process_stp_response(task,
  870. resp_buf
  871. );
  872. } else if (SAS_PROTOCOL_SSP == task->task_proto) {
  873. /* crack the iu response buffer. */
  874. resp_iu
  875. = scic_io_request_get_response_iu_address(
  876. request->sci_request_handle
  877. );
  878. isci_request_process_response_iu(task, resp_iu,
  879. &isci_host->pdev->dev
  880. );
  881. } else if (SAS_PROTOCOL_SMP == task->task_proto) {
  882. dev_err(&isci_host->pdev->dev,
  883. "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
  884. "SAS_PROTOCOL_SMP protocol\n",
  885. __func__);
  886. } else
  887. dev_err(&isci_host->pdev->dev,
  888. "%s: unknown protocol\n", __func__);
  889. /* use the task status set in the task struct by the
  890. * isci_request_process_response_iu call.
  891. */
  892. request->complete_in_target = true;
  893. response = task->task_status.resp;
  894. status = task->task_status.stat;
  895. break;
  896. case SCI_IO_SUCCESS:
  897. case SCI_IO_SUCCESS_IO_DONE_EARLY:
  898. response = SAS_TASK_COMPLETE;
  899. status = SAM_STAT_GOOD;
  900. request->complete_in_target = true;
  901. if (task->task_proto == SAS_PROTOCOL_SMP) {
  902. u8 *command_iu_address
  903. = scic_io_request_get_command_iu_address(
  904. request->sci_request_handle
  905. );
  906. dev_dbg(&isci_host->pdev->dev,
  907. "%s: SMP protocol completion\n",
  908. __func__);
  909. sg_copy_from_buffer(
  910. &task->smp_task.smp_resp, 1,
  911. command_iu_address
  912. + sizeof(struct smp_request),
  913. sizeof(struct smp_resp)
  914. );
  915. } else if (completion_status
  916. == SCI_IO_SUCCESS_IO_DONE_EARLY) {
  917. /* This was an SSP / STP / SATA transfer.
  918. * There is a possibility that less data than
  919. * the maximum was transferred.
  920. */
  921. u32 transferred_length
  922. = scic_io_request_get_number_of_bytes_transferred(
  923. request->sci_request_handle);
  924. task->task_status.residual
  925. = task->total_xfer_len - transferred_length;
  926. /* If there were residual bytes, call this an
  927. * underrun.
  928. */
  929. if (task->task_status.residual != 0)
  930. status = SAS_DATA_UNDERRUN;
  931. dev_dbg(&isci_host->pdev->dev,
  932. "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
  933. __func__,
  934. status);
  935. } else
  936. dev_dbg(&isci_host->pdev->dev,
  937. "%s: SCI_IO_SUCCESS\n",
  938. __func__);
  939. break;
  940. case SCI_IO_FAILURE_TERMINATED:
  941. dev_dbg(&isci_host->pdev->dev,
  942. "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
  943. __func__,
  944. request,
  945. task);
  946. /* The request was terminated explicitly. No handling
  947. * is needed in the SCSI error handler path.
  948. */
  949. request->complete_in_target = true;
  950. response = SAS_TASK_UNDELIVERED;
  951. /* See if the device has been/is being stopped. Note
  952. * that we ignore the quiesce state, since we are
  953. * concerned about the actual device state.
  954. */
  955. if ((isci_device->status == isci_stopping) ||
  956. (isci_device->status == isci_stopped))
  957. status = SAS_DEVICE_UNKNOWN;
  958. else
  959. status = SAS_ABORTED_TASK;
  960. complete_to_host = isci_perform_normal_io_completion;
  961. break;
  962. case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
  963. isci_request_handle_controller_specific_errors(
  964. isci_device, request, task, &response, &status,
  965. &complete_to_host);
  966. break;
  967. case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
  968. /* This is a special case, in that the I/O completion
  969. * is telling us that the device needs a reset.
  970. * In order for the device reset condition to be
  971. * noticed, the I/O has to be handled in the error
  972. * handler. Set the reset flag and cause the
  973. * SCSI error thread to be scheduled.
  974. */
  975. spin_lock_irqsave(&task->task_state_lock, task_flags);
  976. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  977. spin_unlock_irqrestore(&task->task_state_lock, task_flags);
  978. complete_to_host = isci_perform_error_io_completion;
  979. request->complete_in_target = false;
  980. break;
  981. default:
  982. /* Catch any otherwise unhandled error codes here. */
  983. dev_warn(&isci_host->pdev->dev,
  984. "%s: invalid completion code: 0x%x - "
  985. "isci_request = %p\n",
  986. __func__, completion_status, request);
  987. response = SAS_TASK_UNDELIVERED;
  988. /* See if the device has been/is being stopped. Note
  989. * that we ignore the quiesce state, since we are
  990. * concerned about the actual device state.
  991. */
  992. if ((isci_device->status == isci_stopping) ||
  993. (isci_device->status == isci_stopped))
  994. status = SAS_DEVICE_UNKNOWN;
  995. else
  996. status = SAS_ABORTED_TASK;
  997. complete_to_host = isci_perform_error_io_completion;
  998. request->complete_in_target = false;
  999. break;
  1000. }
  1001. break;
  1002. }
  1003. isci_request_unmap_sgl(request, isci_host->pdev);
  1004. /* Put the completed request on the correct list */
  1005. isci_task_save_for_upper_layer_completion(isci_host, request, response,
  1006. status, complete_to_host
  1007. );
  1008. /* complete the io request to the core. */
  1009. scic_controller_complete_io(
  1010. isci_host->core_controller,
  1011. isci_device->sci_device_handle,
  1012. request->sci_request_handle
  1013. );
  1014. /* NULL the request handle so it cannot be completed or
  1015. * terminated again, and to cause any calls into abort
  1016. * task to recognize the already completed case.
  1017. */
  1018. request->sci_request_handle = NULL;
  1019. /* Only remove the request from the remote device list
  1020. * of pending requests if we have not requested error
  1021. * handling on this request.
  1022. */
  1023. if (complete_to_host != isci_perform_error_io_completion)
  1024. list_del_init(&request->dev_node);
  1025. /* Save possible completion ptr. */
  1026. io_request_completion = request->io_request_completion;
  1027. if (io_request_completion) {
  1028. /* This is inherantly a regular I/O request,
  1029. * since we are currently in the regular
  1030. * I/O completion callback function.
  1031. * Signal whoever is waiting that this
  1032. * request is complete.
  1033. */
  1034. complete(io_request_completion);
  1035. }
  1036. isci_host_can_dequeue(isci_host, 1);
  1037. }
  1038. /**
  1039. * isci_request_io_request_get_transfer_length() - This function is called by
  1040. * the sci core to retrieve the transfer length for a given request.
  1041. * @request: This parameter is the isci_request object.
  1042. *
  1043. * length of transfer for specified request.
  1044. */
  1045. u32 isci_request_io_request_get_transfer_length(struct isci_request *request)
  1046. {
  1047. struct sas_task *task = isci_request_access_task(request);
  1048. dev_dbg(&request->isci_host->pdev->dev,
  1049. "%s: total_xfer_len: %d\n",
  1050. __func__,
  1051. task->total_xfer_len);
  1052. return task->total_xfer_len;
  1053. }
  1054. /**
  1055. * isci_request_io_request_get_data_direction() - This function is called by
  1056. * the sci core to retrieve the data direction for a given request.
  1057. * @request: This parameter is the isci_request object.
  1058. *
  1059. * data direction for specified request.
  1060. */
  1061. enum dma_data_direction isci_request_io_request_get_data_direction(
  1062. struct isci_request *request)
  1063. {
  1064. struct sas_task *task = isci_request_access_task(request);
  1065. return task->data_dir;
  1066. }
  1067. /**
  1068. * isci_request_sge_get_address_field() - This function is called by the sci
  1069. * core to retrieve the address field contents for a given sge.
  1070. * @request: This parameter is the isci_request object.
  1071. * @sge_address: This parameter is the sge.
  1072. *
  1073. * physical address in the specified sge.
  1074. */
  1075. dma_addr_t isci_request_sge_get_address_field(
  1076. struct isci_request *request,
  1077. void *sge_address)
  1078. {
  1079. struct sas_task *task = isci_request_access_task(request);
  1080. dma_addr_t ret;
  1081. struct isci_host *isci_host = isci_host_from_sas_ha(
  1082. task->dev->port->ha);
  1083. dev_dbg(&isci_host->pdev->dev,
  1084. "%s: request = %p, sge_address = %p\n",
  1085. __func__,
  1086. request,
  1087. sge_address);
  1088. if (task->data_dir == PCI_DMA_NONE)
  1089. return 0;
  1090. /* the case where num_scatter == 0 is special, in that
  1091. * task->scatter is the actual buffer address, not an sgl.
  1092. * so a map single is required here.
  1093. */
  1094. if ((task->num_scatter == 0) &&
  1095. !sas_protocol_ata(task->task_proto)) {
  1096. ret = dma_map_single(
  1097. &isci_host->pdev->dev,
  1098. task->scatter,
  1099. task->total_xfer_len,
  1100. task->data_dir
  1101. );
  1102. request->zero_scatter_daddr = ret;
  1103. } else
  1104. ret = sg_dma_address(((struct scatterlist *)sge_address));
  1105. dev_dbg(&isci_host->pdev->dev,
  1106. "%s: bus address = %lx\n",
  1107. __func__,
  1108. (unsigned long)ret);
  1109. return ret;
  1110. }
  1111. /**
  1112. * isci_request_sge_get_length_field() - This function is called by the sci
  1113. * core to retrieve the length field contents for a given sge.
  1114. * @request: This parameter is the isci_request object.
  1115. * @sge_address: This parameter is the sge.
  1116. *
  1117. * length field value in the specified sge.
  1118. */
  1119. u32 isci_request_sge_get_length_field(
  1120. struct isci_request *request,
  1121. void *sge_address)
  1122. {
  1123. struct sas_task *task = isci_request_access_task(request);
  1124. int ret;
  1125. dev_dbg(&request->isci_host->pdev->dev,
  1126. "%s: request = %p, sge_address = %p\n",
  1127. __func__,
  1128. request,
  1129. sge_address);
  1130. if (task->data_dir == PCI_DMA_NONE)
  1131. return 0;
  1132. /* the case where num_scatter == 0 is special, in that
  1133. * task->scatter is the actual buffer address, not an sgl.
  1134. * so we return total_xfer_len here.
  1135. */
  1136. if (task->num_scatter == 0)
  1137. ret = task->total_xfer_len;
  1138. else
  1139. ret = sg_dma_len((struct scatterlist *)sge_address);
  1140. dev_dbg(&request->isci_host->pdev->dev,
  1141. "%s: len = %d\n",
  1142. __func__,
  1143. ret);
  1144. return ret;
  1145. }
  1146. /**
  1147. * isci_request_ssp_io_request_get_cdb_address() - This function is called by
  1148. * the sci core to retrieve the cdb address for a given request.
  1149. * @request: This parameter is the isci_request object.
  1150. *
  1151. * cdb address for specified request.
  1152. */
  1153. void *isci_request_ssp_io_request_get_cdb_address(
  1154. struct isci_request *request)
  1155. {
  1156. struct sas_task *task = isci_request_access_task(request);
  1157. dev_dbg(&request->isci_host->pdev->dev,
  1158. "%s: request->task->ssp_task.cdb = %p\n",
  1159. __func__,
  1160. task->ssp_task.cdb);
  1161. return task->ssp_task.cdb;
  1162. }
  1163. /**
  1164. * isci_request_ssp_io_request_get_cdb_length() - This function is called by
  1165. * the sci core to retrieve the cdb length for a given request.
  1166. * @request: This parameter is the isci_request object.
  1167. *
  1168. * cdb length for specified request.
  1169. */
  1170. u32 isci_request_ssp_io_request_get_cdb_length(
  1171. struct isci_request *request)
  1172. {
  1173. return 16;
  1174. }
  1175. /**
  1176. * isci_request_ssp_io_request_get_lun() - This function is called by the sci
  1177. * core to retrieve the lun for a given request.
  1178. * @request: This parameter is the isci_request object.
  1179. *
  1180. * lun for specified request.
  1181. */
  1182. u32 isci_request_ssp_io_request_get_lun(
  1183. struct isci_request *request)
  1184. {
  1185. struct sas_task *task = isci_request_access_task(request);
  1186. #ifdef DEBUG
  1187. int i;
  1188. for (i = 0; i < 8; i++)
  1189. dev_dbg(&request->isci_host->pdev->dev,
  1190. "%s: task->ssp_task.LUN[%d] = %x\n",
  1191. __func__, i, task->ssp_task.LUN[i]);
  1192. #endif
  1193. return task->ssp_task.LUN[0];
  1194. }
  1195. /**
  1196. * isci_request_ssp_io_request_get_task_attribute() - This function is called
  1197. * by the sci core to retrieve the task attribute for a given request.
  1198. * @request: This parameter is the isci_request object.
  1199. *
  1200. * task attribute for specified request.
  1201. */
  1202. u32 isci_request_ssp_io_request_get_task_attribute(
  1203. struct isci_request *request)
  1204. {
  1205. struct sas_task *task = isci_request_access_task(request);
  1206. dev_dbg(&request->isci_host->pdev->dev,
  1207. "%s: request->task->ssp_task.task_attr = %x\n",
  1208. __func__,
  1209. task->ssp_task.task_attr);
  1210. return task->ssp_task.task_attr;
  1211. }
  1212. /**
  1213. * isci_request_ssp_io_request_get_command_priority() - This function is called
  1214. * by the sci core to retrieve the command priority for a given request.
  1215. * @request: This parameter is the isci_request object.
  1216. *
  1217. * command priority for specified request.
  1218. */
  1219. u32 isci_request_ssp_io_request_get_command_priority(
  1220. struct isci_request *request)
  1221. {
  1222. struct sas_task *task = isci_request_access_task(request);
  1223. dev_dbg(&request->isci_host->pdev->dev,
  1224. "%s: request->task->ssp_task.task_prio = %x\n",
  1225. __func__,
  1226. task->ssp_task.task_prio);
  1227. return task->ssp_task.task_prio;
  1228. }