aic94xx_tmf.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Aic94xx Task Management Functions
  3. *
  4. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  5. * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
  6. *
  7. * This file is licensed under GPLv2.
  8. *
  9. * This file is part of the aic94xx driver.
  10. *
  11. * The aic94xx driver is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; version 2 of the
  14. * License.
  15. *
  16. * The aic94xx driver is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with the aic94xx driver; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. */
  26. #include <linux/spinlock.h>
  27. #include "aic94xx.h"
  28. #include "aic94xx_sas.h"
  29. #include "aic94xx_hwi.h"
  30. /* ---------- Internal enqueue ---------- */
  31. static int asd_enqueue_internal(struct asd_ascb *ascb,
  32. void (*tasklet_complete)(struct asd_ascb *,
  33. struct done_list_struct *),
  34. void (*timed_out)(unsigned long))
  35. {
  36. int res;
  37. ascb->tasklet_complete = tasklet_complete;
  38. ascb->uldd_timer = 1;
  39. ascb->timer.data = (unsigned long) ascb;
  40. ascb->timer.function = timed_out;
  41. ascb->timer.expires = jiffies + AIC94XX_SCB_TIMEOUT;
  42. add_timer(&ascb->timer);
  43. res = asd_post_ascb_list(ascb->ha, ascb, 1);
  44. if (unlikely(res))
  45. del_timer(&ascb->timer);
  46. return res;
  47. }
  48. static inline void asd_timedout_common(unsigned long data)
  49. {
  50. struct asd_ascb *ascb = (void *) data;
  51. struct asd_seq_data *seq = &ascb->ha->seq;
  52. unsigned long flags;
  53. spin_lock_irqsave(&seq->pend_q_lock, flags);
  54. seq->pending--;
  55. list_del_init(&ascb->list);
  56. spin_unlock_irqrestore(&seq->pend_q_lock, flags);
  57. }
  58. /* ---------- CLEAR NEXUS ---------- */
  59. static void asd_clear_nexus_tasklet_complete(struct asd_ascb *ascb,
  60. struct done_list_struct *dl)
  61. {
  62. ASD_DPRINTK("%s: here\n", __FUNCTION__);
  63. if (!del_timer(&ascb->timer)) {
  64. ASD_DPRINTK("%s: couldn't delete timer\n", __FUNCTION__);
  65. return;
  66. }
  67. ASD_DPRINTK("%s: opcode: 0x%x\n", __FUNCTION__, dl->opcode);
  68. ascb->uldd_task = (void *) (unsigned long) dl->opcode;
  69. complete(&ascb->completion);
  70. }
  71. static void asd_clear_nexus_timedout(unsigned long data)
  72. {
  73. struct asd_ascb *ascb = (void *) data;
  74. ASD_DPRINTK("%s: here\n", __FUNCTION__);
  75. asd_timedout_common(data);
  76. ascb->uldd_task = (void *) TMF_RESP_FUNC_FAILED;
  77. complete(&ascb->completion);
  78. }
  79. #define CLEAR_NEXUS_PRE \
  80. ASD_DPRINTK("%s: PRE\n", __FUNCTION__); \
  81. res = 1; \
  82. ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL); \
  83. if (!ascb) \
  84. return -ENOMEM; \
  85. \
  86. scb = ascb->scb; \
  87. scb->header.opcode = CLEAR_NEXUS
  88. #define CLEAR_NEXUS_POST \
  89. ASD_DPRINTK("%s: POST\n", __FUNCTION__); \
  90. res = asd_enqueue_internal(ascb, asd_clear_nexus_tasklet_complete, \
  91. asd_clear_nexus_timedout); \
  92. if (res) \
  93. goto out_err; \
  94. ASD_DPRINTK("%s: clear nexus posted, waiting...\n", __FUNCTION__); \
  95. wait_for_completion(&ascb->completion); \
  96. res = (int) (unsigned long) ascb->uldd_task; \
  97. if (res == TC_NO_ERROR) \
  98. res = TMF_RESP_FUNC_COMPLETE; \
  99. out_err: \
  100. asd_ascb_free(ascb); \
  101. return res
  102. int asd_clear_nexus_ha(struct sas_ha_struct *sas_ha)
  103. {
  104. struct asd_ha_struct *asd_ha = sas_ha->lldd_ha;
  105. struct asd_ascb *ascb;
  106. struct scb *scb;
  107. int res;
  108. CLEAR_NEXUS_PRE;
  109. scb->clear_nexus.nexus = NEXUS_ADAPTER;
  110. CLEAR_NEXUS_POST;
  111. }
  112. int asd_clear_nexus_port(struct asd_sas_port *port)
  113. {
  114. struct asd_ha_struct *asd_ha = port->ha->lldd_ha;
  115. struct asd_ascb *ascb;
  116. struct scb *scb;
  117. int res;
  118. CLEAR_NEXUS_PRE;
  119. scb->clear_nexus.nexus = NEXUS_PORT;
  120. scb->clear_nexus.conn_mask = port->phy_mask;
  121. CLEAR_NEXUS_POST;
  122. }
  123. #if 0
  124. static int asd_clear_nexus_I_T(struct domain_device *dev)
  125. {
  126. struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
  127. struct asd_ascb *ascb;
  128. struct scb *scb;
  129. int res;
  130. CLEAR_NEXUS_PRE;
  131. scb->clear_nexus.nexus = NEXUS_I_T;
  132. scb->clear_nexus.flags = SEND_Q | EXEC_Q | NOTINQ;
  133. if (dev->tproto)
  134. scb->clear_nexus.flags |= SUSPEND_TX;
  135. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  136. dev->lldd_dev);
  137. CLEAR_NEXUS_POST;
  138. }
  139. #endif
  140. static int asd_clear_nexus_I_T_L(struct domain_device *dev, u8 *lun)
  141. {
  142. struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
  143. struct asd_ascb *ascb;
  144. struct scb *scb;
  145. int res;
  146. CLEAR_NEXUS_PRE;
  147. scb->clear_nexus.nexus = NEXUS_I_T_L;
  148. scb->clear_nexus.flags = SEND_Q | EXEC_Q | NOTINQ;
  149. if (dev->tproto)
  150. scb->clear_nexus.flags |= SUSPEND_TX;
  151. memcpy(scb->clear_nexus.ssp_task.lun, lun, 8);
  152. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  153. dev->lldd_dev);
  154. CLEAR_NEXUS_POST;
  155. }
  156. static int asd_clear_nexus_tag(struct sas_task *task)
  157. {
  158. struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
  159. struct asd_ascb *tascb = task->lldd_task;
  160. struct asd_ascb *ascb;
  161. struct scb *scb;
  162. int res;
  163. CLEAR_NEXUS_PRE;
  164. scb->clear_nexus.nexus = NEXUS_TAG;
  165. memcpy(scb->clear_nexus.ssp_task.lun, task->ssp_task.LUN, 8);
  166. scb->clear_nexus.ssp_task.tag = tascb->tag;
  167. if (task->dev->tproto)
  168. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  169. task->dev->lldd_dev);
  170. CLEAR_NEXUS_POST;
  171. }
  172. static int asd_clear_nexus_index(struct sas_task *task)
  173. {
  174. struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
  175. struct asd_ascb *tascb = task->lldd_task;
  176. struct asd_ascb *ascb;
  177. struct scb *scb;
  178. int res;
  179. CLEAR_NEXUS_PRE;
  180. scb->clear_nexus.nexus = NEXUS_TRANS_CX;
  181. if (task->dev->tproto)
  182. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  183. task->dev->lldd_dev);
  184. scb->clear_nexus.index = cpu_to_le16(tascb->tc_index);
  185. CLEAR_NEXUS_POST;
  186. }
  187. /* ---------- TMFs ---------- */
  188. static void asd_tmf_timedout(unsigned long data)
  189. {
  190. struct asd_ascb *ascb = (void *) data;
  191. ASD_DPRINTK("tmf timed out\n");
  192. asd_timedout_common(data);
  193. ascb->uldd_task = (void *) TMF_RESP_FUNC_FAILED;
  194. complete(&ascb->completion);
  195. }
  196. static int asd_get_tmf_resp_tasklet(struct asd_ascb *ascb,
  197. struct done_list_struct *dl)
  198. {
  199. struct asd_ha_struct *asd_ha = ascb->ha;
  200. unsigned long flags;
  201. struct tc_resp_sb_struct {
  202. __le16 index_escb;
  203. u8 len_lsb;
  204. u8 flags;
  205. } __attribute__ ((packed)) *resp_sb = (void *) dl->status_block;
  206. int edb_id = ((resp_sb->flags & 0x70) >> 4)-1;
  207. struct asd_ascb *escb;
  208. struct asd_dma_tok *edb;
  209. struct ssp_frame_hdr *fh;
  210. struct ssp_response_iu *ru;
  211. int res = TMF_RESP_FUNC_FAILED;
  212. ASD_DPRINTK("tmf resp tasklet\n");
  213. spin_lock_irqsave(&asd_ha->seq.tc_index_lock, flags);
  214. escb = asd_tc_index_find(&asd_ha->seq,
  215. (int)le16_to_cpu(resp_sb->index_escb));
  216. spin_unlock_irqrestore(&asd_ha->seq.tc_index_lock, flags);
  217. if (!escb) {
  218. ASD_DPRINTK("Uh-oh! No escb for this dl?!\n");
  219. return res;
  220. }
  221. edb = asd_ha->seq.edb_arr[edb_id + escb->edb_index];
  222. ascb->tag = *(__be16 *)(edb->vaddr+4);
  223. fh = edb->vaddr + 16;
  224. ru = edb->vaddr + 16 + sizeof(*fh);
  225. res = ru->status;
  226. if (ru->datapres == 1) /* Response data present */
  227. res = ru->resp_data[3];
  228. #if 0
  229. ascb->tag = fh->tag;
  230. #endif
  231. ascb->tag_valid = 1;
  232. asd_invalidate_edb(escb, edb_id);
  233. return res;
  234. }
  235. static void asd_tmf_tasklet_complete(struct asd_ascb *ascb,
  236. struct done_list_struct *dl)
  237. {
  238. if (!del_timer(&ascb->timer))
  239. return;
  240. ASD_DPRINTK("tmf tasklet complete\n");
  241. if (dl->opcode == TC_SSP_RESP)
  242. ascb->uldd_task = (void *) (unsigned long)
  243. asd_get_tmf_resp_tasklet(ascb, dl);
  244. else
  245. ascb->uldd_task = (void *) 0xFF00 + (unsigned long) dl->opcode;
  246. complete(&ascb->completion);
  247. }
  248. static inline int asd_clear_nexus(struct sas_task *task)
  249. {
  250. int res = TMF_RESP_FUNC_FAILED;
  251. struct asd_ascb *tascb = task->lldd_task;
  252. unsigned long flags;
  253. ASD_DPRINTK("task not done, clearing nexus\n");
  254. if (tascb->tag_valid)
  255. res = asd_clear_nexus_tag(task);
  256. else
  257. res = asd_clear_nexus_index(task);
  258. wait_for_completion_timeout(&tascb->completion,
  259. AIC94XX_SCB_TIMEOUT);
  260. ASD_DPRINTK("came back from clear nexus\n");
  261. spin_lock_irqsave(&task->task_state_lock, flags);
  262. if (task->task_state_flags & SAS_TASK_STATE_DONE)
  263. res = TMF_RESP_FUNC_COMPLETE;
  264. spin_unlock_irqrestore(&task->task_state_lock, flags);
  265. return res;
  266. }
  267. /**
  268. * asd_abort_task -- ABORT TASK TMF
  269. * @task: the task to be aborted
  270. *
  271. * Before calling ABORT TASK the task state flags should be ORed with
  272. * SAS_TASK_STATE_ABORTED (unless SAS_TASK_STATE_DONE is set) under
  273. * the task_state_lock IRQ spinlock, then ABORT TASK *must* be called.
  274. *
  275. * Implements the ABORT TASK TMF, I_T_L_Q nexus.
  276. * Returns: SAS TMF responses (see sas_task.h),
  277. * -ENOMEM,
  278. * -SAS_QUEUE_FULL.
  279. *
  280. * When ABORT TASK returns, the caller of ABORT TASK checks first the
  281. * task->task_state_flags, and then the return value of ABORT TASK.
  282. *
  283. * If the task has task state bit SAS_TASK_STATE_DONE set, then the
  284. * task was completed successfully prior to it being aborted. The
  285. * caller of ABORT TASK has responsibility to call task->task_done()
  286. * xor free the task, depending on their framework. The return code
  287. * is TMF_RESP_FUNC_FAILED in this case.
  288. *
  289. * Else the SAS_TASK_STATE_DONE bit is not set,
  290. * If the return code is TMF_RESP_FUNC_COMPLETE, then
  291. * the task was aborted successfully. The caller of
  292. * ABORT TASK has responsibility to call task->task_done()
  293. * to finish the task, xor free the task depending on their
  294. * framework.
  295. * else
  296. * the ABORT TASK returned some kind of error. The task
  297. * was _not_ cancelled. Nothing can be assumed.
  298. * The caller of ABORT TASK may wish to retry.
  299. */
  300. int asd_abort_task(struct sas_task *task)
  301. {
  302. struct asd_ascb *tascb = task->lldd_task;
  303. struct asd_ha_struct *asd_ha = tascb->ha;
  304. int res = 1;
  305. unsigned long flags;
  306. struct asd_ascb *ascb = NULL;
  307. struct scb *scb;
  308. spin_lock_irqsave(&task->task_state_lock, flags);
  309. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  310. spin_unlock_irqrestore(&task->task_state_lock, flags);
  311. res = TMF_RESP_FUNC_COMPLETE;
  312. ASD_DPRINTK("%s: task 0x%p done\n", __FUNCTION__, task);
  313. goto out_done;
  314. }
  315. spin_unlock_irqrestore(&task->task_state_lock, flags);
  316. ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL);
  317. if (!ascb)
  318. return -ENOMEM;
  319. scb = ascb->scb;
  320. scb->header.opcode = ABORT_TASK;
  321. switch (task->task_proto) {
  322. case SATA_PROTO:
  323. case SAS_PROTO_STP:
  324. scb->abort_task.proto_conn_rate = (1 << 5); /* STP */
  325. break;
  326. case SAS_PROTO_SSP:
  327. scb->abort_task.proto_conn_rate = (1 << 4); /* SSP */
  328. scb->abort_task.proto_conn_rate |= task->dev->linkrate;
  329. break;
  330. case SAS_PROTO_SMP:
  331. break;
  332. default:
  333. break;
  334. }
  335. if (task->task_proto == SAS_PROTO_SSP) {
  336. scb->abort_task.ssp_frame.frame_type = SSP_TASK;
  337. memcpy(scb->abort_task.ssp_frame.hashed_dest_addr,
  338. task->dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
  339. memcpy(scb->abort_task.ssp_frame.hashed_src_addr,
  340. task->dev->port->ha->hashed_sas_addr,
  341. HASHED_SAS_ADDR_SIZE);
  342. scb->abort_task.ssp_frame.tptt = cpu_to_be16(0xFFFF);
  343. memcpy(scb->abort_task.ssp_task.lun, task->ssp_task.LUN, 8);
  344. scb->abort_task.ssp_task.tmf = TMF_ABORT_TASK;
  345. scb->abort_task.ssp_task.tag = cpu_to_be16(0xFFFF);
  346. }
  347. scb->abort_task.sister_scb = cpu_to_le16(0xFFFF);
  348. scb->abort_task.conn_handle = cpu_to_le16(
  349. (u16)(unsigned long)task->dev->lldd_dev);
  350. scb->abort_task.retry_count = 1;
  351. scb->abort_task.index = cpu_to_le16((u16)tascb->tc_index);
  352. scb->abort_task.itnl_to = cpu_to_le16(ITNL_TIMEOUT_CONST);
  353. res = asd_enqueue_internal(ascb, asd_tmf_tasklet_complete,
  354. asd_tmf_timedout);
  355. if (res)
  356. goto out;
  357. wait_for_completion(&ascb->completion);
  358. ASD_DPRINTK("tmf came back\n");
  359. res = (int) (unsigned long) ascb->uldd_task;
  360. tascb->tag = ascb->tag;
  361. tascb->tag_valid = ascb->tag_valid;
  362. spin_lock_irqsave(&task->task_state_lock, flags);
  363. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  364. spin_unlock_irqrestore(&task->task_state_lock, flags);
  365. res = TMF_RESP_FUNC_COMPLETE;
  366. ASD_DPRINTK("%s: task 0x%p done\n", __FUNCTION__, task);
  367. goto out_done;
  368. }
  369. spin_unlock_irqrestore(&task->task_state_lock, flags);
  370. switch (res) {
  371. /* The task to be aborted has been sent to the device.
  372. * We got a Response IU for the ABORT TASK TMF. */
  373. case TC_NO_ERROR + 0xFF00:
  374. case TMF_RESP_FUNC_COMPLETE:
  375. case TMF_RESP_FUNC_FAILED:
  376. res = asd_clear_nexus(task);
  377. break;
  378. case TMF_RESP_INVALID_FRAME:
  379. case TMF_RESP_OVERLAPPED_TAG:
  380. case TMF_RESP_FUNC_ESUPP:
  381. case TMF_RESP_NO_LUN:
  382. goto out_done; break;
  383. }
  384. /* In the following we assume that the managing layer
  385. * will _never_ make a mistake, when issuing ABORT TASK.
  386. */
  387. switch (res) {
  388. default:
  389. res = asd_clear_nexus(task);
  390. /* fallthrough */
  391. case TC_NO_ERROR + 0xFF00:
  392. case TMF_RESP_FUNC_COMPLETE:
  393. break;
  394. /* The task hasn't been sent to the device xor we never got
  395. * a (sane) Response IU for the ABORT TASK TMF.
  396. */
  397. case TF_NAK_RECV + 0xFF00:
  398. res = TMF_RESP_INVALID_FRAME;
  399. break;
  400. case TF_TMF_TASK_DONE + 0xFF00: /* done but not reported yet */
  401. res = TMF_RESP_FUNC_FAILED;
  402. wait_for_completion_timeout(&tascb->completion,
  403. AIC94XX_SCB_TIMEOUT);
  404. spin_lock_irqsave(&task->task_state_lock, flags);
  405. if (task->task_state_flags & SAS_TASK_STATE_DONE)
  406. res = TMF_RESP_FUNC_COMPLETE;
  407. spin_unlock_irqrestore(&task->task_state_lock, flags);
  408. goto out_done;
  409. case TF_TMF_NO_TAG + 0xFF00:
  410. case TF_TMF_TAG_FREE + 0xFF00: /* the tag is in the free list */
  411. case TF_TMF_NO_CONN_HANDLE + 0xFF00: /* no such device */
  412. res = TMF_RESP_FUNC_COMPLETE;
  413. goto out_done;
  414. case TF_TMF_NO_CTX + 0xFF00: /* not in seq, or proto != SSP */
  415. res = TMF_RESP_FUNC_ESUPP;
  416. goto out;
  417. }
  418. out_done:
  419. if (res == TMF_RESP_FUNC_COMPLETE) {
  420. task->lldd_task = NULL;
  421. mb();
  422. asd_ascb_free(tascb);
  423. }
  424. out:
  425. asd_ascb_free(ascb);
  426. ASD_DPRINTK("task 0x%p aborted, res: 0x%x\n", task, res);
  427. return res;
  428. }
  429. /**
  430. * asd_initiate_ssp_tmf -- send a TMF to an I_T_L or I_T_L_Q nexus
  431. * @dev: pointer to struct domain_device of interest
  432. * @lun: pointer to u8[8] which is the LUN
  433. * @tmf: the TMF to be performed (see sas_task.h or the SAS spec)
  434. * @index: the transaction context of the task to be queried if QT TMF
  435. *
  436. * This function is used to send ABORT TASK SET, CLEAR ACA,
  437. * CLEAR TASK SET, LU RESET and QUERY TASK TMFs.
  438. *
  439. * No SCBs should be queued to the I_T_L nexus when this SCB is
  440. * pending.
  441. *
  442. * Returns: TMF response code (see sas_task.h or the SAS spec)
  443. */
  444. static int asd_initiate_ssp_tmf(struct domain_device *dev, u8 *lun,
  445. int tmf, int index)
  446. {
  447. struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
  448. struct asd_ascb *ascb;
  449. int res = 1;
  450. struct scb *scb;
  451. if (!(dev->tproto & SAS_PROTO_SSP))
  452. return TMF_RESP_FUNC_ESUPP;
  453. ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL);
  454. if (!ascb)
  455. return -ENOMEM;
  456. scb = ascb->scb;
  457. if (tmf == TMF_QUERY_TASK)
  458. scb->header.opcode = QUERY_SSP_TASK;
  459. else
  460. scb->header.opcode = INITIATE_SSP_TMF;
  461. scb->ssp_tmf.proto_conn_rate = (1 << 4); /* SSP */
  462. scb->ssp_tmf.proto_conn_rate |= dev->linkrate;
  463. /* SSP frame header */
  464. scb->ssp_tmf.ssp_frame.frame_type = SSP_TASK;
  465. memcpy(scb->ssp_tmf.ssp_frame.hashed_dest_addr,
  466. dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
  467. memcpy(scb->ssp_tmf.ssp_frame.hashed_src_addr,
  468. dev->port->ha->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
  469. scb->ssp_tmf.ssp_frame.tptt = cpu_to_be16(0xFFFF);
  470. /* SSP Task IU */
  471. memcpy(scb->ssp_tmf.ssp_task.lun, lun, 8);
  472. scb->ssp_tmf.ssp_task.tmf = tmf;
  473. scb->ssp_tmf.sister_scb = cpu_to_le16(0xFFFF);
  474. scb->ssp_tmf.conn_handle= cpu_to_le16((u16)(unsigned long)
  475. dev->lldd_dev);
  476. scb->ssp_tmf.retry_count = 1;
  477. scb->ssp_tmf.itnl_to = cpu_to_le16(ITNL_TIMEOUT_CONST);
  478. if (tmf == TMF_QUERY_TASK)
  479. scb->ssp_tmf.index = cpu_to_le16(index);
  480. res = asd_enqueue_internal(ascb, asd_tmf_tasklet_complete,
  481. asd_tmf_timedout);
  482. if (res)
  483. goto out_err;
  484. wait_for_completion(&ascb->completion);
  485. res = (int) (unsigned long) ascb->uldd_task;
  486. switch (res) {
  487. case TC_NO_ERROR + 0xFF00:
  488. res = TMF_RESP_FUNC_COMPLETE;
  489. break;
  490. case TF_NAK_RECV + 0xFF00:
  491. res = TMF_RESP_INVALID_FRAME;
  492. break;
  493. case TF_TMF_TASK_DONE + 0xFF00:
  494. res = TMF_RESP_FUNC_FAILED;
  495. break;
  496. case TF_TMF_NO_TAG + 0xFF00:
  497. case TF_TMF_TAG_FREE + 0xFF00: /* the tag is in the free list */
  498. case TF_TMF_NO_CONN_HANDLE + 0xFF00: /* no such device */
  499. res = TMF_RESP_FUNC_COMPLETE;
  500. break;
  501. case TF_TMF_NO_CTX + 0xFF00: /* not in seq, or proto != SSP */
  502. res = TMF_RESP_FUNC_ESUPP;
  503. break;
  504. default:
  505. ASD_DPRINTK("%s: converting result 0x%x to TMF_RESP_FUNC_FAILED\n",
  506. __FUNCTION__, res);
  507. res = TMF_RESP_FUNC_FAILED;
  508. break;
  509. }
  510. out_err:
  511. asd_ascb_free(ascb);
  512. return res;
  513. }
  514. int asd_abort_task_set(struct domain_device *dev, u8 *lun)
  515. {
  516. int res = asd_initiate_ssp_tmf(dev, lun, TMF_ABORT_TASK_SET, 0);
  517. if (res == TMF_RESP_FUNC_COMPLETE)
  518. asd_clear_nexus_I_T_L(dev, lun);
  519. return res;
  520. }
  521. int asd_clear_aca(struct domain_device *dev, u8 *lun)
  522. {
  523. int res = asd_initiate_ssp_tmf(dev, lun, TMF_CLEAR_ACA, 0);
  524. if (res == TMF_RESP_FUNC_COMPLETE)
  525. asd_clear_nexus_I_T_L(dev, lun);
  526. return res;
  527. }
  528. int asd_clear_task_set(struct domain_device *dev, u8 *lun)
  529. {
  530. int res = asd_initiate_ssp_tmf(dev, lun, TMF_CLEAR_TASK_SET, 0);
  531. if (res == TMF_RESP_FUNC_COMPLETE)
  532. asd_clear_nexus_I_T_L(dev, lun);
  533. return res;
  534. }
  535. int asd_lu_reset(struct domain_device *dev, u8 *lun)
  536. {
  537. int res = asd_initiate_ssp_tmf(dev, lun, TMF_LU_RESET, 0);
  538. if (res == TMF_RESP_FUNC_COMPLETE)
  539. asd_clear_nexus_I_T_L(dev, lun);
  540. return res;
  541. }
  542. /**
  543. * asd_query_task -- send a QUERY TASK TMF to an I_T_L_Q nexus
  544. * task: pointer to sas_task struct of interest
  545. *
  546. * Returns: TMF_RESP_FUNC_COMPLETE if the task is not in the task set,
  547. * or TMF_RESP_FUNC_SUCC if the task is in the task set.
  548. *
  549. * Normally the management layer sets the task to aborted state,
  550. * and then calls query task and then abort task.
  551. */
  552. int asd_query_task(struct sas_task *task)
  553. {
  554. struct asd_ascb *ascb = task->lldd_task;
  555. int index;
  556. if (ascb) {
  557. index = ascb->tc_index;
  558. return asd_initiate_ssp_tmf(task->dev, task->ssp_task.LUN,
  559. TMF_QUERY_TASK, index);
  560. }
  561. return TMF_RESP_FUNC_COMPLETE;
  562. }