pm8001_sas.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /*
  2. * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 USI Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. */
  40. #include <linux/slab.h>
  41. #include "pm8001_sas.h"
  42. /**
  43. * pm8001_find_tag - from sas task to find out tag that belongs to this task
  44. * @task: the task sent to the LLDD
  45. * @tag: the found tag associated with the task
  46. */
  47. static int pm8001_find_tag(struct sas_task *task, u32 *tag)
  48. {
  49. if (task->lldd_task) {
  50. struct pm8001_ccb_info *ccb;
  51. ccb = task->lldd_task;
  52. *tag = ccb->ccb_tag;
  53. return 1;
  54. }
  55. return 0;
  56. }
  57. /**
  58. * pm8001_tag_clear - clear the tags bitmap
  59. * @pm8001_ha: our hba struct
  60. * @tag: the found tag associated with the task
  61. */
  62. static void pm8001_tag_clear(struct pm8001_hba_info *pm8001_ha, u32 tag)
  63. {
  64. void *bitmap = pm8001_ha->tags;
  65. clear_bit(tag, bitmap);
  66. }
  67. static void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag)
  68. {
  69. pm8001_tag_clear(pm8001_ha, tag);
  70. }
  71. static void pm8001_tag_set(struct pm8001_hba_info *pm8001_ha, u32 tag)
  72. {
  73. void *bitmap = pm8001_ha->tags;
  74. set_bit(tag, bitmap);
  75. }
  76. /**
  77. * pm8001_tag_alloc - allocate a empty tag for task used.
  78. * @pm8001_ha: our hba struct
  79. * @tag_out: the found empty tag .
  80. */
  81. inline int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out)
  82. {
  83. unsigned int index, tag;
  84. void *bitmap = pm8001_ha->tags;
  85. index = find_first_zero_bit(bitmap, pm8001_ha->tags_num);
  86. tag = index;
  87. if (tag >= pm8001_ha->tags_num)
  88. return -SAS_QUEUE_FULL;
  89. pm8001_tag_set(pm8001_ha, tag);
  90. *tag_out = tag;
  91. return 0;
  92. }
  93. void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha)
  94. {
  95. int i;
  96. for (i = 0; i < pm8001_ha->tags_num; ++i)
  97. pm8001_tag_clear(pm8001_ha, i);
  98. }
  99. /**
  100. * pm8001_mem_alloc - allocate memory for pm8001.
  101. * @pdev: pci device.
  102. * @virt_addr: the allocated virtual address
  103. * @pphys_addr_hi: the physical address high byte address.
  104. * @pphys_addr_lo: the physical address low byte address.
  105. * @mem_size: memory size.
  106. */
  107. int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
  108. dma_addr_t *pphys_addr, u32 *pphys_addr_hi,
  109. u32 *pphys_addr_lo, u32 mem_size, u32 align)
  110. {
  111. caddr_t mem_virt_alloc;
  112. dma_addr_t mem_dma_handle;
  113. u64 phys_align;
  114. u64 align_offset = 0;
  115. if (align)
  116. align_offset = (dma_addr_t)align - 1;
  117. mem_virt_alloc =
  118. pci_alloc_consistent(pdev, mem_size + align, &mem_dma_handle);
  119. if (!mem_virt_alloc) {
  120. pm8001_printk("memory allocation error\n");
  121. return -1;
  122. }
  123. memset((void *)mem_virt_alloc, 0, mem_size+align);
  124. *pphys_addr = mem_dma_handle;
  125. phys_align = (*pphys_addr + align_offset) & ~align_offset;
  126. *virt_addr = (void *)mem_virt_alloc + phys_align - *pphys_addr;
  127. *pphys_addr_hi = upper_32_bits(phys_align);
  128. *pphys_addr_lo = lower_32_bits(phys_align);
  129. return 0;
  130. }
  131. /**
  132. * pm8001_find_ha_by_dev - from domain device which come from sas layer to
  133. * find out our hba struct.
  134. * @dev: the domain device which from sas layer.
  135. */
  136. static
  137. struct pm8001_hba_info *pm8001_find_ha_by_dev(struct domain_device *dev)
  138. {
  139. struct sas_ha_struct *sha = dev->port->ha;
  140. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  141. return pm8001_ha;
  142. }
  143. /**
  144. * pm8001_phy_control - this function should be registered to
  145. * sas_domain_function_template to provide libsas used, note: this is just
  146. * control the HBA phy rather than other expander phy if you want control
  147. * other phy, you should use SMP command.
  148. * @sas_phy: which phy in HBA phys.
  149. * @func: the operation.
  150. * @funcdata: always NULL.
  151. */
  152. int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
  153. void *funcdata)
  154. {
  155. int rc = 0, phy_id = sas_phy->id;
  156. struct pm8001_hba_info *pm8001_ha = NULL;
  157. struct sas_phy_linkrates *rates;
  158. DECLARE_COMPLETION_ONSTACK(completion);
  159. unsigned long flags;
  160. pm8001_ha = sas_phy->ha->lldd_ha;
  161. pm8001_ha->phy[phy_id].enable_completion = &completion;
  162. switch (func) {
  163. case PHY_FUNC_SET_LINK_RATE:
  164. rates = funcdata;
  165. if (rates->minimum_linkrate) {
  166. pm8001_ha->phy[phy_id].minimum_linkrate =
  167. rates->minimum_linkrate;
  168. }
  169. if (rates->maximum_linkrate) {
  170. pm8001_ha->phy[phy_id].maximum_linkrate =
  171. rates->maximum_linkrate;
  172. }
  173. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  174. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  175. wait_for_completion(&completion);
  176. }
  177. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  178. PHY_LINK_RESET);
  179. break;
  180. case PHY_FUNC_HARD_RESET:
  181. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  182. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  183. wait_for_completion(&completion);
  184. }
  185. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  186. PHY_HARD_RESET);
  187. break;
  188. case PHY_FUNC_LINK_RESET:
  189. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  190. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  191. wait_for_completion(&completion);
  192. }
  193. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  194. PHY_LINK_RESET);
  195. break;
  196. case PHY_FUNC_RELEASE_SPINUP_HOLD:
  197. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  198. PHY_LINK_RESET);
  199. break;
  200. case PHY_FUNC_DISABLE:
  201. PM8001_CHIP_DISP->phy_stop_req(pm8001_ha, phy_id);
  202. break;
  203. case PHY_FUNC_GET_EVENTS:
  204. spin_lock_irqsave(&pm8001_ha->lock, flags);
  205. if (-1 == pm8001_bar4_shift(pm8001_ha,
  206. (phy_id < 4) ? 0x30000 : 0x40000)) {
  207. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  208. return -EINVAL;
  209. }
  210. {
  211. struct sas_phy *phy = sas_phy->phy;
  212. uint32_t *qp = (uint32_t *)(((char *)
  213. pm8001_ha->io_mem[2].memvirtaddr)
  214. + 0x1034 + (0x4000 * (phy_id & 3)));
  215. phy->invalid_dword_count = qp[0];
  216. phy->running_disparity_error_count = qp[1];
  217. phy->loss_of_dword_sync_count = qp[3];
  218. phy->phy_reset_problem_count = qp[4];
  219. }
  220. pm8001_bar4_shift(pm8001_ha, 0);
  221. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  222. return 0;
  223. default:
  224. rc = -EOPNOTSUPP;
  225. }
  226. msleep(300);
  227. return rc;
  228. }
  229. /**
  230. * pm8001_scan_start - we should enable all HBA phys by sending the phy_start
  231. * command to HBA.
  232. * @shost: the scsi host data.
  233. */
  234. void pm8001_scan_start(struct Scsi_Host *shost)
  235. {
  236. int i;
  237. struct pm8001_hba_info *pm8001_ha;
  238. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  239. pm8001_ha = sha->lldd_ha;
  240. PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
  241. for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
  242. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  243. }
  244. int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
  245. {
  246. struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
  247. /* give the phy enabling interrupt event time to come in (1s
  248. * is empirically about all it takes) */
  249. if (time < HZ)
  250. return 0;
  251. /* Wait for discovery to finish */
  252. sas_drain_work(ha);
  253. return 1;
  254. }
  255. /**
  256. * pm8001_task_prep_smp - the dispatcher function, prepare data for smp task
  257. * @pm8001_ha: our hba card information
  258. * @ccb: the ccb which attached to smp task
  259. */
  260. static int pm8001_task_prep_smp(struct pm8001_hba_info *pm8001_ha,
  261. struct pm8001_ccb_info *ccb)
  262. {
  263. return PM8001_CHIP_DISP->smp_req(pm8001_ha, ccb);
  264. }
  265. u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag)
  266. {
  267. struct ata_queued_cmd *qc = task->uldd_task;
  268. if (qc) {
  269. if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
  270. qc->tf.command == ATA_CMD_FPDMA_READ) {
  271. *tag = qc->tag;
  272. return 1;
  273. }
  274. }
  275. return 0;
  276. }
  277. /**
  278. * pm8001_task_prep_ata - the dispatcher function, prepare data for sata task
  279. * @pm8001_ha: our hba card information
  280. * @ccb: the ccb which attached to sata task
  281. */
  282. static int pm8001_task_prep_ata(struct pm8001_hba_info *pm8001_ha,
  283. struct pm8001_ccb_info *ccb)
  284. {
  285. return PM8001_CHIP_DISP->sata_req(pm8001_ha, ccb);
  286. }
  287. /**
  288. * pm8001_task_prep_ssp_tm - the dispatcher function, prepare task management data
  289. * @pm8001_ha: our hba card information
  290. * @ccb: the ccb which attached to TM
  291. * @tmf: the task management IU
  292. */
  293. static int pm8001_task_prep_ssp_tm(struct pm8001_hba_info *pm8001_ha,
  294. struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
  295. {
  296. return PM8001_CHIP_DISP->ssp_tm_req(pm8001_ha, ccb, tmf);
  297. }
  298. /**
  299. * pm8001_task_prep_ssp - the dispatcher function,prepare ssp data for ssp task
  300. * @pm8001_ha: our hba card information
  301. * @ccb: the ccb which attached to ssp task
  302. */
  303. static int pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha,
  304. struct pm8001_ccb_info *ccb)
  305. {
  306. return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb);
  307. }
  308. /* Find the local port id that's attached to this device */
  309. static int sas_find_local_port_id(struct domain_device *dev)
  310. {
  311. struct domain_device *pdev = dev->parent;
  312. /* Directly attached device */
  313. if (!pdev)
  314. return dev->port->id;
  315. while (pdev) {
  316. struct domain_device *pdev_p = pdev->parent;
  317. if (!pdev_p)
  318. return pdev->port->id;
  319. pdev = pdev->parent;
  320. }
  321. return 0;
  322. }
  323. /**
  324. * pm8001_task_exec - queue the task(ssp, smp && ata) to the hardware.
  325. * @task: the task to be execute.
  326. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  327. * we always execute one one time.
  328. * @gfp_flags: gfp_flags.
  329. * @is_tmf: if it is task management task.
  330. * @tmf: the task management IU
  331. */
  332. #define DEV_IS_GONE(pm8001_dev) \
  333. ((!pm8001_dev || (pm8001_dev->dev_type == NO_DEVICE)))
  334. static int pm8001_task_exec(struct sas_task *task, const int num,
  335. gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf)
  336. {
  337. struct domain_device *dev = task->dev;
  338. struct pm8001_hba_info *pm8001_ha;
  339. struct pm8001_device *pm8001_dev;
  340. struct pm8001_port *port = NULL;
  341. struct sas_task *t = task;
  342. struct pm8001_ccb_info *ccb;
  343. u32 tag = 0xdeadbeef, rc, n_elem = 0;
  344. u32 n = num;
  345. unsigned long flags = 0;
  346. if (!dev->port) {
  347. struct task_status_struct *tsm = &t->task_status;
  348. tsm->resp = SAS_TASK_UNDELIVERED;
  349. tsm->stat = SAS_PHY_DOWN;
  350. if (dev->dev_type != SATA_DEV)
  351. t->task_done(t);
  352. return 0;
  353. }
  354. pm8001_ha = pm8001_find_ha_by_dev(task->dev);
  355. PM8001_IO_DBG(pm8001_ha, pm8001_printk("pm8001_task_exec device \n "));
  356. spin_lock_irqsave(&pm8001_ha->lock, flags);
  357. do {
  358. dev = t->dev;
  359. pm8001_dev = dev->lldd_dev;
  360. port = &pm8001_ha->port[sas_find_local_port_id(dev)];
  361. if (DEV_IS_GONE(pm8001_dev) || !port->port_attached) {
  362. if (sas_protocol_ata(t->task_proto)) {
  363. struct task_status_struct *ts = &t->task_status;
  364. ts->resp = SAS_TASK_UNDELIVERED;
  365. ts->stat = SAS_PHY_DOWN;
  366. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  367. t->task_done(t);
  368. spin_lock_irqsave(&pm8001_ha->lock, flags);
  369. if (n > 1)
  370. t = list_entry(t->list.next,
  371. struct sas_task, list);
  372. continue;
  373. } else {
  374. struct task_status_struct *ts = &t->task_status;
  375. ts->resp = SAS_TASK_UNDELIVERED;
  376. ts->stat = SAS_PHY_DOWN;
  377. t->task_done(t);
  378. if (n > 1)
  379. t = list_entry(t->list.next,
  380. struct sas_task, list);
  381. continue;
  382. }
  383. }
  384. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  385. if (rc)
  386. goto err_out;
  387. ccb = &pm8001_ha->ccb_info[tag];
  388. if (!sas_protocol_ata(t->task_proto)) {
  389. if (t->num_scatter) {
  390. n_elem = dma_map_sg(pm8001_ha->dev,
  391. t->scatter,
  392. t->num_scatter,
  393. t->data_dir);
  394. if (!n_elem) {
  395. rc = -ENOMEM;
  396. goto err_out_tag;
  397. }
  398. }
  399. } else {
  400. n_elem = t->num_scatter;
  401. }
  402. t->lldd_task = ccb;
  403. ccb->n_elem = n_elem;
  404. ccb->ccb_tag = tag;
  405. ccb->task = t;
  406. switch (t->task_proto) {
  407. case SAS_PROTOCOL_SMP:
  408. rc = pm8001_task_prep_smp(pm8001_ha, ccb);
  409. break;
  410. case SAS_PROTOCOL_SSP:
  411. if (is_tmf)
  412. rc = pm8001_task_prep_ssp_tm(pm8001_ha,
  413. ccb, tmf);
  414. else
  415. rc = pm8001_task_prep_ssp(pm8001_ha, ccb);
  416. break;
  417. case SAS_PROTOCOL_SATA:
  418. case SAS_PROTOCOL_STP:
  419. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  420. rc = pm8001_task_prep_ata(pm8001_ha, ccb);
  421. break;
  422. default:
  423. dev_printk(KERN_ERR, pm8001_ha->dev,
  424. "unknown sas_task proto: 0x%x\n",
  425. t->task_proto);
  426. rc = -EINVAL;
  427. break;
  428. }
  429. if (rc) {
  430. PM8001_IO_DBG(pm8001_ha,
  431. pm8001_printk("rc is %x\n", rc));
  432. goto err_out_tag;
  433. }
  434. /* TODO: select normal or high priority */
  435. spin_lock(&t->task_state_lock);
  436. t->task_state_flags |= SAS_TASK_AT_INITIATOR;
  437. spin_unlock(&t->task_state_lock);
  438. pm8001_dev->running_req++;
  439. if (n > 1)
  440. t = list_entry(t->list.next, struct sas_task, list);
  441. } while (--n);
  442. rc = 0;
  443. goto out_done;
  444. err_out_tag:
  445. pm8001_tag_free(pm8001_ha, tag);
  446. err_out:
  447. dev_printk(KERN_ERR, pm8001_ha->dev, "pm8001 exec failed[%d]!\n", rc);
  448. if (!sas_protocol_ata(t->task_proto))
  449. if (n_elem)
  450. dma_unmap_sg(pm8001_ha->dev, t->scatter, n_elem,
  451. t->data_dir);
  452. out_done:
  453. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  454. return rc;
  455. }
  456. /**
  457. * pm8001_queue_command - register for upper layer used, all IO commands sent
  458. * to HBA are from this interface.
  459. * @task: the task to be execute.
  460. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  461. * we always execute one one time
  462. * @gfp_flags: gfp_flags
  463. */
  464. int pm8001_queue_command(struct sas_task *task, const int num,
  465. gfp_t gfp_flags)
  466. {
  467. return pm8001_task_exec(task, num, gfp_flags, 0, NULL);
  468. }
  469. void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, u32 ccb_idx)
  470. {
  471. pm8001_tag_clear(pm8001_ha, ccb_idx);
  472. }
  473. /**
  474. * pm8001_ccb_task_free - free the sg for ssp and smp command, free the ccb.
  475. * @pm8001_ha: our hba card information
  476. * @ccb: the ccb which attached to ssp task
  477. * @task: the task to be free.
  478. * @ccb_idx: ccb index.
  479. */
  480. void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
  481. struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx)
  482. {
  483. if (!ccb->task)
  484. return;
  485. if (!sas_protocol_ata(task->task_proto))
  486. if (ccb->n_elem)
  487. dma_unmap_sg(pm8001_ha->dev, task->scatter,
  488. task->num_scatter, task->data_dir);
  489. switch (task->task_proto) {
  490. case SAS_PROTOCOL_SMP:
  491. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_resp, 1,
  492. PCI_DMA_FROMDEVICE);
  493. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_req, 1,
  494. PCI_DMA_TODEVICE);
  495. break;
  496. case SAS_PROTOCOL_SATA:
  497. case SAS_PROTOCOL_STP:
  498. case SAS_PROTOCOL_SSP:
  499. default:
  500. /* do nothing */
  501. break;
  502. }
  503. task->lldd_task = NULL;
  504. ccb->task = NULL;
  505. ccb->ccb_tag = 0xFFFFFFFF;
  506. ccb->open_retry = 0;
  507. pm8001_ccb_free(pm8001_ha, ccb_idx);
  508. }
  509. /**
  510. * pm8001_alloc_dev - find a empty pm8001_device
  511. * @pm8001_ha: our hba card information
  512. */
  513. struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha)
  514. {
  515. u32 dev;
  516. for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
  517. if (pm8001_ha->devices[dev].dev_type == NO_DEVICE) {
  518. pm8001_ha->devices[dev].id = dev;
  519. return &pm8001_ha->devices[dev];
  520. }
  521. }
  522. if (dev == PM8001_MAX_DEVICES) {
  523. PM8001_FAIL_DBG(pm8001_ha,
  524. pm8001_printk("max support %d devices, ignore ..\n",
  525. PM8001_MAX_DEVICES));
  526. }
  527. return NULL;
  528. }
  529. static void pm8001_free_dev(struct pm8001_device *pm8001_dev)
  530. {
  531. u32 id = pm8001_dev->id;
  532. memset(pm8001_dev, 0, sizeof(*pm8001_dev));
  533. pm8001_dev->id = id;
  534. pm8001_dev->dev_type = NO_DEVICE;
  535. pm8001_dev->device_id = PM8001_MAX_DEVICES;
  536. pm8001_dev->sas_device = NULL;
  537. }
  538. /**
  539. * pm8001_dev_found_notify - libsas notify a device is found.
  540. * @dev: the device structure which sas layer used.
  541. *
  542. * when libsas find a sas domain device, it should tell the LLDD that
  543. * device is found, and then LLDD register this device to HBA firmware
  544. * by the command "OPC_INB_REG_DEV", after that the HBA will assign a
  545. * device ID(according to device's sas address) and returned it to LLDD. From
  546. * now on, we communicate with HBA FW with the device ID which HBA assigned
  547. * rather than sas address. it is the necessary step for our HBA but it is
  548. * the optional for other HBA driver.
  549. */
  550. static int pm8001_dev_found_notify(struct domain_device *dev)
  551. {
  552. unsigned long flags = 0;
  553. int res = 0;
  554. struct pm8001_hba_info *pm8001_ha = NULL;
  555. struct domain_device *parent_dev = dev->parent;
  556. struct pm8001_device *pm8001_device;
  557. DECLARE_COMPLETION_ONSTACK(completion);
  558. u32 flag = 0;
  559. pm8001_ha = pm8001_find_ha_by_dev(dev);
  560. spin_lock_irqsave(&pm8001_ha->lock, flags);
  561. pm8001_device = pm8001_alloc_dev(pm8001_ha);
  562. if (!pm8001_device) {
  563. res = -1;
  564. goto found_out;
  565. }
  566. pm8001_device->sas_device = dev;
  567. dev->lldd_dev = pm8001_device;
  568. pm8001_device->dev_type = dev->dev_type;
  569. pm8001_device->dcompletion = &completion;
  570. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) {
  571. int phy_id;
  572. struct ex_phy *phy;
  573. for (phy_id = 0; phy_id < parent_dev->ex_dev.num_phys;
  574. phy_id++) {
  575. phy = &parent_dev->ex_dev.ex_phy[phy_id];
  576. if (SAS_ADDR(phy->attached_sas_addr)
  577. == SAS_ADDR(dev->sas_addr)) {
  578. pm8001_device->attached_phy = phy_id;
  579. break;
  580. }
  581. }
  582. if (phy_id == parent_dev->ex_dev.num_phys) {
  583. PM8001_FAIL_DBG(pm8001_ha,
  584. pm8001_printk("Error: no attached dev:%016llx"
  585. " at ex:%016llx.\n", SAS_ADDR(dev->sas_addr),
  586. SAS_ADDR(parent_dev->sas_addr)));
  587. res = -1;
  588. }
  589. } else {
  590. if (dev->dev_type == SATA_DEV) {
  591. pm8001_device->attached_phy =
  592. dev->rphy->identify.phy_identifier;
  593. flag = 1; /* directly sata*/
  594. }
  595. } /*register this device to HBA*/
  596. PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device\n"));
  597. PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
  598. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  599. wait_for_completion(&completion);
  600. if (dev->dev_type == SAS_END_DEV)
  601. msleep(50);
  602. pm8001_ha->flags = PM8001F_RUN_TIME;
  603. return 0;
  604. found_out:
  605. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  606. return res;
  607. }
  608. int pm8001_dev_found(struct domain_device *dev)
  609. {
  610. return pm8001_dev_found_notify(dev);
  611. }
  612. static void pm8001_task_done(struct sas_task *task)
  613. {
  614. if (!del_timer(&task->timer))
  615. return;
  616. complete(&task->completion);
  617. }
  618. static void pm8001_tmf_timedout(unsigned long data)
  619. {
  620. struct sas_task *task = (struct sas_task *)data;
  621. task->task_state_flags |= SAS_TASK_STATE_ABORTED;
  622. complete(&task->completion);
  623. }
  624. #define PM8001_TASK_TIMEOUT 20
  625. /**
  626. * pm8001_exec_internal_tmf_task - execute some task management commands.
  627. * @dev: the wanted device.
  628. * @tmf: which task management wanted to be take.
  629. * @para_len: para_len.
  630. * @parameter: ssp task parameter.
  631. *
  632. * when errors or exception happened, we may want to do something, for example
  633. * abort the issued task which result in this execption, it is done by calling
  634. * this function, note it is also with the task execute interface.
  635. */
  636. static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
  637. void *parameter, u32 para_len, struct pm8001_tmf_task *tmf)
  638. {
  639. int res, retry;
  640. struct sas_task *task = NULL;
  641. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  642. for (retry = 0; retry < 3; retry++) {
  643. task = sas_alloc_task(GFP_KERNEL);
  644. if (!task)
  645. return -ENOMEM;
  646. task->dev = dev;
  647. task->task_proto = dev->tproto;
  648. memcpy(&task->ssp_task, parameter, para_len);
  649. task->task_done = pm8001_task_done;
  650. task->timer.data = (unsigned long)task;
  651. task->timer.function = pm8001_tmf_timedout;
  652. task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ;
  653. add_timer(&task->timer);
  654. res = pm8001_task_exec(task, 1, GFP_KERNEL, 1, tmf);
  655. if (res) {
  656. del_timer(&task->timer);
  657. PM8001_FAIL_DBG(pm8001_ha,
  658. pm8001_printk("Executing internal task "
  659. "failed\n"));
  660. goto ex_err;
  661. }
  662. wait_for_completion(&task->completion);
  663. res = -TMF_RESP_FUNC_FAILED;
  664. /* Even TMF timed out, return direct. */
  665. if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
  666. if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
  667. PM8001_FAIL_DBG(pm8001_ha,
  668. pm8001_printk("TMF task[%x]timeout.\n",
  669. tmf->tmf));
  670. goto ex_err;
  671. }
  672. }
  673. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  674. task->task_status.stat == SAM_STAT_GOOD) {
  675. res = TMF_RESP_FUNC_COMPLETE;
  676. break;
  677. }
  678. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  679. task->task_status.stat == SAS_DATA_UNDERRUN) {
  680. /* no error, but return the number of bytes of
  681. * underrun */
  682. res = task->task_status.residual;
  683. break;
  684. }
  685. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  686. task->task_status.stat == SAS_DATA_OVERRUN) {
  687. PM8001_FAIL_DBG(pm8001_ha,
  688. pm8001_printk("Blocked task error.\n"));
  689. res = -EMSGSIZE;
  690. break;
  691. } else {
  692. PM8001_EH_DBG(pm8001_ha,
  693. pm8001_printk(" Task to dev %016llx response:"
  694. "0x%x status 0x%x\n",
  695. SAS_ADDR(dev->sas_addr),
  696. task->task_status.resp,
  697. task->task_status.stat));
  698. sas_free_task(task);
  699. task = NULL;
  700. }
  701. }
  702. ex_err:
  703. BUG_ON(retry == 3 && task != NULL);
  704. sas_free_task(task);
  705. return res;
  706. }
  707. static int
  708. pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
  709. struct pm8001_device *pm8001_dev, struct domain_device *dev, u32 flag,
  710. u32 task_tag)
  711. {
  712. int res, retry;
  713. u32 ccb_tag;
  714. struct pm8001_ccb_info *ccb;
  715. struct sas_task *task = NULL;
  716. for (retry = 0; retry < 3; retry++) {
  717. task = sas_alloc_task(GFP_KERNEL);
  718. if (!task)
  719. return -ENOMEM;
  720. task->dev = dev;
  721. task->task_proto = dev->tproto;
  722. task->task_done = pm8001_task_done;
  723. task->timer.data = (unsigned long)task;
  724. task->timer.function = pm8001_tmf_timedout;
  725. task->timer.expires = jiffies + PM8001_TASK_TIMEOUT * HZ;
  726. add_timer(&task->timer);
  727. res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
  728. if (res)
  729. return res;
  730. ccb = &pm8001_ha->ccb_info[ccb_tag];
  731. ccb->device = pm8001_dev;
  732. ccb->ccb_tag = ccb_tag;
  733. ccb->task = task;
  734. res = PM8001_CHIP_DISP->task_abort(pm8001_ha,
  735. pm8001_dev, flag, task_tag, ccb_tag);
  736. if (res) {
  737. del_timer(&task->timer);
  738. PM8001_FAIL_DBG(pm8001_ha,
  739. pm8001_printk("Executing internal task "
  740. "failed\n"));
  741. goto ex_err;
  742. }
  743. wait_for_completion(&task->completion);
  744. res = TMF_RESP_FUNC_FAILED;
  745. /* Even TMF timed out, return direct. */
  746. if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
  747. if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
  748. PM8001_FAIL_DBG(pm8001_ha,
  749. pm8001_printk("TMF task timeout.\n"));
  750. goto ex_err;
  751. }
  752. }
  753. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  754. task->task_status.stat == SAM_STAT_GOOD) {
  755. res = TMF_RESP_FUNC_COMPLETE;
  756. break;
  757. } else {
  758. PM8001_EH_DBG(pm8001_ha,
  759. pm8001_printk(" Task to dev %016llx response: "
  760. "0x%x status 0x%x\n",
  761. SAS_ADDR(dev->sas_addr),
  762. task->task_status.resp,
  763. task->task_status.stat));
  764. sas_free_task(task);
  765. task = NULL;
  766. }
  767. }
  768. ex_err:
  769. BUG_ON(retry == 3 && task != NULL);
  770. sas_free_task(task);
  771. return res;
  772. }
  773. /**
  774. * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify"
  775. * @dev: the device structure which sas layer used.
  776. */
  777. static void pm8001_dev_gone_notify(struct domain_device *dev)
  778. {
  779. unsigned long flags = 0;
  780. u32 tag;
  781. struct pm8001_hba_info *pm8001_ha;
  782. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  783. pm8001_ha = pm8001_find_ha_by_dev(dev);
  784. spin_lock_irqsave(&pm8001_ha->lock, flags);
  785. pm8001_tag_alloc(pm8001_ha, &tag);
  786. if (pm8001_dev) {
  787. u32 device_id = pm8001_dev->device_id;
  788. PM8001_DISC_DBG(pm8001_ha,
  789. pm8001_printk("found dev[%d:%x] is gone.\n",
  790. pm8001_dev->device_id, pm8001_dev->dev_type));
  791. if (pm8001_dev->running_req) {
  792. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  793. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  794. dev, 1, 0);
  795. spin_lock_irqsave(&pm8001_ha->lock, flags);
  796. }
  797. PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
  798. pm8001_free_dev(pm8001_dev);
  799. } else {
  800. PM8001_DISC_DBG(pm8001_ha,
  801. pm8001_printk("Found dev has gone.\n"));
  802. }
  803. dev->lldd_dev = NULL;
  804. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  805. }
  806. void pm8001_dev_gone(struct domain_device *dev)
  807. {
  808. pm8001_dev_gone_notify(dev);
  809. }
  810. static int pm8001_issue_ssp_tmf(struct domain_device *dev,
  811. u8 *lun, struct pm8001_tmf_task *tmf)
  812. {
  813. struct sas_ssp_task ssp_task;
  814. if (!(dev->tproto & SAS_PROTOCOL_SSP))
  815. return TMF_RESP_FUNC_ESUPP;
  816. strncpy((u8 *)&ssp_task.LUN, lun, 8);
  817. return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task),
  818. tmf);
  819. }
  820. /* retry commands by ha, by task and/or by device */
  821. void pm8001_open_reject_retry(
  822. struct pm8001_hba_info *pm8001_ha,
  823. struct sas_task *task_to_close,
  824. struct pm8001_device *device_to_close)
  825. {
  826. int i;
  827. unsigned long flags;
  828. if (pm8001_ha == NULL)
  829. return;
  830. spin_lock_irqsave(&pm8001_ha->lock, flags);
  831. for (i = 0; i < PM8001_MAX_CCB; i++) {
  832. struct sas_task *task;
  833. struct task_status_struct *ts;
  834. struct pm8001_device *pm8001_dev;
  835. unsigned long flags1;
  836. u32 tag;
  837. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[i];
  838. pm8001_dev = ccb->device;
  839. if (!pm8001_dev || (pm8001_dev->dev_type == NO_DEVICE))
  840. continue;
  841. if (!device_to_close) {
  842. uintptr_t d = (uintptr_t)pm8001_dev
  843. - (uintptr_t)&pm8001_ha->devices;
  844. if (((d % sizeof(*pm8001_dev)) != 0)
  845. || ((d / sizeof(*pm8001_dev)) >= PM8001_MAX_DEVICES))
  846. continue;
  847. } else if (pm8001_dev != device_to_close)
  848. continue;
  849. tag = ccb->ccb_tag;
  850. if (!tag || (tag == 0xFFFFFFFF))
  851. continue;
  852. task = ccb->task;
  853. if (!task || !task->task_done)
  854. continue;
  855. if (task_to_close && (task != task_to_close))
  856. continue;
  857. ts = &task->task_status;
  858. ts->resp = SAS_TASK_COMPLETE;
  859. /* Force the midlayer to retry */
  860. ts->stat = SAS_OPEN_REJECT;
  861. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  862. if (pm8001_dev)
  863. pm8001_dev->running_req--;
  864. spin_lock_irqsave(&task->task_state_lock, flags1);
  865. task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  866. task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  867. task->task_state_flags |= SAS_TASK_STATE_DONE;
  868. if (unlikely((task->task_state_flags
  869. & SAS_TASK_STATE_ABORTED))) {
  870. spin_unlock_irqrestore(&task->task_state_lock,
  871. flags1);
  872. pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
  873. } else {
  874. spin_unlock_irqrestore(&task->task_state_lock,
  875. flags1);
  876. pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
  877. mb();/* in order to force CPU ordering */
  878. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  879. task->task_done(task);
  880. spin_lock_irqsave(&pm8001_ha->lock, flags);
  881. }
  882. }
  883. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  884. }
  885. /**
  886. * Standard mandates link reset for ATA (type 0) and hard reset for
  887. * SSP (type 1) , only for RECOVERY
  888. */
  889. int pm8001_I_T_nexus_reset(struct domain_device *dev)
  890. {
  891. int rc = TMF_RESP_FUNC_FAILED;
  892. struct pm8001_device *pm8001_dev;
  893. struct pm8001_hba_info *pm8001_ha;
  894. struct sas_phy *phy;
  895. if (!dev || !dev->lldd_dev)
  896. return -1;
  897. pm8001_dev = dev->lldd_dev;
  898. pm8001_ha = pm8001_find_ha_by_dev(dev);
  899. phy = sas_get_local_phy(dev);
  900. if (dev_is_sata(dev)) {
  901. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  902. if (scsi_is_sas_phy_local(phy)) {
  903. rc = 0;
  904. goto out;
  905. }
  906. rc = sas_phy_reset(phy, 1);
  907. msleep(2000);
  908. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  909. dev, 1, 0);
  910. pm8001_dev->setds_completion = &completion_setstate;
  911. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  912. pm8001_dev, 0x01);
  913. wait_for_completion(&completion_setstate);
  914. } else {
  915. rc = sas_phy_reset(phy, 1);
  916. msleep(2000);
  917. }
  918. PM8001_EH_DBG(pm8001_ha, pm8001_printk(" for device[%x]:rc=%d\n",
  919. pm8001_dev->device_id, rc));
  920. out:
  921. sas_put_local_phy(phy);
  922. return rc;
  923. }
  924. /* mandatory SAM-3, the task reset the specified LUN*/
  925. int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
  926. {
  927. int rc = TMF_RESP_FUNC_FAILED;
  928. struct pm8001_tmf_task tmf_task;
  929. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  930. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  931. if (dev_is_sata(dev)) {
  932. struct sas_phy *phy = sas_get_local_phy(dev);
  933. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  934. dev, 1, 0);
  935. rc = sas_phy_reset(phy, 1);
  936. sas_put_local_phy(phy);
  937. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  938. pm8001_dev, 0x01);
  939. msleep(2000);
  940. } else {
  941. tmf_task.tmf = TMF_LU_RESET;
  942. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  943. }
  944. /* If failed, fall-through I_T_Nexus reset */
  945. PM8001_EH_DBG(pm8001_ha, pm8001_printk("for device[%x]:rc=%d\n",
  946. pm8001_dev->device_id, rc));
  947. return rc;
  948. }
  949. /* optional SAM-3 */
  950. int pm8001_query_task(struct sas_task *task)
  951. {
  952. u32 tag = 0xdeadbeef;
  953. int i = 0;
  954. struct scsi_lun lun;
  955. struct pm8001_tmf_task tmf_task;
  956. int rc = TMF_RESP_FUNC_FAILED;
  957. if (unlikely(!task || !task->lldd_task || !task->dev))
  958. return rc;
  959. if (task->task_proto & SAS_PROTOCOL_SSP) {
  960. struct scsi_cmnd *cmnd = task->uldd_task;
  961. struct domain_device *dev = task->dev;
  962. struct pm8001_hba_info *pm8001_ha =
  963. pm8001_find_ha_by_dev(dev);
  964. int_to_scsilun(cmnd->device->lun, &lun);
  965. rc = pm8001_find_tag(task, &tag);
  966. if (rc == 0) {
  967. rc = TMF_RESP_FUNC_FAILED;
  968. return rc;
  969. }
  970. PM8001_EH_DBG(pm8001_ha, pm8001_printk("Query:["));
  971. for (i = 0; i < 16; i++)
  972. printk(KERN_INFO "%02x ", cmnd->cmnd[i]);
  973. printk(KERN_INFO "]\n");
  974. tmf_task.tmf = TMF_QUERY_TASK;
  975. tmf_task.tag_of_task_to_be_managed = tag;
  976. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  977. switch (rc) {
  978. /* The task is still in Lun, release it then */
  979. case TMF_RESP_FUNC_SUCC:
  980. PM8001_EH_DBG(pm8001_ha,
  981. pm8001_printk("The task is still in Lun\n"));
  982. break;
  983. /* The task is not in Lun or failed, reset the phy */
  984. case TMF_RESP_FUNC_FAILED:
  985. case TMF_RESP_FUNC_COMPLETE:
  986. PM8001_EH_DBG(pm8001_ha,
  987. pm8001_printk("The task is not in Lun or failed,"
  988. " reset the phy\n"));
  989. break;
  990. }
  991. }
  992. pm8001_printk(":rc= %d\n", rc);
  993. return rc;
  994. }
  995. /* mandatory SAM-3, still need free task/ccb info, abord the specified task */
  996. int pm8001_abort_task(struct sas_task *task)
  997. {
  998. unsigned long flags;
  999. u32 tag = 0xdeadbeef;
  1000. u32 device_id;
  1001. struct domain_device *dev ;
  1002. struct pm8001_hba_info *pm8001_ha = NULL;
  1003. struct pm8001_ccb_info *ccb;
  1004. struct scsi_lun lun;
  1005. struct pm8001_device *pm8001_dev;
  1006. struct pm8001_tmf_task tmf_task;
  1007. int rc = TMF_RESP_FUNC_FAILED;
  1008. if (unlikely(!task || !task->lldd_task || !task->dev))
  1009. return rc;
  1010. spin_lock_irqsave(&task->task_state_lock, flags);
  1011. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  1012. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1013. rc = TMF_RESP_FUNC_COMPLETE;
  1014. goto out;
  1015. }
  1016. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1017. if (task->task_proto & SAS_PROTOCOL_SSP) {
  1018. struct scsi_cmnd *cmnd = task->uldd_task;
  1019. dev = task->dev;
  1020. ccb = task->lldd_task;
  1021. pm8001_dev = dev->lldd_dev;
  1022. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1023. int_to_scsilun(cmnd->device->lun, &lun);
  1024. rc = pm8001_find_tag(task, &tag);
  1025. if (rc == 0) {
  1026. printk(KERN_INFO "No such tag in %s\n", __func__);
  1027. rc = TMF_RESP_FUNC_FAILED;
  1028. return rc;
  1029. }
  1030. device_id = pm8001_dev->device_id;
  1031. PM8001_EH_DBG(pm8001_ha,
  1032. pm8001_printk("abort io to deviceid= %d\n", device_id));
  1033. tmf_task.tmf = TMF_ABORT_TASK;
  1034. tmf_task.tag_of_task_to_be_managed = tag;
  1035. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  1036. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1037. pm8001_dev->sas_device, 0, tag);
  1038. } else if (task->task_proto & SAS_PROTOCOL_SATA ||
  1039. task->task_proto & SAS_PROTOCOL_STP) {
  1040. dev = task->dev;
  1041. pm8001_dev = dev->lldd_dev;
  1042. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1043. rc = pm8001_find_tag(task, &tag);
  1044. if (rc == 0) {
  1045. printk(KERN_INFO "No such tag in %s\n", __func__);
  1046. rc = TMF_RESP_FUNC_FAILED;
  1047. return rc;
  1048. }
  1049. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1050. pm8001_dev->sas_device, 0, tag);
  1051. } else if (task->task_proto & SAS_PROTOCOL_SMP) {
  1052. /* SMP */
  1053. dev = task->dev;
  1054. pm8001_dev = dev->lldd_dev;
  1055. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1056. rc = pm8001_find_tag(task, &tag);
  1057. if (rc == 0) {
  1058. printk(KERN_INFO "No such tag in %s\n", __func__);
  1059. rc = TMF_RESP_FUNC_FAILED;
  1060. return rc;
  1061. }
  1062. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1063. pm8001_dev->sas_device, 0, tag);
  1064. }
  1065. out:
  1066. if (rc != TMF_RESP_FUNC_COMPLETE)
  1067. pm8001_printk("rc= %d\n", rc);
  1068. return rc;
  1069. }
  1070. int pm8001_abort_task_set(struct domain_device *dev, u8 *lun)
  1071. {
  1072. int rc = TMF_RESP_FUNC_FAILED;
  1073. struct pm8001_tmf_task tmf_task;
  1074. tmf_task.tmf = TMF_ABORT_TASK_SET;
  1075. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1076. return rc;
  1077. }
  1078. int pm8001_clear_aca(struct domain_device *dev, u8 *lun)
  1079. {
  1080. int rc = TMF_RESP_FUNC_FAILED;
  1081. struct pm8001_tmf_task tmf_task;
  1082. tmf_task.tmf = TMF_CLEAR_ACA;
  1083. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1084. return rc;
  1085. }
  1086. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun)
  1087. {
  1088. int rc = TMF_RESP_FUNC_FAILED;
  1089. struct pm8001_tmf_task tmf_task;
  1090. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1091. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1092. PM8001_EH_DBG(pm8001_ha,
  1093. pm8001_printk("I_T_L_Q clear task set[%x]\n",
  1094. pm8001_dev->device_id));
  1095. tmf_task.tmf = TMF_CLEAR_TASK_SET;
  1096. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1097. return rc;
  1098. }