pm8001_sas.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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. /**
  315. * pm8001_task_exec - queue the task(ssp, smp && ata) to the hardware.
  316. * @task: the task to be execute.
  317. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  318. * we always execute one one time.
  319. * @gfp_flags: gfp_flags.
  320. * @is_tmf: if it is task management task.
  321. * @tmf: the task management IU
  322. */
  323. #define DEV_IS_GONE(pm8001_dev) \
  324. ((!pm8001_dev || (pm8001_dev->dev_type == NO_DEVICE)))
  325. static int pm8001_task_exec(struct sas_task *task, const int num,
  326. gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf)
  327. {
  328. struct domain_device *dev = task->dev;
  329. struct pm8001_hba_info *pm8001_ha;
  330. struct pm8001_device *pm8001_dev;
  331. struct sas_task *t = task;
  332. struct pm8001_ccb_info *ccb;
  333. u32 tag = 0xdeadbeef, rc, n_elem = 0;
  334. u32 n = num;
  335. unsigned long flags = 0;
  336. if (!dev->port) {
  337. struct task_status_struct *tsm = &t->task_status;
  338. tsm->resp = SAS_TASK_UNDELIVERED;
  339. tsm->stat = SAS_PHY_DOWN;
  340. if (dev->dev_type != SATA_DEV)
  341. t->task_done(t);
  342. return 0;
  343. }
  344. pm8001_ha = pm8001_find_ha_by_dev(task->dev);
  345. PM8001_IO_DBG(pm8001_ha, pm8001_printk("pm8001_task_exec device \n "));
  346. spin_lock_irqsave(&pm8001_ha->lock, flags);
  347. do {
  348. dev = t->dev;
  349. pm8001_dev = dev->lldd_dev;
  350. if (DEV_IS_GONE(pm8001_dev)) {
  351. if (pm8001_dev) {
  352. PM8001_IO_DBG(pm8001_ha,
  353. pm8001_printk("device %d not ready.\n",
  354. pm8001_dev->device_id));
  355. } else {
  356. PM8001_IO_DBG(pm8001_ha,
  357. pm8001_printk("device %016llx not "
  358. "ready.\n", SAS_ADDR(dev->sas_addr)));
  359. }
  360. rc = SAS_PHY_DOWN;
  361. goto out_done;
  362. }
  363. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  364. if (rc)
  365. goto err_out;
  366. ccb = &pm8001_ha->ccb_info[tag];
  367. if (!sas_protocol_ata(t->task_proto)) {
  368. if (t->num_scatter) {
  369. n_elem = dma_map_sg(pm8001_ha->dev,
  370. t->scatter,
  371. t->num_scatter,
  372. t->data_dir);
  373. if (!n_elem) {
  374. rc = -ENOMEM;
  375. goto err_out_tag;
  376. }
  377. }
  378. } else {
  379. n_elem = t->num_scatter;
  380. }
  381. t->lldd_task = ccb;
  382. ccb->n_elem = n_elem;
  383. ccb->ccb_tag = tag;
  384. ccb->task = t;
  385. switch (t->task_proto) {
  386. case SAS_PROTOCOL_SMP:
  387. rc = pm8001_task_prep_smp(pm8001_ha, ccb);
  388. break;
  389. case SAS_PROTOCOL_SSP:
  390. if (is_tmf)
  391. rc = pm8001_task_prep_ssp_tm(pm8001_ha,
  392. ccb, tmf);
  393. else
  394. rc = pm8001_task_prep_ssp(pm8001_ha, ccb);
  395. break;
  396. case SAS_PROTOCOL_SATA:
  397. case SAS_PROTOCOL_STP:
  398. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  399. rc = pm8001_task_prep_ata(pm8001_ha, ccb);
  400. break;
  401. default:
  402. dev_printk(KERN_ERR, pm8001_ha->dev,
  403. "unknown sas_task proto: 0x%x\n",
  404. t->task_proto);
  405. rc = -EINVAL;
  406. break;
  407. }
  408. if (rc) {
  409. PM8001_IO_DBG(pm8001_ha,
  410. pm8001_printk("rc is %x\n", rc));
  411. goto err_out_tag;
  412. }
  413. /* TODO: select normal or high priority */
  414. spin_lock(&t->task_state_lock);
  415. t->task_state_flags |= SAS_TASK_AT_INITIATOR;
  416. spin_unlock(&t->task_state_lock);
  417. pm8001_dev->running_req++;
  418. if (n > 1)
  419. t = list_entry(t->list.next, struct sas_task, list);
  420. } while (--n);
  421. rc = 0;
  422. goto out_done;
  423. err_out_tag:
  424. pm8001_tag_free(pm8001_ha, tag);
  425. err_out:
  426. dev_printk(KERN_ERR, pm8001_ha->dev, "pm8001 exec failed[%d]!\n", rc);
  427. if (!sas_protocol_ata(t->task_proto))
  428. if (n_elem)
  429. dma_unmap_sg(pm8001_ha->dev, t->scatter, n_elem,
  430. t->data_dir);
  431. out_done:
  432. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  433. return rc;
  434. }
  435. /**
  436. * pm8001_queue_command - register for upper layer used, all IO commands sent
  437. * to HBA are from this interface.
  438. * @task: the task to be execute.
  439. * @num: if can_queue great than 1, the task can be queued up. for SMP task,
  440. * we always execute one one time
  441. * @gfp_flags: gfp_flags
  442. */
  443. int pm8001_queue_command(struct sas_task *task, const int num,
  444. gfp_t gfp_flags)
  445. {
  446. return pm8001_task_exec(task, num, gfp_flags, 0, NULL);
  447. }
  448. void pm8001_ccb_free(struct pm8001_hba_info *pm8001_ha, u32 ccb_idx)
  449. {
  450. pm8001_tag_clear(pm8001_ha, ccb_idx);
  451. }
  452. /**
  453. * pm8001_ccb_task_free - free the sg for ssp and smp command, free the ccb.
  454. * @pm8001_ha: our hba card information
  455. * @ccb: the ccb which attached to ssp task
  456. * @task: the task to be free.
  457. * @ccb_idx: ccb index.
  458. */
  459. void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
  460. struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx)
  461. {
  462. if (!ccb->task)
  463. return;
  464. if (!sas_protocol_ata(task->task_proto))
  465. if (ccb->n_elem)
  466. dma_unmap_sg(pm8001_ha->dev, task->scatter,
  467. task->num_scatter, task->data_dir);
  468. switch (task->task_proto) {
  469. case SAS_PROTOCOL_SMP:
  470. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_resp, 1,
  471. PCI_DMA_FROMDEVICE);
  472. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_req, 1,
  473. PCI_DMA_TODEVICE);
  474. break;
  475. case SAS_PROTOCOL_SATA:
  476. case SAS_PROTOCOL_STP:
  477. case SAS_PROTOCOL_SSP:
  478. default:
  479. /* do nothing */
  480. break;
  481. }
  482. task->lldd_task = NULL;
  483. ccb->task = NULL;
  484. ccb->ccb_tag = 0xFFFFFFFF;
  485. pm8001_ccb_free(pm8001_ha, ccb_idx);
  486. }
  487. /**
  488. * pm8001_alloc_dev - find a empty pm8001_device
  489. * @pm8001_ha: our hba card information
  490. */
  491. struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha)
  492. {
  493. u32 dev;
  494. for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
  495. if (pm8001_ha->devices[dev].dev_type == NO_DEVICE) {
  496. pm8001_ha->devices[dev].id = dev;
  497. return &pm8001_ha->devices[dev];
  498. }
  499. }
  500. if (dev == PM8001_MAX_DEVICES) {
  501. PM8001_FAIL_DBG(pm8001_ha,
  502. pm8001_printk("max support %d devices, ignore ..\n",
  503. PM8001_MAX_DEVICES));
  504. }
  505. return NULL;
  506. }
  507. static void pm8001_free_dev(struct pm8001_device *pm8001_dev)
  508. {
  509. u32 id = pm8001_dev->id;
  510. memset(pm8001_dev, 0, sizeof(*pm8001_dev));
  511. pm8001_dev->id = id;
  512. pm8001_dev->dev_type = NO_DEVICE;
  513. pm8001_dev->device_id = PM8001_MAX_DEVICES;
  514. pm8001_dev->sas_device = NULL;
  515. }
  516. /**
  517. * pm8001_dev_found_notify - libsas notify a device is found.
  518. * @dev: the device structure which sas layer used.
  519. *
  520. * when libsas find a sas domain device, it should tell the LLDD that
  521. * device is found, and then LLDD register this device to HBA firmware
  522. * by the command "OPC_INB_REG_DEV", after that the HBA will assign a
  523. * device ID(according to device's sas address) and returned it to LLDD. From
  524. * now on, we communicate with HBA FW with the device ID which HBA assigned
  525. * rather than sas address. it is the neccessary step for our HBA but it is
  526. * the optional for other HBA driver.
  527. */
  528. static int pm8001_dev_found_notify(struct domain_device *dev)
  529. {
  530. unsigned long flags = 0;
  531. int res = 0;
  532. struct pm8001_hba_info *pm8001_ha = NULL;
  533. struct domain_device *parent_dev = dev->parent;
  534. struct pm8001_device *pm8001_device;
  535. DECLARE_COMPLETION_ONSTACK(completion);
  536. u32 flag = 0;
  537. pm8001_ha = pm8001_find_ha_by_dev(dev);
  538. spin_lock_irqsave(&pm8001_ha->lock, flags);
  539. pm8001_device = pm8001_alloc_dev(pm8001_ha);
  540. pm8001_device->sas_device = dev;
  541. if (!pm8001_device) {
  542. res = -1;
  543. goto found_out;
  544. }
  545. dev->lldd_dev = pm8001_device;
  546. pm8001_device->dev_type = dev->dev_type;
  547. pm8001_device->dcompletion = &completion;
  548. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) {
  549. int phy_id;
  550. struct ex_phy *phy;
  551. for (phy_id = 0; phy_id < parent_dev->ex_dev.num_phys;
  552. phy_id++) {
  553. phy = &parent_dev->ex_dev.ex_phy[phy_id];
  554. if (SAS_ADDR(phy->attached_sas_addr)
  555. == SAS_ADDR(dev->sas_addr)) {
  556. pm8001_device->attached_phy = phy_id;
  557. break;
  558. }
  559. }
  560. if (phy_id == parent_dev->ex_dev.num_phys) {
  561. PM8001_FAIL_DBG(pm8001_ha,
  562. pm8001_printk("Error: no attached dev:%016llx"
  563. " at ex:%016llx.\n", SAS_ADDR(dev->sas_addr),
  564. SAS_ADDR(parent_dev->sas_addr)));
  565. res = -1;
  566. }
  567. } else {
  568. if (dev->dev_type == SATA_DEV) {
  569. pm8001_device->attached_phy =
  570. dev->rphy->identify.phy_identifier;
  571. flag = 1; /* directly sata*/
  572. }
  573. } /*register this device to HBA*/
  574. PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device \n"));
  575. PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
  576. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  577. wait_for_completion(&completion);
  578. if (dev->dev_type == SAS_END_DEV)
  579. msleep(50);
  580. pm8001_ha->flags = PM8001F_RUN_TIME ;
  581. return 0;
  582. found_out:
  583. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  584. return res;
  585. }
  586. int pm8001_dev_found(struct domain_device *dev)
  587. {
  588. return pm8001_dev_found_notify(dev);
  589. }
  590. /**
  591. * pm8001_alloc_task - allocate a task structure for TMF
  592. */
  593. static struct sas_task *pm8001_alloc_task(void)
  594. {
  595. struct sas_task *task = kzalloc(sizeof(*task), GFP_KERNEL);
  596. if (task) {
  597. INIT_LIST_HEAD(&task->list);
  598. spin_lock_init(&task->task_state_lock);
  599. task->task_state_flags = SAS_TASK_STATE_PENDING;
  600. init_timer(&task->timer);
  601. init_completion(&task->completion);
  602. }
  603. return task;
  604. }
  605. static void pm8001_free_task(struct sas_task *task)
  606. {
  607. if (task) {
  608. BUG_ON(!list_empty(&task->list));
  609. kfree(task);
  610. }
  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 = pm8001_alloc_task();
  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_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. pm8001_free_task(task);
  699. task = NULL;
  700. }
  701. }
  702. ex_err:
  703. BUG_ON(retry == 3 && task != NULL);
  704. if (task != NULL)
  705. pm8001_free_task(task);
  706. return res;
  707. }
  708. static int
  709. pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
  710. struct pm8001_device *pm8001_dev, struct domain_device *dev, u32 flag,
  711. u32 task_tag)
  712. {
  713. int res, retry;
  714. u32 ccb_tag;
  715. struct pm8001_ccb_info *ccb;
  716. struct sas_task *task = NULL;
  717. for (retry = 0; retry < 3; retry++) {
  718. task = pm8001_alloc_task();
  719. if (!task)
  720. return -ENOMEM;
  721. task->dev = dev;
  722. task->task_proto = dev->tproto;
  723. task->task_done = pm8001_task_done;
  724. task->timer.data = (unsigned long)task;
  725. task->timer.function = pm8001_tmf_timedout;
  726. task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ;
  727. add_timer(&task->timer);
  728. res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
  729. if (res)
  730. return res;
  731. ccb = &pm8001_ha->ccb_info[ccb_tag];
  732. ccb->device = pm8001_dev;
  733. ccb->ccb_tag = ccb_tag;
  734. ccb->task = task;
  735. res = PM8001_CHIP_DISP->task_abort(pm8001_ha,
  736. pm8001_dev, flag, task_tag, ccb_tag);
  737. if (res) {
  738. del_timer(&task->timer);
  739. PM8001_FAIL_DBG(pm8001_ha,
  740. pm8001_printk("Executing internal task "
  741. "failed\n"));
  742. goto ex_err;
  743. }
  744. wait_for_completion(&task->completion);
  745. res = TMF_RESP_FUNC_FAILED;
  746. /* Even TMF timed out, return direct. */
  747. if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
  748. if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
  749. PM8001_FAIL_DBG(pm8001_ha,
  750. pm8001_printk("TMF task timeout.\n"));
  751. goto ex_err;
  752. }
  753. }
  754. if (task->task_status.resp == SAS_TASK_COMPLETE &&
  755. task->task_status.stat == SAM_GOOD) {
  756. res = TMF_RESP_FUNC_COMPLETE;
  757. break;
  758. } else {
  759. PM8001_EH_DBG(pm8001_ha,
  760. pm8001_printk(" Task to dev %016llx response: "
  761. "0x%x status 0x%x\n",
  762. SAS_ADDR(dev->sas_addr),
  763. task->task_status.resp,
  764. task->task_status.stat));
  765. pm8001_free_task(task);
  766. task = NULL;
  767. }
  768. }
  769. ex_err:
  770. BUG_ON(retry == 3 && task != NULL);
  771. if (task != NULL)
  772. pm8001_free_task(task);
  773. return res;
  774. }
  775. /**
  776. * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify"
  777. * @dev: the device structure which sas layer used.
  778. */
  779. static void pm8001_dev_gone_notify(struct domain_device *dev)
  780. {
  781. unsigned long flags = 0;
  782. u32 tag;
  783. struct pm8001_hba_info *pm8001_ha;
  784. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  785. u32 device_id = pm8001_dev->device_id;
  786. pm8001_ha = pm8001_find_ha_by_dev(dev);
  787. spin_lock_irqsave(&pm8001_ha->lock, flags);
  788. pm8001_tag_alloc(pm8001_ha, &tag);
  789. if (pm8001_dev) {
  790. PM8001_DISC_DBG(pm8001_ha,
  791. pm8001_printk("found dev[%d:%x] is gone.\n",
  792. pm8001_dev->device_id, pm8001_dev->dev_type));
  793. if (pm8001_dev->running_req) {
  794. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  795. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  796. dev, 1, 0);
  797. spin_lock_irqsave(&pm8001_ha->lock, flags);
  798. }
  799. PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
  800. pm8001_free_dev(pm8001_dev);
  801. } else {
  802. PM8001_DISC_DBG(pm8001_ha,
  803. pm8001_printk("Found dev has gone.\n"));
  804. }
  805. dev->lldd_dev = NULL;
  806. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  807. }
  808. void pm8001_dev_gone(struct domain_device *dev)
  809. {
  810. pm8001_dev_gone_notify(dev);
  811. }
  812. static int pm8001_issue_ssp_tmf(struct domain_device *dev,
  813. u8 *lun, struct pm8001_tmf_task *tmf)
  814. {
  815. struct sas_ssp_task ssp_task;
  816. if (!(dev->tproto & SAS_PROTOCOL_SSP))
  817. return TMF_RESP_FUNC_ESUPP;
  818. strncpy((u8 *)&ssp_task.LUN, lun, 8);
  819. return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task),
  820. tmf);
  821. }
  822. /**
  823. * Standard mandates link reset for ATA (type 0) and hard reset for
  824. * SSP (type 1) , only for RECOVERY
  825. */
  826. int pm8001_I_T_nexus_reset(struct domain_device *dev)
  827. {
  828. int rc = TMF_RESP_FUNC_FAILED;
  829. struct pm8001_device *pm8001_dev;
  830. struct pm8001_hba_info *pm8001_ha;
  831. struct sas_phy *phy;
  832. if (!dev || !dev->lldd_dev)
  833. return -1;
  834. pm8001_dev = dev->lldd_dev;
  835. pm8001_ha = pm8001_find_ha_by_dev(dev);
  836. phy = sas_find_local_phy(dev);
  837. if (dev_is_sata(dev)) {
  838. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  839. rc = sas_phy_reset(phy, 1);
  840. msleep(2000);
  841. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  842. dev, 1, 0);
  843. pm8001_dev->setds_completion = &completion_setstate;
  844. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  845. pm8001_dev, 0x01);
  846. wait_for_completion(&completion_setstate);
  847. } else{
  848. rc = sas_phy_reset(phy, 1);
  849. msleep(2000);
  850. }
  851. PM8001_EH_DBG(pm8001_ha, pm8001_printk(" for device[%x]:rc=%d\n",
  852. pm8001_dev->device_id, rc));
  853. return rc;
  854. }
  855. /* mandatory SAM-3, the task reset the specified LUN*/
  856. int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
  857. {
  858. int rc = TMF_RESP_FUNC_FAILED;
  859. struct pm8001_tmf_task tmf_task;
  860. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  861. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  862. if (dev_is_sata(dev)) {
  863. struct sas_phy *phy = sas_find_local_phy(dev);
  864. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  865. dev, 1, 0);
  866. rc = sas_phy_reset(phy, 1);
  867. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  868. pm8001_dev, 0x01);
  869. msleep(2000);
  870. } else {
  871. tmf_task.tmf = TMF_LU_RESET;
  872. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  873. }
  874. /* If failed, fall-through I_T_Nexus reset */
  875. PM8001_EH_DBG(pm8001_ha, pm8001_printk("for device[%x]:rc=%d\n",
  876. pm8001_dev->device_id, rc));
  877. return rc;
  878. }
  879. /* optional SAM-3 */
  880. int pm8001_query_task(struct sas_task *task)
  881. {
  882. u32 tag = 0xdeadbeef;
  883. int i = 0;
  884. struct scsi_lun lun;
  885. struct pm8001_tmf_task tmf_task;
  886. int rc = TMF_RESP_FUNC_FAILED;
  887. if (unlikely(!task || !task->lldd_task || !task->dev))
  888. return rc;
  889. if (task->task_proto & SAS_PROTOCOL_SSP) {
  890. struct scsi_cmnd *cmnd = task->uldd_task;
  891. struct domain_device *dev = task->dev;
  892. struct pm8001_hba_info *pm8001_ha =
  893. pm8001_find_ha_by_dev(dev);
  894. int_to_scsilun(cmnd->device->lun, &lun);
  895. rc = pm8001_find_tag(task, &tag);
  896. if (rc == 0) {
  897. rc = TMF_RESP_FUNC_FAILED;
  898. return rc;
  899. }
  900. PM8001_EH_DBG(pm8001_ha, pm8001_printk("Query:["));
  901. for (i = 0; i < 16; i++)
  902. printk(KERN_INFO "%02x ", cmnd->cmnd[i]);
  903. printk(KERN_INFO "]\n");
  904. tmf_task.tmf = TMF_QUERY_TASK;
  905. tmf_task.tag_of_task_to_be_managed = tag;
  906. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  907. switch (rc) {
  908. /* The task is still in Lun, release it then */
  909. case TMF_RESP_FUNC_SUCC:
  910. PM8001_EH_DBG(pm8001_ha,
  911. pm8001_printk("The task is still in Lun \n"));
  912. /* The task is not in Lun or failed, reset the phy */
  913. case TMF_RESP_FUNC_FAILED:
  914. case TMF_RESP_FUNC_COMPLETE:
  915. PM8001_EH_DBG(pm8001_ha,
  916. pm8001_printk("The task is not in Lun or failed,"
  917. " reset the phy \n"));
  918. break;
  919. }
  920. }
  921. pm8001_printk(":rc= %d\n", rc);
  922. return rc;
  923. }
  924. /* mandatory SAM-3, still need free task/ccb info, abord the specified task */
  925. int pm8001_abort_task(struct sas_task *task)
  926. {
  927. unsigned long flags;
  928. u32 tag = 0xdeadbeef;
  929. u32 device_id;
  930. struct domain_device *dev ;
  931. struct pm8001_hba_info *pm8001_ha = NULL;
  932. struct pm8001_ccb_info *ccb;
  933. struct scsi_lun lun;
  934. struct pm8001_device *pm8001_dev;
  935. struct pm8001_tmf_task tmf_task;
  936. int rc = TMF_RESP_FUNC_FAILED;
  937. if (unlikely(!task || !task->lldd_task || !task->dev))
  938. return rc;
  939. spin_lock_irqsave(&task->task_state_lock, flags);
  940. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  941. spin_unlock_irqrestore(&task->task_state_lock, flags);
  942. rc = TMF_RESP_FUNC_COMPLETE;
  943. goto out;
  944. }
  945. spin_unlock_irqrestore(&task->task_state_lock, flags);
  946. if (task->task_proto & SAS_PROTOCOL_SSP) {
  947. struct scsi_cmnd *cmnd = task->uldd_task;
  948. dev = task->dev;
  949. ccb = task->lldd_task;
  950. pm8001_dev = dev->lldd_dev;
  951. pm8001_ha = pm8001_find_ha_by_dev(dev);
  952. int_to_scsilun(cmnd->device->lun, &lun);
  953. rc = pm8001_find_tag(task, &tag);
  954. if (rc == 0) {
  955. printk(KERN_INFO "No such tag in %s\n", __func__);
  956. rc = TMF_RESP_FUNC_FAILED;
  957. return rc;
  958. }
  959. device_id = pm8001_dev->device_id;
  960. PM8001_EH_DBG(pm8001_ha,
  961. pm8001_printk("abort io to deviceid= %d\n", device_id));
  962. tmf_task.tmf = TMF_ABORT_TASK;
  963. tmf_task.tag_of_task_to_be_managed = tag;
  964. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  965. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  966. pm8001_dev->sas_device, 0, tag);
  967. } else if (task->task_proto & SAS_PROTOCOL_SATA ||
  968. task->task_proto & SAS_PROTOCOL_STP) {
  969. dev = task->dev;
  970. pm8001_dev = dev->lldd_dev;
  971. pm8001_ha = pm8001_find_ha_by_dev(dev);
  972. rc = pm8001_find_tag(task, &tag);
  973. if (rc == 0) {
  974. printk(KERN_INFO "No such tag in %s\n", __func__);
  975. rc = TMF_RESP_FUNC_FAILED;
  976. return rc;
  977. }
  978. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  979. pm8001_dev->sas_device, 0, tag);
  980. } else if (task->task_proto & SAS_PROTOCOL_SMP) {
  981. /* SMP */
  982. dev = task->dev;
  983. pm8001_dev = dev->lldd_dev;
  984. pm8001_ha = pm8001_find_ha_by_dev(dev);
  985. rc = pm8001_find_tag(task, &tag);
  986. if (rc == 0) {
  987. printk(KERN_INFO "No such tag in %s\n", __func__);
  988. rc = TMF_RESP_FUNC_FAILED;
  989. return rc;
  990. }
  991. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  992. pm8001_dev->sas_device, 0, tag);
  993. }
  994. out:
  995. if (rc != TMF_RESP_FUNC_COMPLETE)
  996. pm8001_printk("rc= %d\n", rc);
  997. return rc;
  998. }
  999. int pm8001_abort_task_set(struct domain_device *dev, u8 *lun)
  1000. {
  1001. int rc = TMF_RESP_FUNC_FAILED;
  1002. struct pm8001_tmf_task tmf_task;
  1003. tmf_task.tmf = TMF_ABORT_TASK_SET;
  1004. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1005. return rc;
  1006. }
  1007. int pm8001_clear_aca(struct domain_device *dev, u8 *lun)
  1008. {
  1009. int rc = TMF_RESP_FUNC_FAILED;
  1010. struct pm8001_tmf_task tmf_task;
  1011. tmf_task.tmf = TMF_CLEAR_ACA;
  1012. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1013. return rc;
  1014. }
  1015. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun)
  1016. {
  1017. int rc = TMF_RESP_FUNC_FAILED;
  1018. struct pm8001_tmf_task tmf_task;
  1019. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1020. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1021. PM8001_EH_DBG(pm8001_ha,
  1022. pm8001_printk("I_T_L_Q clear task set[%x]\n",
  1023. pm8001_dev->device_id));
  1024. tmf_task.tmf = TMF_CLEAR_TASK_SET;
  1025. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1026. return rc;
  1027. }