pm8001_sas.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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. if (scsi_is_sas_phy_local(phy))
  884. return 0;
  885. rc = sas_phy_reset(phy, 1);
  886. msleep(2000);
  887. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  888. dev, 1, 0);
  889. pm8001_dev->setds_completion = &completion_setstate;
  890. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  891. pm8001_dev, 0x01);
  892. wait_for_completion(&completion_setstate);
  893. } else{
  894. rc = sas_phy_reset(phy, 1);
  895. msleep(2000);
  896. }
  897. PM8001_EH_DBG(pm8001_ha, pm8001_printk(" for device[%x]:rc=%d\n",
  898. pm8001_dev->device_id, rc));
  899. return rc;
  900. }
  901. /* mandatory SAM-3, the task reset the specified LUN*/
  902. int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
  903. {
  904. int rc = TMF_RESP_FUNC_FAILED;
  905. struct pm8001_tmf_task tmf_task;
  906. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  907. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  908. if (dev_is_sata(dev)) {
  909. struct sas_phy *phy = sas_find_local_phy(dev);
  910. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
  911. dev, 1, 0);
  912. rc = sas_phy_reset(phy, 1);
  913. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  914. pm8001_dev, 0x01);
  915. msleep(2000);
  916. } else {
  917. tmf_task.tmf = TMF_LU_RESET;
  918. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  919. }
  920. /* If failed, fall-through I_T_Nexus reset */
  921. PM8001_EH_DBG(pm8001_ha, pm8001_printk("for device[%x]:rc=%d\n",
  922. pm8001_dev->device_id, rc));
  923. return rc;
  924. }
  925. /* optional SAM-3 */
  926. int pm8001_query_task(struct sas_task *task)
  927. {
  928. u32 tag = 0xdeadbeef;
  929. int i = 0;
  930. struct scsi_lun lun;
  931. struct pm8001_tmf_task tmf_task;
  932. int rc = TMF_RESP_FUNC_FAILED;
  933. if (unlikely(!task || !task->lldd_task || !task->dev))
  934. return rc;
  935. if (task->task_proto & SAS_PROTOCOL_SSP) {
  936. struct scsi_cmnd *cmnd = task->uldd_task;
  937. struct domain_device *dev = task->dev;
  938. struct pm8001_hba_info *pm8001_ha =
  939. pm8001_find_ha_by_dev(dev);
  940. int_to_scsilun(cmnd->device->lun, &lun);
  941. rc = pm8001_find_tag(task, &tag);
  942. if (rc == 0) {
  943. rc = TMF_RESP_FUNC_FAILED;
  944. return rc;
  945. }
  946. PM8001_EH_DBG(pm8001_ha, pm8001_printk("Query:["));
  947. for (i = 0; i < 16; i++)
  948. printk(KERN_INFO "%02x ", cmnd->cmnd[i]);
  949. printk(KERN_INFO "]\n");
  950. tmf_task.tmf = TMF_QUERY_TASK;
  951. tmf_task.tag_of_task_to_be_managed = tag;
  952. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  953. switch (rc) {
  954. /* The task is still in Lun, release it then */
  955. case TMF_RESP_FUNC_SUCC:
  956. PM8001_EH_DBG(pm8001_ha,
  957. pm8001_printk("The task is still in Lun \n"));
  958. /* The task is not in Lun or failed, reset the phy */
  959. case TMF_RESP_FUNC_FAILED:
  960. case TMF_RESP_FUNC_COMPLETE:
  961. PM8001_EH_DBG(pm8001_ha,
  962. pm8001_printk("The task is not in Lun or failed,"
  963. " reset the phy \n"));
  964. break;
  965. }
  966. }
  967. pm8001_printk(":rc= %d\n", rc);
  968. return rc;
  969. }
  970. /* mandatory SAM-3, still need free task/ccb info, abord the specified task */
  971. int pm8001_abort_task(struct sas_task *task)
  972. {
  973. unsigned long flags;
  974. u32 tag = 0xdeadbeef;
  975. u32 device_id;
  976. struct domain_device *dev ;
  977. struct pm8001_hba_info *pm8001_ha = NULL;
  978. struct pm8001_ccb_info *ccb;
  979. struct scsi_lun lun;
  980. struct pm8001_device *pm8001_dev;
  981. struct pm8001_tmf_task tmf_task;
  982. int rc = TMF_RESP_FUNC_FAILED;
  983. if (unlikely(!task || !task->lldd_task || !task->dev))
  984. return rc;
  985. spin_lock_irqsave(&task->task_state_lock, flags);
  986. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  987. spin_unlock_irqrestore(&task->task_state_lock, flags);
  988. rc = TMF_RESP_FUNC_COMPLETE;
  989. goto out;
  990. }
  991. spin_unlock_irqrestore(&task->task_state_lock, flags);
  992. if (task->task_proto & SAS_PROTOCOL_SSP) {
  993. struct scsi_cmnd *cmnd = task->uldd_task;
  994. dev = task->dev;
  995. ccb = task->lldd_task;
  996. pm8001_dev = dev->lldd_dev;
  997. pm8001_ha = pm8001_find_ha_by_dev(dev);
  998. int_to_scsilun(cmnd->device->lun, &lun);
  999. rc = pm8001_find_tag(task, &tag);
  1000. if (rc == 0) {
  1001. printk(KERN_INFO "No such tag in %s\n", __func__);
  1002. rc = TMF_RESP_FUNC_FAILED;
  1003. return rc;
  1004. }
  1005. device_id = pm8001_dev->device_id;
  1006. PM8001_EH_DBG(pm8001_ha,
  1007. pm8001_printk("abort io to deviceid= %d\n", device_id));
  1008. tmf_task.tmf = TMF_ABORT_TASK;
  1009. tmf_task.tag_of_task_to_be_managed = tag;
  1010. rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
  1011. pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1012. pm8001_dev->sas_device, 0, tag);
  1013. } else if (task->task_proto & SAS_PROTOCOL_SATA ||
  1014. task->task_proto & SAS_PROTOCOL_STP) {
  1015. dev = task->dev;
  1016. pm8001_dev = dev->lldd_dev;
  1017. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1018. rc = pm8001_find_tag(task, &tag);
  1019. if (rc == 0) {
  1020. printk(KERN_INFO "No such tag in %s\n", __func__);
  1021. rc = TMF_RESP_FUNC_FAILED;
  1022. return rc;
  1023. }
  1024. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1025. pm8001_dev->sas_device, 0, tag);
  1026. } else if (task->task_proto & SAS_PROTOCOL_SMP) {
  1027. /* SMP */
  1028. dev = task->dev;
  1029. pm8001_dev = dev->lldd_dev;
  1030. pm8001_ha = pm8001_find_ha_by_dev(dev);
  1031. rc = pm8001_find_tag(task, &tag);
  1032. if (rc == 0) {
  1033. printk(KERN_INFO "No such tag in %s\n", __func__);
  1034. rc = TMF_RESP_FUNC_FAILED;
  1035. return rc;
  1036. }
  1037. rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
  1038. pm8001_dev->sas_device, 0, tag);
  1039. }
  1040. out:
  1041. if (rc != TMF_RESP_FUNC_COMPLETE)
  1042. pm8001_printk("rc= %d\n", rc);
  1043. return rc;
  1044. }
  1045. int pm8001_abort_task_set(struct domain_device *dev, u8 *lun)
  1046. {
  1047. int rc = TMF_RESP_FUNC_FAILED;
  1048. struct pm8001_tmf_task tmf_task;
  1049. tmf_task.tmf = TMF_ABORT_TASK_SET;
  1050. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1051. return rc;
  1052. }
  1053. int pm8001_clear_aca(struct domain_device *dev, u8 *lun)
  1054. {
  1055. int rc = TMF_RESP_FUNC_FAILED;
  1056. struct pm8001_tmf_task tmf_task;
  1057. tmf_task.tmf = TMF_CLEAR_ACA;
  1058. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1059. return rc;
  1060. }
  1061. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun)
  1062. {
  1063. int rc = TMF_RESP_FUNC_FAILED;
  1064. struct pm8001_tmf_task tmf_task;
  1065. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1066. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1067. PM8001_EH_DBG(pm8001_ha,
  1068. pm8001_printk("I_T_L_Q clear task set[%x]\n",
  1069. pm8001_dev->device_id));
  1070. tmf_task.tmf = TMF_CLEAR_TASK_SET;
  1071. rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task);
  1072. return rc;
  1073. }