pm8001_sas.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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. pm8001_ha = sas_phy->ha->lldd_ha;
  160. pm8001_ha->phy[phy_id].enable_completion = &completion;
  161. switch (func) {
  162. case PHY_FUNC_SET_LINK_RATE:
  163. rates = funcdata;
  164. if (rates->minimum_linkrate) {
  165. pm8001_ha->phy[phy_id].minimum_linkrate =
  166. rates->minimum_linkrate;
  167. }
  168. if (rates->maximum_linkrate) {
  169. pm8001_ha->phy[phy_id].maximum_linkrate =
  170. rates->maximum_linkrate;
  171. }
  172. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  173. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  174. wait_for_completion(&completion);
  175. }
  176. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  177. PHY_LINK_RESET);
  178. break;
  179. case PHY_FUNC_HARD_RESET:
  180. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  181. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  182. wait_for_completion(&completion);
  183. }
  184. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  185. PHY_HARD_RESET);
  186. break;
  187. case PHY_FUNC_LINK_RESET:
  188. if (pm8001_ha->phy[phy_id].phy_state == 0) {
  189. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  190. wait_for_completion(&completion);
  191. }
  192. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  193. PHY_LINK_RESET);
  194. break;
  195. case PHY_FUNC_RELEASE_SPINUP_HOLD:
  196. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  197. PHY_LINK_RESET);
  198. break;
  199. case PHY_FUNC_DISABLE:
  200. PM8001_CHIP_DISP->phy_stop_req(pm8001_ha, phy_id);
  201. break;
  202. default:
  203. rc = -EOPNOTSUPP;
  204. }
  205. msleep(300);
  206. return rc;
  207. }
  208. int pm8001_slave_alloc(struct scsi_device *scsi_dev)
  209. {
  210. struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
  211. if (dev_is_sata(dev)) {
  212. /* We don't need to rescan targets
  213. * if REPORT_LUNS request is failed
  214. */
  215. if (scsi_dev->lun > 0)
  216. return -ENXIO;
  217. scsi_dev->tagged_supported = 1;
  218. }
  219. return sas_slave_alloc(scsi_dev);
  220. }
  221. /**
  222. * pm8001_scan_start - we should enable all HBA phys by sending the phy_start
  223. * command to HBA.
  224. * @shost: the scsi host data.
  225. */
  226. void pm8001_scan_start(struct Scsi_Host *shost)
  227. {
  228. int i;
  229. struct pm8001_hba_info *pm8001_ha;
  230. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  231. pm8001_ha = sha->lldd_ha;
  232. PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
  233. for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
  234. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  235. }
  236. int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
  237. {
  238. /* give the phy enabling interrupt event time to come in (1s
  239. * is empirically about all it takes) */
  240. if (time < HZ)
  241. return 0;
  242. /* Wait for discovery to finish */
  243. scsi_flush_work(shost);
  244. return 1;
  245. }
  246. /**
  247. * pm8001_task_prep_smp - the dispatcher function, prepare data for smp task
  248. * @pm8001_ha: our hba card information
  249. * @ccb: the ccb which attached to smp task
  250. */
  251. static int pm8001_task_prep_smp(struct pm8001_hba_info *pm8001_ha,
  252. struct pm8001_ccb_info *ccb)
  253. {
  254. return PM8001_CHIP_DISP->smp_req(pm8001_ha, ccb);
  255. }
  256. u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag)
  257. {
  258. struct ata_queued_cmd *qc = task->uldd_task;
  259. if (qc) {
  260. if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
  261. qc->tf.command == ATA_CMD_FPDMA_READ) {
  262. *tag = qc->tag;
  263. return 1;
  264. }
  265. }
  266. return 0;
  267. }
  268. /**
  269. * pm8001_task_prep_ata - the dispatcher function, prepare data for sata task
  270. * @pm8001_ha: our hba card information
  271. * @ccb: the ccb which attached to sata task
  272. */
  273. static int pm8001_task_prep_ata(struct pm8001_hba_info *pm8001_ha,
  274. struct pm8001_ccb_info *ccb)
  275. {
  276. return PM8001_CHIP_DISP->sata_req(pm8001_ha, ccb);
  277. }
  278. /**
  279. * pm8001_task_prep_ssp_tm - the dispatcher function, prepare task management data
  280. * @pm8001_ha: our hba card information
  281. * @ccb: the ccb which attached to TM
  282. * @tmf: the task management IU
  283. */
  284. static int pm8001_task_prep_ssp_tm(struct pm8001_hba_info *pm8001_ha,
  285. struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
  286. {
  287. return PM8001_CHIP_DISP->ssp_tm_req(pm8001_ha, ccb, tmf);
  288. }
  289. /**
  290. * pm8001_task_prep_ssp - the dispatcher function,prepare ssp data for ssp task
  291. * @pm8001_ha: our hba card information
  292. * @ccb: the ccb which attached to ssp task
  293. */
  294. static int pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha,
  295. struct pm8001_ccb_info *ccb)
  296. {
  297. return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb);
  298. }
  299. int pm8001_slave_configure(struct scsi_device *sdev)
  300. {
  301. struct domain_device *dev = sdev_to_domain_dev(sdev);
  302. int ret = sas_slave_configure(sdev);
  303. if (ret)
  304. return ret;
  305. if (dev_is_sata(dev)) {
  306. #ifdef PM8001_DISABLE_NCQ
  307. struct ata_port *ap = dev->sata_dev.ap;
  308. struct ata_device *adev = ap->link.device;
  309. adev->flags |= ATA_DFLAG_NCQ_OFF;
  310. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, 1);
  311. #endif
  312. }
  313. return 0;
  314. }
  315. /* Find the local port id that's attached to this device */
  316. static int sas_find_local_port_id(struct domain_device *dev)
  317. {
  318. struct domain_device *pdev = dev->parent;
  319. /* Directly attached device */
  320. if (!pdev)
  321. return dev->port->id;
  322. while (pdev) {
  323. struct domain_device *pdev_p = pdev->parent;
  324. if (!pdev_p)
  325. return pdev->port->id;
  326. pdev = pdev->parent;
  327. }
  328. return 0;
  329. }
  330. /**
  331. * pm8001_task_exec - queue the task(ssp, smp && ata) to the hardware.
  332. * @task: the task to be execute.
  333. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  334. * we always execute one one time.
  335. * @gfp_flags: gfp_flags.
  336. * @is_tmf: if it is task management task.
  337. * @tmf: the task management IU
  338. */
  339. #define DEV_IS_GONE(pm8001_dev) \
  340. ((!pm8001_dev || (pm8001_dev->dev_type == NO_DEVICE)))
  341. static int pm8001_task_exec(struct sas_task *task, const int num,
  342. gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf)
  343. {
  344. struct domain_device *dev = task->dev;
  345. struct pm8001_hba_info *pm8001_ha;
  346. struct pm8001_device *pm8001_dev;
  347. struct pm8001_port *port = NULL;
  348. struct sas_task *t = task;
  349. struct pm8001_ccb_info *ccb;
  350. u32 tag = 0xdeadbeef, rc, n_elem = 0;
  351. u32 n = num;
  352. unsigned long flags = 0, flags_libsas = 0;
  353. if (!dev->port) {
  354. struct task_status_struct *tsm = &t->task_status;
  355. tsm->resp = SAS_TASK_UNDELIVERED;
  356. tsm->stat = SAS_PHY_DOWN;
  357. if (dev->dev_type != SATA_DEV)
  358. t->task_done(t);
  359. return 0;
  360. }
  361. pm8001_ha = pm8001_find_ha_by_dev(task->dev);
  362. PM8001_IO_DBG(pm8001_ha, pm8001_printk("pm8001_task_exec device \n "));
  363. spin_lock_irqsave(&pm8001_ha->lock, flags);
  364. do {
  365. dev = t->dev;
  366. pm8001_dev = dev->lldd_dev;
  367. if (DEV_IS_GONE(pm8001_dev)) {
  368. if (pm8001_dev) {
  369. PM8001_IO_DBG(pm8001_ha,
  370. pm8001_printk("device %d not ready.\n",
  371. pm8001_dev->device_id));
  372. } else {
  373. PM8001_IO_DBG(pm8001_ha,
  374. pm8001_printk("device %016llx not "
  375. "ready.\n", SAS_ADDR(dev->sas_addr)));
  376. }
  377. rc = SAS_PHY_DOWN;
  378. goto out_done;
  379. }
  380. port = &pm8001_ha->port[sas_find_local_port_id(dev)];
  381. if (!port->port_attached) {
  382. if (sas_protocol_ata(t->task_proto)) {
  383. struct task_status_struct *ts = &t->task_status;
  384. ts->resp = SAS_TASK_UNDELIVERED;
  385. ts->stat = SAS_PHY_DOWN;
  386. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  387. spin_unlock_irqrestore(dev->sata_dev.ap->lock,
  388. flags_libsas);
  389. t->task_done(t);
  390. spin_lock_irqsave(dev->sata_dev.ap->lock,
  391. flags_libsas);
  392. spin_lock_irqsave(&pm8001_ha->lock, flags);
  393. if (n > 1)
  394. t = list_entry(t->list.next,
  395. struct sas_task, list);
  396. continue;
  397. } else {
  398. struct task_status_struct *ts = &t->task_status;
  399. ts->resp = SAS_TASK_UNDELIVERED;
  400. ts->stat = SAS_PHY_DOWN;
  401. t->task_done(t);
  402. if (n > 1)
  403. t = list_entry(t->list.next,
  404. struct sas_task, list);
  405. continue;
  406. }
  407. }
  408. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  409. if (rc)
  410. goto err_out;
  411. ccb = &pm8001_ha->ccb_info[tag];
  412. if (!sas_protocol_ata(t->task_proto)) {
  413. if (t->num_scatter) {
  414. n_elem = dma_map_sg(pm8001_ha->dev,
  415. t->scatter,
  416. t->num_scatter,
  417. t->data_dir);
  418. if (!n_elem) {
  419. rc = -ENOMEM;
  420. goto err_out_tag;
  421. }
  422. }
  423. } else {
  424. n_elem = t->num_scatter;
  425. }
  426. t->lldd_task = ccb;
  427. ccb->n_elem = n_elem;
  428. ccb->ccb_tag = tag;
  429. ccb->task = t;
  430. switch (t->task_proto) {
  431. case SAS_PROTOCOL_SMP:
  432. rc = pm8001_task_prep_smp(pm8001_ha, ccb);
  433. break;
  434. case SAS_PROTOCOL_SSP:
  435. if (is_tmf)
  436. rc = pm8001_task_prep_ssp_tm(pm8001_ha,
  437. ccb, tmf);
  438. else
  439. rc = pm8001_task_prep_ssp(pm8001_ha, ccb);
  440. break;
  441. case SAS_PROTOCOL_SATA:
  442. case SAS_PROTOCOL_STP:
  443. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  444. rc = pm8001_task_prep_ata(pm8001_ha, ccb);
  445. break;
  446. default:
  447. dev_printk(KERN_ERR, pm8001_ha->dev,
  448. "unknown sas_task proto: 0x%x\n",
  449. t->task_proto);
  450. rc = -EINVAL;
  451. break;
  452. }
  453. if (rc) {
  454. PM8001_IO_DBG(pm8001_ha,
  455. pm8001_printk("rc is %x\n", rc));
  456. goto err_out_tag;
  457. }
  458. /* TODO: select normal or high priority */
  459. spin_lock(&t->task_state_lock);
  460. t->task_state_flags |= SAS_TASK_AT_INITIATOR;
  461. spin_unlock(&t->task_state_lock);
  462. pm8001_dev->running_req++;
  463. if (n > 1)
  464. t = list_entry(t->list.next, struct sas_task, list);
  465. } while (--n);
  466. rc = 0;
  467. goto out_done;
  468. err_out_tag:
  469. pm8001_tag_free(pm8001_ha, tag);
  470. err_out:
  471. dev_printk(KERN_ERR, pm8001_ha->dev, "pm8001 exec failed[%d]!\n", rc);
  472. if (!sas_protocol_ata(t->task_proto))
  473. if (n_elem)
  474. dma_unmap_sg(pm8001_ha->dev, t->scatter, n_elem,
  475. t->data_dir);
  476. out_done:
  477. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  478. return rc;
  479. }
  480. /**
  481. * pm8001_queue_command - register for upper layer used, all IO commands sent
  482. * to HBA are from this interface.
  483. * @task: the task to be execute.
  484. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  485. * we always execute one one time
  486. * @gfp_flags: gfp_flags
  487. */
  488. int pm8001_queue_command(struct sas_task *task, const int num,
  489. gfp_t gfp_flags)
  490. {
  491. return pm8001_task_exec(task, num, gfp_flags, 0, NULL);
  492. }
  493. void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, u32 ccb_idx)
  494. {
  495. pm8001_tag_clear(pm8001_ha, ccb_idx);
  496. }
  497. /**
  498. * pm8001_ccb_task_free - free the sg for ssp and smp command, free the ccb.
  499. * @pm8001_ha: our hba card information
  500. * @ccb: the ccb which attached to ssp task
  501. * @task: the task to be free.
  502. * @ccb_idx: ccb index.
  503. */
  504. void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
  505. struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx)
  506. {
  507. if (!ccb->task)
  508. return;
  509. if (!sas_protocol_ata(task->task_proto))
  510. if (ccb->n_elem)
  511. dma_unmap_sg(pm8001_ha->dev, task->scatter,
  512. task->num_scatter, task->data_dir);
  513. switch (task->task_proto) {
  514. case SAS_PROTOCOL_SMP:
  515. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_resp, 1,
  516. PCI_DMA_FROMDEVICE);
  517. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_req, 1,
  518. PCI_DMA_TODEVICE);
  519. break;
  520. case SAS_PROTOCOL_SATA:
  521. case SAS_PROTOCOL_STP:
  522. case SAS_PROTOCOL_SSP:
  523. default:
  524. /* do nothing */
  525. break;
  526. }
  527. task->lldd_task = NULL;
  528. ccb->task = NULL;
  529. ccb->ccb_tag = 0xFFFFFFFF;
  530. pm8001_ccb_free(pm8001_ha, ccb_idx);
  531. }
  532. /**
  533. * pm8001_alloc_dev - find a empty pm8001_device
  534. * @pm8001_ha: our hba card information
  535. */
  536. struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha)
  537. {
  538. u32 dev;
  539. for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
  540. if (pm8001_ha->devices[dev].dev_type == NO_DEVICE) {
  541. pm8001_ha->devices[dev].id = dev;
  542. return &pm8001_ha->devices[dev];
  543. }
  544. }
  545. if (dev == PM8001_MAX_DEVICES) {
  546. PM8001_FAIL_DBG(pm8001_ha,
  547. pm8001_printk("max support %d devices, ignore ..\n",
  548. PM8001_MAX_DEVICES));
  549. }
  550. return NULL;
  551. }
  552. static void pm8001_free_dev(struct pm8001_device *pm8001_dev)
  553. {
  554. u32 id = pm8001_dev->id;
  555. memset(pm8001_dev, 0, sizeof(*pm8001_dev));
  556. pm8001_dev->id = id;
  557. pm8001_dev->dev_type = NO_DEVICE;
  558. pm8001_dev->device_id = PM8001_MAX_DEVICES;
  559. pm8001_dev->sas_device = NULL;
  560. }
  561. /**
  562. * pm8001_dev_found_notify - libsas notify a device is found.
  563. * @dev: the device structure which sas layer used.
  564. *
  565. * when libsas find a sas domain device, it should tell the LLDD that
  566. * device is found, and then LLDD register this device to HBA firmware
  567. * by the command "OPC_INB_REG_DEV", after that the HBA will assign a
  568. * device ID(according to device's sas address) and returned it to LLDD. From
  569. * now on, we communicate with HBA FW with the device ID which HBA assigned
  570. * rather than sas address. it is the necessary step for our HBA but it is
  571. * the optional for other HBA driver.
  572. */
  573. static int pm8001_dev_found_notify(struct domain_device *dev)
  574. {
  575. unsigned long flags = 0;
  576. int res = 0;
  577. struct pm8001_hba_info *pm8001_ha = NULL;
  578. struct domain_device *parent_dev = dev->parent;
  579. struct pm8001_device *pm8001_device;
  580. DECLARE_COMPLETION_ONSTACK(completion);
  581. u32 flag = 0;
  582. pm8001_ha = pm8001_find_ha_by_dev(dev);
  583. spin_lock_irqsave(&pm8001_ha->lock, flags);
  584. pm8001_device = pm8001_alloc_dev(pm8001_ha);
  585. if (!pm8001_device) {
  586. res = -1;
  587. goto found_out;
  588. }
  589. pm8001_device->sas_device = dev;
  590. dev->lldd_dev = pm8001_device;
  591. pm8001_device->dev_type = dev->dev_type;
  592. pm8001_device->dcompletion = &completion;
  593. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) {
  594. int phy_id;
  595. struct ex_phy *phy;
  596. for (phy_id = 0; phy_id < parent_dev->ex_dev.num_phys;
  597. phy_id++) {
  598. phy = &parent_dev->ex_dev.ex_phy[phy_id];
  599. if (SAS_ADDR(phy->attached_sas_addr)
  600. == SAS_ADDR(dev->sas_addr)) {
  601. pm8001_device->attached_phy = phy_id;
  602. break;
  603. }
  604. }
  605. if (phy_id == parent_dev->ex_dev.num_phys) {
  606. PM8001_FAIL_DBG(pm8001_ha,
  607. pm8001_printk("Error: no attached dev:%016llx"
  608. " at ex:%016llx.\n", SAS_ADDR(dev->sas_addr),
  609. SAS_ADDR(parent_dev->sas_addr)));
  610. res = -1;
  611. }
  612. } else {
  613. if (dev->dev_type == SATA_DEV) {
  614. pm8001_device->attached_phy =
  615. dev->rphy->identify.phy_identifier;
  616. flag = 1; /* directly sata*/
  617. }
  618. } /*register this device to HBA*/
  619. PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device \n"));
  620. PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
  621. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  622. wait_for_completion(&completion);
  623. if (dev->dev_type == SAS_END_DEV)
  624. msleep(50);
  625. pm8001_ha->flags |= PM8001F_RUN_TIME ;
  626. return 0;
  627. found_out:
  628. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  629. return res;
  630. }
  631. int pm8001_dev_found(struct domain_device *dev)
  632. {
  633. return pm8001_dev_found_notify(dev);
  634. }
  635. /**
  636. * pm8001_alloc_task - allocate a task structure for TMF
  637. */
  638. static struct sas_task *pm8001_alloc_task(void)
  639. {
  640. struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
  641. if (task) {
  642. INIT_LIST_HEAD(&task->list);
  643. spin_lock_init(&task->task_state_lock);
  644. task->task_state_flags = SAS_TASK_STATE_PENDING;
  645. init_timer(&task->timer);
  646. init_completion(&task->completion);
  647. }
  648. return task;
  649. }
  650. static void pm8001_free_task(struct sas_task *task)
  651. {
  652. if (task) {
  653. BUG_ON(!list_empty(&task->list));
  654. kfree(task);
  655. }
  656. }
  657. static void pm8001_task_done(struct sas_task *task)
  658. {
  659. if (!del_timer(&task->timer))
  660. return;
  661. complete(&task->completion);
  662. }
  663. static void pm8001_tmf_timedout(unsigned long data)
  664. {
  665. struct sas_task *task = (struct sas_task *)data;
  666. task->task_state_flags |= SAS_TASK_STATE_ABORTED;
  667. complete(&task->completion);
  668. }
  669. #define PM8001_TASK_TIMEOUT 20
  670. /**
  671. * pm8001_exec_internal_tmf_task - execute some task management commands.
  672. * @dev: the wanted device.
  673. * @tmf: which task management wanted to be take.
  674. * @para_len: para_len.
  675. * @parameter: ssp task parameter.
  676. *
  677. * when errors or exception happened, we may want to do something, for example
  678. * abort the issued task which result in this execption, it is done by calling
  679. * this function, note it is also with the task execute interface.
  680. */
  681. static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
  682. void *parameter, u32 para_len, struct pm8001_tmf_task *tmf)
  683. {
  684. int res, retry;
  685. struct sas_task *task = NULL;
  686. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  687. for (retry = 0; retry < 3; retry++) {
  688. task = pm8001_alloc_task();
  689. if (!task)
  690. return -ENOMEM;
  691. task->dev = dev;
  692. task->task_proto = dev->tproto;
  693. memcpy(&task->ssp_task, parameter, para_len);
  694. task->task_done = pm8001_task_done;
  695. task->timer.data = (unsigned long)task;
  696. task->timer.function = pm8001_tmf_timedout;
  697. task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ;
  698. add_timer(&task->timer);
  699. res = pm8001_task_exec(task, 1, GFP_KERNEL, 1, tmf);
  700. if (res) {
  701. del_timer(&task->timer);
  702. PM8001_FAIL_DBG(pm8001_ha,
  703. pm8001_printk("Executing internal task "
  704. "failed\n"));
  705. goto ex_err;
  706. }
  707. wait_for_completion(&task->completion);
  708. res = -TMF_RESP_FUNC_FAILED;
  709. /* Even TMF timed out, return direct. */
  710. if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
  711. if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
  712. PM8001_FAIL_DBG(pm8001_ha,
  713. pm8001_printk("TMF task[%x]timeout.\n",
  714. tmf->tmf));
  715. goto ex_err;
  716. }
  717. }
  718. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  719. task->task_status.stat == SAM_STAT_GOOD) {
  720. res = TMF_RESP_FUNC_COMPLETE;
  721. break;
  722. }
  723. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  724. task->task_status.stat == SAS_DATA_UNDERRUN) {
  725. /* no error, but return the number of bytes of
  726. * underrun */
  727. res = task->task_status.residual;
  728. break;
  729. }
  730. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  731. task->task_status.stat == SAS_DATA_OVERRUN) {
  732. PM8001_FAIL_DBG(pm8001_ha,
  733. pm8001_printk("Blocked task error.\n"));
  734. res = -EMSGSIZE;
  735. break;
  736. } else {
  737. PM8001_EH_DBG(pm8001_ha,
  738. pm8001_printk(" Task to dev %016llx response:"
  739. "0x%x status 0x%x\n",
  740. SAS_ADDR(dev->sas_addr),
  741. task->task_status.resp,
  742. task->task_status.stat));
  743. pm8001_free_task(task);
  744. task = NULL;
  745. }
  746. }
  747. ex_err:
  748. BUG_ON(retry == 3 && task != NULL);
  749. if (task != NULL)
  750. pm8001_free_task(task);
  751. return res;
  752. }
  753. static int
  754. pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
  755. struct pm8001_device *pm8001_dev, struct domain_device *dev, u32 flag,
  756. u32 task_tag)
  757. {
  758. int res, retry;
  759. u32 ccb_tag;
  760. struct pm8001_ccb_info *ccb;
  761. struct sas_task *task = NULL;
  762. for (retry = 0; retry < 3; retry++) {
  763. task = pm8001_alloc_task();
  764. if (!task)
  765. return -ENOMEM;
  766. task->dev = dev;
  767. task->task_proto = dev->tproto;
  768. task->task_done = pm8001_task_done;
  769. task->timer.data = (unsigned long)task;
  770. task->timer.function = pm8001_tmf_timedout;
  771. task->timer.expires = jiffies + PM8001_TASK_TIMEOUT * HZ;
  772. add_timer(&task->timer);
  773. res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
  774. if (res)
  775. return res;
  776. ccb = &pm8001_ha->ccb_info[ccb_tag];
  777. ccb->device = pm8001_dev;
  778. ccb->ccb_tag = ccb_tag;
  779. ccb->task = task;
  780. res = PM8001_CHIP_DISP->task_abort(pm8001_ha,
  781. pm8001_dev, flag, task_tag, ccb_tag);
  782. if (res) {
  783. del_timer(&task->timer);
  784. PM8001_FAIL_DBG(pm8001_ha,
  785. pm8001_printk("Executing internal task "
  786. "failed\n"));
  787. goto ex_err;
  788. }
  789. wait_for_completion(&task->completion);
  790. res = TMF_RESP_FUNC_FAILED;
  791. /* Even TMF timed out, return direct. */
  792. if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
  793. if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
  794. PM8001_FAIL_DBG(pm8001_ha,
  795. pm8001_printk("TMF task timeout.\n"));
  796. goto ex_err;
  797. }
  798. }
  799. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  800. task->task_status.stat == SAM_STAT_GOOD) {
  801. res = TMF_RESP_FUNC_COMPLETE;
  802. break;
  803. } else {
  804. PM8001_EH_DBG(pm8001_ha,
  805. pm8001_printk(" Task to dev %016llx response: "
  806. "0x%x status 0x%x\n",
  807. SAS_ADDR(dev->sas_addr),
  808. task->task_status.resp,
  809. task->task_status.stat));
  810. pm8001_free_task(task);
  811. task = NULL;
  812. }
  813. }
  814. ex_err:
  815. BUG_ON(retry == 3 && task != NULL);
  816. if (task != NULL)
  817. pm8001_free_task(task);
  818. return res;
  819. }
  820. /**
  821. * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify"
  822. * @dev: the device structure which sas layer used.
  823. */
  824. static void pm8001_dev_gone_notify(struct domain_device *dev)
  825. {
  826. unsigned long flags = 0;
  827. u32 tag;
  828. struct pm8001_hba_info *pm8001_ha;
  829. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  830. pm8001_ha = pm8001_find_ha_by_dev(dev);
  831. spin_lock_irqsave(&pm8001_ha->lock, flags);
  832. pm8001_tag_alloc(pm8001_ha, &tag);
  833. if (pm8001_dev) {
  834. u32 device_id = pm8001_dev->device_id;
  835. PM8001_DISC_DBG(pm8001_ha,
  836. pm8001_printk("found dev[%d:%x] is gone.\n",
  837. pm8001_dev->device_id, pm8001_dev->dev_type));
  838. if (pm8001_dev->running_req) {
  839. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  840. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  841. dev, 1, 0);
  842. spin_lock_irqsave(&pm8001_ha->lock, flags);
  843. }
  844. PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
  845. pm8001_free_dev(pm8001_dev);
  846. } else {
  847. PM8001_DISC_DBG(pm8001_ha,
  848. pm8001_printk("Found dev has gone.\n"));
  849. }
  850. dev->lldd_dev = NULL;
  851. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  852. }
  853. void pm8001_dev_gone(struct domain_device *dev)
  854. {
  855. pm8001_dev_gone_notify(dev);
  856. }
  857. static int pm8001_issue_ssp_tmf(struct domain_device *dev,
  858. u8 *lun, struct pm8001_tmf_task *tmf)
  859. {
  860. struct sas_ssp_task ssp_task;
  861. if (!(dev->tproto & SAS_PROTOCOL_SSP))
  862. return TMF_RESP_FUNC_ESUPP;
  863. strncpy((u8 *)&ssp_task.LUN, lun, 8);
  864. return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task),
  865. tmf);
  866. }
  867. /**
  868. * Standard mandates link reset for ATA (type 0) and hard reset for
  869. * SSP (type 1) , only for RECOVERY
  870. */
  871. int pm8001_I_T_nexus_reset(struct domain_device *dev)
  872. {
  873. int rc = TMF_RESP_FUNC_FAILED;
  874. struct pm8001_device *pm8001_dev;
  875. struct pm8001_hba_info *pm8001_ha;
  876. struct sas_phy *phy;
  877. if (!dev || !dev->lldd_dev)
  878. return -1;
  879. pm8001_dev = dev->lldd_dev;
  880. pm8001_ha = pm8001_find_ha_by_dev(dev);
  881. phy = sas_find_local_phy(dev);
  882. if (dev_is_sata(dev)) {
  883. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  884. if (scsi_is_sas_phy_local(phy))
  885. return 0;
  886. rc = sas_phy_reset(phy, 1);
  887. msleep(2000);
  888. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  889. dev, 1, 0);
  890. pm8001_dev->setds_completion = &completion_setstate;
  891. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  892. pm8001_dev, 0x01);
  893. wait_for_completion(&completion_setstate);
  894. } else{
  895. rc = sas_phy_reset(phy, 1);
  896. msleep(2000);
  897. }
  898. PM8001_EH_DBG(pm8001_ha, pm8001_printk(" for device[%x]:rc=%d\n",
  899. pm8001_dev->device_id, rc));
  900. return rc;
  901. }
  902. /* mandatory SAM-3, the task reset the specified LUN*/
  903. int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
  904. {
  905. int rc = TMF_RESP_FUNC_FAILED;
  906. struct pm8001_tmf_task tmf_task;
  907. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  908. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  909. if (dev_is_sata(dev)) {
  910. struct sas_phy *phy = sas_find_local_phy(dev);
  911. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  912. dev, 1, 0);
  913. rc = sas_phy_reset(phy, 1);
  914. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  915. pm8001_dev, 0x01);
  916. msleep(2000);
  917. } else {
  918. tmf_task.tmf = TMF_LU_RESET;
  919. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  920. }
  921. /* If failed, fall-through I_T_Nexus reset */
  922. PM8001_EH_DBG(pm8001_ha, pm8001_printk("for device[%x]:rc=%d\n",
  923. pm8001_dev->device_id, rc));
  924. return rc;
  925. }
  926. /* optional SAM-3 */
  927. int pm8001_query_task(struct sas_task *task)
  928. {
  929. u32 tag = 0xdeadbeef;
  930. int i = 0;
  931. struct scsi_lun lun;
  932. struct pm8001_tmf_task tmf_task;
  933. int rc = TMF_RESP_FUNC_FAILED;
  934. if (unlikely(!task || !task->lldd_task || !task->dev))
  935. return rc;
  936. if (task->task_proto & SAS_PROTOCOL_SSP) {
  937. struct scsi_cmnd *cmnd = task->uldd_task;
  938. struct domain_device *dev = task->dev;
  939. struct pm8001_hba_info *pm8001_ha =
  940. pm8001_find_ha_by_dev(dev);
  941. int_to_scsilun(cmnd->device->lun, &lun);
  942. rc = pm8001_find_tag(task, &tag);
  943. if (rc == 0) {
  944. rc = TMF_RESP_FUNC_FAILED;
  945. return rc;
  946. }
  947. PM8001_EH_DBG(pm8001_ha, pm8001_printk("Query:["));
  948. for (i = 0; i < 16; i++)
  949. printk(KERN_INFO "%02x ", cmnd->cmnd[i]);
  950. printk(KERN_INFO "]\n");
  951. tmf_task.tmf = TMF_QUERY_TASK;
  952. tmf_task.tag_of_task_to_be_managed = tag;
  953. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  954. switch (rc) {
  955. /* The task is still in Lun, release it then */
  956. case TMF_RESP_FUNC_SUCC:
  957. PM8001_EH_DBG(pm8001_ha,
  958. pm8001_printk("The task is still in Lun \n"));
  959. /* The task is not in Lun or failed, reset the phy */
  960. case TMF_RESP_FUNC_FAILED:
  961. case TMF_RESP_FUNC_COMPLETE:
  962. PM8001_EH_DBG(pm8001_ha,
  963. pm8001_printk("The task is not in Lun or failed,"
  964. " reset the phy \n"));
  965. break;
  966. }
  967. }
  968. pm8001_printk(":rc= %d\n", rc);
  969. return rc;
  970. }
  971. /* mandatory SAM-3, still need free task/ccb info, abord the specified task */
  972. int pm8001_abort_task(struct sas_task *task)
  973. {
  974. unsigned long flags;
  975. u32 tag = 0xdeadbeef;
  976. u32 device_id;
  977. struct domain_device *dev ;
  978. struct pm8001_hba_info *pm8001_ha = NULL;
  979. struct pm8001_ccb_info *ccb;
  980. struct scsi_lun lun;
  981. struct pm8001_device *pm8001_dev;
  982. struct pm8001_tmf_task tmf_task;
  983. int rc = TMF_RESP_FUNC_FAILED;
  984. if (unlikely(!task || !task->lldd_task || !task->dev))
  985. return rc;
  986. spin_lock_irqsave(&task->task_state_lock, flags);
  987. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  988. spin_unlock_irqrestore(&task->task_state_lock, flags);
  989. rc = TMF_RESP_FUNC_COMPLETE;
  990. goto out;
  991. }
  992. spin_unlock_irqrestore(&task->task_state_lock, flags);
  993. if (task->task_proto & SAS_PROTOCOL_SSP) {
  994. struct scsi_cmnd *cmnd = task->uldd_task;
  995. dev = task->dev;
  996. ccb = task->lldd_task;
  997. pm8001_dev = dev->lldd_dev;
  998. pm8001_ha = pm8001_find_ha_by_dev(dev);
  999. int_to_scsilun(cmnd->device->lun, &lun);
  1000. rc = pm8001_find_tag(task, &tag);
  1001. if (rc == 0) {
  1002. printk(KERN_INFO "No such tag in %s\n", __func__);
  1003. rc = TMF_RESP_FUNC_FAILED;
  1004. return rc;
  1005. }
  1006. device_id = pm8001_dev->device_id;
  1007. PM8001_EH_DBG(pm8001_ha,
  1008. pm8001_printk("abort io to deviceid= %d\n", device_id));
  1009. tmf_task.tmf = TMF_ABORT_TASK;
  1010. tmf_task.tag_of_task_to_be_managed = tag;
  1011. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  1012. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1013. pm8001_dev->sas_device, 0, tag);
  1014. } else if (task->task_proto & SAS_PROTOCOL_SATA ||
  1015. task->task_proto & SAS_PROTOCOL_STP) {
  1016. dev = task->dev;
  1017. pm8001_dev = dev->lldd_dev;
  1018. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1019. rc = pm8001_find_tag(task, &tag);
  1020. if (rc == 0) {
  1021. printk(KERN_INFO "No such tag in %s\n", __func__);
  1022. rc = TMF_RESP_FUNC_FAILED;
  1023. return rc;
  1024. }
  1025. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1026. pm8001_dev->sas_device, 0, tag);
  1027. } else if (task->task_proto & SAS_PROTOCOL_SMP) {
  1028. /* SMP */
  1029. dev = task->dev;
  1030. pm8001_dev = dev->lldd_dev;
  1031. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1032. rc = pm8001_find_tag(task, &tag);
  1033. if (rc == 0) {
  1034. printk(KERN_INFO "No such tag in %s\n", __func__);
  1035. rc = TMF_RESP_FUNC_FAILED;
  1036. return rc;
  1037. }
  1038. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1039. pm8001_dev->sas_device, 0, tag);
  1040. }
  1041. out:
  1042. if (rc != TMF_RESP_FUNC_COMPLETE)
  1043. pm8001_printk("rc= %d\n", rc);
  1044. return rc;
  1045. }
  1046. int pm8001_abort_task_set(struct domain_device *dev, u8 *lun)
  1047. {
  1048. int rc = TMF_RESP_FUNC_FAILED;
  1049. struct pm8001_tmf_task tmf_task;
  1050. tmf_task.tmf = TMF_ABORT_TASK_SET;
  1051. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1052. return rc;
  1053. }
  1054. int pm8001_clear_aca(struct domain_device *dev, u8 *lun)
  1055. {
  1056. int rc = TMF_RESP_FUNC_FAILED;
  1057. struct pm8001_tmf_task tmf_task;
  1058. tmf_task.tmf = TMF_CLEAR_ACA;
  1059. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1060. return rc;
  1061. }
  1062. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun)
  1063. {
  1064. int rc = TMF_RESP_FUNC_FAILED;
  1065. struct pm8001_tmf_task tmf_task;
  1066. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1067. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1068. PM8001_EH_DBG(pm8001_ha,
  1069. pm8001_printk("I_T_L_Q clear task set[%x]\n",
  1070. pm8001_dev->device_id));
  1071. tmf_task.tmf = TMF_CLEAR_TASK_SET;
  1072. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1073. return rc;
  1074. }