request.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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. dev_warn(&isci_host->pdev->dev,
  410. "%s: failed request start\n",
  411. __func__);
  412. spin_unlock_irqrestore(&isci_host->scic_lock, flags);
  413. } else
  414. dev_warn(&isci_host->pdev->dev,
  415. "%s: request_construct failed - status = 0x%x\n",
  416. __func__,
  417. status);
  418. out:
  419. if (status != SCI_SUCCESS) {
  420. /* release dma memory on failure. */
  421. isci_request_free(isci_host, request);
  422. request = NULL;
  423. ret = SCI_FAILURE;
  424. }
  425. *isci_request = request;
  426. return ret;
  427. }
  428. /**
  429. * isci_request_process_response_iu() - This function sets the status and
  430. * response iu, in the task struct, from the request object for the upper
  431. * layer driver.
  432. * @sas_task: This parameter is the task struct from the upper layer driver.
  433. * @resp_iu: This parameter points to the response iu of the completed request.
  434. * @dev: This parameter specifies the linux device struct.
  435. *
  436. * none.
  437. */
  438. static void isci_request_process_response_iu(
  439. struct sas_task *task,
  440. struct ssp_response_iu *resp_iu,
  441. struct device *dev)
  442. {
  443. dev_dbg(dev,
  444. "%s: resp_iu = %p "
  445. "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
  446. "resp_iu->response_data_len = %x, "
  447. "resp_iu->sense_data_len = %x\nrepsonse data: ",
  448. __func__,
  449. resp_iu,
  450. resp_iu->status,
  451. resp_iu->datapres,
  452. resp_iu->response_data_len,
  453. resp_iu->sense_data_len);
  454. task->task_status.stat = resp_iu->status;
  455. /* libsas updates the task status fields based on the response iu. */
  456. sas_ssp_task_response(dev, task, resp_iu);
  457. }
  458. /**
  459. * isci_request_set_open_reject_status() - This function prepares the I/O
  460. * completion for OPEN_REJECT conditions.
  461. * @request: This parameter is the completed isci_request object.
  462. * @response_ptr: This parameter specifies the service response for the I/O.
  463. * @status_ptr: This parameter specifies the exec status for the I/O.
  464. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  465. * the LLDD with respect to completing this request or forcing an abort
  466. * condition on the I/O.
  467. * @open_rej_reason: This parameter specifies the encoded reason for the
  468. * abandon-class reject.
  469. *
  470. * none.
  471. */
  472. static void isci_request_set_open_reject_status(
  473. struct isci_request *request,
  474. struct sas_task *task,
  475. enum service_response *response_ptr,
  476. enum exec_status *status_ptr,
  477. enum isci_completion_selection *complete_to_host_ptr,
  478. enum sas_open_rej_reason open_rej_reason)
  479. {
  480. /* Task in the target is done. */
  481. request->complete_in_target = true;
  482. *response_ptr = SAS_TASK_UNDELIVERED;
  483. *status_ptr = SAS_OPEN_REJECT;
  484. *complete_to_host_ptr = isci_perform_normal_io_completion;
  485. task->task_status.open_rej_reason = open_rej_reason;
  486. }
  487. /**
  488. * isci_request_handle_controller_specific_errors() - This function decodes
  489. * controller-specific I/O completion error conditions.
  490. * @request: This parameter is the completed isci_request object.
  491. * @response_ptr: This parameter specifies the service response for the I/O.
  492. * @status_ptr: This parameter specifies the exec status for the I/O.
  493. * @complete_to_host_ptr: This parameter specifies the action to be taken by
  494. * the LLDD with respect to completing this request or forcing an abort
  495. * condition on the I/O.
  496. *
  497. * none.
  498. */
  499. static void isci_request_handle_controller_specific_errors(
  500. struct isci_remote_device *isci_device,
  501. struct isci_request *request,
  502. struct sas_task *task,
  503. enum service_response *response_ptr,
  504. enum exec_status *status_ptr,
  505. enum isci_completion_selection *complete_to_host_ptr)
  506. {
  507. unsigned int cstatus;
  508. cstatus = scic_request_get_controller_status(
  509. request->sci_request_handle
  510. );
  511. dev_dbg(&request->isci_host->pdev->dev,
  512. "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
  513. "- controller status = 0x%x\n",
  514. __func__, request, cstatus);
  515. /* Decode the controller-specific errors; most
  516. * important is to recognize those conditions in which
  517. * the target may still have a task outstanding that
  518. * must be aborted.
  519. *
  520. * Note that there are SCU completion codes being
  521. * named in the decode below for which SCIC has already
  522. * done work to handle them in a way other than as
  523. * a controller-specific completion code; these are left
  524. * in the decode below for completeness sake.
  525. */
  526. switch (cstatus) {
  527. case SCU_TASK_DONE_DMASETUP_DIRERR:
  528. /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
  529. case SCU_TASK_DONE_XFERCNT_ERR:
  530. /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
  531. if (task->task_proto == SAS_PROTOCOL_SMP) {
  532. /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
  533. *response_ptr = SAS_TASK_COMPLETE;
  534. /* See if the device has been/is being stopped. Note
  535. * that we ignore the quiesce state, since we are
  536. * concerned about the actual device state.
  537. */
  538. if ((isci_device->status == isci_stopping) ||
  539. (isci_device->status == isci_stopped))
  540. *status_ptr = SAS_DEVICE_UNKNOWN;
  541. else
  542. *status_ptr = SAS_ABORTED_TASK;
  543. request->complete_in_target = true;
  544. *complete_to_host_ptr =
  545. isci_perform_normal_io_completion;
  546. } else {
  547. /* Task in the target is not done. */
  548. *response_ptr = SAS_TASK_UNDELIVERED;
  549. if ((isci_device->status == isci_stopping) ||
  550. (isci_device->status == isci_stopped))
  551. *status_ptr = SAS_DEVICE_UNKNOWN;
  552. else
  553. *status_ptr = SAM_STAT_TASK_ABORTED;
  554. request->complete_in_target = false;
  555. *complete_to_host_ptr =
  556. isci_perform_error_io_completion;
  557. }
  558. break;
  559. case SCU_TASK_DONE_CRC_ERR:
  560. case SCU_TASK_DONE_NAK_CMD_ERR:
  561. case SCU_TASK_DONE_EXCESS_DATA:
  562. case SCU_TASK_DONE_UNEXP_FIS:
  563. /* Also SCU_TASK_DONE_UNEXP_RESP: */
  564. case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
  565. case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
  566. case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
  567. /* These are conditions in which the target
  568. * has completed the task, so that no cleanup
  569. * is necessary.
  570. */
  571. *response_ptr = SAS_TASK_COMPLETE;
  572. /* See if the device has been/is being stopped. Note
  573. * that we ignore the quiesce state, since we are
  574. * concerned about the actual device state.
  575. */
  576. if ((isci_device->status == isci_stopping) ||
  577. (isci_device->status == isci_stopped))
  578. *status_ptr = SAS_DEVICE_UNKNOWN;
  579. else
  580. *status_ptr = SAS_ABORTED_TASK;
  581. request->complete_in_target = true;
  582. *complete_to_host_ptr = isci_perform_normal_io_completion;
  583. break;
  584. /* Note that the only open reject completion codes seen here will be
  585. * abandon-class codes; all others are automatically retried in the SCU.
  586. */
  587. case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
  588. isci_request_set_open_reject_status(
  589. request, task, response_ptr, status_ptr,
  590. complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
  591. break;
  592. case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
  593. /* Note - the return of AB0 will change when
  594. * libsas implements detection of zone violations.
  595. */
  596. isci_request_set_open_reject_status(
  597. request, task, response_ptr, status_ptr,
  598. complete_to_host_ptr, SAS_OREJ_RESV_AB0);
  599. break;
  600. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
  601. isci_request_set_open_reject_status(
  602. request, task, response_ptr, status_ptr,
  603. complete_to_host_ptr, SAS_OREJ_RESV_AB1);
  604. break;
  605. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
  606. isci_request_set_open_reject_status(
  607. request, task, response_ptr, status_ptr,
  608. complete_to_host_ptr, SAS_OREJ_RESV_AB2);
  609. break;
  610. case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
  611. isci_request_set_open_reject_status(
  612. request, task, response_ptr, status_ptr,
  613. complete_to_host_ptr, SAS_OREJ_RESV_AB3);
  614. break;
  615. case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
  616. isci_request_set_open_reject_status(
  617. request, task, response_ptr, status_ptr,
  618. complete_to_host_ptr, SAS_OREJ_BAD_DEST);
  619. break;
  620. case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
  621. isci_request_set_open_reject_status(
  622. request, task, response_ptr, status_ptr,
  623. complete_to_host_ptr, SAS_OREJ_STP_NORES);
  624. break;
  625. case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
  626. isci_request_set_open_reject_status(
  627. request, task, response_ptr, status_ptr,
  628. complete_to_host_ptr, SAS_OREJ_EPROTO);
  629. break;
  630. case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
  631. isci_request_set_open_reject_status(
  632. request, task, response_ptr, status_ptr,
  633. complete_to_host_ptr, SAS_OREJ_CONN_RATE);
  634. break;
  635. case SCU_TASK_DONE_LL_R_ERR:
  636. /* Also SCU_TASK_DONE_ACK_NAK_TO: */
  637. case SCU_TASK_DONE_LL_PERR:
  638. case SCU_TASK_DONE_LL_SY_TERM:
  639. /* Also SCU_TASK_DONE_NAK_ERR:*/
  640. case SCU_TASK_DONE_LL_LF_TERM:
  641. /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
  642. case SCU_TASK_DONE_LL_ABORT_ERR:
  643. case SCU_TASK_DONE_SEQ_INV_TYPE:
  644. /* Also SCU_TASK_DONE_UNEXP_XR: */
  645. case SCU_TASK_DONE_XR_IU_LEN_ERR:
  646. case SCU_TASK_DONE_INV_FIS_LEN:
  647. /* Also SCU_TASK_DONE_XR_WD_LEN: */
  648. case SCU_TASK_DONE_SDMA_ERR:
  649. case SCU_TASK_DONE_OFFSET_ERR:
  650. case SCU_TASK_DONE_MAX_PLD_ERR:
  651. case SCU_TASK_DONE_LF_ERR:
  652. case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
  653. case SCU_TASK_DONE_SMP_LL_RX_ERR:
  654. case SCU_TASK_DONE_UNEXP_DATA:
  655. case SCU_TASK_DONE_UNEXP_SDBFIS:
  656. case SCU_TASK_DONE_REG_ERR:
  657. case SCU_TASK_DONE_SDB_ERR:
  658. case SCU_TASK_DONE_TASK_ABORT:
  659. default:
  660. /* Task in the target is not done. */
  661. *response_ptr = SAS_TASK_UNDELIVERED;
  662. *status_ptr = SAM_STAT_TASK_ABORTED;
  663. request->complete_in_target = false;
  664. *complete_to_host_ptr = isci_perform_error_io_completion;
  665. break;
  666. }
  667. }
  668. /**
  669. * isci_task_save_for_upper_layer_completion() - This function saves the
  670. * request for later completion to the upper layer driver.
  671. * @host: This parameter is a pointer to the host on which the the request
  672. * should be queued (either as an error or success).
  673. * @request: This parameter is the completed request.
  674. * @response: This parameter is the response code for the completed task.
  675. * @status: This parameter is the status code for the completed task.
  676. *
  677. * none.
  678. */
  679. static void isci_task_save_for_upper_layer_completion(
  680. struct isci_host *host,
  681. struct isci_request *request,
  682. enum service_response response,
  683. enum exec_status status,
  684. enum isci_completion_selection task_notification_selection)
  685. {
  686. struct sas_task *task = isci_request_access_task(request);
  687. isci_task_set_completion_status(task, response, status,
  688. task_notification_selection);
  689. /* Tasks aborted specifically by a call to the lldd_abort_task
  690. * function should not be completed to the host in the regular path.
  691. */
  692. switch (task_notification_selection) {
  693. case isci_perform_normal_io_completion:
  694. /* Normal notification (task_done) */
  695. dev_dbg(&host->pdev->dev,
  696. "%s: Normal - task = %p, response=%d, status=%d\n",
  697. __func__,
  698. task,
  699. response,
  700. status);
  701. /* Add to the completed list. */
  702. list_add(&request->completed_node,
  703. &host->requests_to_complete);
  704. break;
  705. case isci_perform_aborted_io_completion:
  706. /*
  707. * No notification because this request is already
  708. * in the abort path.
  709. */
  710. dev_warn(&host->pdev->dev,
  711. "%s: Aborted - task = %p, response=%d, status=%d\n",
  712. __func__,
  713. task,
  714. response,
  715. status);
  716. break;
  717. case isci_perform_error_io_completion:
  718. /* Use sas_task_abort */
  719. dev_warn(&host->pdev->dev,
  720. "%s: Error - task = %p, response=%d, status=%d\n",
  721. __func__,
  722. task,
  723. response,
  724. status);
  725. /* Add to the aborted list. */
  726. list_add(&request->completed_node,
  727. &host->requests_to_abort);
  728. break;
  729. default:
  730. dev_warn(&host->pdev->dev,
  731. "%s: Unknown - task = %p, response=%d, status=%d\n",
  732. __func__,
  733. task,
  734. response,
  735. status);
  736. /* Add to the aborted list. */
  737. list_add(&request->completed_node,
  738. &host->requests_to_abort);
  739. break;
  740. }
  741. }
  742. /**
  743. * isci_request_io_request_complete() - This function is called by the sci core
  744. * when an io request completes.
  745. * @isci_host: This parameter specifies the ISCI host object
  746. * @request: This parameter is the completed isci_request object.
  747. * @completion_status: This parameter specifies the completion status from the
  748. * sci core.
  749. *
  750. * none.
  751. */
  752. void isci_request_io_request_complete(
  753. struct isci_host *isci_host,
  754. struct isci_request *request,
  755. enum sci_io_status completion_status)
  756. {
  757. struct sas_task *task = isci_request_access_task(request);
  758. struct ssp_response_iu *resp_iu;
  759. void *resp_buf;
  760. unsigned long task_flags;
  761. unsigned long state_flags;
  762. struct completion *io_request_completion;
  763. struct isci_remote_device *isci_device = request->isci_device;
  764. enum service_response response = SAS_TASK_UNDELIVERED;
  765. enum exec_status status = SAS_ABORTED_TASK;
  766. enum isci_request_status request_status;
  767. enum isci_completion_selection complete_to_host
  768. = isci_perform_normal_io_completion;
  769. dev_dbg(&isci_host->pdev->dev,
  770. "%s: request = %p, task = %p,\n"
  771. "task->data_dir = %d completion_status = 0x%x\n",
  772. __func__,
  773. request,
  774. task,
  775. task->data_dir,
  776. completion_status);
  777. spin_lock_irqsave(&request->state_lock, state_flags);
  778. request_status = isci_request_get_state(request);
  779. spin_unlock_irqrestore(&request->state_lock, state_flags);
  780. /* Decode the request status. Note that if the request has been
  781. * aborted by a task management function, we don't care
  782. * what the status is.
  783. */
  784. switch (request_status) {
  785. case aborted:
  786. /* "aborted" indicates that the request was aborted by a task
  787. * management function, since once a task management request is
  788. * perfomed by the device, the request only completes because
  789. * of the subsequent driver terminate.
  790. *
  791. * Aborted also means an external thread is explicitly managing
  792. * this request, so that we do not complete it up the stack.
  793. *
  794. * The target is still there (since the TMF was successful).
  795. */
  796. request->complete_in_target = true;
  797. response = SAS_TASK_COMPLETE;
  798. /* See if the device has been/is being stopped. Note
  799. * that we ignore the quiesce state, since we are
  800. * concerned about the actual device state.
  801. */
  802. if ((isci_device->status == isci_stopping)
  803. || (isci_device->status == isci_stopped)
  804. )
  805. status = SAS_DEVICE_UNKNOWN;
  806. else
  807. status = SAS_ABORTED_TASK;
  808. complete_to_host = isci_perform_aborted_io_completion;
  809. /* This was an aborted request. */
  810. break;
  811. case aborting:
  812. /* aborting means that the task management function tried and
  813. * failed to abort the request. We need to note the request
  814. * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
  815. * target as down.
  816. *
  817. * Aborting also means an external thread is explicitly managing
  818. * this request, so that we do not complete it up the stack.
  819. */
  820. request->complete_in_target = true;
  821. response = SAS_TASK_UNDELIVERED;
  822. if ((isci_device->status == isci_stopping) ||
  823. (isci_device->status == isci_stopped))
  824. /* The device has been /is being stopped. Note that
  825. * we ignore the quiesce state, since we are
  826. * concerned about the actual device state.
  827. */
  828. status = SAS_DEVICE_UNKNOWN;
  829. else
  830. status = SAS_PHY_DOWN;
  831. complete_to_host = isci_perform_aborted_io_completion;
  832. /* This was an aborted request. */
  833. break;
  834. case terminating:
  835. /* This was an terminated request. This happens when
  836. * the I/O is being terminated because of an action on
  837. * the device (reset, tear down, etc.), and the I/O needs
  838. * to be completed up the stack.
  839. */
  840. request->complete_in_target = true;
  841. response = SAS_TASK_UNDELIVERED;
  842. /* See if the device has been/is being stopped. Note
  843. * that we ignore the quiesce state, since we are
  844. * concerned about the actual device state.
  845. */
  846. if ((isci_device->status == isci_stopping) ||
  847. (isci_device->status == isci_stopped))
  848. status = SAS_DEVICE_UNKNOWN;
  849. else
  850. status = SAS_ABORTED_TASK;
  851. complete_to_host = isci_perform_normal_io_completion;
  852. /* This was a terminated request. */
  853. break;
  854. default:
  855. /* This is an active request being completed from the core. */
  856. switch (completion_status) {
  857. case SCI_IO_FAILURE_RESPONSE_VALID:
  858. dev_dbg(&isci_host->pdev->dev,
  859. "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
  860. __func__,
  861. request,
  862. task);
  863. if (sas_protocol_ata(task->task_proto)) {
  864. resp_buf
  865. = scic_stp_io_request_get_d2h_reg_address(
  866. request->sci_request_handle
  867. );
  868. isci_request_process_stp_response(task,
  869. resp_buf
  870. );
  871. } else if (SAS_PROTOCOL_SSP == task->task_proto) {
  872. /* crack the iu response buffer. */
  873. resp_iu
  874. = scic_io_request_get_response_iu_address(
  875. request->sci_request_handle
  876. );
  877. isci_request_process_response_iu(task, resp_iu,
  878. &isci_host->pdev->dev
  879. );
  880. } else if (SAS_PROTOCOL_SMP == task->task_proto) {
  881. dev_err(&isci_host->pdev->dev,
  882. "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
  883. "SAS_PROTOCOL_SMP protocol\n",
  884. __func__);
  885. } else
  886. dev_err(&isci_host->pdev->dev,
  887. "%s: unknown protocol\n", __func__);
  888. /* use the task status set in the task struct by the
  889. * isci_request_process_response_iu call.
  890. */
  891. request->complete_in_target = true;
  892. response = task->task_status.resp;
  893. status = task->task_status.stat;
  894. break;
  895. case SCI_IO_SUCCESS:
  896. case SCI_IO_SUCCESS_IO_DONE_EARLY:
  897. response = SAS_TASK_COMPLETE;
  898. status = SAM_STAT_GOOD;
  899. request->complete_in_target = true;
  900. if (task->task_proto == SAS_PROTOCOL_SMP) {
  901. u8 *command_iu_address
  902. = scic_io_request_get_command_iu_address(
  903. request->sci_request_handle
  904. );
  905. dev_dbg(&isci_host->pdev->dev,
  906. "%s: SMP protocol completion\n",
  907. __func__);
  908. sg_copy_from_buffer(
  909. &task->smp_task.smp_resp, 1,
  910. command_iu_address
  911. + sizeof(struct smp_request),
  912. sizeof(struct smp_resp)
  913. );
  914. } else if (completion_status
  915. == SCI_IO_SUCCESS_IO_DONE_EARLY) {
  916. /* This was an SSP / STP / SATA transfer.
  917. * There is a possibility that less data than
  918. * the maximum was transferred.
  919. */
  920. u32 transferred_length
  921. = scic_io_request_get_number_of_bytes_transferred(
  922. request->sci_request_handle);
  923. task->task_status.residual
  924. = task->total_xfer_len - transferred_length;
  925. /* If there were residual bytes, call this an
  926. * underrun.
  927. */
  928. if (task->task_status.residual != 0)
  929. status = SAS_DATA_UNDERRUN;
  930. dev_dbg(&isci_host->pdev->dev,
  931. "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
  932. __func__,
  933. status);
  934. } else
  935. dev_dbg(&isci_host->pdev->dev,
  936. "%s: SCI_IO_SUCCESS\n",
  937. __func__);
  938. break;
  939. case SCI_IO_FAILURE_TERMINATED:
  940. dev_dbg(&isci_host->pdev->dev,
  941. "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
  942. __func__,
  943. request,
  944. task);
  945. /* The request was terminated explicitly. No handling
  946. * is needed in the SCSI error handler path.
  947. */
  948. request->complete_in_target = true;
  949. response = SAS_TASK_UNDELIVERED;
  950. /* See if the device has been/is being stopped. Note
  951. * that we ignore the quiesce state, since we are
  952. * concerned about the actual device state.
  953. */
  954. if ((isci_device->status == isci_stopping) ||
  955. (isci_device->status == isci_stopped))
  956. status = SAS_DEVICE_UNKNOWN;
  957. else
  958. status = SAS_ABORTED_TASK;
  959. complete_to_host = isci_perform_normal_io_completion;
  960. break;
  961. case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
  962. isci_request_handle_controller_specific_errors(
  963. isci_device, request, task, &response, &status,
  964. &complete_to_host);
  965. break;
  966. case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
  967. /* This is a special case, in that the I/O completion
  968. * is telling us that the device needs a reset.
  969. * In order for the device reset condition to be
  970. * noticed, the I/O has to be handled in the error
  971. * handler. Set the reset flag and cause the
  972. * SCSI error thread to be scheduled.
  973. */
  974. spin_lock_irqsave(&task->task_state_lock, task_flags);
  975. task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
  976. spin_unlock_irqrestore(&task->task_state_lock, task_flags);
  977. complete_to_host = isci_perform_error_io_completion;
  978. request->complete_in_target = false;
  979. break;
  980. default:
  981. /* Catch any otherwise unhandled error codes here. */
  982. dev_warn(&isci_host->pdev->dev,
  983. "%s: invalid completion code: 0x%x - "
  984. "isci_request = %p\n",
  985. __func__, completion_status, request);
  986. response = SAS_TASK_UNDELIVERED;
  987. /* See if the device has been/is being stopped. Note
  988. * that we ignore the quiesce state, since we are
  989. * concerned about the actual device state.
  990. */
  991. if ((isci_device->status == isci_stopping) ||
  992. (isci_device->status == isci_stopped))
  993. status = SAS_DEVICE_UNKNOWN;
  994. else
  995. status = SAS_ABORTED_TASK;
  996. complete_to_host = isci_perform_error_io_completion;
  997. request->complete_in_target = false;
  998. break;
  999. }
  1000. break;
  1001. }
  1002. isci_request_unmap_sgl(request, isci_host->pdev);
  1003. /* Put the completed request on the correct list */
  1004. isci_task_save_for_upper_layer_completion(isci_host, request, response,
  1005. status, complete_to_host
  1006. );
  1007. /* complete the io request to the core. */
  1008. scic_controller_complete_io(
  1009. isci_host->core_controller,
  1010. to_sci_dev(isci_device),
  1011. request->sci_request_handle
  1012. );
  1013. /* NULL the request handle so it cannot be completed or
  1014. * terminated again, and to cause any calls into abort
  1015. * task to recognize the already completed case.
  1016. */
  1017. request->sci_request_handle = NULL;
  1018. /* Only remove the request from the remote device list
  1019. * of pending requests if we have not requested error
  1020. * handling on this request.
  1021. */
  1022. if (complete_to_host != isci_perform_error_io_completion)
  1023. list_del_init(&request->dev_node);
  1024. /* Save possible completion ptr. */
  1025. io_request_completion = request->io_request_completion;
  1026. if (io_request_completion) {
  1027. /* This is inherantly a regular I/O request,
  1028. * since we are currently in the regular
  1029. * I/O completion callback function.
  1030. * Signal whoever is waiting that this
  1031. * request is complete.
  1032. */
  1033. complete(io_request_completion);
  1034. }
  1035. isci_host_can_dequeue(isci_host, 1);
  1036. }
  1037. /**
  1038. * isci_request_io_request_get_transfer_length() - This function is called by
  1039. * the sci core to retrieve the transfer length for a given request.
  1040. * @request: This parameter is the isci_request object.
  1041. *
  1042. * length of transfer for specified request.
  1043. */
  1044. u32 isci_request_io_request_get_transfer_length(struct isci_request *request)
  1045. {
  1046. struct sas_task *task = isci_request_access_task(request);
  1047. dev_dbg(&request->isci_host->pdev->dev,
  1048. "%s: total_xfer_len: %d\n",
  1049. __func__,
  1050. task->total_xfer_len);
  1051. return task->total_xfer_len;
  1052. }
  1053. /**
  1054. * isci_request_io_request_get_data_direction() - This function is called by
  1055. * the sci core to retrieve the data direction for a given request.
  1056. * @request: This parameter is the isci_request object.
  1057. *
  1058. * data direction for specified request.
  1059. */
  1060. enum dma_data_direction isci_request_io_request_get_data_direction(
  1061. struct isci_request *request)
  1062. {
  1063. struct sas_task *task = isci_request_access_task(request);
  1064. return task->data_dir;
  1065. }
  1066. /**
  1067. * isci_request_sge_get_address_field() - This function is called by the sci
  1068. * core to retrieve the address field contents for a given sge.
  1069. * @request: This parameter is the isci_request object.
  1070. * @sge_address: This parameter is the sge.
  1071. *
  1072. * physical address in the specified sge.
  1073. */
  1074. dma_addr_t isci_request_sge_get_address_field(
  1075. struct isci_request *request,
  1076. void *sge_address)
  1077. {
  1078. struct sas_task *task = isci_request_access_task(request);
  1079. dma_addr_t ret;
  1080. struct isci_host *isci_host = isci_host_from_sas_ha(
  1081. task->dev->port->ha);
  1082. dev_dbg(&isci_host->pdev->dev,
  1083. "%s: request = %p, sge_address = %p\n",
  1084. __func__,
  1085. request,
  1086. sge_address);
  1087. if (task->data_dir == PCI_DMA_NONE)
  1088. return 0;
  1089. /* the case where num_scatter == 0 is special, in that
  1090. * task->scatter is the actual buffer address, not an sgl.
  1091. * so a map single is required here.
  1092. */
  1093. if ((task->num_scatter == 0) &&
  1094. !sas_protocol_ata(task->task_proto)) {
  1095. ret = dma_map_single(
  1096. &isci_host->pdev->dev,
  1097. task->scatter,
  1098. task->total_xfer_len,
  1099. task->data_dir
  1100. );
  1101. request->zero_scatter_daddr = ret;
  1102. } else
  1103. ret = sg_dma_address(((struct scatterlist *)sge_address));
  1104. dev_dbg(&isci_host->pdev->dev,
  1105. "%s: bus address = %lx\n",
  1106. __func__,
  1107. (unsigned long)ret);
  1108. return ret;
  1109. }
  1110. /**
  1111. * isci_request_sge_get_length_field() - This function is called by the sci
  1112. * core to retrieve the length field contents for a given sge.
  1113. * @request: This parameter is the isci_request object.
  1114. * @sge_address: This parameter is the sge.
  1115. *
  1116. * length field value in the specified sge.
  1117. */
  1118. u32 isci_request_sge_get_length_field(
  1119. struct isci_request *request,
  1120. void *sge_address)
  1121. {
  1122. struct sas_task *task = isci_request_access_task(request);
  1123. int ret;
  1124. dev_dbg(&request->isci_host->pdev->dev,
  1125. "%s: request = %p, sge_address = %p\n",
  1126. __func__,
  1127. request,
  1128. sge_address);
  1129. if (task->data_dir == PCI_DMA_NONE)
  1130. return 0;
  1131. /* the case where num_scatter == 0 is special, in that
  1132. * task->scatter is the actual buffer address, not an sgl.
  1133. * so we return total_xfer_len here.
  1134. */
  1135. if (task->num_scatter == 0)
  1136. ret = task->total_xfer_len;
  1137. else
  1138. ret = sg_dma_len((struct scatterlist *)sge_address);
  1139. dev_dbg(&request->isci_host->pdev->dev,
  1140. "%s: len = %d\n",
  1141. __func__,
  1142. ret);
  1143. return ret;
  1144. }
  1145. /**
  1146. * isci_request_ssp_io_request_get_cdb_address() - This function is called by
  1147. * the sci core to retrieve the cdb address for a given request.
  1148. * @request: This parameter is the isci_request object.
  1149. *
  1150. * cdb address for specified request.
  1151. */
  1152. void *isci_request_ssp_io_request_get_cdb_address(
  1153. struct isci_request *request)
  1154. {
  1155. struct sas_task *task = isci_request_access_task(request);
  1156. dev_dbg(&request->isci_host->pdev->dev,
  1157. "%s: request->task->ssp_task.cdb = %p\n",
  1158. __func__,
  1159. task->ssp_task.cdb);
  1160. return task->ssp_task.cdb;
  1161. }
  1162. /**
  1163. * isci_request_ssp_io_request_get_cdb_length() - This function is called by
  1164. * the sci core to retrieve the cdb length for a given request.
  1165. * @request: This parameter is the isci_request object.
  1166. *
  1167. * cdb length for specified request.
  1168. */
  1169. u32 isci_request_ssp_io_request_get_cdb_length(
  1170. struct isci_request *request)
  1171. {
  1172. return 16;
  1173. }
  1174. /**
  1175. * isci_request_ssp_io_request_get_lun() - This function is called by the sci
  1176. * core to retrieve the lun for a given request.
  1177. * @request: This parameter is the isci_request object.
  1178. *
  1179. * lun for specified request.
  1180. */
  1181. u32 isci_request_ssp_io_request_get_lun(
  1182. struct isci_request *request)
  1183. {
  1184. struct sas_task *task = isci_request_access_task(request);
  1185. #ifdef DEBUG
  1186. int i;
  1187. for (i = 0; i < 8; i++)
  1188. dev_dbg(&request->isci_host->pdev->dev,
  1189. "%s: task->ssp_task.LUN[%d] = %x\n",
  1190. __func__, i, task->ssp_task.LUN[i]);
  1191. #endif
  1192. return task->ssp_task.LUN[0];
  1193. }
  1194. /**
  1195. * isci_request_ssp_io_request_get_task_attribute() - This function is called
  1196. * by the sci core to retrieve the task attribute for a given request.
  1197. * @request: This parameter is the isci_request object.
  1198. *
  1199. * task attribute for specified request.
  1200. */
  1201. u32 isci_request_ssp_io_request_get_task_attribute(
  1202. struct isci_request *request)
  1203. {
  1204. struct sas_task *task = isci_request_access_task(request);
  1205. dev_dbg(&request->isci_host->pdev->dev,
  1206. "%s: request->task->ssp_task.task_attr = %x\n",
  1207. __func__,
  1208. task->ssp_task.task_attr);
  1209. return task->ssp_task.task_attr;
  1210. }
  1211. /**
  1212. * isci_request_ssp_io_request_get_command_priority() - This function is called
  1213. * by the sci core to retrieve the command priority for a given request.
  1214. * @request: This parameter is the isci_request object.
  1215. *
  1216. * command priority for specified request.
  1217. */
  1218. u32 isci_request_ssp_io_request_get_command_priority(
  1219. struct isci_request *request)
  1220. {
  1221. struct sas_task *task = isci_request_access_task(request);
  1222. dev_dbg(&request->isci_host->pdev->dev,
  1223. "%s: request->task->ssp_task.task_prio = %x\n",
  1224. __func__,
  1225. task->ssp_task.task_prio);
  1226. return task->ssp_task.task_prio;
  1227. }