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