pm8001_sas.c 31 KB

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