events.c 20 KB

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