2 * Marvell 88SE64xx/88SE94xx main function
4 * Copyright 2007 Red Hat, Inc.
5 * Copyright 2008 Marvell. <kewei@marvell.com>
6 * Copyright 2009-2011 Marvell. <yuxiangl@marvell.com>
8 * This file is licensed under GPLv2.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; version 2 of the
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 static int mvs_find_tag(struct mvs_info
*mvi
, struct sas_task
*task
, u32
*tag
)
30 if (task
->lldd_task
) {
31 struct mvs_slot_info
*slot
;
32 slot
= task
->lldd_task
;
33 *tag
= slot
->slot_tag
;
39 void mvs_tag_clear(struct mvs_info
*mvi
, u32 tag
)
41 void *bitmap
= mvi
->tags
;
42 clear_bit(tag
, bitmap
);
45 void mvs_tag_free(struct mvs_info
*mvi
, u32 tag
)
47 mvs_tag_clear(mvi
, tag
);
50 void mvs_tag_set(struct mvs_info
*mvi
, unsigned int tag
)
52 void *bitmap
= mvi
->tags
;
56 inline int mvs_tag_alloc(struct mvs_info
*mvi
, u32
*tag_out
)
58 unsigned int index
, tag
;
59 void *bitmap
= mvi
->tags
;
61 index
= find_first_zero_bit(bitmap
, mvi
->tags_num
);
63 if (tag
>= mvi
->tags_num
)
64 return -SAS_QUEUE_FULL
;
65 mvs_tag_set(mvi
, tag
);
70 void mvs_tag_init(struct mvs_info
*mvi
)
73 for (i
= 0; i
< mvi
->tags_num
; ++i
)
74 mvs_tag_clear(mvi
, i
);
77 struct mvs_info
*mvs_find_dev_mvi(struct domain_device
*dev
)
79 unsigned long i
= 0, j
= 0, hi
= 0;
80 struct sas_ha_struct
*sha
= dev
->port
->ha
;
81 struct mvs_info
*mvi
= NULL
;
82 struct asd_sas_phy
*phy
;
84 while (sha
->sas_port
[i
]) {
85 if (sha
->sas_port
[i
] == dev
->port
) {
86 phy
= container_of(sha
->sas_port
[i
]->phy_list
.next
,
87 struct asd_sas_phy
, port_phy_el
);
89 while (sha
->sas_phy
[j
]) {
90 if (sha
->sas_phy
[j
] == phy
)
98 hi
= j
/((struct mvs_prv_info
*)sha
->lldd_ha
)->n_phy
;
99 mvi
= ((struct mvs_prv_info
*)sha
->lldd_ha
)->mvi
[hi
];
105 int mvs_find_dev_phyno(struct domain_device
*dev
, int *phyno
)
107 unsigned long i
= 0, j
= 0, n
= 0, num
= 0;
108 struct mvs_device
*mvi_dev
= (struct mvs_device
*)dev
->lldd_dev
;
109 struct mvs_info
*mvi
= mvi_dev
->mvi_info
;
110 struct sas_ha_struct
*sha
= dev
->port
->ha
;
112 while (sha
->sas_port
[i
]) {
113 if (sha
->sas_port
[i
] == dev
->port
) {
114 struct asd_sas_phy
*phy
;
115 list_for_each_entry(phy
,
116 &sha
->sas_port
[i
]->phy_list
, port_phy_el
) {
118 while (sha
->sas_phy
[j
]) {
119 if (sha
->sas_phy
[j
] == phy
)
123 phyno
[n
] = (j
>= mvi
->chip
->n_phy
) ?
124 (j
- mvi
->chip
->n_phy
) : j
;
135 struct mvs_device
*mvs_find_dev_by_reg_set(struct mvs_info
*mvi
,
139 for (dev_no
= 0; dev_no
< MVS_MAX_DEVICES
; dev_no
++) {
140 if (mvi
->devices
[dev_no
].taskfileset
== MVS_ID_NOT_MAPPED
)
143 if (mvi
->devices
[dev_no
].taskfileset
== reg_set
)
144 return &mvi
->devices
[dev_no
];
149 static inline void mvs_free_reg_set(struct mvs_info
*mvi
,
150 struct mvs_device
*dev
)
153 mv_printk("device has been free.\n");
156 if (dev
->taskfileset
== MVS_ID_NOT_MAPPED
)
158 MVS_CHIP_DISP
->free_reg_set(mvi
, &dev
->taskfileset
);
161 static inline u8
mvs_assign_reg_set(struct mvs_info
*mvi
,
162 struct mvs_device
*dev
)
164 if (dev
->taskfileset
!= MVS_ID_NOT_MAPPED
)
166 return MVS_CHIP_DISP
->assign_reg_set(mvi
, &dev
->taskfileset
);
169 void mvs_phys_reset(struct mvs_info
*mvi
, u32 phy_mask
, int hard
)
172 for_each_phy(phy_mask
, phy_mask
, no
) {
175 MVS_CHIP_DISP
->phy_reset(mvi
, no
, hard
);
179 int mvs_phy_control(struct asd_sas_phy
*sas_phy
, enum phy_func func
,
182 int rc
= 0, phy_id
= sas_phy
->id
;
184 struct sas_ha_struct
*sha
= sas_phy
->ha
;
185 struct mvs_info
*mvi
= NULL
;
187 while (sha
->sas_phy
[i
]) {
188 if (sha
->sas_phy
[i
] == sas_phy
)
192 hi
= i
/((struct mvs_prv_info
*)sha
->lldd_ha
)->n_phy
;
193 mvi
= ((struct mvs_prv_info
*)sha
->lldd_ha
)->mvi
[hi
];
196 case PHY_FUNC_SET_LINK_RATE
:
197 MVS_CHIP_DISP
->phy_set_link_rate(mvi
, phy_id
, funcdata
);
200 case PHY_FUNC_HARD_RESET
:
201 tmp
= MVS_CHIP_DISP
->read_phy_ctl(mvi
, phy_id
);
202 if (tmp
& PHY_RST_HARD
)
204 MVS_CHIP_DISP
->phy_reset(mvi
, phy_id
, MVS_HARD_RESET
);
207 case PHY_FUNC_LINK_RESET
:
208 MVS_CHIP_DISP
->phy_enable(mvi
, phy_id
);
209 MVS_CHIP_DISP
->phy_reset(mvi
, phy_id
, MVS_SOFT_RESET
);
212 case PHY_FUNC_DISABLE
:
213 MVS_CHIP_DISP
->phy_disable(mvi
, phy_id
);
215 case PHY_FUNC_RELEASE_SPINUP_HOLD
:
223 void mvs_set_sas_addr(struct mvs_info
*mvi
, int port_id
, u32 off_lo
,
224 u32 off_hi
, u64 sas_addr
)
226 u32 lo
= (u32
)sas_addr
;
227 u32 hi
= (u32
)(sas_addr
>>32);
229 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, port_id
, off_lo
);
230 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, port_id
, lo
);
231 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, port_id
, off_hi
);
232 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, port_id
, hi
);
235 static void mvs_bytes_dmaed(struct mvs_info
*mvi
, int i
)
237 struct mvs_phy
*phy
= &mvi
->phy
[i
];
238 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
239 struct sas_ha_struct
*sas_ha
;
240 if (!phy
->phy_attached
)
243 if (!(phy
->att_dev_info
& PORT_DEV_TRGT_MASK
)
244 && phy
->phy_type
& PORT_TYPE_SAS
) {
249 sas_ha
->notify_phy_event(sas_phy
, PHYE_OOB_DONE
);
252 struct sas_phy
*sphy
= sas_phy
->phy
;
254 sphy
->negotiated_linkrate
= sas_phy
->linkrate
;
255 sphy
->minimum_linkrate
= phy
->minimum_linkrate
;
256 sphy
->minimum_linkrate_hw
= SAS_LINK_RATE_1_5_GBPS
;
257 sphy
->maximum_linkrate
= phy
->maximum_linkrate
;
258 sphy
->maximum_linkrate_hw
= MVS_CHIP_DISP
->phy_max_link_rate();
261 if (phy
->phy_type
& PORT_TYPE_SAS
) {
262 struct sas_identify_frame
*id
;
264 id
= (struct sas_identify_frame
*)phy
->frame_rcvd
;
265 id
->dev_type
= phy
->identify
.device_type
;
266 id
->initiator_bits
= SAS_PROTOCOL_ALL
;
267 id
->target_bits
= phy
->identify
.target_port_protocols
;
269 /* direct attached SAS device */
270 if (phy
->att_dev_info
& PORT_SSP_TRGT_MASK
) {
271 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_PHY_STAT
);
272 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, i
, 0x00);
274 } else if (phy
->phy_type
& PORT_TYPE_SATA
) {
277 mv_dprintk("phy %d byte dmaded.\n", i
+ mvi
->id
* mvi
->chip
->n_phy
);
279 sas_phy
->frame_rcvd_size
= phy
->frame_rcvd_size
;
281 mvi
->sas
->notify_port_event(sas_phy
,
285 void mvs_scan_start(struct Scsi_Host
*shost
)
288 unsigned short core_nr
;
289 struct mvs_info
*mvi
;
290 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
291 struct mvs_prv_info
*mvs_prv
= sha
->lldd_ha
;
293 core_nr
= ((struct mvs_prv_info
*)sha
->lldd_ha
)->n_host
;
295 for (j
= 0; j
< core_nr
; j
++) {
296 mvi
= ((struct mvs_prv_info
*)sha
->lldd_ha
)->mvi
[j
];
297 for (i
= 0; i
< mvi
->chip
->n_phy
; ++i
)
298 mvs_bytes_dmaed(mvi
, i
);
300 mvs_prv
->scan_finished
= 1;
303 int mvs_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
305 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
306 struct mvs_prv_info
*mvs_prv
= sha
->lldd_ha
;
308 if (mvs_prv
->scan_finished
== 0)
315 static int mvs_task_prep_smp(struct mvs_info
*mvi
,
316 struct mvs_task_exec_info
*tei
)
319 struct sas_ha_struct
*sha
= mvi
->sas
;
320 struct sas_task
*task
= tei
->task
;
321 struct mvs_cmd_hdr
*hdr
= tei
->hdr
;
322 struct domain_device
*dev
= task
->dev
;
323 struct asd_sas_port
*sas_port
= dev
->port
;
324 struct sas_phy
*sphy
= dev
->phy
;
325 struct asd_sas_phy
*sas_phy
= sha
->sas_phy
[sphy
->number
];
326 struct scatterlist
*sg_req
, *sg_resp
;
327 u32 req_len
, resp_len
, tag
= tei
->tag
;
330 dma_addr_t buf_tmp_dma
;
332 struct mvs_slot_info
*slot
= &mvi
->slot_info
[tag
];
333 u32 flags
= (tei
->n_elem
<< MCH_PRD_LEN_SHIFT
);
336 * DMA-map SMP request, response buffers
338 sg_req
= &task
->smp_task
.smp_req
;
339 elem
= dma_map_sg(mvi
->dev
, sg_req
, 1, PCI_DMA_TODEVICE
);
342 req_len
= sg_dma_len(sg_req
);
344 sg_resp
= &task
->smp_task
.smp_resp
;
345 elem
= dma_map_sg(mvi
->dev
, sg_resp
, 1, PCI_DMA_FROMDEVICE
);
350 resp_len
= SB_RFB_MAX
;
352 /* must be in dwords */
353 if ((req_len
& 0x3) || (resp_len
& 0x3)) {
359 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
362 /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ***** */
364 buf_tmp_dma
= slot
->buf_dma
;
366 hdr
->cmd_tbl
= cpu_to_le64(sg_dma_address(sg_req
));
368 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
370 hdr
->open_frame
= cpu_to_le64(buf_tmp_dma
);
372 buf_tmp
+= MVS_OAF_SZ
;
373 buf_tmp_dma
+= MVS_OAF_SZ
;
375 /* region 3: PRD table *********************************** */
378 hdr
->prd_tbl
= cpu_to_le64(buf_tmp_dma
);
382 i
= MVS_CHIP_DISP
->prd_size() * tei
->n_elem
;
386 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
387 slot
->response
= buf_tmp
;
388 hdr
->status_buf
= cpu_to_le64(buf_tmp_dma
);
389 if (mvi
->flags
& MVF_FLAG_SOC
)
390 hdr
->reserved
[0] = 0;
393 * Fill in TX ring and command slot header
395 slot
->tx
= mvi
->tx_prod
;
396 mvi
->tx
[mvi
->tx_prod
] = cpu_to_le32((TXQ_CMD_SMP
<< TXQ_CMD_SHIFT
) |
398 (MVS_PHY_ID
<< TXQ_PHY_SHIFT
));
401 hdr
->lens
= cpu_to_le32(((resp_len
/ 4) << 16) | ((req_len
- 4) / 4));
402 hdr
->tags
= cpu_to_le32(tag
);
405 /* generate open address frame hdr (first 12 bytes) */
406 /* initiator, SMP, ftype 1h */
407 buf_oaf
[0] = (1 << 7) | (PROTOCOL_SMP
<< 4) | 0x01;
408 buf_oaf
[1] = min(sas_port
->linkrate
, dev
->linkrate
) & 0xf;
409 *(u16
*)(buf_oaf
+ 2) = 0xFFFF; /* SAS SPEC */
410 memcpy(buf_oaf
+ 4, dev
->sas_addr
, SAS_ADDR_SIZE
);
412 /* fill in PRD (scatter/gather) table, if any */
413 MVS_CHIP_DISP
->make_prd(task
->scatter
, tei
->n_elem
, buf_prd
);
418 dma_unmap_sg(mvi
->dev
, &tei
->task
->smp_task
.smp_resp
, 1,
421 dma_unmap_sg(mvi
->dev
, &tei
->task
->smp_task
.smp_req
, 1,
426 static u32
mvs_get_ncq_tag(struct sas_task
*task
, u32
*tag
)
428 struct ata_queued_cmd
*qc
= task
->uldd_task
;
431 if (qc
->tf
.command
== ATA_CMD_FPDMA_WRITE
||
432 qc
->tf
.command
== ATA_CMD_FPDMA_READ
) {
441 static int mvs_task_prep_ata(struct mvs_info
*mvi
,
442 struct mvs_task_exec_info
*tei
)
444 struct sas_task
*task
= tei
->task
;
445 struct domain_device
*dev
= task
->dev
;
446 struct mvs_device
*mvi_dev
= dev
->lldd_dev
;
447 struct mvs_cmd_hdr
*hdr
= tei
->hdr
;
448 struct asd_sas_port
*sas_port
= dev
->port
;
449 struct mvs_slot_info
*slot
;
451 u32 tag
= tei
->tag
, hdr_tag
;
454 u8
*buf_cmd
, *buf_oaf
;
455 dma_addr_t buf_tmp_dma
;
456 u32 i
, req_len
, resp_len
;
457 const u32 max_resp_len
= SB_RFB_MAX
;
459 if (mvs_assign_reg_set(mvi
, mvi_dev
) == MVS_ID_NOT_MAPPED
) {
460 mv_dprintk("Have not enough regiset for dev %d.\n",
464 slot
= &mvi
->slot_info
[tag
];
465 slot
->tx
= mvi
->tx_prod
;
466 del_q
= TXQ_MODE_I
| tag
|
467 (TXQ_CMD_STP
<< TXQ_CMD_SHIFT
) |
468 ((sas_port
->phy_mask
& TXQ_PHY_MASK
) << TXQ_PHY_SHIFT
) |
469 (mvi_dev
->taskfileset
<< TXQ_SRS_SHIFT
);
470 mvi
->tx
[mvi
->tx_prod
] = cpu_to_le32(del_q
);
472 if (task
->data_dir
== DMA_FROM_DEVICE
)
473 flags
= (MVS_CHIP_DISP
->prd_count() << MCH_PRD_LEN_SHIFT
);
475 flags
= (tei
->n_elem
<< MCH_PRD_LEN_SHIFT
);
477 if (task
->ata_task
.use_ncq
)
479 if (dev
->sata_dev
.class == ATA_DEV_ATAPI
) {
480 if (task
->ata_task
.fis
.command
!= ATA_CMD_ID_ATAPI
)
484 hdr
->flags
= cpu_to_le32(flags
);
486 if (task
->ata_task
.use_ncq
&& mvs_get_ncq_tag(task
, &hdr_tag
))
487 task
->ata_task
.fis
.sector_count
|= (u8
) (hdr_tag
<< 3);
491 hdr
->tags
= cpu_to_le32(hdr_tag
);
493 hdr
->data_len
= cpu_to_le32(task
->total_xfer_len
);
496 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
499 /* region 1: command table area (MVS_ATA_CMD_SZ bytes) ************** */
500 buf_cmd
= buf_tmp
= slot
->buf
;
501 buf_tmp_dma
= slot
->buf_dma
;
503 hdr
->cmd_tbl
= cpu_to_le64(buf_tmp_dma
);
505 buf_tmp
+= MVS_ATA_CMD_SZ
;
506 buf_tmp_dma
+= MVS_ATA_CMD_SZ
;
508 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
509 /* used for STP. unused for SATA? */
511 hdr
->open_frame
= cpu_to_le64(buf_tmp_dma
);
513 buf_tmp
+= MVS_OAF_SZ
;
514 buf_tmp_dma
+= MVS_OAF_SZ
;
516 /* region 3: PRD table ********************************************* */
520 hdr
->prd_tbl
= cpu_to_le64(buf_tmp_dma
);
523 i
= MVS_CHIP_DISP
->prd_size() * MVS_CHIP_DISP
->prd_count();
528 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
529 slot
->response
= buf_tmp
;
530 hdr
->status_buf
= cpu_to_le64(buf_tmp_dma
);
531 if (mvi
->flags
& MVF_FLAG_SOC
)
532 hdr
->reserved
[0] = 0;
534 req_len
= sizeof(struct host_to_dev_fis
);
535 resp_len
= MVS_SLOT_BUF_SZ
- MVS_ATA_CMD_SZ
-
536 sizeof(struct mvs_err_info
) - i
;
538 /* request, response lengths */
539 resp_len
= min(resp_len
, max_resp_len
);
540 hdr
->lens
= cpu_to_le32(((resp_len
/ 4) << 16) | (req_len
/ 4));
542 if (likely(!task
->ata_task
.device_control_reg_update
))
543 task
->ata_task
.fis
.flags
|= 0x80; /* C=1: update ATA cmd reg */
544 /* fill in command FIS and ATAPI CDB */
545 memcpy(buf_cmd
, &task
->ata_task
.fis
, sizeof(struct host_to_dev_fis
));
546 if (dev
->sata_dev
.class == ATA_DEV_ATAPI
)
547 memcpy(buf_cmd
+ STP_ATAPI_CMD
,
548 task
->ata_task
.atapi_packet
, 16);
550 /* generate open address frame hdr (first 12 bytes) */
551 /* initiator, STP, ftype 1h */
552 buf_oaf
[0] = (1 << 7) | (PROTOCOL_STP
<< 4) | 0x1;
553 buf_oaf
[1] = min(sas_port
->linkrate
, dev
->linkrate
) & 0xf;
554 *(u16
*)(buf_oaf
+ 2) = cpu_to_be16(mvi_dev
->device_id
+ 1);
555 memcpy(buf_oaf
+ 4, dev
->sas_addr
, SAS_ADDR_SIZE
);
557 /* fill in PRD (scatter/gather) table, if any */
558 MVS_CHIP_DISP
->make_prd(task
->scatter
, tei
->n_elem
, buf_prd
);
560 if (task
->data_dir
== DMA_FROM_DEVICE
)
561 MVS_CHIP_DISP
->dma_fix(mvi
, sas_port
->phy_mask
,
562 TRASH_BUCKET_SIZE
, tei
->n_elem
, buf_prd
);
567 static int mvs_task_prep_ssp(struct mvs_info
*mvi
,
568 struct mvs_task_exec_info
*tei
, int is_tmf
,
569 struct mvs_tmf_task
*tmf
)
571 struct sas_task
*task
= tei
->task
;
572 struct mvs_cmd_hdr
*hdr
= tei
->hdr
;
573 struct mvs_port
*port
= tei
->port
;
574 struct domain_device
*dev
= task
->dev
;
575 struct mvs_device
*mvi_dev
= dev
->lldd_dev
;
576 struct asd_sas_port
*sas_port
= dev
->port
;
577 struct mvs_slot_info
*slot
;
579 struct ssp_frame_hdr
*ssp_hdr
;
581 u8
*buf_cmd
, *buf_oaf
, fburst
= 0;
582 dma_addr_t buf_tmp_dma
;
584 u32 resp_len
, req_len
, i
, tag
= tei
->tag
;
585 const u32 max_resp_len
= SB_RFB_MAX
;
588 slot
= &mvi
->slot_info
[tag
];
590 phy_mask
= ((port
->wide_port_phymap
) ? port
->wide_port_phymap
:
591 sas_port
->phy_mask
) & TXQ_PHY_MASK
;
593 slot
->tx
= mvi
->tx_prod
;
594 mvi
->tx
[mvi
->tx_prod
] = cpu_to_le32(TXQ_MODE_I
| tag
|
595 (TXQ_CMD_SSP
<< TXQ_CMD_SHIFT
) |
596 (phy_mask
<< TXQ_PHY_SHIFT
));
599 if (task
->ssp_task
.enable_first_burst
) {
604 flags
|= (MCH_SSP_FR_TASK
<< MCH_SSP_FR_TYPE_SHIFT
);
606 flags
|= (MCH_SSP_FR_CMD
<< MCH_SSP_FR_TYPE_SHIFT
);
608 hdr
->flags
= cpu_to_le32(flags
| (tei
->n_elem
<< MCH_PRD_LEN_SHIFT
));
609 hdr
->tags
= cpu_to_le32(tag
);
610 hdr
->data_len
= cpu_to_le32(task
->total_xfer_len
);
613 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
616 /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ************** */
617 buf_cmd
= buf_tmp
= slot
->buf
;
618 buf_tmp_dma
= slot
->buf_dma
;
620 hdr
->cmd_tbl
= cpu_to_le64(buf_tmp_dma
);
622 buf_tmp
+= MVS_SSP_CMD_SZ
;
623 buf_tmp_dma
+= MVS_SSP_CMD_SZ
;
625 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
627 hdr
->open_frame
= cpu_to_le64(buf_tmp_dma
);
629 buf_tmp
+= MVS_OAF_SZ
;
630 buf_tmp_dma
+= MVS_OAF_SZ
;
632 /* region 3: PRD table ********************************************* */
635 hdr
->prd_tbl
= cpu_to_le64(buf_tmp_dma
);
639 i
= MVS_CHIP_DISP
->prd_size() * tei
->n_elem
;
643 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
644 slot
->response
= buf_tmp
;
645 hdr
->status_buf
= cpu_to_le64(buf_tmp_dma
);
646 if (mvi
->flags
& MVF_FLAG_SOC
)
647 hdr
->reserved
[0] = 0;
649 resp_len
= MVS_SLOT_BUF_SZ
- MVS_SSP_CMD_SZ
- MVS_OAF_SZ
-
650 sizeof(struct mvs_err_info
) - i
;
651 resp_len
= min(resp_len
, max_resp_len
);
653 req_len
= sizeof(struct ssp_frame_hdr
) + 28;
655 /* request, response lengths */
656 hdr
->lens
= cpu_to_le32(((resp_len
/ 4) << 16) | (req_len
/ 4));
658 /* generate open address frame hdr (first 12 bytes) */
659 /* initiator, SSP, ftype 1h */
660 buf_oaf
[0] = (1 << 7) | (PROTOCOL_SSP
<< 4) | 0x1;
661 buf_oaf
[1] = min(sas_port
->linkrate
, dev
->linkrate
) & 0xf;
662 *(u16
*)(buf_oaf
+ 2) = cpu_to_be16(mvi_dev
->device_id
+ 1);
663 memcpy(buf_oaf
+ 4, dev
->sas_addr
, SAS_ADDR_SIZE
);
665 /* fill in SSP frame header (Command Table.SSP frame header) */
666 ssp_hdr
= (struct ssp_frame_hdr
*)buf_cmd
;
669 ssp_hdr
->frame_type
= SSP_TASK
;
671 ssp_hdr
->frame_type
= SSP_COMMAND
;
673 memcpy(ssp_hdr
->hashed_dest_addr
, dev
->hashed_sas_addr
,
674 HASHED_SAS_ADDR_SIZE
);
675 memcpy(ssp_hdr
->hashed_src_addr
,
676 dev
->hashed_sas_addr
, HASHED_SAS_ADDR_SIZE
);
677 ssp_hdr
->tag
= cpu_to_be16(tag
);
679 /* fill in IU for TASK and Command Frame */
680 buf_cmd
+= sizeof(*ssp_hdr
);
681 memcpy(buf_cmd
, &task
->ssp_task
.LUN
, 8);
683 if (ssp_hdr
->frame_type
!= SSP_TASK
) {
684 buf_cmd
[9] = fburst
| task
->ssp_task
.task_attr
|
685 (task
->ssp_task
.task_prio
<< 3);
686 memcpy(buf_cmd
+ 12, task
->ssp_task
.cmd
->cmnd
,
687 task
->ssp_task
.cmd
->cmd_len
);
689 buf_cmd
[10] = tmf
->tmf
;
694 (tmf
->tag_of_task_to_be_managed
>> 8) & 0xff;
696 tmf
->tag_of_task_to_be_managed
& 0xff;
702 /* fill in PRD (scatter/gather) table, if any */
703 MVS_CHIP_DISP
->make_prd(task
->scatter
, tei
->n_elem
, buf_prd
);
707 #define DEV_IS_GONE(mvi_dev) ((!mvi_dev || (mvi_dev->dev_type == SAS_PHY_UNUSED)))
708 static int mvs_task_prep(struct sas_task
*task
, struct mvs_info
*mvi
, int is_tmf
,
709 struct mvs_tmf_task
*tmf
, int *pass
)
711 struct domain_device
*dev
= task
->dev
;
712 struct mvs_device
*mvi_dev
= dev
->lldd_dev
;
713 struct mvs_task_exec_info tei
;
714 struct mvs_slot_info
*slot
;
715 u32 tag
= 0xdeadbeef, n_elem
= 0;
719 struct task_status_struct
*tsm
= &task
->task_status
;
721 tsm
->resp
= SAS_TASK_UNDELIVERED
;
722 tsm
->stat
= SAS_PHY_DOWN
;
724 * libsas will use dev->port, should
725 * not call task_done for sata
727 if (dev
->dev_type
!= SAS_SATA_DEV
)
728 task
->task_done(task
);
732 if (DEV_IS_GONE(mvi_dev
)) {
734 mv_dprintk("device %d not ready.\n",
737 mv_dprintk("device %016llx not ready.\n",
738 SAS_ADDR(dev
->sas_addr
));
743 tei
.port
= dev
->port
->lldd_port
;
744 if (tei
.port
&& !tei
.port
->port_attached
&& !tmf
) {
745 if (sas_protocol_ata(task
->task_proto
)) {
746 struct task_status_struct
*ts
= &task
->task_status
;
747 mv_dprintk("SATA/STP port %d does not attach"
748 "device.\n", dev
->port
->id
);
749 ts
->resp
= SAS_TASK_COMPLETE
;
750 ts
->stat
= SAS_PHY_DOWN
;
752 task
->task_done(task
);
755 struct task_status_struct
*ts
= &task
->task_status
;
756 mv_dprintk("SAS port %d does not attach"
757 "device.\n", dev
->port
->id
);
758 ts
->resp
= SAS_TASK_UNDELIVERED
;
759 ts
->stat
= SAS_PHY_DOWN
;
760 task
->task_done(task
);
765 if (!sas_protocol_ata(task
->task_proto
)) {
766 if (task
->num_scatter
) {
767 n_elem
= dma_map_sg(mvi
->dev
,
777 n_elem
= task
->num_scatter
;
780 rc
= mvs_tag_alloc(mvi
, &tag
);
784 slot
= &mvi
->slot_info
[tag
];
786 task
->lldd_task
= NULL
;
787 slot
->n_elem
= n_elem
;
788 slot
->slot_tag
= tag
;
790 slot
->buf
= pci_pool_alloc(mvi
->dma_pool
, GFP_ATOMIC
, &slot
->buf_dma
);
793 memset(slot
->buf
, 0, MVS_SLOT_BUF_SZ
);
796 tei
.hdr
= &mvi
->slot
[tag
];
799 switch (task
->task_proto
) {
800 case SAS_PROTOCOL_SMP
:
801 rc
= mvs_task_prep_smp(mvi
, &tei
);
803 case SAS_PROTOCOL_SSP
:
804 rc
= mvs_task_prep_ssp(mvi
, &tei
, is_tmf
, tmf
);
806 case SAS_PROTOCOL_SATA
:
807 case SAS_PROTOCOL_STP
:
808 case SAS_PROTOCOL_SATA
| SAS_PROTOCOL_STP
:
809 rc
= mvs_task_prep_ata(mvi
, &tei
);
812 dev_printk(KERN_ERR
, mvi
->dev
,
813 "unknown sas_task proto: 0x%x\n",
820 mv_dprintk("rc is %x\n", rc
);
821 goto err_out_slot_buf
;
824 slot
->port
= tei
.port
;
825 task
->lldd_task
= slot
;
826 list_add_tail(&slot
->entry
, &tei
.port
->list
);
827 spin_lock(&task
->task_state_lock
);
828 task
->task_state_flags
|= SAS_TASK_AT_INITIATOR
;
829 spin_unlock(&task
->task_state_lock
);
831 mvi_dev
->running_req
++;
833 mvi
->tx_prod
= (mvi
->tx_prod
+ 1) & (MVS_CHIP_SLOT_SZ
- 1);
838 pci_pool_free(mvi
->dma_pool
, slot
->buf
, slot
->buf_dma
);
840 mvs_tag_free(mvi
, tag
);
843 dev_printk(KERN_ERR
, mvi
->dev
, "mvsas prep failed[%d]!\n", rc
);
844 if (!sas_protocol_ata(task
->task_proto
))
846 dma_unmap_sg(mvi
->dev
, task
->scatter
, n_elem
,
852 static int mvs_task_exec(struct sas_task
*task
, gfp_t gfp_flags
,
853 struct completion
*completion
, int is_tmf
,
854 struct mvs_tmf_task
*tmf
)
856 struct mvs_info
*mvi
= NULL
;
859 unsigned long flags
= 0;
861 mvi
= ((struct mvs_device
*)task
->dev
->lldd_dev
)->mvi_info
;
863 spin_lock_irqsave(&mvi
->lock
, flags
);
864 rc
= mvs_task_prep(task
, mvi
, is_tmf
, tmf
, &pass
);
866 dev_printk(KERN_ERR
, mvi
->dev
, "mvsas exec failed[%d]!\n", rc
);
869 MVS_CHIP_DISP
->start_delivery(mvi
, (mvi
->tx_prod
- 1) &
870 (MVS_CHIP_SLOT_SZ
- 1));
871 spin_unlock_irqrestore(&mvi
->lock
, flags
);
876 int mvs_queue_command(struct sas_task
*task
, gfp_t gfp_flags
)
878 return mvs_task_exec(task
, gfp_flags
, NULL
, 0, NULL
);
881 static void mvs_slot_free(struct mvs_info
*mvi
, u32 rx_desc
)
883 u32 slot_idx
= rx_desc
& RXQ_SLOT_MASK
;
884 mvs_tag_clear(mvi
, slot_idx
);
887 static void mvs_slot_task_free(struct mvs_info
*mvi
, struct sas_task
*task
,
888 struct mvs_slot_info
*slot
, u32 slot_idx
)
894 if (!sas_protocol_ata(task
->task_proto
))
896 dma_unmap_sg(mvi
->dev
, task
->scatter
,
897 slot
->n_elem
, task
->data_dir
);
899 switch (task
->task_proto
) {
900 case SAS_PROTOCOL_SMP
:
901 dma_unmap_sg(mvi
->dev
, &task
->smp_task
.smp_resp
, 1,
903 dma_unmap_sg(mvi
->dev
, &task
->smp_task
.smp_req
, 1,
907 case SAS_PROTOCOL_SATA
:
908 case SAS_PROTOCOL_STP
:
909 case SAS_PROTOCOL_SSP
:
916 pci_pool_free(mvi
->dma_pool
, slot
->buf
, slot
->buf_dma
);
919 list_del_init(&slot
->entry
);
920 task
->lldd_task
= NULL
;
923 slot
->slot_tag
= 0xFFFFFFFF;
924 mvs_slot_free(mvi
, slot_idx
);
927 static void mvs_update_wideport(struct mvs_info
*mvi
, int phy_no
)
929 struct mvs_phy
*phy
= &mvi
->phy
[phy_no
];
930 struct mvs_port
*port
= phy
->port
;
933 for_each_phy(port
->wide_port_phymap
, j
, no
) {
935 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, no
,
937 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, no
,
938 port
->wide_port_phymap
);
940 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, no
,
942 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, no
,
948 static u32
mvs_is_phy_ready(struct mvs_info
*mvi
, int i
)
951 struct mvs_phy
*phy
= &mvi
->phy
[i
];
952 struct mvs_port
*port
= phy
->port
;
954 tmp
= MVS_CHIP_DISP
->read_phy_ctl(mvi
, i
);
955 if ((tmp
& PHY_READY_MASK
) && !(phy
->irq_status
& PHYEV_POOF
)) {
957 phy
->phy_attached
= 1;
962 if (phy
->phy_type
& PORT_TYPE_SAS
) {
963 port
->wide_port_phymap
&= ~(1U << i
);
964 if (!port
->wide_port_phymap
)
965 port
->port_attached
= 0;
966 mvs_update_wideport(mvi
, i
);
967 } else if (phy
->phy_type
& PORT_TYPE_SATA
)
968 port
->port_attached
= 0;
970 phy
->phy_attached
= 0;
971 phy
->phy_type
&= ~(PORT_TYPE_SAS
| PORT_TYPE_SATA
);
976 static void *mvs_get_d2h_reg(struct mvs_info
*mvi
, int i
, void *buf
)
978 u32
*s
= (u32
*) buf
;
983 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_SATA_SIG3
);
984 s
[3] = cpu_to_le32(MVS_CHIP_DISP
->read_port_cfg_data(mvi
, i
));
986 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_SATA_SIG2
);
987 s
[2] = cpu_to_le32(MVS_CHIP_DISP
->read_port_cfg_data(mvi
, i
));
989 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_SATA_SIG1
);
990 s
[1] = cpu_to_le32(MVS_CHIP_DISP
->read_port_cfg_data(mvi
, i
));
992 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_SATA_SIG0
);
993 s
[0] = cpu_to_le32(MVS_CHIP_DISP
->read_port_cfg_data(mvi
, i
));
995 if (((s
[1] & 0x00FFFFFF) == 0x00EB1401) && (*(u8
*)&s
[3] == 0x01))
996 s
[1] = 0x00EB1401 | (*((u8
*)&s
[1] + 3) & 0x10);
1001 static u32
mvs_is_sig_fis_received(u32 irq_status
)
1003 return irq_status
& PHYEV_SIG_FIS
;
1006 static void mvs_sig_remove_timer(struct mvs_phy
*phy
)
1008 if (phy
->timer
.function
)
1009 del_timer(&phy
->timer
);
1010 phy
->timer
.function
= NULL
;
1013 void mvs_update_phyinfo(struct mvs_info
*mvi
, int i
, int get_st
)
1015 struct mvs_phy
*phy
= &mvi
->phy
[i
];
1016 struct sas_identify_frame
*id
;
1018 id
= (struct sas_identify_frame
*)phy
->frame_rcvd
;
1021 phy
->irq_status
= MVS_CHIP_DISP
->read_port_irq_stat(mvi
, i
);
1022 phy
->phy_status
= mvs_is_phy_ready(mvi
, i
);
1025 if (phy
->phy_status
) {
1027 struct asd_sas_phy
*sas_phy
= &mvi
->phy
[i
].sas_phy
;
1029 oob_done
= MVS_CHIP_DISP
->oob_done(mvi
, i
);
1031 MVS_CHIP_DISP
->fix_phy_info(mvi
, i
, id
);
1032 if (phy
->phy_type
& PORT_TYPE_SATA
) {
1033 phy
->identify
.target_port_protocols
= SAS_PROTOCOL_STP
;
1034 if (mvs_is_sig_fis_received(phy
->irq_status
)) {
1035 mvs_sig_remove_timer(phy
);
1036 phy
->phy_attached
= 1;
1037 phy
->att_dev_sas_addr
=
1038 i
+ mvi
->id
* mvi
->chip
->n_phy
;
1040 sas_phy
->oob_mode
= SATA_OOB_MODE
;
1041 phy
->frame_rcvd_size
=
1042 sizeof(struct dev_to_host_fis
);
1043 mvs_get_d2h_reg(mvi
, i
, id
);
1046 dev_printk(KERN_DEBUG
, mvi
->dev
,
1047 "Phy%d : No sig fis\n", i
);
1048 tmp
= MVS_CHIP_DISP
->read_port_irq_mask(mvi
, i
);
1049 MVS_CHIP_DISP
->write_port_irq_mask(mvi
, i
,
1050 tmp
| PHYEV_SIG_FIS
);
1051 phy
->phy_attached
= 0;
1052 phy
->phy_type
&= ~PORT_TYPE_SATA
;
1055 } else if (phy
->phy_type
& PORT_TYPE_SAS
1056 || phy
->att_dev_info
& PORT_SSP_INIT_MASK
) {
1057 phy
->phy_attached
= 1;
1058 phy
->identify
.device_type
=
1059 phy
->att_dev_info
& PORT_DEV_TYPE_MASK
;
1061 if (phy
->identify
.device_type
== SAS_END_DEVICE
)
1062 phy
->identify
.target_port_protocols
=
1064 else if (phy
->identify
.device_type
!= SAS_PHY_UNUSED
)
1065 phy
->identify
.target_port_protocols
=
1068 sas_phy
->oob_mode
= SAS_OOB_MODE
;
1069 phy
->frame_rcvd_size
=
1070 sizeof(struct sas_identify_frame
);
1072 memcpy(sas_phy
->attached_sas_addr
,
1073 &phy
->att_dev_sas_addr
, SAS_ADDR_SIZE
);
1075 if (MVS_CHIP_DISP
->phy_work_around
)
1076 MVS_CHIP_DISP
->phy_work_around(mvi
, i
);
1078 mv_dprintk("phy %d attach dev info is %x\n",
1079 i
+ mvi
->id
* mvi
->chip
->n_phy
, phy
->att_dev_info
);
1080 mv_dprintk("phy %d attach sas addr is %llx\n",
1081 i
+ mvi
->id
* mvi
->chip
->n_phy
, phy
->att_dev_sas_addr
);
1084 MVS_CHIP_DISP
->write_port_irq_stat(mvi
, i
, phy
->irq_status
);
1087 static void mvs_port_notify_formed(struct asd_sas_phy
*sas_phy
, int lock
)
1089 struct sas_ha_struct
*sas_ha
= sas_phy
->ha
;
1090 struct mvs_info
*mvi
= NULL
; int i
= 0, hi
;
1091 struct mvs_phy
*phy
= sas_phy
->lldd_phy
;
1092 struct asd_sas_port
*sas_port
= sas_phy
->port
;
1093 struct mvs_port
*port
;
1094 unsigned long flags
= 0;
1098 while (sas_ha
->sas_phy
[i
]) {
1099 if (sas_ha
->sas_phy
[i
] == sas_phy
)
1103 hi
= i
/((struct mvs_prv_info
*)sas_ha
->lldd_ha
)->n_phy
;
1104 mvi
= ((struct mvs_prv_info
*)sas_ha
->lldd_ha
)->mvi
[hi
];
1105 if (i
>= mvi
->chip
->n_phy
)
1106 port
= &mvi
->port
[i
- mvi
->chip
->n_phy
];
1108 port
= &mvi
->port
[i
];
1110 spin_lock_irqsave(&mvi
->lock
, flags
);
1111 port
->port_attached
= 1;
1113 sas_port
->lldd_port
= port
;
1114 if (phy
->phy_type
& PORT_TYPE_SAS
) {
1115 port
->wide_port_phymap
= sas_port
->phy_mask
;
1116 mv_printk("set wide port phy map %x\n", sas_port
->phy_mask
);
1117 mvs_update_wideport(mvi
, sas_phy
->id
);
1119 /* direct attached SAS device */
1120 if (phy
->att_dev_info
& PORT_SSP_TRGT_MASK
) {
1121 MVS_CHIP_DISP
->write_port_cfg_addr(mvi
, i
, PHYR_PHY_STAT
);
1122 MVS_CHIP_DISP
->write_port_cfg_data(mvi
, i
, 0x04);
1126 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1129 static void mvs_port_notify_deformed(struct asd_sas_phy
*sas_phy
, int lock
)
1131 struct domain_device
*dev
;
1132 struct mvs_phy
*phy
= sas_phy
->lldd_phy
;
1133 struct mvs_info
*mvi
= phy
->mvi
;
1134 struct asd_sas_port
*port
= sas_phy
->port
;
1137 while (phy
!= &mvi
->phy
[phy_no
]) {
1139 if (phy_no
>= MVS_MAX_PHYS
)
1142 list_for_each_entry(dev
, &port
->dev_list
, dev_list_node
)
1143 mvs_do_release_task(phy
->mvi
, phy_no
, dev
);
1148 void mvs_port_formed(struct asd_sas_phy
*sas_phy
)
1150 mvs_port_notify_formed(sas_phy
, 1);
1153 void mvs_port_deformed(struct asd_sas_phy
*sas_phy
)
1155 mvs_port_notify_deformed(sas_phy
, 1);
1158 struct mvs_device
*mvs_alloc_dev(struct mvs_info
*mvi
)
1161 for (dev
= 0; dev
< MVS_MAX_DEVICES
; dev
++) {
1162 if (mvi
->devices
[dev
].dev_type
== SAS_PHY_UNUSED
) {
1163 mvi
->devices
[dev
].device_id
= dev
;
1164 return &mvi
->devices
[dev
];
1168 if (dev
== MVS_MAX_DEVICES
)
1169 mv_printk("max support %d devices, ignore ..\n",
1175 void mvs_free_dev(struct mvs_device
*mvi_dev
)
1177 u32 id
= mvi_dev
->device_id
;
1178 memset(mvi_dev
, 0, sizeof(*mvi_dev
));
1179 mvi_dev
->device_id
= id
;
1180 mvi_dev
->dev_type
= SAS_PHY_UNUSED
;
1181 mvi_dev
->dev_status
= MVS_DEV_NORMAL
;
1182 mvi_dev
->taskfileset
= MVS_ID_NOT_MAPPED
;
1185 int mvs_dev_found_notify(struct domain_device
*dev
, int lock
)
1187 unsigned long flags
= 0;
1189 struct mvs_info
*mvi
= NULL
;
1190 struct domain_device
*parent_dev
= dev
->parent
;
1191 struct mvs_device
*mvi_device
;
1193 mvi
= mvs_find_dev_mvi(dev
);
1196 spin_lock_irqsave(&mvi
->lock
, flags
);
1198 mvi_device
= mvs_alloc_dev(mvi
);
1203 dev
->lldd_dev
= mvi_device
;
1204 mvi_device
->dev_status
= MVS_DEV_NORMAL
;
1205 mvi_device
->dev_type
= dev
->dev_type
;
1206 mvi_device
->mvi_info
= mvi
;
1207 mvi_device
->sas_device
= dev
;
1208 if (parent_dev
&& DEV_IS_EXPANDER(parent_dev
->dev_type
)) {
1210 u8 phy_num
= parent_dev
->ex_dev
.num_phys
;
1212 for (phy_id
= 0; phy_id
< phy_num
; phy_id
++) {
1213 phy
= &parent_dev
->ex_dev
.ex_phy
[phy_id
];
1214 if (SAS_ADDR(phy
->attached_sas_addr
) ==
1215 SAS_ADDR(dev
->sas_addr
)) {
1216 mvi_device
->attached_phy
= phy_id
;
1221 if (phy_id
== phy_num
) {
1222 mv_printk("Error: no attached dev:%016llx"
1224 SAS_ADDR(dev
->sas_addr
),
1225 SAS_ADDR(parent_dev
->sas_addr
));
1232 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1236 int mvs_dev_found(struct domain_device
*dev
)
1238 return mvs_dev_found_notify(dev
, 1);
1241 void mvs_dev_gone_notify(struct domain_device
*dev
)
1243 unsigned long flags
= 0;
1244 struct mvs_device
*mvi_dev
= dev
->lldd_dev
;
1245 struct mvs_info
*mvi
;
1248 mv_dprintk("found dev has gone.\n");
1252 mvi
= mvi_dev
->mvi_info
;
1254 spin_lock_irqsave(&mvi
->lock
, flags
);
1256 mv_dprintk("found dev[%d:%x] is gone.\n",
1257 mvi_dev
->device_id
, mvi_dev
->dev_type
);
1258 mvs_release_task(mvi
, dev
);
1259 mvs_free_reg_set(mvi
, mvi_dev
);
1260 mvs_free_dev(mvi_dev
);
1262 dev
->lldd_dev
= NULL
;
1263 mvi_dev
->sas_device
= NULL
;
1265 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1269 void mvs_dev_gone(struct domain_device
*dev
)
1271 mvs_dev_gone_notify(dev
);
1274 static void mvs_task_done(struct sas_task
*task
)
1276 if (!del_timer(&task
->slow_task
->timer
))
1278 complete(&task
->slow_task
->completion
);
1281 static void mvs_tmf_timedout(unsigned long data
)
1283 struct sas_task
*task
= (struct sas_task
*)data
;
1285 task
->task_state_flags
|= SAS_TASK_STATE_ABORTED
;
1286 complete(&task
->slow_task
->completion
);
1289 #define MVS_TASK_TIMEOUT 20
1290 static int mvs_exec_internal_tmf_task(struct domain_device
*dev
,
1291 void *parameter
, u32 para_len
, struct mvs_tmf_task
*tmf
)
1294 struct sas_task
*task
= NULL
;
1296 for (retry
= 0; retry
< 3; retry
++) {
1297 task
= sas_alloc_slow_task(GFP_KERNEL
);
1302 task
->task_proto
= dev
->tproto
;
1304 memcpy(&task
->ssp_task
, parameter
, para_len
);
1305 task
->task_done
= mvs_task_done
;
1307 task
->slow_task
->timer
.data
= (unsigned long) task
;
1308 task
->slow_task
->timer
.function
= mvs_tmf_timedout
;
1309 task
->slow_task
->timer
.expires
= jiffies
+ MVS_TASK_TIMEOUT
*HZ
;
1310 add_timer(&task
->slow_task
->timer
);
1312 res
= mvs_task_exec(task
, GFP_KERNEL
, NULL
, 1, tmf
);
1315 del_timer(&task
->slow_task
->timer
);
1316 mv_printk("executing internal task failed:%d\n", res
);
1320 wait_for_completion(&task
->slow_task
->completion
);
1321 res
= TMF_RESP_FUNC_FAILED
;
1322 /* Even TMF timed out, return direct. */
1323 if ((task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
1324 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
)) {
1325 mv_printk("TMF task[%x] timeout.\n", tmf
->tmf
);
1330 if (task
->task_status
.resp
== SAS_TASK_COMPLETE
&&
1331 task
->task_status
.stat
== SAM_STAT_GOOD
) {
1332 res
= TMF_RESP_FUNC_COMPLETE
;
1336 if (task
->task_status
.resp
== SAS_TASK_COMPLETE
&&
1337 task
->task_status
.stat
== SAS_DATA_UNDERRUN
) {
1338 /* no error, but return the number of bytes of
1340 res
= task
->task_status
.residual
;
1344 if (task
->task_status
.resp
== SAS_TASK_COMPLETE
&&
1345 task
->task_status
.stat
== SAS_DATA_OVERRUN
) {
1346 mv_dprintk("blocked task error.\n");
1350 mv_dprintk(" task to dev %016llx response: 0x%x "
1352 SAS_ADDR(dev
->sas_addr
),
1353 task
->task_status
.resp
,
1354 task
->task_status
.stat
);
1355 sas_free_task(task
);
1361 BUG_ON(retry
== 3 && task
!= NULL
);
1362 sas_free_task(task
);
1366 static int mvs_debug_issue_ssp_tmf(struct domain_device
*dev
,
1367 u8
*lun
, struct mvs_tmf_task
*tmf
)
1369 struct sas_ssp_task ssp_task
;
1370 if (!(dev
->tproto
& SAS_PROTOCOL_SSP
))
1371 return TMF_RESP_FUNC_ESUPP
;
1373 memcpy(ssp_task
.LUN
, lun
, 8);
1375 return mvs_exec_internal_tmf_task(dev
, &ssp_task
,
1376 sizeof(ssp_task
), tmf
);
1380 /* Standard mandates link reset for ATA (type 0)
1381 and hard reset for SSP (type 1) , only for RECOVERY */
1382 static int mvs_debug_I_T_nexus_reset(struct domain_device
*dev
)
1385 struct sas_phy
*phy
= sas_get_local_phy(dev
);
1386 int reset_type
= (dev
->dev_type
== SAS_SATA_DEV
||
1387 (dev
->tproto
& SAS_PROTOCOL_STP
)) ? 0 : 1;
1388 rc
= sas_phy_reset(phy
, reset_type
);
1389 sas_put_local_phy(phy
);
1394 /* mandatory SAM-3 */
1395 int mvs_lu_reset(struct domain_device
*dev
, u8
*lun
)
1397 unsigned long flags
;
1398 int rc
= TMF_RESP_FUNC_FAILED
;
1399 struct mvs_tmf_task tmf_task
;
1400 struct mvs_device
* mvi_dev
= dev
->lldd_dev
;
1401 struct mvs_info
*mvi
= mvi_dev
->mvi_info
;
1403 tmf_task
.tmf
= TMF_LU_RESET
;
1404 mvi_dev
->dev_status
= MVS_DEV_EH
;
1405 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
, &tmf_task
);
1406 if (rc
== TMF_RESP_FUNC_COMPLETE
) {
1407 spin_lock_irqsave(&mvi
->lock
, flags
);
1408 mvs_release_task(mvi
, dev
);
1409 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1411 /* If failed, fall-through I_T_Nexus reset */
1412 mv_printk("%s for device[%x]:rc= %d\n", __func__
,
1413 mvi_dev
->device_id
, rc
);
1417 int mvs_I_T_nexus_reset(struct domain_device
*dev
)
1419 unsigned long flags
;
1420 int rc
= TMF_RESP_FUNC_FAILED
;
1421 struct mvs_device
* mvi_dev
= (struct mvs_device
*)dev
->lldd_dev
;
1422 struct mvs_info
*mvi
= mvi_dev
->mvi_info
;
1424 if (mvi_dev
->dev_status
!= MVS_DEV_EH
)
1425 return TMF_RESP_FUNC_COMPLETE
;
1427 mvi_dev
->dev_status
= MVS_DEV_NORMAL
;
1428 rc
= mvs_debug_I_T_nexus_reset(dev
);
1429 mv_printk("%s for device[%x]:rc= %d\n",
1430 __func__
, mvi_dev
->device_id
, rc
);
1432 spin_lock_irqsave(&mvi
->lock
, flags
);
1433 mvs_release_task(mvi
, dev
);
1434 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1438 /* optional SAM-3 */
1439 int mvs_query_task(struct sas_task
*task
)
1442 struct scsi_lun lun
;
1443 struct mvs_tmf_task tmf_task
;
1444 int rc
= TMF_RESP_FUNC_FAILED
;
1446 if (task
->lldd_task
&& task
->task_proto
& SAS_PROTOCOL_SSP
) {
1447 struct scsi_cmnd
* cmnd
= (struct scsi_cmnd
*)task
->uldd_task
;
1448 struct domain_device
*dev
= task
->dev
;
1449 struct mvs_device
*mvi_dev
= (struct mvs_device
*)dev
->lldd_dev
;
1450 struct mvs_info
*mvi
= mvi_dev
->mvi_info
;
1452 int_to_scsilun(cmnd
->device
->lun
, &lun
);
1453 rc
= mvs_find_tag(mvi
, task
, &tag
);
1455 rc
= TMF_RESP_FUNC_FAILED
;
1459 tmf_task
.tmf
= TMF_QUERY_TASK
;
1460 tmf_task
.tag_of_task_to_be_managed
= cpu_to_le16(tag
);
1462 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
.scsi_lun
, &tmf_task
);
1464 /* The task is still in Lun, release it then */
1465 case TMF_RESP_FUNC_SUCC
:
1466 /* The task is not in Lun or failed, reset the phy */
1467 case TMF_RESP_FUNC_FAILED
:
1468 case TMF_RESP_FUNC_COMPLETE
:
1472 mv_printk("%s:rc= %d\n", __func__
, rc
);
1476 /* mandatory SAM-3, still need free task/slot info */
1477 int mvs_abort_task(struct sas_task
*task
)
1479 struct scsi_lun lun
;
1480 struct mvs_tmf_task tmf_task
;
1481 struct domain_device
*dev
= task
->dev
;
1482 struct mvs_device
*mvi_dev
= (struct mvs_device
*)dev
->lldd_dev
;
1483 struct mvs_info
*mvi
;
1484 int rc
= TMF_RESP_FUNC_FAILED
;
1485 unsigned long flags
;
1489 mv_printk("Device has removed\n");
1490 return TMF_RESP_FUNC_FAILED
;
1493 mvi
= mvi_dev
->mvi_info
;
1495 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1496 if (task
->task_state_flags
& SAS_TASK_STATE_DONE
) {
1497 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1498 rc
= TMF_RESP_FUNC_COMPLETE
;
1501 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1502 mvi_dev
->dev_status
= MVS_DEV_EH
;
1503 if (task
->lldd_task
&& task
->task_proto
& SAS_PROTOCOL_SSP
) {
1504 struct scsi_cmnd
* cmnd
= (struct scsi_cmnd
*)task
->uldd_task
;
1506 int_to_scsilun(cmnd
->device
->lun
, &lun
);
1507 rc
= mvs_find_tag(mvi
, task
, &tag
);
1509 mv_printk("No such tag in %s\n", __func__
);
1510 rc
= TMF_RESP_FUNC_FAILED
;
1514 tmf_task
.tmf
= TMF_ABORT_TASK
;
1515 tmf_task
.tag_of_task_to_be_managed
= cpu_to_le16(tag
);
1517 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
.scsi_lun
, &tmf_task
);
1519 /* if successful, clear the task and callback forwards.*/
1520 if (rc
== TMF_RESP_FUNC_COMPLETE
) {
1522 struct mvs_slot_info
*slot
;
1524 if (task
->lldd_task
) {
1525 slot
= task
->lldd_task
;
1526 slot_no
= (u32
) (slot
- mvi
->slot_info
);
1527 spin_lock_irqsave(&mvi
->lock
, flags
);
1528 mvs_slot_complete(mvi
, slot_no
, 1);
1529 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1533 } else if (task
->task_proto
& SAS_PROTOCOL_SATA
||
1534 task
->task_proto
& SAS_PROTOCOL_STP
) {
1535 if (SAS_SATA_DEV
== dev
->dev_type
) {
1536 struct mvs_slot_info
*slot
= task
->lldd_task
;
1537 u32 slot_idx
= (u32
)(slot
- mvi
->slot_info
);
1538 mv_dprintk("mvs_abort_task() mvi=%p task=%p "
1539 "slot=%p slot_idx=x%x\n",
1540 mvi
, task
, slot
, slot_idx
);
1541 task
->task_state_flags
|= SAS_TASK_STATE_ABORTED
;
1542 mvs_slot_task_free(mvi
, task
, slot
, slot_idx
);
1543 rc
= TMF_RESP_FUNC_COMPLETE
;
1549 if (rc
!= TMF_RESP_FUNC_COMPLETE
)
1550 mv_printk("%s:rc= %d\n", __func__
, rc
);
1554 int mvs_abort_task_set(struct domain_device
*dev
, u8
*lun
)
1556 int rc
= TMF_RESP_FUNC_FAILED
;
1557 struct mvs_tmf_task tmf_task
;
1559 tmf_task
.tmf
= TMF_ABORT_TASK_SET
;
1560 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
, &tmf_task
);
1565 int mvs_clear_aca(struct domain_device
*dev
, u8
*lun
)
1567 int rc
= TMF_RESP_FUNC_FAILED
;
1568 struct mvs_tmf_task tmf_task
;
1570 tmf_task
.tmf
= TMF_CLEAR_ACA
;
1571 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
, &tmf_task
);
1576 int mvs_clear_task_set(struct domain_device
*dev
, u8
*lun
)
1578 int rc
= TMF_RESP_FUNC_FAILED
;
1579 struct mvs_tmf_task tmf_task
;
1581 tmf_task
.tmf
= TMF_CLEAR_TASK_SET
;
1582 rc
= mvs_debug_issue_ssp_tmf(dev
, lun
, &tmf_task
);
1587 static int mvs_sata_done(struct mvs_info
*mvi
, struct sas_task
*task
,
1588 u32 slot_idx
, int err
)
1590 struct mvs_device
*mvi_dev
= task
->dev
->lldd_dev
;
1591 struct task_status_struct
*tstat
= &task
->task_status
;
1592 struct ata_task_resp
*resp
= (struct ata_task_resp
*)tstat
->buf
;
1593 int stat
= SAM_STAT_GOOD
;
1596 resp
->frame_len
= sizeof(struct dev_to_host_fis
);
1597 memcpy(&resp
->ending_fis
[0],
1598 SATA_RECEIVED_D2H_FIS(mvi_dev
->taskfileset
),
1599 sizeof(struct dev_to_host_fis
));
1600 tstat
->buf_valid_size
= sizeof(*resp
);
1601 if (unlikely(err
)) {
1602 if (unlikely(err
& CMD_ISS_STPD
))
1603 stat
= SAS_OPEN_REJECT
;
1605 stat
= SAS_PROTO_RESPONSE
;
1611 void mvs_set_sense(u8
*buffer
, int len
, int d_sense
,
1612 int key
, int asc
, int ascq
)
1614 memset(buffer
, 0, len
);
1617 /* Descriptor format */
1619 mv_printk("Length %d of sense buffer too small to "
1620 "fit sense %x:%x:%x", len
, key
, asc
, ascq
);
1623 buffer
[0] = 0x72; /* Response Code */
1625 buffer
[1] = key
; /* Sense Key */
1627 buffer
[2] = asc
; /* ASC */
1629 buffer
[3] = ascq
; /* ASCQ */
1632 mv_printk("Length %d of sense buffer too small to "
1633 "fit sense %x:%x:%x", len
, key
, asc
, ascq
);
1636 buffer
[0] = 0x70; /* Response Code */
1638 buffer
[2] = key
; /* Sense Key */
1640 buffer
[7] = 0x0a; /* Additional Sense Length */
1642 buffer
[12] = asc
; /* ASC */
1644 buffer
[13] = ascq
; /* ASCQ */
1650 void mvs_fill_ssp_resp_iu(struct ssp_response_iu
*iu
,
1651 u8 key
, u8 asc
, u8 asc_q
)
1654 iu
->response_data_len
= 0;
1655 iu
->sense_data_len
= 17;
1657 mvs_set_sense(iu
->sense_data
, 17, 0,
1661 static int mvs_slot_err(struct mvs_info
*mvi
, struct sas_task
*task
,
1664 struct mvs_slot_info
*slot
= &mvi
->slot_info
[slot_idx
];
1666 u32 err_dw0
= le32_to_cpu(*(u32
*)slot
->response
);
1667 u32 err_dw1
= le32_to_cpu(*((u32
*)slot
->response
+ 1));
1669 enum mvs_port_type type
= PORT_TYPE_SAS
;
1671 if (err_dw0
& CMD_ISS_STPD
)
1672 MVS_CHIP_DISP
->issue_stop(mvi
, type
, tfs
);
1674 MVS_CHIP_DISP
->command_active(mvi
, slot_idx
);
1676 stat
= SAM_STAT_CHECK_CONDITION
;
1677 switch (task
->task_proto
) {
1678 case SAS_PROTOCOL_SSP
:
1680 stat
= SAS_ABORTED_TASK
;
1681 if ((err_dw0
& NO_DEST
) || err_dw1
& bit(31)) {
1682 struct ssp_response_iu
*iu
= slot
->response
+
1683 sizeof(struct mvs_err_info
);
1684 mvs_fill_ssp_resp_iu(iu
, NOT_READY
, 0x04, 01);
1685 sas_ssp_task_response(mvi
->dev
, task
, iu
);
1686 stat
= SAM_STAT_CHECK_CONDITION
;
1688 if (err_dw1
& bit(31))
1689 mv_printk("reuse same slot, retry command.\n");
1692 case SAS_PROTOCOL_SMP
:
1693 stat
= SAM_STAT_CHECK_CONDITION
;
1696 case SAS_PROTOCOL_SATA
:
1697 case SAS_PROTOCOL_STP
:
1698 case SAS_PROTOCOL_SATA
| SAS_PROTOCOL_STP
:
1700 task
->ata_task
.use_ncq
= 0;
1701 stat
= SAS_PROTO_RESPONSE
;
1702 mvs_sata_done(mvi
, task
, slot_idx
, err_dw0
);
1712 int mvs_slot_complete(struct mvs_info
*mvi
, u32 rx_desc
, u32 flags
)
1714 u32 slot_idx
= rx_desc
& RXQ_SLOT_MASK
;
1715 struct mvs_slot_info
*slot
= &mvi
->slot_info
[slot_idx
];
1716 struct sas_task
*task
= slot
->task
;
1717 struct mvs_device
*mvi_dev
= NULL
;
1718 struct task_status_struct
*tstat
;
1719 struct domain_device
*dev
;
1723 enum exec_status sts
;
1725 if (unlikely(!task
|| !task
->lldd_task
|| !task
->dev
))
1728 tstat
= &task
->task_status
;
1730 mvi_dev
= dev
->lldd_dev
;
1732 spin_lock(&task
->task_state_lock
);
1733 task
->task_state_flags
&=
1734 ~(SAS_TASK_STATE_PENDING
| SAS_TASK_AT_INITIATOR
);
1735 task
->task_state_flags
|= SAS_TASK_STATE_DONE
;
1737 aborted
= task
->task_state_flags
& SAS_TASK_STATE_ABORTED
;
1738 spin_unlock(&task
->task_state_lock
);
1740 memset(tstat
, 0, sizeof(*tstat
));
1741 tstat
->resp
= SAS_TASK_COMPLETE
;
1743 if (unlikely(aborted
)) {
1744 tstat
->stat
= SAS_ABORTED_TASK
;
1745 if (mvi_dev
&& mvi_dev
->running_req
)
1746 mvi_dev
->running_req
--;
1747 if (sas_protocol_ata(task
->task_proto
))
1748 mvs_free_reg_set(mvi
, mvi_dev
);
1750 mvs_slot_task_free(mvi
, task
, slot
, slot_idx
);
1754 /* when no device attaching, go ahead and complete by error handling*/
1755 if (unlikely(!mvi_dev
|| flags
)) {
1757 mv_dprintk("port has not device.\n");
1758 tstat
->stat
= SAS_PHY_DOWN
;
1763 * error info record present; slot->response is 32 bit aligned but may
1764 * not be 64 bit aligned, so check for zero in two 32 bit reads
1766 if (unlikely((rx_desc
& RXQ_ERR
)
1767 && (*((u32
*)slot
->response
)
1768 || *(((u32
*)slot
->response
) + 1)))) {
1769 mv_dprintk("port %d slot %d rx_desc %X has error info"
1770 "%016llX.\n", slot
->port
->sas_port
.id
, slot_idx
,
1771 rx_desc
, get_unaligned_le64(slot
->response
));
1772 tstat
->stat
= mvs_slot_err(mvi
, task
, slot_idx
);
1773 tstat
->resp
= SAS_TASK_COMPLETE
;
1777 switch (task
->task_proto
) {
1778 case SAS_PROTOCOL_SSP
:
1779 /* hw says status == 0, datapres == 0 */
1780 if (rx_desc
& RXQ_GOOD
) {
1781 tstat
->stat
= SAM_STAT_GOOD
;
1782 tstat
->resp
= SAS_TASK_COMPLETE
;
1784 /* response frame present */
1785 else if (rx_desc
& RXQ_RSP
) {
1786 struct ssp_response_iu
*iu
= slot
->response
+
1787 sizeof(struct mvs_err_info
);
1788 sas_ssp_task_response(mvi
->dev
, task
, iu
);
1790 tstat
->stat
= SAM_STAT_CHECK_CONDITION
;
1793 case SAS_PROTOCOL_SMP
: {
1794 struct scatterlist
*sg_resp
= &task
->smp_task
.smp_resp
;
1795 tstat
->stat
= SAM_STAT_GOOD
;
1796 to
= kmap_atomic(sg_page(sg_resp
));
1797 memcpy(to
+ sg_resp
->offset
,
1798 slot
->response
+ sizeof(struct mvs_err_info
),
1799 sg_dma_len(sg_resp
));
1804 case SAS_PROTOCOL_SATA
:
1805 case SAS_PROTOCOL_STP
:
1806 case SAS_PROTOCOL_SATA
| SAS_PROTOCOL_STP
: {
1807 tstat
->stat
= mvs_sata_done(mvi
, task
, slot_idx
, 0);
1812 tstat
->stat
= SAM_STAT_CHECK_CONDITION
;
1815 if (!slot
->port
->port_attached
) {
1816 mv_dprintk("port %d has removed.\n", slot
->port
->sas_port
.id
);
1817 tstat
->stat
= SAS_PHY_DOWN
;
1822 if (mvi_dev
&& mvi_dev
->running_req
) {
1823 mvi_dev
->running_req
--;
1824 if (sas_protocol_ata(task
->task_proto
) && !mvi_dev
->running_req
)
1825 mvs_free_reg_set(mvi
, mvi_dev
);
1827 mvs_slot_task_free(mvi
, task
, slot
, slot_idx
);
1830 spin_unlock(&mvi
->lock
);
1831 if (task
->task_done
)
1832 task
->task_done(task
);
1834 spin_lock(&mvi
->lock
);
1839 void mvs_do_release_task(struct mvs_info
*mvi
,
1840 int phy_no
, struct domain_device
*dev
)
1843 struct mvs_phy
*phy
;
1844 struct mvs_port
*port
;
1845 struct mvs_slot_info
*slot
, *slot2
;
1847 phy
= &mvi
->phy
[phy_no
];
1851 /* clean cmpl queue in case request is already finished */
1852 mvs_int_rx(mvi
, false);
1856 list_for_each_entry_safe(slot
, slot2
, &port
->list
, entry
) {
1857 struct sas_task
*task
;
1858 slot_idx
= (u32
) (slot
- mvi
->slot_info
);
1861 if (dev
&& task
->dev
!= dev
)
1864 mv_printk("Release slot [%x] tag[%x], task [%p]:\n",
1865 slot_idx
, slot
->slot_tag
, task
);
1866 MVS_CHIP_DISP
->command_active(mvi
, slot_idx
);
1868 mvs_slot_complete(mvi
, slot_idx
, 1);
1872 void mvs_release_task(struct mvs_info
*mvi
,
1873 struct domain_device
*dev
)
1875 int i
, phyno
[WIDE_PORT_MAX_PHY
], num
;
1876 num
= mvs_find_dev_phyno(dev
, phyno
);
1877 for (i
= 0; i
< num
; i
++)
1878 mvs_do_release_task(mvi
, phyno
[i
], dev
);
1881 static void mvs_phy_disconnected(struct mvs_phy
*phy
)
1883 phy
->phy_attached
= 0;
1884 phy
->att_dev_info
= 0;
1885 phy
->att_dev_sas_addr
= 0;
1888 static void mvs_work_queue(struct work_struct
*work
)
1890 struct delayed_work
*dw
= container_of(work
, struct delayed_work
, work
);
1891 struct mvs_wq
*mwq
= container_of(dw
, struct mvs_wq
, work_q
);
1892 struct mvs_info
*mvi
= mwq
->mvi
;
1893 unsigned long flags
;
1894 u32 phy_no
= (unsigned long) mwq
->data
;
1895 struct sas_ha_struct
*sas_ha
= mvi
->sas
;
1896 struct mvs_phy
*phy
= &mvi
->phy
[phy_no
];
1897 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
1899 spin_lock_irqsave(&mvi
->lock
, flags
);
1900 if (mwq
->handler
& PHY_PLUG_EVENT
) {
1902 if (phy
->phy_event
& PHY_PLUG_OUT
) {
1904 struct sas_identify_frame
*id
;
1905 id
= (struct sas_identify_frame
*)phy
->frame_rcvd
;
1906 tmp
= MVS_CHIP_DISP
->read_phy_ctl(mvi
, phy_no
);
1907 phy
->phy_event
&= ~PHY_PLUG_OUT
;
1908 if (!(tmp
& PHY_READY_MASK
)) {
1909 sas_phy_disconnected(sas_phy
);
1910 mvs_phy_disconnected(phy
);
1911 sas_ha
->notify_phy_event(sas_phy
,
1912 PHYE_LOSS_OF_SIGNAL
);
1913 mv_dprintk("phy%d Removed Device\n", phy_no
);
1915 MVS_CHIP_DISP
->detect_porttype(mvi
, phy_no
);
1916 mvs_update_phyinfo(mvi
, phy_no
, 1);
1917 mvs_bytes_dmaed(mvi
, phy_no
);
1918 mvs_port_notify_formed(sas_phy
, 0);
1919 mv_dprintk("phy%d Attached Device\n", phy_no
);
1922 } else if (mwq
->handler
& EXP_BRCT_CHG
) {
1923 phy
->phy_event
&= ~EXP_BRCT_CHG
;
1924 sas_ha
->notify_port_event(sas_phy
,
1925 PORTE_BROADCAST_RCVD
);
1926 mv_dprintk("phy%d Got Broadcast Change\n", phy_no
);
1928 list_del(&mwq
->entry
);
1929 spin_unlock_irqrestore(&mvi
->lock
, flags
);
1933 static int mvs_handle_event(struct mvs_info
*mvi
, void *data
, int handler
)
1938 mwq
= kmalloc(sizeof(struct mvs_wq
), GFP_ATOMIC
);
1942 mwq
->handler
= handler
;
1943 MV_INIT_DELAYED_WORK(&mwq
->work_q
, mvs_work_queue
, mwq
);
1944 list_add_tail(&mwq
->entry
, &mvi
->wq_list
);
1945 schedule_delayed_work(&mwq
->work_q
, HZ
* 2);
1952 static void mvs_sig_time_out(unsigned long tphy
)
1954 struct mvs_phy
*phy
= (struct mvs_phy
*)tphy
;
1955 struct mvs_info
*mvi
= phy
->mvi
;
1958 for (phy_no
= 0; phy_no
< mvi
->chip
->n_phy
; phy_no
++) {
1959 if (&mvi
->phy
[phy_no
] == phy
) {
1960 mv_dprintk("Get signature time out, reset phy %d\n",
1961 phy_no
+mvi
->id
*mvi
->chip
->n_phy
);
1962 MVS_CHIP_DISP
->phy_reset(mvi
, phy_no
, MVS_HARD_RESET
);
1967 void mvs_int_port(struct mvs_info
*mvi
, int phy_no
, u32 events
)
1970 struct mvs_phy
*phy
= &mvi
->phy
[phy_no
];
1972 phy
->irq_status
= MVS_CHIP_DISP
->read_port_irq_stat(mvi
, phy_no
);
1973 MVS_CHIP_DISP
->write_port_irq_stat(mvi
, phy_no
, phy
->irq_status
);
1974 mv_dprintk("phy %d ctrl sts=0x%08X.\n", phy_no
+mvi
->id
*mvi
->chip
->n_phy
,
1975 MVS_CHIP_DISP
->read_phy_ctl(mvi
, phy_no
));
1976 mv_dprintk("phy %d irq sts = 0x%08X\n", phy_no
+mvi
->id
*mvi
->chip
->n_phy
,
1980 * events is port event now ,
1981 * we need check the interrupt status which belongs to per port.
1984 if (phy
->irq_status
& PHYEV_DCDR_ERR
) {
1985 mv_dprintk("phy %d STP decoding error.\n",
1986 phy_no
+ mvi
->id
*mvi
->chip
->n_phy
);
1989 if (phy
->irq_status
& PHYEV_POOF
) {
1991 if (!(phy
->phy_event
& PHY_PLUG_OUT
)) {
1992 int dev_sata
= phy
->phy_type
& PORT_TYPE_SATA
;
1994 mvs_do_release_task(mvi
, phy_no
, NULL
);
1995 phy
->phy_event
|= PHY_PLUG_OUT
;
1996 MVS_CHIP_DISP
->clear_srs_irq(mvi
, 0, 1);
1997 mvs_handle_event(mvi
,
1998 (void *)(unsigned long)phy_no
,
2000 ready
= mvs_is_phy_ready(mvi
, phy_no
);
2001 if (ready
|| dev_sata
) {
2002 if (MVS_CHIP_DISP
->stp_reset
)
2003 MVS_CHIP_DISP
->stp_reset(mvi
,
2006 MVS_CHIP_DISP
->phy_reset(mvi
,
2007 phy_no
, MVS_SOFT_RESET
);
2013 if (phy
->irq_status
& PHYEV_COMWAKE
) {
2014 tmp
= MVS_CHIP_DISP
->read_port_irq_mask(mvi
, phy_no
);
2015 MVS_CHIP_DISP
->write_port_irq_mask(mvi
, phy_no
,
2016 tmp
| PHYEV_SIG_FIS
);
2017 if (phy
->timer
.function
== NULL
) {
2018 phy
->timer
.data
= (unsigned long)phy
;
2019 phy
->timer
.function
= mvs_sig_time_out
;
2020 phy
->timer
.expires
= jiffies
+ 5*HZ
;
2021 add_timer(&phy
->timer
);
2024 if (phy
->irq_status
& (PHYEV_SIG_FIS
| PHYEV_ID_DONE
)) {
2025 phy
->phy_status
= mvs_is_phy_ready(mvi
, phy_no
);
2026 mv_dprintk("notify plug in on phy[%d]\n", phy_no
);
2027 if (phy
->phy_status
) {
2029 MVS_CHIP_DISP
->detect_porttype(mvi
, phy_no
);
2030 if (phy
->phy_type
& PORT_TYPE_SATA
) {
2031 tmp
= MVS_CHIP_DISP
->read_port_irq_mask(
2033 tmp
&= ~PHYEV_SIG_FIS
;
2034 MVS_CHIP_DISP
->write_port_irq_mask(mvi
,
2037 mvs_update_phyinfo(mvi
, phy_no
, 0);
2038 if (phy
->phy_type
& PORT_TYPE_SAS
) {
2039 MVS_CHIP_DISP
->phy_reset(mvi
, phy_no
, MVS_PHY_TUNE
);
2043 mvs_bytes_dmaed(mvi
, phy_no
);
2044 /* whether driver is going to handle hot plug */
2045 if (phy
->phy_event
& PHY_PLUG_OUT
) {
2046 mvs_port_notify_formed(&phy
->sas_phy
, 0);
2047 phy
->phy_event
&= ~PHY_PLUG_OUT
;
2050 mv_dprintk("plugin interrupt but phy%d is gone\n",
2051 phy_no
+ mvi
->id
*mvi
->chip
->n_phy
);
2053 } else if (phy
->irq_status
& PHYEV_BROAD_CH
) {
2054 mv_dprintk("phy %d broadcast change.\n",
2055 phy_no
+ mvi
->id
*mvi
->chip
->n_phy
);
2056 mvs_handle_event(mvi
, (void *)(unsigned long)phy_no
,
2061 int mvs_int_rx(struct mvs_info
*mvi
, bool self_clear
)
2063 u32 rx_prod_idx
, rx_desc
;
2066 /* the first dword in the RX ring is special: it contains
2067 * a mirror of the hardware's RX producer index, so that
2068 * we don't have to stall the CPU reading that register.
2069 * The actual RX ring is offset by one dword, due to this.
2071 rx_prod_idx
= mvi
->rx_cons
;
2072 mvi
->rx_cons
= le32_to_cpu(mvi
->rx
[0]);
2073 if (mvi
->rx_cons
== 0xfff) /* h/w hasn't touched RX ring yet */
2076 /* The CMPL_Q may come late, read from register and try again
2077 * note: if coalescing is enabled,
2078 * it will need to read from register every time for sure
2080 if (unlikely(mvi
->rx_cons
== rx_prod_idx
))
2081 mvi
->rx_cons
= MVS_CHIP_DISP
->rx_update(mvi
) & RX_RING_SZ_MASK
;
2083 if (mvi
->rx_cons
== rx_prod_idx
)
2086 while (mvi
->rx_cons
!= rx_prod_idx
) {
2087 /* increment our internal RX consumer pointer */
2088 rx_prod_idx
= (rx_prod_idx
+ 1) & (MVS_RX_RING_SZ
- 1);
2089 rx_desc
= le32_to_cpu(mvi
->rx
[rx_prod_idx
+ 1]);
2091 if (likely(rx_desc
& RXQ_DONE
))
2092 mvs_slot_complete(mvi
, rx_desc
, 0);
2093 if (rx_desc
& RXQ_ATTN
) {
2095 } else if (rx_desc
& RXQ_ERR
) {
2096 if (!(rx_desc
& RXQ_DONE
))
2097 mvs_slot_complete(mvi
, rx_desc
, 0);
2098 } else if (rx_desc
& RXQ_SLOT_RESET
) {
2099 mvs_slot_free(mvi
, rx_desc
);
2103 if (attn
&& self_clear
)
2104 MVS_CHIP_DISP
->int_full(mvi
);
2108 int mvs_gpio_write(struct sas_ha_struct
*sha
, u8 reg_type
, u8 reg_index
,
2109 u8 reg_count
, u8
*write_data
)
2111 struct mvs_prv_info
*mvs_prv
= sha
->lldd_ha
;
2112 struct mvs_info
*mvi
= mvs_prv
->mvi
[0];
2114 if (MVS_CHIP_DISP
->gpio_write
) {
2115 return MVS_CHIP_DISP
->gpio_write(mvs_prv
, reg_type
,
2116 reg_index
, reg_count
, write_data
);