request.c 42 KB

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