pm8001_sas.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. * PMC-Sierra PM8001/8081/8088/8089 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. #include "pm80xx_tracepoints.h"
  43. /**
  44. * pm8001_find_tag - from sas task to find out tag that belongs to this task
  45. * @task: the task sent to the LLDD
  46. * @tag: the found tag associated with the task
  47. */
  48. static int pm8001_find_tag(struct sas_task *task, u32 *tag)
  49. {
  50. if (task->lldd_task) {
  51. struct pm8001_ccb_info *ccb;
  52. ccb = task->lldd_task;
  53. *tag = ccb->ccb_tag;
  54. return 1;
  55. }
  56. return 0;
  57. }
  58. /**
  59. * pm8001_tag_free - free the no more needed tag
  60. * @pm8001_ha: our hba struct
  61. * @tag: the found tag associated with the task
  62. */
  63. void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag)
  64. {
  65. void *bitmap = pm8001_ha->tags;
  66. unsigned long flags;
  67. spin_lock_irqsave(&pm8001_ha->bitmap_lock, flags);
  68. __clear_bit(tag, bitmap);
  69. spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags);
  70. }
  71. /**
  72. * pm8001_tag_alloc - allocate a empty tag for task used.
  73. * @pm8001_ha: our hba struct
  74. * @tag_out: the found empty tag .
  75. */
  76. int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out)
  77. {
  78. void *bitmap = pm8001_ha->tags;
  79. unsigned long flags;
  80. unsigned int tag;
  81. spin_lock_irqsave(&pm8001_ha->bitmap_lock, flags);
  82. tag = find_first_zero_bit(bitmap, pm8001_ha->tags_num);
  83. if (tag >= pm8001_ha->tags_num) {
  84. spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags);
  85. return -SAS_QUEUE_FULL;
  86. }
  87. __set_bit(tag, bitmap);
  88. spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags);
  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_free(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: DMA address for this device
  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. * @align: requested byte alignment
  107. */
  108. int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
  109. dma_addr_t *pphys_addr, u32 *pphys_addr_hi,
  110. u32 *pphys_addr_lo, u32 mem_size, u32 align)
  111. {
  112. caddr_t mem_virt_alloc;
  113. dma_addr_t mem_dma_handle;
  114. u64 phys_align;
  115. u64 align_offset = 0;
  116. if (align)
  117. align_offset = (dma_addr_t)align - 1;
  118. mem_virt_alloc = dma_alloc_coherent(&pdev->dev, mem_size + align,
  119. &mem_dma_handle, GFP_KERNEL);
  120. if (!mem_virt_alloc)
  121. return -ENOMEM;
  122. *pphys_addr = mem_dma_handle;
  123. phys_align = (*pphys_addr + align_offset) & ~align_offset;
  124. *virt_addr = (void *)mem_virt_alloc + phys_align - *pphys_addr;
  125. *pphys_addr_hi = upper_32_bits(phys_align);
  126. *pphys_addr_lo = lower_32_bits(phys_align);
  127. return 0;
  128. }
  129. /**
  130. * pm8001_find_ha_by_dev - from domain device which come from sas layer to
  131. * find out our hba struct.
  132. * @dev: the domain device which from sas layer.
  133. */
  134. static
  135. struct pm8001_hba_info *pm8001_find_ha_by_dev(struct domain_device *dev)
  136. {
  137. struct sas_ha_struct *sha = dev->port->ha;
  138. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  139. return pm8001_ha;
  140. }
  141. /**
  142. * pm8001_phy_control - this function should be registered to
  143. * sas_domain_function_template to provide libsas used, note: this is just
  144. * control the HBA phy rather than other expander phy if you want control
  145. * other phy, you should use SMP command.
  146. * @sas_phy: which phy in HBA phys.
  147. * @func: the operation.
  148. * @funcdata: always NULL.
  149. */
  150. int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
  151. void *funcdata)
  152. {
  153. int rc = 0, phy_id = sas_phy->id;
  154. struct pm8001_hba_info *pm8001_ha = NULL;
  155. struct sas_phy_linkrates *rates;
  156. struct pm8001_phy *phy;
  157. DECLARE_COMPLETION_ONSTACK(completion);
  158. unsigned long flags;
  159. pm8001_ha = sas_phy->ha->lldd_ha;
  160. phy = &pm8001_ha->phy[phy_id];
  161. pm8001_ha->phy[phy_id].enable_completion = &completion;
  162. switch (func) {
  163. case PHY_FUNC_SET_LINK_RATE:
  164. rates = funcdata;
  165. if (rates->minimum_linkrate) {
  166. pm8001_ha->phy[phy_id].minimum_linkrate =
  167. rates->minimum_linkrate;
  168. }
  169. if (rates->maximum_linkrate) {
  170. pm8001_ha->phy[phy_id].maximum_linkrate =
  171. rates->maximum_linkrate;
  172. }
  173. if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) {
  174. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  175. wait_for_completion(&completion);
  176. }
  177. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  178. PHY_LINK_RESET);
  179. break;
  180. case PHY_FUNC_HARD_RESET:
  181. if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) {
  182. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  183. wait_for_completion(&completion);
  184. }
  185. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  186. PHY_HARD_RESET);
  187. break;
  188. case PHY_FUNC_LINK_RESET:
  189. if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) {
  190. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id);
  191. wait_for_completion(&completion);
  192. }
  193. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  194. PHY_LINK_RESET);
  195. break;
  196. case PHY_FUNC_RELEASE_SPINUP_HOLD:
  197. PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  198. PHY_LINK_RESET);
  199. break;
  200. case PHY_FUNC_DISABLE:
  201. if (pm8001_ha->chip_id != chip_8001) {
  202. if (pm8001_ha->phy[phy_id].phy_state ==
  203. PHY_STATE_LINK_UP_SPCV) {
  204. sas_phy_disconnected(&phy->sas_phy);
  205. sas_notify_phy_event(&phy->sas_phy,
  206. PHYE_LOSS_OF_SIGNAL, GFP_KERNEL);
  207. phy->phy_attached = 0;
  208. }
  209. } else {
  210. if (pm8001_ha->phy[phy_id].phy_state ==
  211. PHY_STATE_LINK_UP_SPC) {
  212. sas_phy_disconnected(&phy->sas_phy);
  213. sas_notify_phy_event(&phy->sas_phy,
  214. PHYE_LOSS_OF_SIGNAL, GFP_KERNEL);
  215. phy->phy_attached = 0;
  216. }
  217. }
  218. PM8001_CHIP_DISP->phy_stop_req(pm8001_ha, phy_id);
  219. break;
  220. case PHY_FUNC_GET_EVENTS:
  221. spin_lock_irqsave(&pm8001_ha->lock, flags);
  222. if (pm8001_ha->chip_id == chip_8001) {
  223. if (-1 == pm8001_bar4_shift(pm8001_ha,
  224. (phy_id < 4) ? 0x30000 : 0x40000)) {
  225. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  226. return -EINVAL;
  227. }
  228. }
  229. {
  230. struct sas_phy *phy = sas_phy->phy;
  231. u32 __iomem *qp = pm8001_ha->io_mem[2].memvirtaddr
  232. + 0x1034 + (0x4000 * (phy_id & 3));
  233. phy->invalid_dword_count = readl(qp);
  234. phy->running_disparity_error_count = readl(&qp[1]);
  235. phy->loss_of_dword_sync_count = readl(&qp[3]);
  236. phy->phy_reset_problem_count = readl(&qp[4]);
  237. }
  238. if (pm8001_ha->chip_id == chip_8001)
  239. pm8001_bar4_shift(pm8001_ha, 0);
  240. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  241. return 0;
  242. default:
  243. pm8001_dbg(pm8001_ha, DEVIO, "func 0x%x\n", func);
  244. rc = -EOPNOTSUPP;
  245. }
  246. msleep(300);
  247. return rc;
  248. }
  249. /**
  250. * pm8001_scan_start - we should enable all HBA phys by sending the phy_start
  251. * command to HBA.
  252. * @shost: the scsi host data.
  253. */
  254. void pm8001_scan_start(struct Scsi_Host *shost)
  255. {
  256. int i;
  257. struct pm8001_hba_info *pm8001_ha;
  258. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  259. DECLARE_COMPLETION_ONSTACK(completion);
  260. pm8001_ha = sha->lldd_ha;
  261. /* SAS_RE_INITIALIZATION not available in SPCv/ve */
  262. if (pm8001_ha->chip_id == chip_8001)
  263. PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
  264. for (i = 0; i < pm8001_ha->chip->n_phy; ++i) {
  265. pm8001_ha->phy[i].enable_completion = &completion;
  266. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  267. wait_for_completion(&completion);
  268. msleep(300);
  269. }
  270. }
  271. int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
  272. {
  273. struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
  274. /* give the phy enabling interrupt event time to come in (1s
  275. * is empirically about all it takes) */
  276. if (time < HZ)
  277. return 0;
  278. /* Wait for discovery to finish */
  279. sas_drain_work(ha);
  280. return 1;
  281. }
  282. /**
  283. * pm8001_task_prep_smp - the dispatcher function, prepare data for smp task
  284. * @pm8001_ha: our hba card information
  285. * @ccb: the ccb which attached to smp task
  286. */
  287. static int pm8001_task_prep_smp(struct pm8001_hba_info *pm8001_ha,
  288. struct pm8001_ccb_info *ccb)
  289. {
  290. return PM8001_CHIP_DISP->smp_req(pm8001_ha, ccb);
  291. }
  292. u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag)
  293. {
  294. struct ata_queued_cmd *qc = task->uldd_task;
  295. if (qc && ata_is_ncq(qc->tf.protocol)) {
  296. *tag = qc->tag;
  297. return 1;
  298. }
  299. return 0;
  300. }
  301. /**
  302. * pm8001_task_prep_ata - the dispatcher function, prepare data for sata task
  303. * @pm8001_ha: our hba card information
  304. * @ccb: the ccb which attached to sata task
  305. */
  306. static int pm8001_task_prep_ata(struct pm8001_hba_info *pm8001_ha,
  307. struct pm8001_ccb_info *ccb)
  308. {
  309. return PM8001_CHIP_DISP->sata_req(pm8001_ha, ccb);
  310. }
  311. /**
  312. * pm8001_task_prep_internal_abort - the dispatcher function, prepare data
  313. * for internal abort task
  314. * @pm8001_ha: our hba card information
  315. * @ccb: the ccb which attached to sata task
  316. */
  317. static int pm8001_task_prep_internal_abort(struct pm8001_hba_info *pm8001_ha,
  318. struct pm8001_ccb_info *ccb)
  319. {
  320. return PM8001_CHIP_DISP->task_abort(pm8001_ha, ccb);
  321. }
  322. /**
  323. * pm8001_task_prep_ssp_tm - the dispatcher function, prepare task management data
  324. * @pm8001_ha: our hba card information
  325. * @ccb: the ccb which attached to TM
  326. * @tmf: the task management IU
  327. */
  328. static int pm8001_task_prep_ssp_tm(struct pm8001_hba_info *pm8001_ha,
  329. struct pm8001_ccb_info *ccb, struct sas_tmf_task *tmf)
  330. {
  331. return PM8001_CHIP_DISP->ssp_tm_req(pm8001_ha, ccb, tmf);
  332. }
  333. /**
  334. * pm8001_task_prep_ssp - the dispatcher function, prepare ssp data for ssp task
  335. * @pm8001_ha: our hba card information
  336. * @ccb: the ccb which attached to ssp task
  337. */
  338. static int pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha,
  339. struct pm8001_ccb_info *ccb)
  340. {
  341. return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb);
  342. }
  343. /* Find the local port id that's attached to this device */
  344. static int sas_find_local_port_id(struct domain_device *dev)
  345. {
  346. struct domain_device *pdev = dev->parent;
  347. /* Directly attached device */
  348. if (!pdev)
  349. return dev->port->id;
  350. while (pdev) {
  351. struct domain_device *pdev_p = pdev->parent;
  352. if (!pdev_p)
  353. return pdev->port->id;
  354. pdev = pdev->parent;
  355. }
  356. return 0;
  357. }
  358. #define DEV_IS_GONE(pm8001_dev) \
  359. ((!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED)))
  360. static int pm8001_deliver_command(struct pm8001_hba_info *pm8001_ha,
  361. struct pm8001_ccb_info *ccb)
  362. {
  363. struct sas_task *task = ccb->task;
  364. enum sas_protocol task_proto = task->task_proto;
  365. struct sas_tmf_task *tmf = task->tmf;
  366. int is_tmf = !!tmf;
  367. switch (task_proto) {
  368. case SAS_PROTOCOL_SMP:
  369. return pm8001_task_prep_smp(pm8001_ha, ccb);
  370. case SAS_PROTOCOL_SSP:
  371. if (is_tmf)
  372. return pm8001_task_prep_ssp_tm(pm8001_ha, ccb, tmf);
  373. return pm8001_task_prep_ssp(pm8001_ha, ccb);
  374. case SAS_PROTOCOL_SATA:
  375. case SAS_PROTOCOL_STP:
  376. return pm8001_task_prep_ata(pm8001_ha, ccb);
  377. case SAS_PROTOCOL_INTERNAL_ABORT:
  378. return pm8001_task_prep_internal_abort(pm8001_ha, ccb);
  379. default:
  380. dev_err(pm8001_ha->dev, "unknown sas_task proto: 0x%x\n",
  381. task_proto);
  382. }
  383. return -EINVAL;
  384. }
  385. /**
  386. * pm8001_queue_command - register for upper layer used, all IO commands sent
  387. * to HBA are from this interface.
  388. * @task: the task to be execute.
  389. * @gfp_flags: gfp_flags
  390. */
  391. int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags)
  392. {
  393. struct task_status_struct *ts = &task->task_status;
  394. enum sas_protocol task_proto = task->task_proto;
  395. struct domain_device *dev = task->dev;
  396. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  397. bool internal_abort = sas_is_internal_abort(task);
  398. struct pm8001_hba_info *pm8001_ha;
  399. struct pm8001_port *port = NULL;
  400. struct pm8001_ccb_info *ccb;
  401. unsigned long flags;
  402. u32 n_elem = 0;
  403. int rc = 0;
  404. if (!internal_abort && !dev->port) {
  405. ts->resp = SAS_TASK_UNDELIVERED;
  406. ts->stat = SAS_PHY_DOWN;
  407. if (dev->dev_type != SAS_SATA_DEV)
  408. task->task_done(task);
  409. return 0;
  410. }
  411. pm8001_ha = pm8001_find_ha_by_dev(dev);
  412. if (pm8001_ha->controller_fatal_error) {
  413. ts->resp = SAS_TASK_UNDELIVERED;
  414. task->task_done(task);
  415. return 0;
  416. }
  417. pm8001_dbg(pm8001_ha, IO, "pm8001_task_exec device\n");
  418. spin_lock_irqsave(&pm8001_ha->lock, flags);
  419. pm8001_dev = dev->lldd_dev;
  420. port = &pm8001_ha->port[sas_find_local_port_id(dev)];
  421. if (!internal_abort &&
  422. (DEV_IS_GONE(pm8001_dev) || !port->port_attached)) {
  423. ts->resp = SAS_TASK_UNDELIVERED;
  424. ts->stat = SAS_PHY_DOWN;
  425. if (sas_protocol_ata(task_proto)) {
  426. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  427. task->task_done(task);
  428. spin_lock_irqsave(&pm8001_ha->lock, flags);
  429. } else {
  430. task->task_done(task);
  431. }
  432. rc = -ENODEV;
  433. goto err_out;
  434. }
  435. ccb = pm8001_ccb_alloc(pm8001_ha, pm8001_dev, task);
  436. if (!ccb) {
  437. rc = -SAS_QUEUE_FULL;
  438. goto err_out;
  439. }
  440. if (!sas_protocol_ata(task_proto)) {
  441. if (task->num_scatter) {
  442. n_elem = dma_map_sg(pm8001_ha->dev, task->scatter,
  443. task->num_scatter, task->data_dir);
  444. if (!n_elem) {
  445. rc = -ENOMEM;
  446. goto err_out_ccb;
  447. }
  448. }
  449. } else {
  450. n_elem = task->num_scatter;
  451. }
  452. task->lldd_task = ccb;
  453. ccb->n_elem = n_elem;
  454. atomic_inc(&pm8001_dev->running_req);
  455. rc = pm8001_deliver_command(pm8001_ha, ccb);
  456. if (rc) {
  457. atomic_dec(&pm8001_dev->running_req);
  458. if (!sas_protocol_ata(task_proto) && n_elem)
  459. dma_unmap_sg(pm8001_ha->dev, task->scatter,
  460. task->num_scatter, task->data_dir);
  461. err_out_ccb:
  462. pm8001_ccb_free(pm8001_ha, ccb);
  463. err_out:
  464. pm8001_dbg(pm8001_ha, IO, "pm8001_task_exec failed[%d]!\n", rc);
  465. }
  466. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  467. return rc;
  468. }
  469. /**
  470. * pm8001_ccb_task_free - free the sg for ssp and smp command, free the ccb.
  471. * @pm8001_ha: our hba card information
  472. * @ccb: the ccb which attached to ssp task to free
  473. */
  474. void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
  475. struct pm8001_ccb_info *ccb)
  476. {
  477. struct sas_task *task = ccb->task;
  478. struct ata_queued_cmd *qc;
  479. struct pm8001_device *pm8001_dev;
  480. if (!task)
  481. return;
  482. if (!sas_protocol_ata(task->task_proto) && ccb->n_elem)
  483. dma_unmap_sg(pm8001_ha->dev, task->scatter,
  484. task->num_scatter, task->data_dir);
  485. switch (task->task_proto) {
  486. case SAS_PROTOCOL_SMP:
  487. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_resp, 1,
  488. DMA_FROM_DEVICE);
  489. dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_req, 1,
  490. DMA_TO_DEVICE);
  491. break;
  492. case SAS_PROTOCOL_SATA:
  493. case SAS_PROTOCOL_STP:
  494. case SAS_PROTOCOL_SSP:
  495. default:
  496. /* do nothing */
  497. break;
  498. }
  499. if (sas_protocol_ata(task->task_proto)) {
  500. /* For SCSI/ATA commands uldd_task points to ata_queued_cmd */
  501. qc = task->uldd_task;
  502. pm8001_dev = ccb->device;
  503. trace_pm80xx_request_complete(pm8001_ha->id,
  504. pm8001_dev ? pm8001_dev->attached_phy : PM8001_MAX_PHYS,
  505. ccb->ccb_tag, 0 /* ctlr_opcode not known */,
  506. qc ? qc->tf.command : 0, // ata opcode
  507. pm8001_dev ? atomic_read(&pm8001_dev->running_req) : -1);
  508. }
  509. task->lldd_task = NULL;
  510. pm8001_ccb_free(pm8001_ha, ccb);
  511. }
  512. /**
  513. * pm8001_alloc_dev - find a empty pm8001_device
  514. * @pm8001_ha: our hba card information
  515. */
  516. static struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha)
  517. {
  518. u32 dev;
  519. for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
  520. if (pm8001_ha->devices[dev].dev_type == SAS_PHY_UNUSED) {
  521. pm8001_ha->devices[dev].id = dev;
  522. return &pm8001_ha->devices[dev];
  523. }
  524. }
  525. if (dev == PM8001_MAX_DEVICES) {
  526. pm8001_dbg(pm8001_ha, FAIL,
  527. "max support %d devices, ignore ..\n",
  528. PM8001_MAX_DEVICES);
  529. }
  530. return NULL;
  531. }
  532. /**
  533. * pm8001_find_dev - find a matching pm8001_device
  534. * @pm8001_ha: our hba card information
  535. * @device_id: device ID to match against
  536. */
  537. struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha,
  538. u32 device_id)
  539. {
  540. u32 dev;
  541. for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
  542. if (pm8001_ha->devices[dev].device_id == device_id)
  543. return &pm8001_ha->devices[dev];
  544. }
  545. if (dev == PM8001_MAX_DEVICES) {
  546. pm8001_dbg(pm8001_ha, FAIL, "NO MATCHING DEVICE FOUND !!!\n");
  547. }
  548. return NULL;
  549. }
  550. void pm8001_free_dev(struct pm8001_device *pm8001_dev)
  551. {
  552. u32 id = pm8001_dev->id;
  553. memset(pm8001_dev, 0, sizeof(*pm8001_dev));
  554. pm8001_dev->id = id;
  555. pm8001_dev->dev_type = SAS_PHY_UNUSED;
  556. pm8001_dev->device_id = PM8001_MAX_DEVICES;
  557. pm8001_dev->sas_device = NULL;
  558. }
  559. /**
  560. * pm8001_dev_found_notify - libsas notify a device is found.
  561. * @dev: the device structure which sas layer used.
  562. *
  563. * when libsas find a sas domain device, it should tell the LLDD that
  564. * device is found, and then LLDD register this device to HBA firmware
  565. * by the command "OPC_INB_REG_DEV", after that the HBA will assign a
  566. * device ID(according to device's sas address) and returned it to LLDD. From
  567. * now on, we communicate with HBA FW with the device ID which HBA assigned
  568. * rather than sas address. it is the necessary step for our HBA but it is
  569. * the optional for other HBA driver.
  570. */
  571. static int pm8001_dev_found_notify(struct domain_device *dev)
  572. {
  573. unsigned long flags = 0;
  574. int res = 0;
  575. struct pm8001_hba_info *pm8001_ha = NULL;
  576. struct domain_device *parent_dev = dev->parent;
  577. struct pm8001_device *pm8001_device;
  578. DECLARE_COMPLETION_ONSTACK(completion);
  579. u32 flag = 0;
  580. pm8001_ha = pm8001_find_ha_by_dev(dev);
  581. spin_lock_irqsave(&pm8001_ha->lock, flags);
  582. pm8001_device = pm8001_alloc_dev(pm8001_ha);
  583. if (!pm8001_device) {
  584. res = -1;
  585. goto found_out;
  586. }
  587. pm8001_device->sas_device = dev;
  588. dev->lldd_dev = pm8001_device;
  589. pm8001_device->dev_type = dev->dev_type;
  590. pm8001_device->dcompletion = &completion;
  591. if (parent_dev && dev_is_expander(parent_dev->dev_type)) {
  592. int phy_id;
  593. struct ex_phy *phy;
  594. for (phy_id = 0; phy_id < parent_dev->ex_dev.num_phys;
  595. phy_id++) {
  596. phy = &parent_dev->ex_dev.ex_phy[phy_id];
  597. if (SAS_ADDR(phy->attached_sas_addr)
  598. == SAS_ADDR(dev->sas_addr)) {
  599. pm8001_device->attached_phy = phy_id;
  600. break;
  601. }
  602. }
  603. if (phy_id == parent_dev->ex_dev.num_phys) {
  604. pm8001_dbg(pm8001_ha, FAIL,
  605. "Error: no attached dev:%016llx at ex:%016llx.\n",
  606. SAS_ADDR(dev->sas_addr),
  607. SAS_ADDR(parent_dev->sas_addr));
  608. res = -1;
  609. }
  610. } else {
  611. if (dev->dev_type == SAS_SATA_DEV) {
  612. pm8001_device->attached_phy =
  613. dev->rphy->identify.phy_identifier;
  614. flag = 1; /* directly sata */
  615. }
  616. } /*register this device to HBA*/
  617. pm8001_dbg(pm8001_ha, DISC, "Found device\n");
  618. PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
  619. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  620. wait_for_completion(&completion);
  621. if (dev->dev_type == SAS_END_DEVICE)
  622. msleep(50);
  623. pm8001_ha->flags = PM8001F_RUN_TIME;
  624. return 0;
  625. found_out:
  626. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  627. return res;
  628. }
  629. int pm8001_dev_found(struct domain_device *dev)
  630. {
  631. return pm8001_dev_found_notify(dev);
  632. }
  633. void pm8001_task_done(struct sas_task *task)
  634. {
  635. del_timer(&task->slow_task->timer);
  636. complete(&task->slow_task->completion);
  637. }
  638. #define PM8001_TASK_TIMEOUT 20
  639. /**
  640. * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify"
  641. * @dev: the device structure which sas layer used.
  642. */
  643. static void pm8001_dev_gone_notify(struct domain_device *dev)
  644. {
  645. unsigned long flags = 0;
  646. struct pm8001_hba_info *pm8001_ha;
  647. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  648. pm8001_ha = pm8001_find_ha_by_dev(dev);
  649. spin_lock_irqsave(&pm8001_ha->lock, flags);
  650. if (pm8001_dev) {
  651. u32 device_id = pm8001_dev->device_id;
  652. pm8001_dbg(pm8001_ha, DISC, "found dev[%d:%x] is gone.\n",
  653. pm8001_dev->device_id, pm8001_dev->dev_type);
  654. if (atomic_read(&pm8001_dev->running_req)) {
  655. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  656. sas_execute_internal_abort_dev(dev, 0, NULL);
  657. while (atomic_read(&pm8001_dev->running_req))
  658. msleep(20);
  659. spin_lock_irqsave(&pm8001_ha->lock, flags);
  660. }
  661. PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
  662. pm8001_free_dev(pm8001_dev);
  663. } else {
  664. pm8001_dbg(pm8001_ha, DISC, "Found dev has gone.\n");
  665. }
  666. dev->lldd_dev = NULL;
  667. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  668. }
  669. void pm8001_dev_gone(struct domain_device *dev)
  670. {
  671. pm8001_dev_gone_notify(dev);
  672. }
  673. /* retry commands by ha, by task and/or by device */
  674. void pm8001_open_reject_retry(
  675. struct pm8001_hba_info *pm8001_ha,
  676. struct sas_task *task_to_close,
  677. struct pm8001_device *device_to_close)
  678. {
  679. int i;
  680. unsigned long flags;
  681. if (pm8001_ha == NULL)
  682. return;
  683. spin_lock_irqsave(&pm8001_ha->lock, flags);
  684. for (i = 0; i < PM8001_MAX_CCB; i++) {
  685. struct sas_task *task;
  686. struct task_status_struct *ts;
  687. struct pm8001_device *pm8001_dev;
  688. unsigned long flags1;
  689. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[i];
  690. if (ccb->ccb_tag == PM8001_INVALID_TAG)
  691. continue;
  692. pm8001_dev = ccb->device;
  693. if (!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED))
  694. continue;
  695. if (!device_to_close) {
  696. uintptr_t d = (uintptr_t)pm8001_dev
  697. - (uintptr_t)&pm8001_ha->devices;
  698. if (((d % sizeof(*pm8001_dev)) != 0)
  699. || ((d / sizeof(*pm8001_dev)) >= PM8001_MAX_DEVICES))
  700. continue;
  701. } else if (pm8001_dev != device_to_close)
  702. continue;
  703. task = ccb->task;
  704. if (!task || !task->task_done)
  705. continue;
  706. if (task_to_close && (task != task_to_close))
  707. continue;
  708. ts = &task->task_status;
  709. ts->resp = SAS_TASK_COMPLETE;
  710. /* Force the midlayer to retry */
  711. ts->stat = SAS_OPEN_REJECT;
  712. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  713. if (pm8001_dev)
  714. atomic_dec(&pm8001_dev->running_req);
  715. spin_lock_irqsave(&task->task_state_lock, flags1);
  716. task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  717. task->task_state_flags |= SAS_TASK_STATE_DONE;
  718. if (unlikely((task->task_state_flags
  719. & SAS_TASK_STATE_ABORTED))) {
  720. spin_unlock_irqrestore(&task->task_state_lock,
  721. flags1);
  722. pm8001_ccb_task_free(pm8001_ha, ccb);
  723. } else {
  724. spin_unlock_irqrestore(&task->task_state_lock,
  725. flags1);
  726. pm8001_ccb_task_free(pm8001_ha, ccb);
  727. mb();/* in order to force CPU ordering */
  728. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  729. task->task_done(task);
  730. spin_lock_irqsave(&pm8001_ha->lock, flags);
  731. }
  732. }
  733. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  734. }
  735. /**
  736. * pm8001_I_T_nexus_reset() - reset the initiator/target connection
  737. * @dev: the device structure for the device to reset.
  738. *
  739. * Standard mandates link reset for ATA (type 0) and hard reset for
  740. * SSP (type 1), only for RECOVERY
  741. */
  742. int pm8001_I_T_nexus_reset(struct domain_device *dev)
  743. {
  744. int rc = TMF_RESP_FUNC_FAILED;
  745. struct pm8001_device *pm8001_dev;
  746. struct pm8001_hba_info *pm8001_ha;
  747. struct sas_phy *phy;
  748. if (!dev || !dev->lldd_dev)
  749. return -ENODEV;
  750. pm8001_dev = dev->lldd_dev;
  751. pm8001_ha = pm8001_find_ha_by_dev(dev);
  752. phy = sas_get_local_phy(dev);
  753. if (dev_is_sata(dev)) {
  754. if (scsi_is_sas_phy_local(phy)) {
  755. rc = 0;
  756. goto out;
  757. }
  758. rc = sas_phy_reset(phy, 1);
  759. if (rc) {
  760. pm8001_dbg(pm8001_ha, EH,
  761. "phy reset failed for device %x\n"
  762. "with rc %d\n", pm8001_dev->device_id, rc);
  763. rc = TMF_RESP_FUNC_FAILED;
  764. goto out;
  765. }
  766. msleep(2000);
  767. rc = sas_execute_internal_abort_dev(dev, 0, NULL);
  768. if (rc) {
  769. pm8001_dbg(pm8001_ha, EH, "task abort failed %x\n"
  770. "with rc %d\n", pm8001_dev->device_id, rc);
  771. rc = TMF_RESP_FUNC_FAILED;
  772. }
  773. } else {
  774. rc = sas_phy_reset(phy, 1);
  775. msleep(2000);
  776. }
  777. pm8001_dbg(pm8001_ha, EH, " for device[%x]:rc=%d\n",
  778. pm8001_dev->device_id, rc);
  779. out:
  780. sas_put_local_phy(phy);
  781. return rc;
  782. }
  783. /*
  784. * This function handle the IT_NEXUS_XXX event or completion
  785. * status code for SSP/SATA/SMP I/O request.
  786. */
  787. int pm8001_I_T_nexus_event_handler(struct domain_device *dev)
  788. {
  789. int rc = TMF_RESP_FUNC_FAILED;
  790. struct pm8001_device *pm8001_dev;
  791. struct pm8001_hba_info *pm8001_ha;
  792. struct sas_phy *phy;
  793. if (!dev || !dev->lldd_dev)
  794. return -1;
  795. pm8001_dev = dev->lldd_dev;
  796. pm8001_ha = pm8001_find_ha_by_dev(dev);
  797. pm8001_dbg(pm8001_ha, EH, "I_T_Nexus handler invoked !!\n");
  798. phy = sas_get_local_phy(dev);
  799. if (dev_is_sata(dev)) {
  800. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  801. if (scsi_is_sas_phy_local(phy)) {
  802. rc = 0;
  803. goto out;
  804. }
  805. /* send internal ssp/sata/smp abort command to FW */
  806. sas_execute_internal_abort_dev(dev, 0, NULL);
  807. msleep(100);
  808. /* deregister the target device */
  809. pm8001_dev_gone_notify(dev);
  810. msleep(200);
  811. /*send phy reset to hard reset target */
  812. rc = sas_phy_reset(phy, 1);
  813. msleep(2000);
  814. pm8001_dev->setds_completion = &completion_setstate;
  815. wait_for_completion(&completion_setstate);
  816. } else {
  817. /* send internal ssp/sata/smp abort command to FW */
  818. sas_execute_internal_abort_dev(dev, 0, NULL);
  819. msleep(100);
  820. /* deregister the target device */
  821. pm8001_dev_gone_notify(dev);
  822. msleep(200);
  823. /*send phy reset to hard reset target */
  824. rc = sas_phy_reset(phy, 1);
  825. msleep(2000);
  826. }
  827. pm8001_dbg(pm8001_ha, EH, " for device[%x]:rc=%d\n",
  828. pm8001_dev->device_id, rc);
  829. out:
  830. sas_put_local_phy(phy);
  831. return rc;
  832. }
  833. /* mandatory SAM-3, the task reset the specified LUN*/
  834. int pm8001_lu_reset(struct domain_device *dev, u8 *lun)
  835. {
  836. int rc = TMF_RESP_FUNC_FAILED;
  837. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  838. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  839. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  840. if (dev_is_sata(dev)) {
  841. struct sas_phy *phy = sas_get_local_phy(dev);
  842. sas_execute_internal_abort_dev(dev, 0, NULL);
  843. rc = sas_phy_reset(phy, 1);
  844. sas_put_local_phy(phy);
  845. pm8001_dev->setds_completion = &completion_setstate;
  846. rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  847. pm8001_dev, DS_OPERATIONAL);
  848. wait_for_completion(&completion_setstate);
  849. } else {
  850. rc = sas_lu_reset(dev, lun);
  851. }
  852. /* If failed, fall-through I_T_Nexus reset */
  853. pm8001_dbg(pm8001_ha, EH, "for device[%x]:rc=%d\n",
  854. pm8001_dev->device_id, rc);
  855. return rc;
  856. }
  857. /* optional SAM-3 */
  858. int pm8001_query_task(struct sas_task *task)
  859. {
  860. u32 tag = 0xdeadbeef;
  861. int rc = TMF_RESP_FUNC_FAILED;
  862. if (unlikely(!task || !task->lldd_task || !task->dev))
  863. return rc;
  864. if (task->task_proto & SAS_PROTOCOL_SSP) {
  865. struct scsi_cmnd *cmnd = task->uldd_task;
  866. struct domain_device *dev = task->dev;
  867. struct pm8001_hba_info *pm8001_ha =
  868. pm8001_find_ha_by_dev(dev);
  869. rc = pm8001_find_tag(task, &tag);
  870. if (rc == 0) {
  871. rc = TMF_RESP_FUNC_FAILED;
  872. return rc;
  873. }
  874. pm8001_dbg(pm8001_ha, EH, "Query:[%16ph]\n", cmnd->cmnd);
  875. rc = sas_query_task(task, tag);
  876. switch (rc) {
  877. /* The task is still in Lun, release it then */
  878. case TMF_RESP_FUNC_SUCC:
  879. pm8001_dbg(pm8001_ha, EH,
  880. "The task is still in Lun\n");
  881. break;
  882. /* The task is not in Lun or failed, reset the phy */
  883. case TMF_RESP_FUNC_FAILED:
  884. case TMF_RESP_FUNC_COMPLETE:
  885. pm8001_dbg(pm8001_ha, EH,
  886. "The task is not in Lun or failed, reset the phy\n");
  887. break;
  888. }
  889. }
  890. pr_err("pm80xx: rc= %d\n", rc);
  891. return rc;
  892. }
  893. /* mandatory SAM-3, still need free task/ccb info, abort the specified task */
  894. int pm8001_abort_task(struct sas_task *task)
  895. {
  896. unsigned long flags;
  897. u32 tag;
  898. struct domain_device *dev ;
  899. struct pm8001_hba_info *pm8001_ha;
  900. struct pm8001_device *pm8001_dev;
  901. int rc = TMF_RESP_FUNC_FAILED, ret;
  902. u32 phy_id, port_id;
  903. struct sas_task_slow slow_task;
  904. if (unlikely(!task || !task->lldd_task || !task->dev))
  905. return TMF_RESP_FUNC_FAILED;
  906. dev = task->dev;
  907. pm8001_dev = dev->lldd_dev;
  908. pm8001_ha = pm8001_find_ha_by_dev(dev);
  909. phy_id = pm8001_dev->attached_phy;
  910. if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) {
  911. // If the controller is seeing fatal errors
  912. // abort task will not get a response from the controller
  913. return TMF_RESP_FUNC_FAILED;
  914. }
  915. ret = pm8001_find_tag(task, &tag);
  916. if (ret == 0) {
  917. pm8001_info(pm8001_ha, "no tag for task:%p\n", task);
  918. return TMF_RESP_FUNC_FAILED;
  919. }
  920. spin_lock_irqsave(&task->task_state_lock, flags);
  921. if (task->task_state_flags & SAS_TASK_STATE_DONE) {
  922. spin_unlock_irqrestore(&task->task_state_lock, flags);
  923. return TMF_RESP_FUNC_COMPLETE;
  924. }
  925. task->task_state_flags |= SAS_TASK_STATE_ABORTED;
  926. if (task->slow_task == NULL) {
  927. init_completion(&slow_task.completion);
  928. task->slow_task = &slow_task;
  929. }
  930. spin_unlock_irqrestore(&task->task_state_lock, flags);
  931. if (task->task_proto & SAS_PROTOCOL_SSP) {
  932. rc = sas_abort_task(task, tag);
  933. sas_execute_internal_abort_single(dev, tag, 0, NULL);
  934. } else if (task->task_proto & SAS_PROTOCOL_SATA ||
  935. task->task_proto & SAS_PROTOCOL_STP) {
  936. if (pm8001_ha->chip_id == chip_8006) {
  937. DECLARE_COMPLETION_ONSTACK(completion_reset);
  938. DECLARE_COMPLETION_ONSTACK(completion);
  939. struct pm8001_phy *phy = pm8001_ha->phy + phy_id;
  940. port_id = phy->port->port_id;
  941. /* 1. Set Device state as Recovery */
  942. pm8001_dev->setds_completion = &completion;
  943. PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  944. pm8001_dev, DS_IN_RECOVERY);
  945. wait_for_completion(&completion);
  946. /* 2. Send Phy Control Hard Reset */
  947. reinit_completion(&completion);
  948. phy->port_reset_status = PORT_RESET_TMO;
  949. phy->reset_success = false;
  950. phy->enable_completion = &completion;
  951. phy->reset_completion = &completion_reset;
  952. ret = PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
  953. PHY_HARD_RESET);
  954. if (ret) {
  955. phy->enable_completion = NULL;
  956. phy->reset_completion = NULL;
  957. goto out;
  958. }
  959. /* In the case of the reset timeout/fail we still
  960. * abort the command at the firmware. The assumption
  961. * here is that the drive is off doing something so
  962. * that it's not processing requests, and we want to
  963. * avoid getting a completion for this and either
  964. * leaking the task in libsas or losing the race and
  965. * getting a double free.
  966. */
  967. pm8001_dbg(pm8001_ha, MSG,
  968. "Waiting for local phy ctl\n");
  969. ret = wait_for_completion_timeout(&completion,
  970. PM8001_TASK_TIMEOUT * HZ);
  971. if (!ret || !phy->reset_success) {
  972. phy->enable_completion = NULL;
  973. phy->reset_completion = NULL;
  974. } else {
  975. /* 3. Wait for Port Reset complete or
  976. * Port reset TMO
  977. */
  978. pm8001_dbg(pm8001_ha, MSG,
  979. "Waiting for Port reset\n");
  980. ret = wait_for_completion_timeout(
  981. &completion_reset,
  982. PM8001_TASK_TIMEOUT * HZ);
  983. if (!ret)
  984. phy->reset_completion = NULL;
  985. WARN_ON(phy->port_reset_status ==
  986. PORT_RESET_TMO);
  987. if (phy->port_reset_status == PORT_RESET_TMO) {
  988. pm8001_dev_gone_notify(dev);
  989. PM8001_CHIP_DISP->hw_event_ack_req(
  990. pm8001_ha, 0,
  991. 0x07, /*HW_EVENT_PHY_DOWN ack*/
  992. port_id, phy_id, 0, 0);
  993. goto out;
  994. }
  995. }
  996. /*
  997. * 4. SATA Abort ALL
  998. * we wait for the task to be aborted so that the task
  999. * is removed from the ccb. on success the caller is
  1000. * going to free the task.
  1001. */
  1002. ret = sas_execute_internal_abort_dev(dev, 0, NULL);
  1003. if (ret)
  1004. goto out;
  1005. ret = wait_for_completion_timeout(
  1006. &task->slow_task->completion,
  1007. PM8001_TASK_TIMEOUT * HZ);
  1008. if (!ret)
  1009. goto out;
  1010. /* 5. Set Device State as Operational */
  1011. reinit_completion(&completion);
  1012. pm8001_dev->setds_completion = &completion;
  1013. PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  1014. pm8001_dev, DS_OPERATIONAL);
  1015. wait_for_completion(&completion);
  1016. } else {
  1017. ret = sas_execute_internal_abort_single(dev, tag, 0, NULL);
  1018. }
  1019. rc = TMF_RESP_FUNC_COMPLETE;
  1020. } else if (task->task_proto & SAS_PROTOCOL_SMP) {
  1021. /* SMP */
  1022. rc = sas_execute_internal_abort_single(dev, tag, 0, NULL);
  1023. }
  1024. out:
  1025. spin_lock_irqsave(&task->task_state_lock, flags);
  1026. if (task->slow_task == &slow_task)
  1027. task->slow_task = NULL;
  1028. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1029. if (rc != TMF_RESP_FUNC_COMPLETE)
  1030. pm8001_info(pm8001_ha, "rc= %d\n", rc);
  1031. return rc;
  1032. }
  1033. int pm8001_clear_task_set(struct domain_device *dev, u8 *lun)
  1034. {
  1035. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1036. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1037. pm8001_dbg(pm8001_ha, EH, "I_T_L_Q clear task set[%x]\n",
  1038. pm8001_dev->device_id);
  1039. return sas_clear_task_set(dev, lun);
  1040. }
  1041. void pm8001_port_formed(struct asd_sas_phy *sas_phy)
  1042. {
  1043. struct sas_ha_struct *sas_ha = sas_phy->ha;
  1044. struct pm8001_hba_info *pm8001_ha = sas_ha->lldd_ha;
  1045. struct pm8001_phy *phy = sas_phy->lldd_phy;
  1046. struct asd_sas_port *sas_port = sas_phy->port;
  1047. struct pm8001_port *port = phy->port;
  1048. if (!sas_port) {
  1049. pm8001_dbg(pm8001_ha, FAIL, "Received null port\n");
  1050. return;
  1051. }
  1052. sas_port->lldd_port = port;
  1053. }
  1054. void pm8001_setds_completion(struct domain_device *dev)
  1055. {
  1056. struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev);
  1057. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  1058. DECLARE_COMPLETION_ONSTACK(completion_setstate);
  1059. if (pm8001_ha->chip_id != chip_8001) {
  1060. pm8001_dev->setds_completion = &completion_setstate;
  1061. PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
  1062. pm8001_dev, DS_OPERATIONAL);
  1063. wait_for_completion(&completion_setstate);
  1064. }
  1065. }
  1066. void pm8001_tmf_aborted(struct sas_task *task)
  1067. {
  1068. struct pm8001_ccb_info *ccb = task->lldd_task;
  1069. if (ccb)
  1070. ccb->task = NULL;
  1071. }