pm8001_sas.c 32 KB

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