request.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. #ifndef _ISCI_REQUEST_H_
  56. #define _ISCI_REQUEST_H_
  57. #include "isci.h"
  58. #include "host.h"
  59. #include "scu_task_context.h"
  60. /**
  61. * struct isci_request_status - This enum defines the possible states of an I/O
  62. * request.
  63. *
  64. *
  65. */
  66. enum isci_request_status {
  67. unallocated = 0x00,
  68. allocated = 0x01,
  69. started = 0x02,
  70. completed = 0x03,
  71. aborting = 0x04,
  72. aborted = 0x05,
  73. terminating = 0x06,
  74. dead = 0x07
  75. };
  76. enum task_type {
  77. io_task = 0,
  78. tmf_task = 1
  79. };
  80. enum sci_request_protocol {
  81. SCIC_NO_PROTOCOL,
  82. SCIC_SMP_PROTOCOL,
  83. SCIC_SSP_PROTOCOL,
  84. SCIC_STP_PROTOCOL
  85. }; /* XXX remove me, use sas_task.{dev|task_proto} instead */;
  86. struct scic_sds_stp_request {
  87. union {
  88. u32 ncq;
  89. u32 udma;
  90. struct scic_sds_stp_pio_request {
  91. /**
  92. * Total transfer for the entire PIO request recorded at request constuction
  93. * time.
  94. *
  95. * @todo Should we just decrement this value for each byte of data transitted
  96. * or received to elemenate the current_transfer_bytes field?
  97. */
  98. u32 total_transfer_bytes;
  99. /**
  100. * Total number of bytes received/transmitted in data frames since the start
  101. * of the IO request. At the end of the IO request this should equal the
  102. * total_transfer_bytes.
  103. */
  104. u32 current_transfer_bytes;
  105. /**
  106. * The number of bytes requested in the in the PIO setup.
  107. */
  108. u32 pio_transfer_bytes;
  109. /**
  110. * PIO Setup ending status value to tell us if we need to wait for another FIS
  111. * or if the transfer is complete. On the receipt of a D2H FIS this will be
  112. * the status field of that FIS.
  113. */
  114. u8 ending_status;
  115. /**
  116. * On receipt of a D2H FIS this will be the ending error field if the
  117. * ending_status has the SATA_STATUS_ERR bit set.
  118. */
  119. u8 ending_error;
  120. struct scic_sds_request_pio_sgl {
  121. struct scu_sgl_element_pair *sgl_pair;
  122. u8 sgl_set;
  123. u32 sgl_offset;
  124. } request_current;
  125. } pio;
  126. struct {
  127. /**
  128. * The number of bytes requested in the PIO setup before CDB data frame.
  129. */
  130. u32 device_preferred_cdb_length;
  131. } packet;
  132. } type;
  133. };
  134. struct scic_sds_request {
  135. /**
  136. * This field contains the information for the base request state machine.
  137. */
  138. struct sci_base_state_machine state_machine;
  139. /**
  140. * This field simply points to the controller to which this IO request
  141. * is associated.
  142. */
  143. struct scic_sds_controller *owning_controller;
  144. /**
  145. * This field simply points to the remote device to which this IO request
  146. * is associated.
  147. */
  148. struct scic_sds_remote_device *target_device;
  149. /**
  150. * This field is utilized to determine if the SCI user is managing
  151. * the IO tag for this request or if the core is managing it.
  152. */
  153. bool was_tag_assigned_by_user;
  154. /**
  155. * This field indicates the IO tag for this request. The IO tag is
  156. * comprised of the task_index and a sequence count. The sequence count
  157. * is utilized to help identify tasks from one life to another.
  158. */
  159. u16 io_tag;
  160. /**
  161. * This field specifies the protocol being utilized for this
  162. * IO request.
  163. */
  164. enum sci_request_protocol protocol;
  165. /**
  166. * This field indicates the completion status taken from the SCUs
  167. * completion code. It indicates the completion result for the SCU hardware.
  168. */
  169. u32 scu_status;
  170. /**
  171. * This field indicates the completion status returned to the SCI user. It
  172. * indicates the users view of the io request completion.
  173. */
  174. u32 sci_status;
  175. /**
  176. * This field contains the value to be utilized when posting (e.g. Post_TC,
  177. * Post_TC_Abort) this request to the silicon.
  178. */
  179. u32 post_context;
  180. struct scu_task_context *task_context_buffer;
  181. struct scu_task_context tc ____cacheline_aligned;
  182. /* could be larger with sg chaining */
  183. #define SCU_SGL_SIZE ((SCU_IO_REQUEST_SGE_COUNT + 1) / 2)
  184. struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
  185. /**
  186. * This field indicates if this request is a task management request or
  187. * normal IO request.
  188. */
  189. bool is_task_management_request;
  190. /**
  191. * This field is a pointer to the stored rx frame data. It is used in STP
  192. * internal requests and SMP response frames. If this field is non-NULL the
  193. * saved frame must be released on IO request completion.
  194. *
  195. * @todo In the future do we want to keep a list of RX frame buffers?
  196. */
  197. u32 saved_rx_frame_index;
  198. /**
  199. * This field specifies the current state handlers in place for this
  200. * IO Request object. This field is updated each time the request
  201. * changes state.
  202. */
  203. const struct scic_sds_io_request_state_handler *state_handlers;
  204. /**
  205. * This field in the recorded device sequence for the io request. This is
  206. * recorded during the build operation and is compared in the start
  207. * operation. If the sequence is different then there was a change of
  208. * devices from the build to start operations.
  209. */
  210. u8 device_sequence;
  211. union {
  212. struct {
  213. union {
  214. struct ssp_cmd_iu cmd;
  215. struct ssp_task_iu tmf;
  216. };
  217. union {
  218. struct ssp_response_iu rsp;
  219. u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
  220. };
  221. } ssp;
  222. struct {
  223. struct smp_req cmd;
  224. struct smp_resp rsp;
  225. } smp;
  226. struct {
  227. struct scic_sds_stp_request req;
  228. struct host_to_dev_fis cmd;
  229. struct dev_to_host_fis rsp;
  230. } stp;
  231. };
  232. };
  233. static inline struct scic_sds_request *to_sci_req(struct scic_sds_stp_request *stp_req)
  234. {
  235. struct scic_sds_request *sci_req;
  236. sci_req = container_of(stp_req, typeof(*sci_req), stp.req);
  237. return sci_req;
  238. }
  239. struct isci_request {
  240. enum isci_request_status status;
  241. enum task_type ttype;
  242. unsigned short io_tag;
  243. bool complete_in_target;
  244. bool terminated;
  245. union ttype_ptr_union {
  246. struct sas_task *io_task_ptr; /* When ttype==io_task */
  247. struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
  248. } ttype_ptr;
  249. struct isci_host *isci_host;
  250. struct isci_remote_device *isci_device;
  251. /* For use in the requests_to_{complete|abort} lists: */
  252. struct list_head completed_node;
  253. /* For use in the reqs_in_process list: */
  254. struct list_head dev_node;
  255. spinlock_t state_lock;
  256. dma_addr_t request_daddr;
  257. dma_addr_t zero_scatter_daddr;
  258. unsigned int num_sg_entries; /* returned by pci_alloc_sg */
  259. /** Note: "io_request_completion" is completed in two different ways
  260. * depending on whether this is a TMF or regular request.
  261. * - TMF requests are completed in the thread that started them;
  262. * - regular requests are completed in the request completion callback
  263. * function.
  264. * This difference in operation allows the aborter of a TMF request
  265. * to be sure that once the TMF request completes, the I/O that the
  266. * TMF was aborting is guaranteed to have completed.
  267. */
  268. struct completion *io_request_completion;
  269. struct scic_sds_request sci;
  270. };
  271. static inline struct isci_request *sci_req_to_ireq(struct scic_sds_request *sci_req)
  272. {
  273. struct isci_request *ireq = container_of(sci_req, typeof(*ireq), sci);
  274. return ireq;
  275. }
  276. /**
  277. * enum sci_base_request_states - This enumeration depicts all the states for
  278. * the common request state machine.
  279. *
  280. *
  281. */
  282. enum sci_base_request_states {
  283. /**
  284. * Simply the initial state for the base request state machine.
  285. */
  286. SCI_BASE_REQUEST_STATE_INITIAL,
  287. /**
  288. * This state indicates that the request has been constructed. This state
  289. * is entered from the INITIAL state.
  290. */
  291. SCI_BASE_REQUEST_STATE_CONSTRUCTED,
  292. /**
  293. * This state indicates that the request has been started. This state is
  294. * entered from the CONSTRUCTED state.
  295. */
  296. SCI_BASE_REQUEST_STATE_STARTED,
  297. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE,
  298. SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE,
  299. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE,
  300. SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE,
  301. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE,
  302. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE,
  303. SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE,
  304. /**
  305. * While in this state the IO request object is waiting for the TC completion
  306. * notification for the H2D Register FIS
  307. */
  308. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE,
  309. /**
  310. * While in this state the IO request object is waiting for either a PIO Setup
  311. * FIS or a D2H register FIS. The type of frame received is based on the
  312. * result of the prior frame and line conditions.
  313. */
  314. SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE,
  315. /**
  316. * While in this state the IO request object is waiting for a DATA frame from
  317. * the device.
  318. */
  319. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE,
  320. /**
  321. * While in this state the IO request object is waiting to transmit the next data
  322. * frame to the device.
  323. */
  324. SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE,
  325. /**
  326. * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
  327. * task management request is waiting for the transmission of the
  328. * initial frame (i.e. command, task, etc.).
  329. */
  330. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION,
  331. /**
  332. * This sub-state indicates that the started task management request
  333. * is waiting for the reception of an unsolicited frame
  334. * (i.e. response IU).
  335. */
  336. SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE,
  337. /**
  338. * This sub-state indicates that the started task management request
  339. * is waiting for the reception of an unsolicited frame
  340. * (i.e. response IU).
  341. */
  342. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE,
  343. /**
  344. * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP request is
  345. * waiting for the transmission of the initial frame (i.e. command, task, etc.).
  346. */
  347. SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION,
  348. /**
  349. * This state indicates that the request has completed.
  350. * This state is entered from the STARTED state. This state is entered from
  351. * the ABORTING state.
  352. */
  353. SCI_BASE_REQUEST_STATE_COMPLETED,
  354. /**
  355. * This state indicates that the request is in the process of being
  356. * terminated/aborted.
  357. * This state is entered from the CONSTRUCTED state.
  358. * This state is entered from the STARTED state.
  359. */
  360. SCI_BASE_REQUEST_STATE_ABORTING,
  361. /**
  362. * Simply the final state for the base request state machine.
  363. */
  364. SCI_BASE_REQUEST_STATE_FINAL,
  365. };
  366. typedef enum sci_status (*scic_sds_io_request_handler_t)
  367. (struct scic_sds_request *request);
  368. typedef enum sci_status (*scic_sds_io_request_frame_handler_t)
  369. (struct scic_sds_request *req, u32 frame);
  370. typedef enum sci_status (*scic_sds_io_request_event_handler_t)
  371. (struct scic_sds_request *req, u32 event);
  372. typedef enum sci_status (*scic_sds_io_request_task_completion_handler_t)
  373. (struct scic_sds_request *req, u32 completion_code);
  374. /**
  375. * struct scic_sds_io_request_state_handler - This is the SDS core definition
  376. * of the state handlers.
  377. *
  378. *
  379. */
  380. struct scic_sds_io_request_state_handler {
  381. /**
  382. * The start_handler specifies the method invoked when a user attempts to
  383. * start a request.
  384. */
  385. scic_sds_io_request_handler_t start_handler;
  386. /**
  387. * The abort_handler specifies the method invoked when a user attempts to
  388. * abort a request.
  389. */
  390. scic_sds_io_request_handler_t abort_handler;
  391. /**
  392. * The complete_handler specifies the method invoked when a user attempts to
  393. * complete a request.
  394. */
  395. scic_sds_io_request_handler_t complete_handler;
  396. scic_sds_io_request_task_completion_handler_t tc_completion_handler;
  397. scic_sds_io_request_event_handler_t event_handler;
  398. scic_sds_io_request_frame_handler_t frame_handler;
  399. };
  400. /**
  401. * scic_sds_request_get_controller() -
  402. *
  403. * This macro will return the controller for this io request object
  404. */
  405. #define scic_sds_request_get_controller(sci_req) \
  406. ((sci_req)->owning_controller)
  407. /**
  408. * scic_sds_request_get_device() -
  409. *
  410. * This macro will return the device for this io request object
  411. */
  412. #define scic_sds_request_get_device(sci_req) \
  413. ((sci_req)->target_device)
  414. /**
  415. * scic_sds_request_get_port() -
  416. *
  417. * This macro will return the port for this io request object
  418. */
  419. #define scic_sds_request_get_port(sci_req) \
  420. scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req))
  421. /**
  422. * scic_sds_request_get_post_context() -
  423. *
  424. * This macro returns the constructed post context result for the io request.
  425. */
  426. #define scic_sds_request_get_post_context(sci_req) \
  427. ((sci_req)->post_context)
  428. /**
  429. * scic_sds_request_get_task_context() -
  430. *
  431. * This is a helper macro to return the os handle for this request object.
  432. */
  433. #define scic_sds_request_get_task_context(request) \
  434. ((request)->task_context_buffer)
  435. /**
  436. * scic_sds_request_set_status() -
  437. *
  438. * This macro will set the scu hardware status and sci request completion
  439. * status for an io request.
  440. */
  441. #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
  442. { \
  443. (request)->scu_status = (scu_status_code); \
  444. (request)->sci_status = (sci_status_code); \
  445. }
  446. #define scic_sds_request_complete(a_request) \
  447. ((a_request)->state_handlers->complete_handler(a_request))
  448. extern enum sci_status
  449. scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code);
  450. /**
  451. * SCU_SGL_ZERO() -
  452. *
  453. * This macro zeros the hardware SGL element data
  454. */
  455. #define SCU_SGL_ZERO(scu_sge) \
  456. { \
  457. (scu_sge).length = 0; \
  458. (scu_sge).address_lower = 0; \
  459. (scu_sge).address_upper = 0; \
  460. (scu_sge).address_modifier = 0; \
  461. }
  462. /**
  463. * SCU_SGL_COPY() -
  464. *
  465. * This macro copys the SGL Element data from the host os to the hardware SGL
  466. * elment data
  467. */
  468. #define SCU_SGL_COPY(scu_sge, os_sge) \
  469. { \
  470. (scu_sge).length = sg_dma_len(sg); \
  471. (scu_sge).address_upper = \
  472. upper_32_bits(sg_dma_address(sg)); \
  473. (scu_sge).address_lower = \
  474. lower_32_bits(sg_dma_address(sg)); \
  475. (scu_sge).address_modifier = 0; \
  476. }
  477. enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req);
  478. enum sci_status scic_sds_io_request_terminate(struct scic_sds_request *sci_req);
  479. enum sci_status scic_sds_io_request_event_handler(struct scic_sds_request *sci_req,
  480. u32 event_code);
  481. enum sci_status scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req,
  482. u32 frame_index);
  483. enum sci_status scic_sds_task_request_terminate(struct scic_sds_request *sci_req);
  484. /* XXX open code in caller */
  485. static inline void *scic_request_get_virt_addr(struct scic_sds_request *sci_req,
  486. dma_addr_t phys_addr)
  487. {
  488. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  489. dma_addr_t offset;
  490. BUG_ON(phys_addr < ireq->request_daddr);
  491. offset = phys_addr - ireq->request_daddr;
  492. BUG_ON(offset >= sizeof(*ireq));
  493. return (char *)ireq + offset;
  494. }
  495. /* XXX open code in caller */
  496. static inline dma_addr_t scic_io_request_get_dma_addr(struct scic_sds_request *sci_req,
  497. void *virt_addr)
  498. {
  499. struct isci_request *ireq = sci_req_to_ireq(sci_req);
  500. char *requested_addr = (char *)virt_addr;
  501. char *base_addr = (char *)ireq;
  502. BUG_ON(requested_addr < base_addr);
  503. BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
  504. return ireq->request_daddr + (requested_addr - base_addr);
  505. }
  506. /**
  507. * This function gets the status of the request object.
  508. * @request: This parameter points to the isci_request object
  509. *
  510. * status of the object as a isci_request_status enum.
  511. */
  512. static inline
  513. enum isci_request_status isci_request_get_state(
  514. struct isci_request *isci_request)
  515. {
  516. BUG_ON(isci_request == NULL);
  517. /*probably a bad sign... */
  518. if (isci_request->status == unallocated)
  519. dev_warn(&isci_request->isci_host->pdev->dev,
  520. "%s: isci_request->status == unallocated\n",
  521. __func__);
  522. return isci_request->status;
  523. }
  524. /**
  525. * isci_request_change_state() - This function sets the status of the request
  526. * object.
  527. * @request: This parameter points to the isci_request object
  528. * @status: This Parameter is the new status of the object
  529. *
  530. */
  531. static inline enum isci_request_status isci_request_change_state(
  532. struct isci_request *isci_request,
  533. enum isci_request_status status)
  534. {
  535. enum isci_request_status old_state;
  536. unsigned long flags;
  537. dev_dbg(&isci_request->isci_host->pdev->dev,
  538. "%s: isci_request = %p, state = 0x%x\n",
  539. __func__,
  540. isci_request,
  541. status);
  542. BUG_ON(isci_request == NULL);
  543. spin_lock_irqsave(&isci_request->state_lock, flags);
  544. old_state = isci_request->status;
  545. isci_request->status = status;
  546. spin_unlock_irqrestore(&isci_request->state_lock, flags);
  547. return old_state;
  548. }
  549. /**
  550. * isci_request_change_started_to_newstate() - This function sets the status of
  551. * the request object.
  552. * @request: This parameter points to the isci_request object
  553. * @status: This Parameter is the new status of the object
  554. *
  555. * state previous to any change.
  556. */
  557. static inline enum isci_request_status isci_request_change_started_to_newstate(
  558. struct isci_request *isci_request,
  559. struct completion *completion_ptr,
  560. enum isci_request_status newstate)
  561. {
  562. enum isci_request_status old_state;
  563. unsigned long flags;
  564. spin_lock_irqsave(&isci_request->state_lock, flags);
  565. old_state = isci_request->status;
  566. if (old_state == started || old_state == aborting) {
  567. BUG_ON(isci_request->io_request_completion != NULL);
  568. isci_request->io_request_completion = completion_ptr;
  569. isci_request->status = newstate;
  570. }
  571. spin_unlock_irqrestore(&isci_request->state_lock, flags);
  572. dev_dbg(&isci_request->isci_host->pdev->dev,
  573. "%s: isci_request = %p, old_state = 0x%x\n",
  574. __func__,
  575. isci_request,
  576. old_state);
  577. return old_state;
  578. }
  579. /**
  580. * isci_request_change_started_to_aborted() - This function sets the status of
  581. * the request object.
  582. * @request: This parameter points to the isci_request object
  583. * @completion_ptr: This parameter is saved as the kernel completion structure
  584. * signalled when the old request completes.
  585. *
  586. * state previous to any change.
  587. */
  588. static inline enum isci_request_status isci_request_change_started_to_aborted(
  589. struct isci_request *isci_request,
  590. struct completion *completion_ptr)
  591. {
  592. return isci_request_change_started_to_newstate(
  593. isci_request, completion_ptr, aborted
  594. );
  595. }
  596. /**
  597. * isci_request_free() - This function frees the request object.
  598. * @isci_host: This parameter specifies the ISCI host object
  599. * @isci_request: This parameter points to the isci_request object
  600. *
  601. */
  602. static inline void isci_request_free(
  603. struct isci_host *isci_host,
  604. struct isci_request *isci_request)
  605. {
  606. if (!isci_request)
  607. return;
  608. /* release the dma memory if we fail. */
  609. dma_pool_free(isci_host->dma_pool, isci_request,
  610. isci_request->request_daddr);
  611. }
  612. /* #define ISCI_REQUEST_VALIDATE_ACCESS
  613. */
  614. #ifdef ISCI_REQUEST_VALIDATE_ACCESS
  615. static inline
  616. struct sas_task *isci_request_access_task(struct isci_request *isci_request)
  617. {
  618. BUG_ON(isci_request->ttype != io_task);
  619. return isci_request->ttype_ptr.io_task_ptr;
  620. }
  621. static inline
  622. struct isci_tmf *isci_request_access_tmf(struct isci_request *isci_request)
  623. {
  624. BUG_ON(isci_request->ttype != tmf_task);
  625. return isci_request->ttype_ptr.tmf_task_ptr;
  626. }
  627. #else /* not ISCI_REQUEST_VALIDATE_ACCESS */
  628. #define isci_request_access_task(RequestPtr) \
  629. ((RequestPtr)->ttype_ptr.io_task_ptr)
  630. #define isci_request_access_tmf(RequestPtr) \
  631. ((RequestPtr)->ttype_ptr.tmf_task_ptr)
  632. #endif /* not ISCI_REQUEST_VALIDATE_ACCESS */
  633. int isci_request_alloc_tmf(
  634. struct isci_host *isci_host,
  635. struct isci_tmf *isci_tmf,
  636. struct isci_request **isci_request,
  637. struct isci_remote_device *isci_device,
  638. gfp_t gfp_flags);
  639. int isci_request_execute(
  640. struct isci_host *isci_host,
  641. struct sas_task *task,
  642. struct isci_request **request,
  643. gfp_t gfp_flags);
  644. /**
  645. * isci_request_unmap_sgl() - This function unmaps the DMA address of a given
  646. * sgl
  647. * @request: This parameter points to the isci_request object
  648. * @*pdev: This Parameter is the pci_device struct for the controller
  649. *
  650. */
  651. static inline void isci_request_unmap_sgl(
  652. struct isci_request *request,
  653. struct pci_dev *pdev)
  654. {
  655. struct sas_task *task = isci_request_access_task(request);
  656. dev_dbg(&request->isci_host->pdev->dev,
  657. "%s: request = %p, task = %p,\n"
  658. "task->data_dir = %d, is_sata = %d\n ",
  659. __func__,
  660. request,
  661. task,
  662. task->data_dir,
  663. sas_protocol_ata(task->task_proto));
  664. if ((task->data_dir != PCI_DMA_NONE) &&
  665. !sas_protocol_ata(task->task_proto)) {
  666. if (task->num_scatter == 0)
  667. /* 0 indicates a single dma address */
  668. dma_unmap_single(
  669. &pdev->dev,
  670. request->zero_scatter_daddr,
  671. task->total_xfer_len,
  672. task->data_dir
  673. );
  674. else /* unmap the sgl dma addresses */
  675. dma_unmap_sg(
  676. &pdev->dev,
  677. task->scatter,
  678. request->num_sg_entries,
  679. task->data_dir
  680. );
  681. }
  682. }
  683. /**
  684. * isci_request_io_request_get_next_sge() - This function is called by the sci
  685. * core to retrieve the next sge for a given request.
  686. * @request: This parameter is the isci_request object.
  687. * @current_sge_address: This parameter is the last sge retrieved by the sci
  688. * core for this request.
  689. *
  690. * pointer to the next sge for specified request.
  691. */
  692. static inline void *isci_request_io_request_get_next_sge(
  693. struct isci_request *request,
  694. void *current_sge_address)
  695. {
  696. struct sas_task *task = isci_request_access_task(request);
  697. void *ret = NULL;
  698. dev_dbg(&request->isci_host->pdev->dev,
  699. "%s: request = %p, "
  700. "current_sge_address = %p, "
  701. "num_scatter = %d\n",
  702. __func__,
  703. request,
  704. current_sge_address,
  705. task->num_scatter);
  706. if (!current_sge_address) /* First time through.. */
  707. ret = task->scatter; /* always task->scatter */
  708. else if (task->num_scatter == 0) /* Next element, if num_scatter == 0 */
  709. ret = NULL; /* there is only one element. */
  710. else
  711. ret = sg_next(current_sge_address); /* sg_next returns NULL
  712. * for the last element
  713. */
  714. dev_dbg(&request->isci_host->pdev->dev,
  715. "%s: next sge address = %p\n",
  716. __func__,
  717. ret);
  718. return ret;
  719. }
  720. void isci_terminate_pending_requests(struct isci_host *isci_host,
  721. struct isci_remote_device *isci_device,
  722. enum isci_request_status new_request_state);
  723. enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
  724. struct scic_sds_remote_device *sci_dev,
  725. u16 io_tag,
  726. struct scic_sds_request *sci_req);
  727. enum sci_status scic_task_request_construct_ssp(struct scic_sds_request *sci_req);
  728. enum sci_status scic_task_request_construct_sata(struct scic_sds_request *sci_req);
  729. enum sci_status scic_sds_stp_udma_request_construct(struct scic_sds_request *sci_req,
  730. u32 transfer_length,
  731. enum dma_data_direction dir);
  732. void scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag);
  733. void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req);
  734. #endif /* !defined(_ISCI_REQUEST_H_) */