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. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  134. dev->lldd_dev);
  135. CLEAR_NEXUS_POST;
  136. }
  137. #endif
  138. static int asd_clear_nexus_I_T_L(struct domain_device *dev, u8 *lun)
  139. {
  140. struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
  141. struct asd_ascb *ascb;
  142. struct scb *scb;
  143. int res;
  144. CLEAR_NEXUS_PRE;
  145. scb->clear_nexus.nexus = NEXUS_I_T_L;
  146. scb->clear_nexus.flags = SEND_Q | EXEC_Q | NOTINQ;
  147. memcpy(scb->clear_nexus.ssp_task.lun, lun, 8);
  148. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  149. dev->lldd_dev);
  150. CLEAR_NEXUS_POST;
  151. }
  152. static int asd_clear_nexus_tag(struct sas_task *task)
  153. {
  154. struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
  155. struct asd_ascb *tascb = task->lldd_task;
  156. struct asd_ascb *ascb;
  157. struct scb *scb;
  158. int res;
  159. CLEAR_NEXUS_PRE;
  160. scb->clear_nexus.nexus = NEXUS_TAG;
  161. memcpy(scb->clear_nexus.ssp_task.lun, task->ssp_task.LUN, 8);
  162. scb->clear_nexus.ssp_task.tag = tascb->tag;
  163. if (task->dev->tproto)
  164. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  165. task->dev->lldd_dev);
  166. CLEAR_NEXUS_POST;
  167. }
  168. static int asd_clear_nexus_index(struct sas_task *task)
  169. {
  170. struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
  171. struct asd_ascb *tascb = task->lldd_task;
  172. struct asd_ascb *ascb;
  173. struct scb *scb;
  174. int res;
  175. CLEAR_NEXUS_PRE;
  176. scb->clear_nexus.nexus = NEXUS_TRANS_CX;
  177. if (task->dev->tproto)
  178. scb->clear_nexus.conn_handle = cpu_to_le16((u16)(unsigned long)
  179. task->dev->lldd_dev);
  180. scb->clear_nexus.index = cpu_to_le16(tascb->tc_index);
  181. CLEAR_NEXUS_POST;
  182. }
  183. /* ---------- TMFs ---------- */
  184. static void asd_tmf_timedout(unsigned long data)
  185. {
  186. struct asd_ascb *ascb = (void *) data;
  187. ASD_DPRINTK("tmf timed out\n");
  188. asd_timedout_common(data);
  189. ascb->uldd_task = (void *) TMF_RESP_FUNC_FAILED;
  190. complete(&ascb->completion);
  191. }
  192. static int asd_get_tmf_resp_tasklet(struct asd_ascb *ascb,
  193. struct done_list_struct *dl)
  194. {
  195. struct asd_ha_struct *asd_ha = ascb->ha;
  196. unsigned long flags;
  197. struct tc_resp_sb_struct {
  198. __le16 index_escb;
  199. u8 len_lsb;
  200. u8 flags;
  201. } __attribute__ ((packed)) *resp_sb = (void *) dl->status_block;
  202. int edb_id = ((resp_sb->flags & 0x70) >> 4)-1;
  203. struct asd_ascb *escb;
  204. struct asd_dma_tok *edb;
  205. struct ssp_frame_hdr *fh;
  206. struct ssp_response_iu *ru;
  207. int res = TMF_RESP_FUNC_FAILED;
  208. ASD_DPRINTK("tmf resp tasklet\n");
  209. spin_lock_irqsave(&asd_ha->seq.tc_index_lock, flags);
  210. escb = asd_tc_index_find(&asd_ha->seq,
  211. (int)le16_to_cpu(resp_sb->index_escb));
  212. spin_unlock_irqrestore(&asd_ha->seq.tc_index_lock, flags);
  213. if (!escb) {
  214. ASD_DPRINTK("Uh-oh! No escb for this dl?!\n");
  215. return res;
  216. }
  217. edb = asd_ha->seq.edb_arr[edb_id + escb->edb_index];
  218. ascb->tag = *(__be16 *)(edb->vaddr+4);
  219. fh = edb->vaddr + 16;
  220. ru = edb->vaddr + 16 + sizeof(*fh);
  221. res = ru->status;
  222. if (ru->datapres == 1) /* Response data present */
  223. res = ru->resp_data[3];
  224. #if 0
  225. ascb->tag = fh->tag;
  226. #endif
  227. ascb->tag_valid = 1;
  228. asd_invalidate_edb(escb, edb_id);
  229. return res;
  230. }
  231. static void asd_tmf_tasklet_complete(struct asd_ascb *ascb,
  232. struct done_list_struct *dl)
  233. {
  234. if (!del_timer(&ascb->timer))
  235. return;
  236. ASD_DPRINTK("tmf tasklet complete\n");
  237. if (dl->opcode == TC_SSP_RESP)
  238. ascb->uldd_task = (void *) (unsigned long)
  239. asd_get_tmf_resp_tasklet(ascb, dl);
  240. else
  241. ascb->uldd_task = (void *) 0xFF00 + (unsigned long) dl->opcode;
  242. complete(&ascb->completion);
  243. }
  244. static inline int asd_clear_nexus(struct sas_task *task)
  245. {
  246. int res = TMF_RESP_FUNC_FAILED;
  247. int leftover;
  248. struct asd_ascb *tascb = task->lldd_task;
  249. unsigned long flags;
  250. ASD_DPRINTK("task not done, clearing nexus\n");
  251. if (tascb->tag_valid)
  252. res = asd_clear_nexus_tag(task);
  253. else
  254. res = asd_clear_nexus_index(task);
  255. leftover = wait_for_completion_timeout(&tascb->completion,
  256. AIC94XX_SCB_TIMEOUT);
  257. ASD_DPRINTK("came back from clear nexus\n");
  258. spin_lock_irqsave(&task->task_state_lock, flags);
  259. if (leftover < 1)
  260. res = TMF_RESP_FUNC_FAILED;
  261. if (task->task_state_flags & SAS_TASK_STATE_DONE)
  262. res = TMF_RESP_FUNC_COMPLETE;
  263. spin_unlock_irqrestore(&task->task_state_lock, flags);
  264. return res;
  265. }
  266. /**
  267. * asd_abort_task -- ABORT TASK TMF
  268. * @task: the task to be aborted
  269. *
  270. * Before calling ABORT TASK the task state flags should be ORed with
  271. * SAS_TASK_STATE_ABORTED (unless SAS_TASK_STATE_DONE is set) under
  272. * the task_state_lock IRQ spinlock, then ABORT TASK *must* be called.
  273. *
  274. * Implements the ABORT TASK TMF, I_T_L_Q nexus.
  275. * Returns: SAS TMF responses (see sas_task.h),
  276. * -ENOMEM,
  277. * -SAS_QUEUE_FULL.
  278. *
  279. * When ABORT TASK returns, the caller of ABORT TASK checks first the
  280. * task->task_state_flags, and then the return value of ABORT TASK.
  281. *
  282. * If the task has task state bit SAS_TASK_STATE_DONE set, then the
  283. * task was completed successfully prior to it being aborted. The
  284. * caller of ABORT TASK has responsibility to call task->task_done()
  285. * xor free the task, depending on their framework. The return code
  286. * is TMF_RESP_FUNC_FAILED in this case.
  287. *
  288. * Else the SAS_TASK_STATE_DONE bit is not set,
  289. * If the return code is TMF_RESP_FUNC_COMPLETE, then
  290. * the task was aborted successfully. The caller of
  291. * ABORT TASK has responsibility to call task->task_done()
  292. * to finish the task, xor free the task depending on their
  293. * framework.
  294. * else
  295. * the ABORT TASK returned some kind of error. The task
  296. * was _not_ cancelled. Nothing can be assumed.
  297. * The caller of ABORT TASK may wish to retry.
  298. */
  299. int asd_abort_task(struct sas_task *task)
  300. {
  301. struct asd_ascb *tascb = task->lldd_task;
  302. struct asd_ha_struct *asd_ha = tascb->ha;
  303. int res = 1;
  304. unsigned long flags;
  305. struct asd_ascb *ascb = NULL;
  306. struct scb *scb;
  307. int leftover;
  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 = SCB_ABORT_TASK;
  321. switch (task->task_proto) {
  322. case SAS_PROTOCOL_SATA:
  323. case SAS_PROTOCOL_STP:
  324. scb->abort_task.proto_conn_rate = (1 << 5); /* STP */
  325. break;
  326. case SAS_PROTOCOL_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_PROTOCOL_SMP:
  331. break;
  332. default:
  333. break;
  334. }
  335. if (task->task_proto == SAS_PROTOCOL_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. leftover = wait_for_completion_timeout(&tascb->completion,
  403. AIC94XX_SCB_TIMEOUT);
  404. spin_lock_irqsave(&task->task_state_lock, flags);
  405. if (leftover < 1)
  406. res = TMF_RESP_FUNC_FAILED;
  407. if (task->task_state_flags & SAS_TASK_STATE_DONE)
  408. res = TMF_RESP_FUNC_COMPLETE;
  409. spin_unlock_irqrestore(&task->task_state_lock, flags);
  410. goto out_done;
  411. case TF_TMF_NO_TAG + 0xFF00:
  412. case TF_TMF_TAG_FREE + 0xFF00: /* the tag is in the free list */
  413. case TF_TMF_NO_CONN_HANDLE + 0xFF00: /* no such device */
  414. res = TMF_RESP_FUNC_COMPLETE;
  415. goto out_done;
  416. case TF_TMF_NO_CTX + 0xFF00: /* not in seq, or proto != SSP */
  417. res = TMF_RESP_FUNC_ESUPP;
  418. goto out;
  419. }
  420. out_done:
  421. if (res == TMF_RESP_FUNC_COMPLETE) {
  422. task->lldd_task = NULL;
  423. mb();
  424. asd_ascb_free(tascb);
  425. }
  426. out:
  427. asd_ascb_free(ascb);
  428. ASD_DPRINTK("task 0x%p aborted, res: 0x%x\n", task, res);
  429. return res;
  430. }
  431. /**
  432. * asd_initiate_ssp_tmf -- send a TMF to an I_T_L or I_T_L_Q nexus
  433. * @dev: pointer to struct domain_device of interest
  434. * @lun: pointer to u8[8] which is the LUN
  435. * @tmf: the TMF to be performed (see sas_task.h or the SAS spec)
  436. * @index: the transaction context of the task to be queried if QT TMF
  437. *
  438. * This function is used to send ABORT TASK SET, CLEAR ACA,
  439. * CLEAR TASK SET, LU RESET and QUERY TASK TMFs.
  440. *
  441. * No SCBs should be queued to the I_T_L nexus when this SCB is
  442. * pending.
  443. *
  444. * Returns: TMF response code (see sas_task.h or the SAS spec)
  445. */
  446. static int asd_initiate_ssp_tmf(struct domain_device *dev, u8 *lun,
  447. int tmf, int index)
  448. {
  449. struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
  450. struct asd_ascb *ascb;
  451. int res = 1;
  452. struct scb *scb;
  453. if (!(dev->tproto & SAS_PROTOCOL_SSP))
  454. return TMF_RESP_FUNC_ESUPP;
  455. ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL);
  456. if (!ascb)
  457. return -ENOMEM;
  458. scb = ascb->scb;
  459. if (tmf == TMF_QUERY_TASK)
  460. scb->header.opcode = QUERY_SSP_TASK;
  461. else
  462. scb->header.opcode = INITIATE_SSP_TMF;
  463. scb->ssp_tmf.proto_conn_rate = (1 << 4); /* SSP */
  464. scb->ssp_tmf.proto_conn_rate |= dev->linkrate;
  465. /* SSP frame header */
  466. scb->ssp_tmf.ssp_frame.frame_type = SSP_TASK;
  467. memcpy(scb->ssp_tmf.ssp_frame.hashed_dest_addr,
  468. dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
  469. memcpy(scb->ssp_tmf.ssp_frame.hashed_src_addr,
  470. dev->port->ha->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
  471. scb->ssp_tmf.ssp_frame.tptt = cpu_to_be16(0xFFFF);
  472. /* SSP Task IU */
  473. memcpy(scb->ssp_tmf.ssp_task.lun, lun, 8);
  474. scb->ssp_tmf.ssp_task.tmf = tmf;
  475. scb->ssp_tmf.sister_scb = cpu_to_le16(0xFFFF);
  476. scb->ssp_tmf.conn_handle= cpu_to_le16((u16)(unsigned long)
  477. dev->lldd_dev);
  478. scb->ssp_tmf.retry_count = 1;
  479. scb->ssp_tmf.itnl_to = cpu_to_le16(ITNL_TIMEOUT_CONST);
  480. if (tmf == TMF_QUERY_TASK)
  481. scb->ssp_tmf.index = cpu_to_le16(index);
  482. res = asd_enqueue_internal(ascb, asd_tmf_tasklet_complete,
  483. asd_tmf_timedout);
  484. if (res)
  485. goto out_err;
  486. wait_for_completion(&ascb->completion);
  487. res = (int) (unsigned long) ascb->uldd_task;
  488. switch (res) {
  489. case TC_NO_ERROR + 0xFF00:
  490. res = TMF_RESP_FUNC_COMPLETE;
  491. break;
  492. case TF_NAK_RECV + 0xFF00:
  493. res = TMF_RESP_INVALID_FRAME;
  494. break;
  495. case TF_TMF_TASK_DONE + 0xFF00:
  496. res = TMF_RESP_FUNC_FAILED;
  497. break;
  498. case TF_TMF_NO_TAG + 0xFF00:
  499. case TF_TMF_TAG_FREE + 0xFF00: /* the tag is in the free list */
  500. case TF_TMF_NO_CONN_HANDLE + 0xFF00: /* no such device */
  501. res = TMF_RESP_FUNC_COMPLETE;
  502. break;
  503. case TF_TMF_NO_CTX + 0xFF00: /* not in seq, or proto != SSP */
  504. res = TMF_RESP_FUNC_ESUPP;
  505. break;
  506. default:
  507. /* Allow TMF response codes to propagate upwards */
  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. }