events.c 20 KB

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