events.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. /**
  56. * This file contains isci module object implementation.
  57. *
  58. *
  59. */
  60. #include "isci.h"
  61. #include "request.h"
  62. #include "sata.h"
  63. #include "task.h"
  64. #include "events.h"
  65. /**
  66. * isci_event_timer_create() - This callback method asks the user to create a
  67. * timer and provide a handle for this timer for use in further timer
  68. * interactions. The appropriate isci timer object function is called to
  69. * create a timer object.
  70. * @timer_callback: This parameter specifies the callback method to be invoked
  71. * whenever the timer expires.
  72. * @controller: This parameter specifies the controller with which this timer
  73. * is to be associated.
  74. * @cookie: This parameter specifies a piece of information that the user must
  75. * retain. This cookie is to be supplied by the user anytime a timeout
  76. * occurs for the created timer.
  77. *
  78. * This method returns a handle to a timer object created by the user. The
  79. * handle will be utilized for all further interactions relating to this timer.
  80. */
  81. void *isci_event_timer_create(
  82. struct scic_sds_controller *controller,
  83. void (*timer_callback)(void *),
  84. void *cookie)
  85. {
  86. struct isci_host *isci_host;
  87. struct isci_timer *timer = NULL;
  88. isci_host = (struct isci_host *)sci_object_get_association(controller);
  89. dev_dbg(&isci_host->pdev->dev,
  90. "%s: isci_host = %p",
  91. __func__, isci_host);
  92. timer = isci_timer_create(&isci_host->timer_list_struct,
  93. isci_host,
  94. cookie,
  95. timer_callback);
  96. dev_dbg(&isci_host->pdev->dev, "%s: timer = %p\n", __func__, timer);
  97. return (void *)timer;
  98. }
  99. /**
  100. * isci_event_timer_start() - This callback method asks the user to start the
  101. * supplied timer. The appropriate isci timer object function is called to
  102. * start the timer.
  103. * @controller: This parameter specifies the controller with which this timer
  104. * is to associated.
  105. * @timer: This parameter specifies the timer to be started.
  106. * @milliseconds: This parameter specifies the number of milliseconds for which
  107. * to stall. The operating system driver is allowed to round this value up
  108. * where necessary.
  109. *
  110. */
  111. void isci_event_timer_start(
  112. struct scic_sds_controller *controller,
  113. void *timer,
  114. u32 milliseconds)
  115. {
  116. struct isci_host *isci_host;
  117. isci_host =
  118. (struct isci_host *)sci_object_get_association(controller);
  119. dev_dbg(&isci_host->pdev->dev,
  120. "%s: isci_host = %p, timer = %p, milliseconds = %d\n",
  121. __func__, isci_host, timer, milliseconds);
  122. isci_timer_start((struct isci_timer *)timer, milliseconds);
  123. }
  124. /**
  125. * isci_event_timer_stop() - This callback method asks the user to stop the
  126. * supplied timer. The appropriate isci timer object function is called to
  127. * stop the timer.
  128. * @controller: This parameter specifies the controller with which this timer
  129. * is to associated.
  130. * @timer: This parameter specifies the timer to be stopped.
  131. *
  132. */
  133. void isci_event_timer_stop(
  134. struct scic_sds_controller *controller,
  135. void *timer)
  136. {
  137. struct isci_host *isci_host;
  138. isci_host =
  139. (struct isci_host *)sci_object_get_association(controller);
  140. dev_dbg(&isci_host->pdev->dev,
  141. "%s: isci_host = %p, timer = %p\n",
  142. __func__, isci_host, timer);
  143. isci_timer_stop((struct isci_timer *)timer);
  144. }
  145. /**
  146. * isci_event_controller_start_complete() - This user callback will inform the
  147. * user that the controller has finished the start process. The associated
  148. * isci host adapter's start_complete function is called.
  149. * @controller: This parameter specifies the controller that was started.
  150. * @completion_status: This parameter specifies the results of the start
  151. * operation. SCI_SUCCESS indicates successful completion.
  152. *
  153. */
  154. void isci_event_controller_start_complete(
  155. struct scic_sds_controller *controller,
  156. enum sci_status completion_status)
  157. {
  158. struct isci_host *isci_host =
  159. (struct isci_host *)sci_object_get_association(controller);
  160. dev_dbg(&isci_host->pdev->dev,
  161. "%s: isci_host = %p\n", __func__, isci_host);
  162. isci_host_start_complete(isci_host, completion_status);
  163. }
  164. /**
  165. * isci_event_controller_stop_complete() - This user callback will inform the user
  166. * that the controller has finished the stop process. The associated isci
  167. * host adapter's start_complete function is called.
  168. * @controller: This parameter specifies the controller that was stopped.
  169. * @completion_status: This parameter specifies the results of the stop
  170. * operation. SCI_SUCCESS indicates successful completion.
  171. *
  172. */
  173. void isci_event_controller_stop_complete(
  174. struct scic_sds_controller *controller,
  175. enum sci_status completion_status)
  176. {
  177. struct isci_host *isci_host =
  178. (struct isci_host *)sci_object_get_association(controller);
  179. dev_dbg(&isci_host->pdev->dev,
  180. "%s: status = 0x%x\n", __func__, completion_status);
  181. isci_host_stop_complete(isci_host, completion_status);
  182. }
  183. /**
  184. * isci_event_io_request_complete() - This user callback will inform the user that
  185. * an IO request has completed.
  186. * @controller: This parameter specifies the controller on which the IO is
  187. * completing.
  188. * @remote_device: This parameter specifies the remote device on which this IO
  189. * request is completing.
  190. * @io_request: This parameter specifies the IO request that has completed.
  191. * @completion_status: This parameter specifies the results of the IO request
  192. * operation. SCI_SUCCESS indicates successful completion.
  193. *
  194. */
  195. void isci_event_io_request_complete(
  196. struct scic_sds_controller *controller,
  197. struct scic_sds_remote_device *remote_device,
  198. struct scic_sds_request *scic_io_request,
  199. enum sci_io_status completion_status)
  200. {
  201. struct isci_request *request;
  202. struct isci_host *isci_host;
  203. isci_host =
  204. (struct isci_host *)sci_object_get_association(controller);
  205. request =
  206. (struct isci_request *)sci_object_get_association(
  207. scic_io_request
  208. );
  209. isci_request_io_request_complete(isci_host,
  210. request,
  211. completion_status);
  212. }
  213. /**
  214. * isci_event_task_request_complete() - This user callback will inform the user
  215. * that a task management request completed.
  216. * @controller: This parameter specifies the controller on which the task
  217. * management request is completing.
  218. * @remote_device: This parameter specifies the remote device on which this
  219. * task management request is completing.
  220. * @task_request: This parameter specifies the task management request that has
  221. * completed.
  222. * @completion_status: This parameter specifies the results of the IO request
  223. * operation. SCI_SUCCESS indicates successful completion.
  224. *
  225. */
  226. void isci_event_task_request_complete(
  227. struct scic_sds_controller *controller,
  228. struct scic_sds_remote_device *remote_device,
  229. struct scic_sds_request *scic_task_request,
  230. enum sci_task_status completion_status)
  231. {
  232. struct isci_request *request;
  233. struct isci_host *isci_host;
  234. isci_host =
  235. (struct isci_host *)sci_object_get_association(controller);
  236. request =
  237. (struct isci_request *)sci_object_get_association(
  238. scic_task_request);
  239. isci_task_request_complete(isci_host, request, completion_status);
  240. }
  241. /**
  242. * isci_event_port_stop_complete() - This method informs the user when a stop
  243. * operation on the port has completed.
  244. * @controller: This parameter represents the controller which contains the
  245. * port.
  246. * @port: This parameter specifies the SCI port object for which the callback
  247. * is being invoked.
  248. * @completion_status: This parameter specifies the status for the operation
  249. * being completed.
  250. *
  251. */
  252. void isci_event_port_stop_complete(
  253. struct scic_sds_controller *controller,
  254. struct scic_sds_port *port,
  255. enum sci_status completion_status)
  256. {
  257. struct isci_host *isci_host;
  258. isci_host = (struct isci_host *)sci_object_get_association(controller);
  259. dev_notice(&isci_host->pdev->dev, "Port stop complete\n");
  260. }
  261. /**
  262. * isci_event_port_hard_reset_complete() - This method informs the user when a
  263. * hard reset on the port has completed. This hard reset could have been
  264. * initiated by the user or by the remote port.
  265. * @controller: This parameter represents the controller which contains the
  266. * port.
  267. * @port: This parameter specifies the SCI port object for which the callback
  268. * is being invoked.
  269. * @completion_status: This parameter specifies the status for the operation
  270. * being completed.
  271. *
  272. */
  273. void isci_event_port_hard_reset_complete(
  274. struct scic_sds_controller *controller,
  275. struct scic_sds_port *port,
  276. enum sci_status completion_status)
  277. {
  278. struct isci_port *isci_port
  279. = (struct isci_port *)sci_object_get_association(port);
  280. isci_port_hard_reset_complete(isci_port, completion_status);
  281. }
  282. /**
  283. * isci_event_port_ready() - This method informs the user that the port is now in
  284. * a ready state and can be utilized to issue IOs.
  285. * @controller: This parameter represents the controller which contains the
  286. * port.
  287. * @port: This parameter specifies the SCI port object for which the callback
  288. * is being invoked.
  289. *
  290. */
  291. void isci_event_port_ready(
  292. struct scic_sds_controller *controller,
  293. struct scic_sds_port *port)
  294. {
  295. struct isci_port *isci_port;
  296. struct isci_host *isci_host;
  297. isci_host =
  298. (struct isci_host *)sci_object_get_association(controller);
  299. isci_port =
  300. (struct isci_port *)sci_object_get_association(port);
  301. dev_dbg(&isci_host->pdev->dev,
  302. "%s: isci_port = %p\n", __func__, isci_port);
  303. isci_port_ready(isci_host, isci_port);
  304. }
  305. /**
  306. * isci_event_port_not_ready() - This method informs the user that the port is now
  307. * not in a ready (i.e. busy) state and can't be utilized to issue IOs.
  308. * @controller: This parameter represents the controller which contains the
  309. * port.
  310. * @port: This parameter specifies the SCI port object for which the callback
  311. * is being invoked.
  312. *
  313. */
  314. void isci_event_port_not_ready(
  315. struct scic_sds_controller *controller,
  316. struct scic_sds_port *port,
  317. u32 reason_code)
  318. {
  319. struct isci_port *isci_port;
  320. struct isci_host *isci_host;
  321. isci_host =
  322. (struct isci_host *)sci_object_get_association(controller);
  323. isci_port =
  324. (struct isci_port *)sci_object_get_association(port);
  325. dev_dbg(&isci_host->pdev->dev,
  326. "%s: isci_port = %p\n", __func__, isci_port);
  327. isci_port_not_ready(isci_host, isci_port);
  328. }
  329. /**
  330. * isci_event_port_invalid_link_up() - This method informs the SCI Core user that
  331. * a phy/link became ready, but the phy is not allowed in the port. In some
  332. * situations the underlying hardware only allows for certain phy to port
  333. * mappings. If these mappings are violated, then this API is invoked.
  334. * @controller: This parameter represents the controller which contains the
  335. * port.
  336. * @port: This parameter specifies the SCI port object for which the callback
  337. * is being invoked.
  338. * @phy: This parameter specifies the phy that came ready, but the phy can't be
  339. * a valid member of the port.
  340. *
  341. */
  342. void isci_event_port_invalid_link_up(
  343. struct scic_sds_controller *controller,
  344. struct scic_sds_port *port,
  345. struct scic_sds_phy *phy)
  346. {
  347. struct isci_host *isci_host;
  348. isci_host = (struct isci_host *)sci_object_get_association(controller);
  349. dev_warn(&isci_host->pdev->dev, "Invalid link up!\n");
  350. }
  351. /**
  352. * isci_event_port_bc_change_primitive_received() - This callback method informs
  353. * the user that a broadcast change primitive was received.
  354. * @controller: This parameter represents the controller which contains the
  355. * port.
  356. * @port: This parameter specifies the SCI port object for which the callback
  357. * is being invoked. For instances where the phy on which the primitive was
  358. * received is not part of a port, this parameter will be NULL.
  359. * @phy: This parameter specifies the phy on which the primitive was received.
  360. *
  361. */
  362. void isci_event_port_bc_change_primitive_received(
  363. struct scic_sds_controller *controller,
  364. struct scic_sds_port *port,
  365. struct scic_sds_phy *phy)
  366. {
  367. struct isci_host *isci_host;
  368. isci_host =
  369. (struct isci_host *)sci_object_get_association(controller);
  370. dev_dbg(&isci_host->pdev->dev,
  371. "%s: port = %p, phy = %p\n", __func__, port, phy);
  372. isci_port_bc_change_received(isci_host, port, phy);
  373. }
  374. /**
  375. * isci_event_port_link_up() - This callback method informs the user that a phy
  376. * has become operational and is capable of communicating with the remote
  377. * end point.
  378. * @controller: This parameter represents the controller associated with the
  379. * phy.
  380. * @port: This parameter specifies the port object for which the user callback
  381. * is being invoked. There may be conditions where this parameter can be
  382. * NULL
  383. * @phy: This parameter specifies the phy object for which the user callback is
  384. * being invoked.
  385. *
  386. * none.
  387. */
  388. void isci_event_port_link_up(
  389. struct scic_sds_controller *controller,
  390. struct scic_sds_port *port,
  391. struct scic_sds_phy *phy)
  392. {
  393. struct isci_host *isci_host;
  394. isci_host =
  395. (struct isci_host *)sci_object_get_association(controller);
  396. dev_dbg(&isci_host->pdev->dev,
  397. "%s: phy = %p\n", __func__, phy);
  398. isci_port_link_up(isci_host, port, phy);
  399. }
  400. /**
  401. * isci_event_port_link_down() - This callback method informs the user that a phy
  402. * is no longer operational and is not capable of communicating with the
  403. * remote end point.
  404. * @controller: This parameter represents the controller associated with the
  405. * phy.
  406. * @port: This parameter specifies the port object for which the user callback
  407. * is being invoked. There may be conditions where this parameter can be
  408. * NULL
  409. * @phy: This parameter specifies the phy object for which the user callback is
  410. * being invoked.
  411. *
  412. * none.
  413. */
  414. void isci_event_port_link_down(
  415. struct scic_sds_controller *controller,
  416. struct scic_sds_port *port,
  417. struct scic_sds_phy *phy)
  418. {
  419. struct isci_host *isci_host;
  420. struct isci_phy *isci_phy;
  421. struct isci_port *isci_port;
  422. isci_host =
  423. (struct isci_host *)sci_object_get_association(controller);
  424. isci_phy =
  425. (struct isci_phy *)sci_object_get_association(phy);
  426. isci_port =
  427. (struct isci_port *)sci_object_get_association(port);
  428. dev_dbg(&isci_host->pdev->dev,
  429. "%s: isci_port = %p\n", __func__, isci_port);
  430. isci_port_link_down(isci_host, isci_phy, isci_port);
  431. }
  432. /**
  433. * isci_event_remote_device_start_complete() - This user callback method will
  434. * inform the user that a start operation has completed.
  435. * @controller: This parameter specifies the core controller associated with
  436. * the completion callback.
  437. * @remote_device: This parameter specifies the remote device associated with
  438. * the completion callback.
  439. * @completion_status: This parameter specifies the completion status for the
  440. * operation.
  441. *
  442. */
  443. void isci_event_remote_device_start_complete(
  444. struct scic_sds_controller *controller,
  445. struct scic_sds_remote_device *remote_device,
  446. enum sci_status completion_status)
  447. {
  448. struct isci_host *isci_host;
  449. struct isci_remote_device *isci_device;
  450. isci_host =
  451. (struct isci_host *)sci_object_get_association(controller);
  452. isci_device =
  453. (struct isci_remote_device *)sci_object_get_association(
  454. remote_device
  455. );
  456. dev_dbg(&isci_host->pdev->dev,
  457. "%s: isci_device = %p\n", __func__, isci_device);
  458. isci_remote_device_start_complete(
  459. isci_host, isci_device, completion_status);
  460. }
  461. /**
  462. * isci_event_remote_device_stop_complete() - This user callback method will
  463. * inform the user that a stop operation has completed.
  464. * @controller: This parameter specifies the core controller associated with
  465. * the completion callback.
  466. * @remote_device: This parameter specifies the remote device associated with
  467. * the completion callback.
  468. * @completion_status: This parameter specifies the completion status for the
  469. * operation.
  470. *
  471. */
  472. void isci_event_remote_device_stop_complete(
  473. struct scic_sds_controller *controller,
  474. struct scic_sds_remote_device *remote_device,
  475. enum sci_status completion_status)
  476. {
  477. struct isci_host *isci_host;
  478. struct isci_remote_device *isci_device;
  479. isci_host =
  480. (struct isci_host *)sci_object_get_association(controller);
  481. isci_device =
  482. (struct isci_remote_device *)sci_object_get_association(
  483. remote_device
  484. );
  485. dev_dbg(&isci_host->pdev->dev,
  486. "%s: isci_device = %p\n", __func__, isci_device);
  487. isci_remote_device_stop_complete(
  488. isci_host, isci_device, completion_status);
  489. }
  490. /**
  491. * isci_event_remote_device_ready() - This user callback method will inform the
  492. * user that a remote device is now capable of handling IO requests.
  493. * @controller: This parameter specifies the core controller associated with
  494. * the completion callback.
  495. * @remote_device: This parameter specifies the remote device associated with
  496. * the callback.
  497. *
  498. */
  499. void isci_event_remote_device_ready(
  500. struct scic_sds_controller *controller,
  501. struct scic_sds_remote_device *remote_device)
  502. {
  503. struct isci_remote_device *isci_device =
  504. (struct isci_remote_device *)
  505. sci_object_get_association(remote_device);
  506. dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
  507. "%s: isci_device = %p\n", __func__, isci_device);
  508. isci_remote_device_ready(isci_device);
  509. }
  510. /**
  511. * isci_event_remote_device_not_ready() - This user callback method will inform
  512. * the user that a remote device is no longer capable of handling IO
  513. * requests (until a ready callback is invoked).
  514. * @controller: This parameter specifies the core controller associated with
  515. * the completion callback.
  516. * @remote_device: This parameter specifies the remote device associated with
  517. * the callback.
  518. * @reason_code: This parameter specifies the reason for the remote device
  519. * going to a not ready state.
  520. *
  521. */
  522. void isci_event_remote_device_not_ready(
  523. struct scic_sds_controller *controller,
  524. struct scic_sds_remote_device *remote_device,
  525. u32 reason_code)
  526. {
  527. struct isci_remote_device *isci_device =
  528. (struct isci_remote_device *)
  529. sci_object_get_association(remote_device);
  530. struct isci_host *isci_host;
  531. isci_host =
  532. (struct isci_host *)sci_object_get_association(controller);
  533. dev_dbg(&isci_host->pdev->dev,
  534. "%s: isci_device = %p, reason_code = %x\n",
  535. __func__, isci_device, reason_code);
  536. isci_remote_device_not_ready(isci_device, reason_code);
  537. }