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];
106 int mvs_find_dev_phyno(struct domain_device *dev, int *phyno)
108 unsigned long i = 0, j = 0, n = 0, num = 0;
109 struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev;
110 struct mvs_info *mvi = mvi_dev->mvi_info;
111 struct sas_ha_struct *sha = dev->port->ha;
113 while (sha->sas_port[i]) {
114 if (sha->sas_port[i] == dev->port) {
115 struct asd_sas_phy *phy;
116 list_for_each_entry(phy,
117 &sha->sas_port[i]->phy_list, port_phy_el) {
119 while (sha->sas_phy[j]) {
120 if (sha->sas_phy[j] == phy)
124 phyno[n] = (j >= mvi->chip->n_phy) ?
125 (j - mvi->chip->n_phy) : j;
136 struct mvs_device *mvs_find_dev_by_reg_set(struct mvs_info *mvi,
140 for (dev_no = 0; dev_no < MVS_MAX_DEVICES; dev_no++) {
141 if (mvi->devices[dev_no].taskfileset == MVS_ID_NOT_MAPPED)
144 if (mvi->devices[dev_no].taskfileset == reg_set)
145 return &mvi->devices[dev_no];
150 static inline void mvs_free_reg_set(struct mvs_info *mvi,
151 struct mvs_device *dev)
154 mv_printk("device has been free.\n");
157 if (dev->taskfileset == MVS_ID_NOT_MAPPED)
159 MVS_CHIP_DISP->free_reg_set(mvi, &dev->taskfileset);
162 static inline u8 mvs_assign_reg_set(struct mvs_info *mvi,
163 struct mvs_device *dev)
165 if (dev->taskfileset != MVS_ID_NOT_MAPPED)
167 return MVS_CHIP_DISP->assign_reg_set(mvi, &dev->taskfileset);
170 void mvs_phys_reset(struct mvs_info *mvi, u32 phy_mask, int hard)
173 for_each_phy(phy_mask, phy_mask, no) {
176 MVS_CHIP_DISP->phy_reset(mvi, no, hard);
180 /* FIXME: locking? */
181 int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
184 int rc = 0, phy_id = sas_phy->id;
186 struct sas_ha_struct *sha = sas_phy->ha;
187 struct mvs_info *mvi = NULL;
189 while (sha->sas_phy[i]) {
190 if (sha->sas_phy[i] == sas_phy)
194 hi = i/((struct mvs_prv_info *)sha->lldd_ha)->n_phy;
195 mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[hi];
198 case PHY_FUNC_SET_LINK_RATE:
199 MVS_CHIP_DISP->phy_set_link_rate(mvi, phy_id, funcdata);
202 case PHY_FUNC_HARD_RESET:
203 tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, phy_id);
204 if (tmp & PHY_RST_HARD)
206 MVS_CHIP_DISP->phy_reset(mvi, phy_id, 1);
209 case PHY_FUNC_LINK_RESET:
210 MVS_CHIP_DISP->phy_enable(mvi, phy_id);
211 MVS_CHIP_DISP->phy_reset(mvi, phy_id, 0);
214 case PHY_FUNC_DISABLE:
215 MVS_CHIP_DISP->phy_disable(mvi, phy_id);
217 case PHY_FUNC_RELEASE_SPINUP_HOLD:
225 void __devinit mvs_set_sas_addr(struct mvs_info *mvi, int port_id,
226 u32 off_lo, u32 off_hi, u64 sas_addr)
228 u32 lo = (u32)sas_addr;
229 u32 hi = (u32)(sas_addr>>32);
231 MVS_CHIP_DISP->write_port_cfg_addr(mvi, port_id, off_lo);
232 MVS_CHIP_DISP->write_port_cfg_data(mvi, port_id, lo);
233 MVS_CHIP_DISP->write_port_cfg_addr(mvi, port_id, off_hi);
234 MVS_CHIP_DISP->write_port_cfg_data(mvi, port_id, hi);
237 static void mvs_bytes_dmaed(struct mvs_info *mvi, int i)
239 struct mvs_phy *phy = &mvi->phy[i];
240 struct asd_sas_phy *sas_phy = &phy->sas_phy;
241 struct sas_ha_struct *sas_ha;
242 if (!phy->phy_attached)
245 if (!(phy->att_dev_info & PORT_DEV_TRGT_MASK)
246 && phy->phy_type & PORT_TYPE_SAS) {
251 sas_ha->notify_phy_event(sas_phy, PHYE_OOB_DONE);
254 struct sas_phy *sphy = sas_phy->phy;
256 sphy->negotiated_linkrate = sas_phy->linkrate;
257 sphy->minimum_linkrate = phy->minimum_linkrate;
258 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
259 sphy->maximum_linkrate = phy->maximum_linkrate;
260 sphy->maximum_linkrate_hw = MVS_CHIP_DISP->phy_max_link_rate();
263 if (phy->phy_type & PORT_TYPE_SAS) {
264 struct sas_identify_frame *id;
266 id = (struct sas_identify_frame *)phy->frame_rcvd;
267 id->dev_type = phy->identify.device_type;
268 id->initiator_bits = SAS_PROTOCOL_ALL;
269 id->target_bits = phy->identify.target_port_protocols;
270 } else if (phy->phy_type & PORT_TYPE_SATA) {
273 mv_dprintk("phy %d byte dmaded.\n", i + mvi->id * mvi->chip->n_phy);
275 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
277 mvi->sas->notify_port_event(sas_phy,
281 int mvs_slave_alloc(struct scsi_device *scsi_dev)
283 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
284 if (dev_is_sata(dev)) {
285 /* We don't need to rescan targets
286 * if REPORT_LUNS request is failed
288 if (scsi_dev->lun > 0)
290 scsi_dev->tagged_supported = 1;
293 return sas_slave_alloc(scsi_dev);
296 int mvs_slave_configure(struct scsi_device *sdev)
298 struct domain_device *dev = sdev_to_domain_dev(sdev);
299 int ret = sas_slave_configure(sdev);
303 if (dev_is_sata(dev)) {
308 void mvs_scan_start(struct Scsi_Host *shost)
311 unsigned short core_nr;
312 struct mvs_info *mvi;
313 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
315 core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
317 for (j = 0; j < core_nr; j++) {
318 mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[j];
319 for (i = 0; i < mvi->chip->n_phy; ++i)
320 mvs_bytes_dmaed(mvi, i);
324 int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time)
326 /* give the phy enabling interrupt event time to come in (1s
327 * is empirically about all it takes) */
330 /* Wait for discovery to finish */
331 scsi_flush_work(shost);
335 static int mvs_task_prep_smp(struct mvs_info *mvi,
336 struct mvs_task_exec_info *tei)
339 struct sas_task *task = tei->task;
340 struct mvs_cmd_hdr *hdr = tei->hdr;
341 struct domain_device *dev = task->dev;
342 struct asd_sas_port *sas_port = dev->port;
343 struct scatterlist *sg_req, *sg_resp;
344 u32 req_len, resp_len, tag = tei->tag;
347 dma_addr_t buf_tmp_dma;
349 struct mvs_slot_info *slot = &mvi->slot_info[tag];
350 u32 flags = (tei->n_elem << MCH_PRD_LEN_SHIFT);
353 * DMA-map SMP request, response buffers
355 sg_req = &task->smp_task.smp_req;
356 elem = dma_map_sg(mvi->dev, sg_req, 1, PCI_DMA_TODEVICE);
359 req_len = sg_dma_len(sg_req);
361 sg_resp = &task->smp_task.smp_resp;
362 elem = dma_map_sg(mvi->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
367 resp_len = SB_RFB_MAX;
369 /* must be in dwords */
370 if ((req_len & 0x3) || (resp_len & 0x3)) {
376 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
379 /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ***** */
381 buf_tmp_dma = slot->buf_dma;
383 hdr->cmd_tbl = cpu_to_le64(sg_dma_address(sg_req));
385 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
387 hdr->open_frame = cpu_to_le64(buf_tmp_dma);
389 buf_tmp += MVS_OAF_SZ;
390 buf_tmp_dma += MVS_OAF_SZ;
392 /* region 3: PRD table *********************************** */
395 hdr->prd_tbl = cpu_to_le64(buf_tmp_dma);
399 i = MVS_CHIP_DISP->prd_size() * tei->n_elem;
403 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
404 slot->response = buf_tmp;
405 hdr->status_buf = cpu_to_le64(buf_tmp_dma);
406 if (mvi->flags & MVF_FLAG_SOC)
407 hdr->reserved[0] = 0;
410 * Fill in TX ring and command slot header
412 slot->tx = mvi->tx_prod;
413 mvi->tx[mvi->tx_prod] = cpu_to_le32((TXQ_CMD_SMP << TXQ_CMD_SHIFT) |
415 (sas_port->phy_mask << TXQ_PHY_SHIFT));
418 hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | ((req_len - 4) / 4));
419 hdr->tags = cpu_to_le32(tag);
422 /* generate open address frame hdr (first 12 bytes) */
423 /* initiator, SMP, ftype 1h */
424 buf_oaf[0] = (1 << 7) | (PROTOCOL_SMP << 4) | 0x01;
425 buf_oaf[1] = dev->linkrate & 0xf;
426 *(u16 *)(buf_oaf + 2) = 0xFFFF; /* SAS SPEC */
427 memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
429 /* fill in PRD (scatter/gather) table, if any */
430 MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd);
435 dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_resp, 1,
438 dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_req, 1,
443 static u32 mvs_get_ncq_tag(struct sas_task *task, u32 *tag)
445 struct ata_queued_cmd *qc = task->uldd_task;
448 if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
449 qc->tf.command == ATA_CMD_FPDMA_READ) {
458 static int mvs_task_prep_ata(struct mvs_info *mvi,
459 struct mvs_task_exec_info *tei)
461 struct sas_task *task = tei->task;
462 struct domain_device *dev = task->dev;
463 struct mvs_device *mvi_dev = dev->lldd_dev;
464 struct mvs_cmd_hdr *hdr = tei->hdr;
465 struct asd_sas_port *sas_port = dev->port;
466 struct mvs_slot_info *slot;
468 u32 tag = tei->tag, hdr_tag;
471 u8 *buf_cmd, *buf_oaf;
472 dma_addr_t buf_tmp_dma;
473 u32 i, req_len, resp_len;
474 const u32 max_resp_len = SB_RFB_MAX;
476 if (mvs_assign_reg_set(mvi, mvi_dev) == MVS_ID_NOT_MAPPED) {
477 mv_dprintk("Have not enough regiset for dev %d.\n",
481 slot = &mvi->slot_info[tag];
482 slot->tx = mvi->tx_prod;
483 del_q = TXQ_MODE_I | tag |
484 (TXQ_CMD_STP << TXQ_CMD_SHIFT) |
485 (sas_port->phy_mask << TXQ_PHY_SHIFT) |
486 (mvi_dev->taskfileset << TXQ_SRS_SHIFT);
487 mvi->tx[mvi->tx_prod] = cpu_to_le32(del_q);
489 if (task->data_dir == DMA_FROM_DEVICE)
490 flags = (MVS_CHIP_DISP->prd_count() << MCH_PRD_LEN_SHIFT);
492 flags = (tei->n_elem << MCH_PRD_LEN_SHIFT);
494 if (task->ata_task.use_ncq)
496 if (dev->sata_dev.command_set == ATAPI_COMMAND_SET) {
497 if (task->ata_task.fis.command != ATA_CMD_ID_ATAPI)
501 /* FIXME: fill in port multiplier number */
503 hdr->flags = cpu_to_le32(flags);
505 /* FIXME: the low order order 5 bits for the TAG if enable NCQ */
506 if (task->ata_task.use_ncq && mvs_get_ncq_tag(task, &hdr_tag))
507 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
511 hdr->tags = cpu_to_le32(hdr_tag);
513 hdr->data_len = cpu_to_le32(task->total_xfer_len);
516 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
519 /* region 1: command table area (MVS_ATA_CMD_SZ bytes) ************** */
520 buf_cmd = buf_tmp = slot->buf;
521 buf_tmp_dma = slot->buf_dma;
523 hdr->cmd_tbl = cpu_to_le64(buf_tmp_dma);
525 buf_tmp += MVS_ATA_CMD_SZ;
526 buf_tmp_dma += MVS_ATA_CMD_SZ;
528 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
529 /* used for STP. unused for SATA? */
531 hdr->open_frame = cpu_to_le64(buf_tmp_dma);
533 buf_tmp += MVS_OAF_SZ;
534 buf_tmp_dma += MVS_OAF_SZ;
536 /* region 3: PRD table ********************************************* */
540 hdr->prd_tbl = cpu_to_le64(buf_tmp_dma);
543 i = MVS_CHIP_DISP->prd_size() * MVS_CHIP_DISP->prd_count();
548 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
549 /* FIXME: probably unused, for SATA. kept here just in case
550 * we get a STP/SATA error information record
552 slot->response = buf_tmp;
553 hdr->status_buf = cpu_to_le64(buf_tmp_dma);
554 if (mvi->flags & MVF_FLAG_SOC)
555 hdr->reserved[0] = 0;
557 req_len = sizeof(struct host_to_dev_fis);
558 resp_len = MVS_SLOT_BUF_SZ - MVS_ATA_CMD_SZ -
559 sizeof(struct mvs_err_info) - i;
561 /* request, response lengths */
562 resp_len = min(resp_len, max_resp_len);
563 hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | (req_len / 4));
565 if (likely(!task->ata_task.device_control_reg_update))
566 task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
567 /* fill in command FIS and ATAPI CDB */
568 memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
569 if (dev->sata_dev.command_set == ATAPI_COMMAND_SET)
570 memcpy(buf_cmd + STP_ATAPI_CMD,
571 task->ata_task.atapi_packet, 16);
573 /* generate open address frame hdr (first 12 bytes) */
574 /* initiator, STP, ftype 1h */
575 buf_oaf[0] = (1 << 7) | (PROTOCOL_STP << 4) | 0x1;
576 buf_oaf[1] = dev->linkrate & 0xf;
577 *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1);
578 memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
580 /* fill in PRD (scatter/gather) table, if any */
581 MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd);
583 if (task->data_dir == DMA_FROM_DEVICE)
584 MVS_CHIP_DISP->dma_fix(mvi, sas_port->phy_mask,
585 TRASH_BUCKET_SIZE, tei->n_elem, buf_prd);
590 static int mvs_task_prep_ssp(struct mvs_info *mvi,
591 struct mvs_task_exec_info *tei, int is_tmf,
592 struct mvs_tmf_task *tmf)
594 struct sas_task *task = tei->task;
595 struct mvs_cmd_hdr *hdr = tei->hdr;
596 struct mvs_port *port = tei->port;
597 struct domain_device *dev = task->dev;
598 struct mvs_device *mvi_dev = dev->lldd_dev;
599 struct asd_sas_port *sas_port = dev->port;
600 struct mvs_slot_info *slot;
602 struct ssp_frame_hdr *ssp_hdr;
604 u8 *buf_cmd, *buf_oaf, fburst = 0;
605 dma_addr_t buf_tmp_dma;
607 u32 resp_len, req_len, i, tag = tei->tag;
608 const u32 max_resp_len = SB_RFB_MAX;
611 slot = &mvi->slot_info[tag];
613 phy_mask = ((port->wide_port_phymap) ? port->wide_port_phymap :
614 sas_port->phy_mask) & TXQ_PHY_MASK;
616 slot->tx = mvi->tx_prod;
617 mvi->tx[mvi->tx_prod] = cpu_to_le32(TXQ_MODE_I | tag |
618 (TXQ_CMD_SSP << TXQ_CMD_SHIFT) |
619 (phy_mask << TXQ_PHY_SHIFT));
622 if (task->ssp_task.enable_first_burst) {
627 flags |= (MCH_SSP_FR_TASK << MCH_SSP_FR_TYPE_SHIFT);
628 hdr->flags = cpu_to_le32(flags | (tei->n_elem << MCH_PRD_LEN_SHIFT));
629 hdr->tags = cpu_to_le32(tag);
630 hdr->data_len = cpu_to_le32(task->total_xfer_len);
633 * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs
636 /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ************** */
637 buf_cmd = buf_tmp = slot->buf;
638 buf_tmp_dma = slot->buf_dma;
640 hdr->cmd_tbl = cpu_to_le64(buf_tmp_dma);
642 buf_tmp += MVS_SSP_CMD_SZ;
643 buf_tmp_dma += MVS_SSP_CMD_SZ;
645 /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */
647 hdr->open_frame = cpu_to_le64(buf_tmp_dma);
649 buf_tmp += MVS_OAF_SZ;
650 buf_tmp_dma += MVS_OAF_SZ;
652 /* region 3: PRD table ********************************************* */
655 hdr->prd_tbl = cpu_to_le64(buf_tmp_dma);
659 i = MVS_CHIP_DISP->prd_size() * tei->n_elem;
663 /* region 4: status buffer (larger the PRD, smaller this buf) ****** */
664 slot->response = buf_tmp;
665 hdr->status_buf = cpu_to_le64(buf_tmp_dma);
666 if (mvi->flags & MVF_FLAG_SOC)
667 hdr->reserved[0] = 0;
669 resp_len = MVS_SLOT_BUF_SZ - MVS_SSP_CMD_SZ - MVS_OAF_SZ -
670 sizeof(struct mvs_err_info) - i;
671 resp_len = min(resp_len, max_resp_len);
673 req_len = sizeof(struct ssp_frame_hdr) + 28;
675 /* request, response lengths */
676 hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | (req_len / 4));
678 /* generate open address frame hdr (first 12 bytes) */
679 /* initiator, SSP, ftype 1h */
680 buf_oaf[0] = (1 << 7) | (PROTOCOL_SSP << 4) | 0x1;
681 buf_oaf[1] = dev->linkrate & 0xf;
682 *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1);
683 memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE);
685 /* fill in SSP frame header (Command Table.SSP frame header) */
686 ssp_hdr = (struct ssp_frame_hdr *)buf_cmd;
689 ssp_hdr->frame_type = SSP_TASK;
691 ssp_hdr->frame_type = SSP_COMMAND;
693 memcpy(ssp_hdr->hashed_dest_addr, dev->hashed_sas_addr,
694 HASHED_SAS_ADDR_SIZE);
695 memcpy(ssp_hdr->hashed_src_addr,
696 dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE);
697 ssp_hdr->tag = cpu_to_be16(tag);
699 /* fill in IU for TASK and Command Frame */
700 buf_cmd += sizeof(*ssp_hdr);
701 memcpy(buf_cmd, &task->ssp_task.LUN, 8);
703 if (ssp_hdr->frame_type != SSP_TASK) {
704 buf_cmd[9] = fburst | task->ssp_task.task_attr |
705 (task->ssp_task.task_prio << 3);
706 memcpy(buf_cmd + 12, &task->ssp_task.cdb, 16);
708 buf_cmd[10] = tmf->tmf;
713 (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
715 tmf->tag_of_task_to_be_managed & 0xff;
721 /* fill in PRD (scatter/gather) table, if any */
722 MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd);
726 #define DEV_IS_GONE(mvi_dev) ((!mvi_dev || (mvi_dev->dev_type == NO_DEVICE)))
727 static int mvs_task_prep(struct sas_task *task, struct mvs_info *mvi, int is_tmf,
728 struct mvs_tmf_task *tmf, int *pass)
730 struct domain_device *dev = task->dev;
731 struct mvs_device *mvi_dev = dev->lldd_dev;
732 struct mvs_task_exec_info tei;
733 struct mvs_slot_info *slot;
734 u32 tag = 0xdeadbeef, n_elem = 0;
738 struct task_status_struct *tsm = &task->task_status;
740 tsm->resp = SAS_TASK_UNDELIVERED;
741 tsm->stat = SAS_PHY_DOWN;
743 * libsas will use dev->port, should
744 * not call task_done for sata
746 if (dev->dev_type != SATA_DEV)
747 task->task_done(task);
751 if (DEV_IS_GONE(mvi_dev)) {
753 mv_dprintk("device %d not ready.\n",
756 mv_dprintk("device %016llx not ready.\n",
757 SAS_ADDR(dev->sas_addr));
762 tei.port = dev->port->lldd_port;
763 if (tei.port && !tei.port->port_attached && !tmf) {
764 if (sas_protocol_ata(task->task_proto)) {
765 struct task_status_struct *ts = &task->task_status;
766 mv_dprintk("SATA/STP port %d does not attach"
767 "device.\n", dev->port->id);
768 ts->resp = SAS_TASK_COMPLETE;
769 ts->stat = SAS_PHY_DOWN;
771 task->task_done(task);
774 struct task_status_struct *ts = &task->task_status;
775 mv_dprintk("SAS port %d does not attach"
776 "device.\n", dev->port->id);
777 ts->resp = SAS_TASK_UNDELIVERED;
778 ts->stat = SAS_PHY_DOWN;
779 task->task_done(task);
784 if (!sas_protocol_ata(task->task_proto)) {
785 if (task->num_scatter) {
786 n_elem = dma_map_sg(mvi->dev,
796 n_elem = task->num_scatter;
799 rc = mvs_tag_alloc(mvi, &tag);
803 slot = &mvi->slot_info[tag];
805 task->lldd_task = NULL;
806 slot->n_elem = n_elem;
807 slot->slot_tag = tag;
809 slot->buf = pci_pool_alloc(mvi->dma_pool, GFP_ATOMIC, &slot->buf_dma);
812 memset(slot->buf, 0, MVS_SLOT_BUF_SZ);
815 tei.hdr = &mvi->slot[tag];
818 switch (task->task_proto) {
819 case SAS_PROTOCOL_SMP:
820 rc = mvs_task_prep_smp(mvi, &tei);
822 case SAS_PROTOCOL_SSP:
823 rc = mvs_task_prep_ssp(mvi, &tei, is_tmf, tmf);
825 case SAS_PROTOCOL_SATA:
826 case SAS_PROTOCOL_STP:
827 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
828 rc = mvs_task_prep_ata(mvi, &tei);
831 dev_printk(KERN_ERR, mvi->dev,
832 "unknown sas_task proto: 0x%x\n",
839 mv_dprintk("rc is %x\n", rc);
840 goto err_out_slot_buf;
843 slot->port = tei.port;
844 task->lldd_task = slot;
845 list_add_tail(&slot->entry, &tei.port->list);
846 spin_lock(&task->task_state_lock);
847 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
848 spin_unlock(&task->task_state_lock);
850 mvi_dev->running_req++;
852 mvi->tx_prod = (mvi->tx_prod + 1) & (MVS_CHIP_SLOT_SZ - 1);
857 pci_pool_free(mvi->dma_pool, slot->buf, slot->buf_dma);
859 mvs_tag_free(mvi, tag);
862 dev_printk(KERN_ERR, mvi->dev, "mvsas prep failed[%d]!\n", rc);
863 if (!sas_protocol_ata(task->task_proto))
865 dma_unmap_sg(mvi->dev, task->scatter, n_elem,
871 static struct mvs_task_list *mvs_task_alloc_list(int *num, gfp_t gfp_flags)
873 struct mvs_task_list *first = NULL;
875 for (; *num > 0; --*num) {
876 struct mvs_task_list *mvs_list = kmem_cache_zalloc(mvs_task_list_cache, gfp_flags);
881 INIT_LIST_HEAD(&mvs_list->list);
885 list_add_tail(&mvs_list->list, &first->list);
892 static inline void mvs_task_free_list(struct mvs_task_list *mvs_list)
895 struct list_head *pos, *a;
896 struct mvs_task_list *mlist = NULL;
898 __list_add(&list, mvs_list->list.prev, &mvs_list->list);
900 list_for_each_safe(pos, a, &list) {
902 mlist = list_entry(pos, struct mvs_task_list, list);
903 kmem_cache_free(mvs_task_list_cache, mlist);
907 static int mvs_task_exec(struct sas_task *task, const int num, gfp_t gfp_flags,
908 struct completion *completion, int is_tmf,
909 struct mvs_tmf_task *tmf)
911 struct domain_device *dev = task->dev;
912 struct mvs_info *mvi = NULL;
915 unsigned long flags = 0;
917 mvi = ((struct mvs_device *)task->dev->lldd_dev)->mvi_info;
919 if ((dev->dev_type == SATA_DEV) && (dev->sata_dev.ap != NULL))
920 spin_unlock_irq(dev->sata_dev.ap->lock);
922 spin_lock_irqsave(&mvi->lock, flags);
923 rc = mvs_task_prep(task, mvi, is_tmf, tmf, &pass);
925 dev_printk(KERN_ERR, mvi->dev, "mvsas exec failed[%d]!\n", rc);
928 MVS_CHIP_DISP->start_delivery(mvi, (mvi->tx_prod - 1) &
929 (MVS_CHIP_SLOT_SZ - 1));
930 spin_unlock_irqrestore(&mvi->lock, flags);
932 if ((dev->dev_type == SATA_DEV) && (dev->sata_dev.ap != NULL))
933 spin_lock_irq(dev->sata_dev.ap->lock);
938 static int mvs_collector_task_exec(struct sas_task *task, const int num, gfp_t gfp_flags,
939 struct completion *completion, int is_tmf,
940 struct mvs_tmf_task *tmf)
942 struct domain_device *dev = task->dev;
943 struct mvs_prv_info *mpi = dev->port->ha->lldd_ha;
944 struct mvs_info *mvi = NULL;
945 struct sas_task *t = task;
946 struct mvs_task_list *mvs_list = NULL, *a;
951 unsigned long flags = 0;
953 mvs_list = mvs_task_alloc_list(&n, gfp_flags);
955 printk(KERN_ERR "%s: mvs alloc list failed.\n", __func__);
960 __list_add(&q, mvs_list->list.prev, &mvs_list->list);
962 list_for_each_entry(a, &q, list) {
964 t = list_entry(t->list.next, struct sas_task, list);
967 list_for_each_entry(a, &q , list) {
970 mvi = ((struct mvs_device *)t->dev->lldd_dev)->mvi_info;
972 spin_lock_irqsave(&mvi->lock, flags);
973 rc = mvs_task_prep(t, mvi, is_tmf, tmf, &pass[mvi->id]);
975 dev_printk(KERN_ERR, mvi->dev, "mvsas exec failed[%d]!\n", rc);
976 spin_unlock_irqrestore(&mvi->lock, flags);
980 MVS_CHIP_DISP->start_delivery(mpi->mvi[0],
981 (mpi->mvi[0]->tx_prod - 1) & (MVS_CHIP_SLOT_SZ - 1));
984 MVS_CHIP_DISP->start_delivery(mpi->mvi[1],
985 (mpi->mvi[1]->tx_prod - 1) & (MVS_CHIP_SLOT_SZ - 1));
991 mvs_task_free_list(mvs_list);
996 int mvs_queue_command(struct sas_task *task, const int num,
999 struct mvs_device *mvi_dev = task->dev->lldd_dev;
1000 struct sas_ha_struct *sas = mvi_dev->mvi_info->sas;
1002 if (sas->lldd_max_execute_num < 2)
1003 return mvs_task_exec(task, num, gfp_flags, NULL, 0, NULL);
1005 return mvs_collector_task_exec(task, num, gfp_flags, NULL, 0, NULL);
1008 static void mvs_slot_free(struct mvs_info *mvi, u32 rx_desc)
1010 u32 slot_idx = rx_desc & RXQ_SLOT_MASK;
1011 mvs_tag_clear(mvi, slot_idx);
1014 static void mvs_slot_task_free(struct mvs_info *mvi, struct sas_task *task,
1015 struct mvs_slot_info *slot, u32 slot_idx)
1019 if (!sas_protocol_ata(task->task_proto))
1021 dma_unmap_sg(mvi->dev, task->scatter,
1022 slot->n_elem, task->data_dir);
1024 switch (task->task_proto) {
1025 case SAS_PROTOCOL_SMP:
1026 dma_unmap_sg(mvi->dev, &task->smp_task.smp_resp, 1,
1027 PCI_DMA_FROMDEVICE);
1028 dma_unmap_sg(mvi->dev, &task->smp_task.smp_req, 1,
1032 case SAS_PROTOCOL_SATA:
1033 case SAS_PROTOCOL_STP:
1034 case SAS_PROTOCOL_SSP:
1041 pci_pool_free(mvi->dma_pool, slot->buf, slot->buf_dma);
1044 list_del_init(&slot->entry);
1045 task->lldd_task = NULL;
1048 slot->slot_tag = 0xFFFFFFFF;
1049 mvs_slot_free(mvi, slot_idx);
1052 static void mvs_update_wideport(struct mvs_info *mvi, int i)
1054 struct mvs_phy *phy = &mvi->phy[i];
1055 struct mvs_port *port = phy->port;
1058 for_each_phy(port->wide_port_phymap, j, no) {
1060 MVS_CHIP_DISP->write_port_cfg_addr(mvi, no,
1062 MVS_CHIP_DISP->write_port_cfg_data(mvi, no,
1063 port->wide_port_phymap);
1065 MVS_CHIP_DISP->write_port_cfg_addr(mvi, no,
1067 MVS_CHIP_DISP->write_port_cfg_data(mvi, no,
1073 static u32 mvs_is_phy_ready(struct mvs_info *mvi, int i)
1076 struct mvs_phy *phy = &mvi->phy[i];
1077 struct mvs_port *port = phy->port;
1079 tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, i);
1080 if ((tmp & PHY_READY_MASK) && !(phy->irq_status & PHYEV_POOF)) {
1082 phy->phy_attached = 1;
1087 if (phy->phy_type & PORT_TYPE_SAS) {
1088 port->wide_port_phymap &= ~(1U << i);
1089 if (!port->wide_port_phymap)
1090 port->port_attached = 0;
1091 mvs_update_wideport(mvi, i);
1092 } else if (phy->phy_type & PORT_TYPE_SATA)
1093 port->port_attached = 0;
1095 phy->phy_attached = 0;
1096 phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
1101 static void *mvs_get_d2h_reg(struct mvs_info *mvi, int i, void *buf)
1103 u32 *s = (u32 *) buf;
1108 MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG3);
1109 s[3] = MVS_CHIP_DISP->read_port_cfg_data(mvi, i);
1111 MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG2);
1112 s[2] = MVS_CHIP_DISP->read_port_cfg_data(mvi, i);
1114 MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG1);
1115 s[1] = MVS_CHIP_DISP->read_port_cfg_data(mvi, i);
1117 MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG0);
1118 s[0] = MVS_CHIP_DISP->read_port_cfg_data(mvi, i);
1120 /* Workaround: take some ATAPI devices for ATA */
1121 if (((s[1] & 0x00FFFFFF) == 0x00EB1401) && (*(u8 *)&s[3] == 0x01))
1122 s[1] = 0x00EB1401 | (*((u8 *)&s[1] + 3) & 0x10);
1127 static u32 mvs_is_sig_fis_received(u32 irq_status)
1129 return irq_status & PHYEV_SIG_FIS;
1132 static void mvs_sig_remove_timer(struct mvs_phy *phy)
1134 if (phy->timer.function)
1135 del_timer(&phy->timer);
1136 phy->timer.function = NULL;
1139 void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st)
1141 struct mvs_phy *phy = &mvi->phy[i];
1142 struct sas_identify_frame *id;
1144 id = (struct sas_identify_frame *)phy->frame_rcvd;
1147 phy->irq_status = MVS_CHIP_DISP->read_port_irq_stat(mvi, i);
1148 phy->phy_status = mvs_is_phy_ready(mvi, i);
1151 if (phy->phy_status) {
1153 struct asd_sas_phy *sas_phy = &mvi->phy[i].sas_phy;
1155 oob_done = MVS_CHIP_DISP->oob_done(mvi, i);
1157 MVS_CHIP_DISP->fix_phy_info(mvi, i, id);
1158 if (phy->phy_type & PORT_TYPE_SATA) {
1159 phy->identify.target_port_protocols = SAS_PROTOCOL_STP;
1160 if (mvs_is_sig_fis_received(phy->irq_status)) {
1161 mvs_sig_remove_timer(phy);
1162 phy->phy_attached = 1;
1163 phy->att_dev_sas_addr =
1164 i + mvi->id * mvi->chip->n_phy;
1166 sas_phy->oob_mode = SATA_OOB_MODE;
1167 phy->frame_rcvd_size =
1168 sizeof(struct dev_to_host_fis);
1169 mvs_get_d2h_reg(mvi, i, id);
1172 dev_printk(KERN_DEBUG, mvi->dev,
1173 "Phy%d : No sig fis\n", i);
1174 tmp = MVS_CHIP_DISP->read_port_irq_mask(mvi, i);
1175 MVS_CHIP_DISP->write_port_irq_mask(mvi, i,
1176 tmp | PHYEV_SIG_FIS);
1177 phy->phy_attached = 0;
1178 phy->phy_type &= ~PORT_TYPE_SATA;
1181 } else if (phy->phy_type & PORT_TYPE_SAS
1182 || phy->att_dev_info & PORT_SSP_INIT_MASK) {
1183 phy->phy_attached = 1;
1184 phy->identify.device_type =
1185 phy->att_dev_info & PORT_DEV_TYPE_MASK;
1187 if (phy->identify.device_type == SAS_END_DEV)
1188 phy->identify.target_port_protocols =
1190 else if (phy->identify.device_type != NO_DEVICE)
1191 phy->identify.target_port_protocols =
1194 sas_phy->oob_mode = SAS_OOB_MODE;
1195 phy->frame_rcvd_size =
1196 sizeof(struct sas_identify_frame);
1198 memcpy(sas_phy->attached_sas_addr,
1199 &phy->att_dev_sas_addr, SAS_ADDR_SIZE);
1201 if (MVS_CHIP_DISP->phy_work_around)
1202 MVS_CHIP_DISP->phy_work_around(mvi, i);
1204 mv_dprintk("port %d attach dev info is %x\n",
1205 i + mvi->id * mvi->chip->n_phy, phy->att_dev_info);
1206 mv_dprintk("port %d attach sas addr is %llx\n",
1207 i + mvi->id * mvi->chip->n_phy, phy->att_dev_sas_addr);
1210 MVS_CHIP_DISP->write_port_irq_stat(mvi, i, phy->irq_status);
1213 static void mvs_port_notify_formed(struct asd_sas_phy *sas_phy, int lock)
1215 struct sas_ha_struct *sas_ha = sas_phy->ha;
1216 struct mvs_info *mvi = NULL; int i = 0, hi;
1217 struct mvs_phy *phy = sas_phy->lldd_phy;
1218 struct asd_sas_port *sas_port = sas_phy->port;
1219 struct mvs_port *port;
1220 unsigned long flags = 0;
1224 while (sas_ha->sas_phy[i]) {
1225 if (sas_ha->sas_phy[i] == sas_phy)
1229 hi = i/((struct mvs_prv_info *)sas_ha->lldd_ha)->n_phy;
1230 mvi = ((struct mvs_prv_info *)sas_ha->lldd_ha)->mvi[hi];
1231 if (sas_port->id >= mvi->chip->n_phy)
1232 port = &mvi->port[sas_port->id - mvi->chip->n_phy];
1234 port = &mvi->port[sas_port->id];
1236 spin_lock_irqsave(&mvi->lock, flags);
1237 port->port_attached = 1;
1239 sas_port->lldd_port = port;
1240 if (phy->phy_type & PORT_TYPE_SAS) {
1241 port->wide_port_phymap = sas_port->phy_mask;
1242 mv_printk("set wide port phy map %x\n", sas_port->phy_mask);
1243 mvs_update_wideport(mvi, sas_phy->id);
1246 spin_unlock_irqrestore(&mvi->lock, flags);
1249 static void mvs_port_notify_deformed(struct asd_sas_phy *sas_phy, int lock)
1251 struct domain_device *dev;
1252 struct mvs_phy *phy = sas_phy->lldd_phy;
1253 struct mvs_info *mvi = phy->mvi;
1254 struct asd_sas_port *port = sas_phy->port;
1257 while (phy != &mvi->phy[phy_no]) {
1259 if (phy_no >= MVS_MAX_PHYS)
1262 list_for_each_entry(dev, &port->dev_list, dev_list_node)
1263 mvs_do_release_task(phy->mvi, phy_no, NULL);
1268 void mvs_port_formed(struct asd_sas_phy *sas_phy)
1270 mvs_port_notify_formed(sas_phy, 1);
1273 void mvs_port_deformed(struct asd_sas_phy *sas_phy)
1275 mvs_port_notify_deformed(sas_phy, 1);
1278 struct mvs_device *mvs_alloc_dev(struct mvs_info *mvi)
1281 for (dev = 0; dev < MVS_MAX_DEVICES; dev++) {
1282 if (mvi->devices[dev].dev_type == NO_DEVICE) {
1283 mvi->devices[dev].device_id = dev;
1284 return &mvi->devices[dev];
1288 if (dev == MVS_MAX_DEVICES)
1289 mv_printk("max support %d devices, ignore ..\n",
1295 void mvs_free_dev(struct mvs_device *mvi_dev)
1297 u32 id = mvi_dev->device_id;
1298 memset(mvi_dev, 0, sizeof(*mvi_dev));
1299 mvi_dev->device_id = id;
1300 mvi_dev->dev_type = NO_DEVICE;
1301 mvi_dev->dev_status = MVS_DEV_NORMAL;
1302 mvi_dev->taskfileset = MVS_ID_NOT_MAPPED;
1305 int mvs_dev_found_notify(struct domain_device *dev, int lock)
1307 unsigned long flags = 0;
1309 struct mvs_info *mvi = NULL;
1310 struct domain_device *parent_dev = dev->parent;
1311 struct mvs_device *mvi_device;
1313 mvi = mvs_find_dev_mvi(dev);
1316 spin_lock_irqsave(&mvi->lock, flags);
1318 mvi_device = mvs_alloc_dev(mvi);
1323 dev->lldd_dev = mvi_device;
1324 mvi_device->dev_status = MVS_DEV_NORMAL;
1325 mvi_device->dev_type = dev->dev_type;
1326 mvi_device->mvi_info = mvi;
1327 if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) {
1329 u8 phy_num = parent_dev->ex_dev.num_phys;
1331 for (phy_id = 0; phy_id < phy_num; phy_id++) {
1332 phy = &parent_dev->ex_dev.ex_phy[phy_id];
1333 if (SAS_ADDR(phy->attached_sas_addr) ==
1334 SAS_ADDR(dev->sas_addr)) {
1335 mvi_device->attached_phy = phy_id;
1340 if (phy_id == phy_num) {
1341 mv_printk("Error: no attached dev:%016llx"
1343 SAS_ADDR(dev->sas_addr),
1344 SAS_ADDR(parent_dev->sas_addr));
1351 spin_unlock_irqrestore(&mvi->lock, flags);
1355 int mvs_dev_found(struct domain_device *dev)
1357 return mvs_dev_found_notify(dev, 1);
1360 void mvs_dev_gone_notify(struct domain_device *dev)
1362 unsigned long flags = 0;
1363 struct mvs_device *mvi_dev = dev->lldd_dev;
1364 struct mvs_info *mvi = mvi_dev->mvi_info;
1366 spin_lock_irqsave(&mvi->lock, flags);
1369 mv_dprintk("found dev[%d:%x] is gone.\n",
1370 mvi_dev->device_id, mvi_dev->dev_type);
1371 mvs_release_task(mvi, dev);
1372 mvs_free_reg_set(mvi, mvi_dev);
1373 mvs_free_dev(mvi_dev);
1375 mv_dprintk("found dev has gone.\n");
1377 dev->lldd_dev = NULL;
1379 spin_unlock_irqrestore(&mvi->lock, flags);
1383 void mvs_dev_gone(struct domain_device *dev)
1385 mvs_dev_gone_notify(dev);
1388 static struct sas_task *mvs_alloc_task(void)
1390 struct sas_task *task = kzalloc(sizeof(struct sas_task), GFP_KERNEL);
1393 INIT_LIST_HEAD(&task->list);
1394 spin_lock_init(&task->task_state_lock);
1395 task->task_state_flags = SAS_TASK_STATE_PENDING;
1396 init_timer(&task->timer);
1397 init_completion(&task->completion);
1402 static void mvs_free_task(struct sas_task *task)
1405 BUG_ON(!list_empty(&task->list));
1410 static void mvs_task_done(struct sas_task *task)
1412 if (!del_timer(&task->timer))
1414 complete(&task->completion);
1417 static void mvs_tmf_timedout(unsigned long data)
1419 struct sas_task *task = (struct sas_task *)data;
1421 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1422 complete(&task->completion);
1426 #define MVS_TASK_TIMEOUT 20
1427 static int mvs_exec_internal_tmf_task(struct domain_device *dev,
1428 void *parameter, u32 para_len, struct mvs_tmf_task *tmf)
1431 struct sas_task *task = NULL;
1433 for (retry = 0; retry < 3; retry++) {
1434 task = mvs_alloc_task();
1439 task->task_proto = dev->tproto;
1441 memcpy(&task->ssp_task, parameter, para_len);
1442 task->task_done = mvs_task_done;
1444 task->timer.data = (unsigned long) task;
1445 task->timer.function = mvs_tmf_timedout;
1446 task->timer.expires = jiffies + MVS_TASK_TIMEOUT*HZ;
1447 add_timer(&task->timer);
1449 res = mvs_task_exec(task, 1, GFP_KERNEL, NULL, 1, tmf);
1452 del_timer(&task->timer);
1453 mv_printk("executing internel task failed:%d\n", res);
1457 wait_for_completion(&task->completion);
1458 res = -TMF_RESP_FUNC_FAILED;
1459 /* Even TMF timed out, return direct. */
1460 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
1461 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1462 mv_printk("TMF task[%x] timeout.\n", tmf->tmf);
1467 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1468 task->task_status.stat == SAM_STAT_GOOD) {
1469 res = TMF_RESP_FUNC_COMPLETE;
1473 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1474 task->task_status.stat == SAS_DATA_UNDERRUN) {
1475 /* no error, but return the number of bytes of
1477 res = task->task_status.residual;
1481 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1482 task->task_status.stat == SAS_DATA_OVERRUN) {
1483 mv_dprintk("blocked task error.\n");
1487 mv_dprintk(" task to dev %016llx response: 0x%x "
1489 SAS_ADDR(dev->sas_addr),
1490 task->task_status.resp,
1491 task->task_status.stat);
1492 mvs_free_task(task);
1498 BUG_ON(retry == 3 && task != NULL);
1500 mvs_free_task(task);
1504 static int mvs_debug_issue_ssp_tmf(struct domain_device *dev,
1505 u8 *lun, struct mvs_tmf_task *tmf)
1507 struct sas_ssp_task ssp_task;
1508 DECLARE_COMPLETION_ONSTACK(completion);
1509 if (!(dev->tproto & SAS_PROTOCOL_SSP))
1510 return TMF_RESP_FUNC_ESUPP;
1512 strncpy((u8 *)&ssp_task.LUN, lun, 8);
1514 return mvs_exec_internal_tmf_task(dev, &ssp_task,
1515 sizeof(ssp_task), tmf);
1519 /* Standard mandates link reset for ATA (type 0)
1520 and hard reset for SSP (type 1) , only for RECOVERY */
1521 static int mvs_debug_I_T_nexus_reset(struct domain_device *dev)
1524 struct sas_phy *phy = sas_find_local_phy(dev);
1525 int reset_type = (dev->dev_type == SATA_DEV ||
1526 (dev->tproto & SAS_PROTOCOL_STP)) ? 0 : 1;
1527 rc = sas_phy_reset(phy, reset_type);
1532 /* mandatory SAM-3 */
1533 int mvs_lu_reset(struct domain_device *dev, u8 *lun)
1535 unsigned long flags;
1536 int i, phyno[WIDE_PORT_MAX_PHY], num , rc = TMF_RESP_FUNC_FAILED;
1537 struct mvs_tmf_task tmf_task;
1538 struct mvs_device * mvi_dev = dev->lldd_dev;
1539 struct mvs_info *mvi = mvi_dev->mvi_info;
1541 tmf_task.tmf = TMF_LU_RESET;
1542 mvi_dev->dev_status = MVS_DEV_EH;
1543 rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task);
1544 if (rc == TMF_RESP_FUNC_COMPLETE) {
1545 num = mvs_find_dev_phyno(dev, phyno);
1546 spin_lock_irqsave(&mvi->lock, flags);
1547 for (i = 0; i < num; i++)
1548 mvs_release_task(mvi, dev);
1549 spin_unlock_irqrestore(&mvi->lock, flags);
1551 /* If failed, fall-through I_T_Nexus reset */
1552 mv_printk("%s for device[%x]:rc= %d\n", __func__,
1553 mvi_dev->device_id, rc);
1557 int mvs_I_T_nexus_reset(struct domain_device *dev)
1559 unsigned long flags;
1560 int rc = TMF_RESP_FUNC_FAILED;
1561 struct mvs_device * mvi_dev = (struct mvs_device *)dev->lldd_dev;
1562 struct mvs_info *mvi = mvi_dev->mvi_info;
1564 if (mvi_dev->dev_status != MVS_DEV_EH)
1565 return TMF_RESP_FUNC_COMPLETE;
1566 rc = mvs_debug_I_T_nexus_reset(dev);
1567 mv_printk("%s for device[%x]:rc= %d\n",
1568 __func__, mvi_dev->device_id, rc);
1571 spin_lock_irqsave(&mvi->lock, flags);
1572 mvs_release_task(mvi, dev);
1573 spin_unlock_irqrestore(&mvi->lock, flags);
1577 /* optional SAM-3 */
1578 int mvs_query_task(struct sas_task *task)
1581 struct scsi_lun lun;
1582 struct mvs_tmf_task tmf_task;
1583 int rc = TMF_RESP_FUNC_FAILED;
1585 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
1586 struct scsi_cmnd * cmnd = (struct scsi_cmnd *)task->uldd_task;
1587 struct domain_device *dev = task->dev;
1588 struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev;
1589 struct mvs_info *mvi = mvi_dev->mvi_info;
1591 int_to_scsilun(cmnd->device->lun, &lun);
1592 rc = mvs_find_tag(mvi, task, &tag);
1594 rc = TMF_RESP_FUNC_FAILED;
1598 tmf_task.tmf = TMF_QUERY_TASK;
1599 tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag);
1601 rc = mvs_debug_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
1603 /* The task is still in Lun, release it then */
1604 case TMF_RESP_FUNC_SUCC:
1605 /* The task is not in Lun or failed, reset the phy */
1606 case TMF_RESP_FUNC_FAILED:
1607 case TMF_RESP_FUNC_COMPLETE:
1610 rc = TMF_RESP_FUNC_COMPLETE;
1614 mv_printk("%s:rc= %d\n", __func__, rc);
1618 /* mandatory SAM-3, still need free task/slot info */
1619 int mvs_abort_task(struct sas_task *task)
1621 struct scsi_lun lun;
1622 struct mvs_tmf_task tmf_task;
1623 struct domain_device *dev = task->dev;
1624 struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev;
1625 struct mvs_info *mvi;
1626 int rc = TMF_RESP_FUNC_FAILED;
1627 unsigned long flags;
1631 mv_printk("%s:%d TMF_RESP_FUNC_FAILED\n", __func__, __LINE__);
1632 rc = TMF_RESP_FUNC_FAILED;
1635 mvi = mvi_dev->mvi_info;
1637 spin_lock_irqsave(&task->task_state_lock, flags);
1638 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
1639 spin_unlock_irqrestore(&task->task_state_lock, flags);
1640 rc = TMF_RESP_FUNC_COMPLETE;
1643 spin_unlock_irqrestore(&task->task_state_lock, flags);
1644 mvi_dev->dev_status = MVS_DEV_EH;
1645 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
1646 struct scsi_cmnd * cmnd = (struct scsi_cmnd *)task->uldd_task;
1648 int_to_scsilun(cmnd->device->lun, &lun);
1649 rc = mvs_find_tag(mvi, task, &tag);
1651 mv_printk("No such tag in %s\n", __func__);
1652 rc = TMF_RESP_FUNC_FAILED;
1656 tmf_task.tmf = TMF_ABORT_TASK;
1657 tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag);
1659 rc = mvs_debug_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task);
1661 /* if successful, clear the task and callback forwards.*/
1662 if (rc == TMF_RESP_FUNC_COMPLETE) {
1664 struct mvs_slot_info *slot;
1666 if (task->lldd_task) {
1667 slot = task->lldd_task;
1668 slot_no = (u32) (slot - mvi->slot_info);
1669 spin_lock_irqsave(&mvi->lock, flags);
1670 mvs_slot_complete(mvi, slot_no, 1);
1671 spin_unlock_irqrestore(&mvi->lock, flags);
1675 } else if (task->task_proto & SAS_PROTOCOL_SATA ||
1676 task->task_proto & SAS_PROTOCOL_STP) {
1677 /* to do free register_set */
1678 if (SATA_DEV == dev->dev_type) {
1679 struct mvs_slot_info *slot = task->lldd_task;
1680 struct task_status_struct *tstat;
1681 u32 slot_idx = (u32)(slot - mvi->slot_info);
1682 tstat = &task->task_status;
1683 mv_dprintk(KERN_DEBUG "mv_abort_task() mvi=%p task=%p "
1684 "slot=%p slot_idx=x%x\n",
1685 mvi, task, slot, slot_idx);
1686 tstat->stat = SAS_ABORTED_TASK;
1687 if (mvi_dev && mvi_dev->running_req)
1688 mvi_dev->running_req--;
1689 if (sas_protocol_ata(task->task_proto))
1690 mvs_free_reg_set(mvi, mvi_dev);
1691 mvs_slot_task_free(mvi, task, slot, slot_idx);
1699 if (rc != TMF_RESP_FUNC_COMPLETE)
1700 mv_printk("%s:rc= %d\n", __func__, rc);
1704 int mvs_abort_task_set(struct domain_device *dev, u8 *lun)
1706 int rc = TMF_RESP_FUNC_FAILED;
1707 struct mvs_tmf_task tmf_task;
1709 tmf_task.tmf = TMF_ABORT_TASK_SET;
1710 rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task);
1715 int mvs_clear_aca(struct domain_device *dev, u8 *lun)
1717 int rc = TMF_RESP_FUNC_FAILED;
1718 struct mvs_tmf_task tmf_task;
1720 tmf_task.tmf = TMF_CLEAR_ACA;
1721 rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task);
1726 int mvs_clear_task_set(struct domain_device *dev, u8 *lun)
1728 int rc = TMF_RESP_FUNC_FAILED;
1729 struct mvs_tmf_task tmf_task;
1731 tmf_task.tmf = TMF_CLEAR_TASK_SET;
1732 rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task);
1737 static int mvs_sata_done(struct mvs_info *mvi, struct sas_task *task,
1738 u32 slot_idx, int err)
1740 struct mvs_device *mvi_dev = task->dev->lldd_dev;
1741 struct task_status_struct *tstat = &task->task_status;
1742 struct ata_task_resp *resp = (struct ata_task_resp *)tstat->buf;
1743 int stat = SAM_STAT_GOOD;
1746 resp->frame_len = sizeof(struct dev_to_host_fis);
1747 memcpy(&resp->ending_fis[0],
1748 SATA_RECEIVED_D2H_FIS(mvi_dev->taskfileset),
1749 sizeof(struct dev_to_host_fis));
1750 tstat->buf_valid_size = sizeof(*resp);
1751 if (unlikely(err)) {
1752 if (unlikely(err & CMD_ISS_STPD))
1753 stat = SAS_OPEN_REJECT;
1755 stat = SAS_PROTO_RESPONSE;
1761 static int mvs_slot_err(struct mvs_info *mvi, struct sas_task *task,
1764 struct mvs_slot_info *slot = &mvi->slot_info[slot_idx];
1766 u32 err_dw0 = le32_to_cpu(*(u32 *) (slot->response));
1768 enum mvs_port_type type = PORT_TYPE_SAS;
1770 if (err_dw0 & CMD_ISS_STPD)
1771 MVS_CHIP_DISP->issue_stop(mvi, type, tfs);
1773 MVS_CHIP_DISP->command_active(mvi, slot_idx);
1775 stat = SAM_STAT_CHECK_CONDITION;
1776 switch (task->task_proto) {
1777 case SAS_PROTOCOL_SSP:
1778 stat = SAS_ABORTED_TASK;
1780 case SAS_PROTOCOL_SMP:
1781 stat = SAM_STAT_CHECK_CONDITION;
1784 case SAS_PROTOCOL_SATA:
1785 case SAS_PROTOCOL_STP:
1786 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
1788 if (err_dw0 == 0x80400002)
1789 mv_printk("find reserved error, why?\n");
1791 task->ata_task.use_ncq = 0;
1792 mvs_sata_done(mvi, task, slot_idx, err_dw0);
1802 int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags)
1804 u32 slot_idx = rx_desc & RXQ_SLOT_MASK;
1805 struct mvs_slot_info *slot = &mvi->slot_info[slot_idx];
1806 struct sas_task *task = slot->task;
1807 struct mvs_device *mvi_dev = NULL;
1808 struct task_status_struct *tstat;
1809 struct domain_device *dev;
1813 enum exec_status sts;
1815 if (unlikely(!task || !task->lldd_task || !task->dev))
1818 tstat = &task->task_status;
1820 mvi_dev = dev->lldd_dev;
1822 spin_lock(&task->task_state_lock);
1823 task->task_state_flags &=
1824 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
1825 task->task_state_flags |= SAS_TASK_STATE_DONE;
1827 aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED;
1828 spin_unlock(&task->task_state_lock);
1830 memset(tstat, 0, sizeof(*tstat));
1831 tstat->resp = SAS_TASK_COMPLETE;
1833 if (unlikely(aborted)) {
1834 tstat->stat = SAS_ABORTED_TASK;
1835 if (mvi_dev && mvi_dev->running_req)
1836 mvi_dev->running_req--;
1837 if (sas_protocol_ata(task->task_proto))
1838 mvs_free_reg_set(mvi, mvi_dev);
1840 mvs_slot_task_free(mvi, task, slot, slot_idx);
1844 if (unlikely(!mvi_dev || flags)) {
1846 mv_dprintk("port has not device.\n");
1847 tstat->stat = SAS_PHY_DOWN;
1851 /* error info record present */
1852 if (unlikely((rx_desc & RXQ_ERR) && (*(u64 *) slot->response))) {
1853 tstat->stat = mvs_slot_err(mvi, task, slot_idx);
1854 tstat->resp = SAS_TASK_COMPLETE;
1858 switch (task->task_proto) {
1859 case SAS_PROTOCOL_SSP:
1860 /* hw says status == 0, datapres == 0 */
1861 if (rx_desc & RXQ_GOOD) {
1862 tstat->stat = SAM_STAT_GOOD;
1863 tstat->resp = SAS_TASK_COMPLETE;
1865 /* response frame present */
1866 else if (rx_desc & RXQ_RSP) {
1867 struct ssp_response_iu *iu = slot->response +
1868 sizeof(struct mvs_err_info);
1869 sas_ssp_task_response(mvi->dev, task, iu);
1871 tstat->stat = SAM_STAT_CHECK_CONDITION;
1874 case SAS_PROTOCOL_SMP: {
1875 struct scatterlist *sg_resp = &task->smp_task.smp_resp;
1876 tstat->stat = SAM_STAT_GOOD;
1877 to = kmap_atomic(sg_page(sg_resp), KM_IRQ0);
1878 memcpy(to + sg_resp->offset,
1879 slot->response + sizeof(struct mvs_err_info),
1880 sg_dma_len(sg_resp));
1881 kunmap_atomic(to, KM_IRQ0);
1885 case SAS_PROTOCOL_SATA:
1886 case SAS_PROTOCOL_STP:
1887 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: {
1888 tstat->stat = mvs_sata_done(mvi, task, slot_idx, 0);
1893 tstat->stat = SAM_STAT_CHECK_CONDITION;
1896 if (!slot->port->port_attached) {
1897 mv_dprintk("port %d has removed.\n", slot->port->sas_port.id);
1898 tstat->stat = SAS_PHY_DOWN;
1903 if (mvi_dev && mvi_dev->running_req) {
1904 mvi_dev->running_req--;
1905 if (sas_protocol_ata(task->task_proto) && !mvi_dev->running_req)
1906 mvs_free_reg_set(mvi, mvi_dev);
1908 mvs_slot_task_free(mvi, task, slot, slot_idx);
1911 spin_unlock(&mvi->lock);
1912 if (task->task_done)
1913 task->task_done(task);
1915 mv_dprintk("why has not task_done.\n");
1916 spin_lock(&mvi->lock);
1921 void mvs_do_release_task(struct mvs_info *mvi,
1922 int phy_no, struct domain_device *dev)
1925 struct mvs_phy *phy;
1926 struct mvs_port *port;
1927 struct mvs_slot_info *slot, *slot2;
1929 phy = &mvi->phy[phy_no];
1933 /* clean cmpl queue in case request is already finished */
1934 mvs_int_rx(mvi, false);
1938 list_for_each_entry_safe(slot, slot2, &port->list, entry) {
1939 struct sas_task *task;
1940 slot_idx = (u32) (slot - mvi->slot_info);
1943 if (dev && task->dev != dev)
1946 mv_printk("Release slot [%x] tag[%x], task [%p]:\n",
1947 slot_idx, slot->slot_tag, task);
1948 MVS_CHIP_DISP->command_active(mvi, slot_idx);
1950 mvs_slot_complete(mvi, slot_idx, 1);
1954 void mvs_release_task(struct mvs_info *mvi,
1955 struct domain_device *dev)
1957 int i, phyno[WIDE_PORT_MAX_PHY], num;
1959 num = mvs_find_dev_phyno(dev, phyno);
1960 for (i = 0; i < num; i++)
1961 mvs_do_release_task(mvi, phyno[i], dev);
1964 static void mvs_phy_disconnected(struct mvs_phy *phy)
1966 phy->phy_attached = 0;
1967 phy->att_dev_info = 0;
1968 phy->att_dev_sas_addr = 0;
1971 static void mvs_work_queue(struct work_struct *work)
1973 struct delayed_work *dw = container_of(work, struct delayed_work, work);
1974 struct mvs_wq *mwq = container_of(dw, struct mvs_wq, work_q);
1975 struct mvs_info *mvi = mwq->mvi;
1976 unsigned long flags;
1978 spin_lock_irqsave(&mvi->lock, flags);
1979 if (mwq->handler & PHY_PLUG_EVENT) {
1980 u32 phy_no = (unsigned long) mwq->data;
1981 struct sas_ha_struct *sas_ha = mvi->sas;
1982 struct mvs_phy *phy = &mvi->phy[phy_no];
1983 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1985 if (phy->phy_event & PHY_PLUG_OUT) {
1987 struct sas_identify_frame *id;
1988 id = (struct sas_identify_frame *)phy->frame_rcvd;
1989 tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, phy_no);
1990 phy->phy_event &= ~PHY_PLUG_OUT;
1991 if (!(tmp & PHY_READY_MASK)) {
1992 sas_phy_disconnected(sas_phy);
1993 mvs_phy_disconnected(phy);
1994 sas_ha->notify_phy_event(sas_phy,
1995 PHYE_LOSS_OF_SIGNAL);
1996 mv_dprintk("phy%d Removed Device\n", phy_no);
1998 MVS_CHIP_DISP->detect_porttype(mvi, phy_no);
1999 mvs_update_phyinfo(mvi, phy_no, 1);
2000 mvs_bytes_dmaed(mvi, phy_no);
2001 mvs_port_notify_formed(sas_phy, 0);
2002 mv_dprintk("phy%d Attached Device\n", phy_no);
2006 list_del(&mwq->entry);
2007 spin_unlock_irqrestore(&mvi->lock, flags);
2011 static int mvs_handle_event(struct mvs_info *mvi, void *data, int handler)
2016 mwq = kmalloc(sizeof(struct mvs_wq), GFP_ATOMIC);
2020 mwq->handler = handler;
2021 MV_INIT_DELAYED_WORK(&mwq->work_q, mvs_work_queue, mwq);
2022 list_add_tail(&mwq->entry, &mvi->wq_list);
2023 schedule_delayed_work(&mwq->work_q, HZ * 2);
2030 static void mvs_sig_time_out(unsigned long tphy)
2032 struct mvs_phy *phy = (struct mvs_phy *)tphy;
2033 struct mvs_info *mvi = phy->mvi;
2036 for (phy_no = 0; phy_no < mvi->chip->n_phy; phy_no++) {
2037 if (&mvi->phy[phy_no] == phy) {
2038 mv_dprintk("Get signature time out, reset phy %d\n",
2039 phy_no+mvi->id*mvi->chip->n_phy);
2040 MVS_CHIP_DISP->phy_reset(mvi, phy_no, 1);
2045 void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events)
2048 struct sas_ha_struct *sas_ha = mvi->sas;
2049 struct mvs_phy *phy = &mvi->phy[phy_no];
2050 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2052 phy->irq_status = MVS_CHIP_DISP->read_port_irq_stat(mvi, phy_no);
2053 mv_dprintk("port %d ctrl sts=0x%X.\n", phy_no+mvi->id*mvi->chip->n_phy,
2054 MVS_CHIP_DISP->read_phy_ctl(mvi, phy_no));
2055 mv_dprintk("Port %d irq sts = 0x%X\n", phy_no+mvi->id*mvi->chip->n_phy,
2059 * events is port event now ,
2060 * we need check the interrupt status which belongs to per port.
2063 if (phy->irq_status & PHYEV_DCDR_ERR) {
2064 mv_dprintk("port %d STP decoding error.\n",
2065 phy_no + mvi->id*mvi->chip->n_phy);
2068 if (phy->irq_status & PHYEV_POOF) {
2069 if (!(phy->phy_event & PHY_PLUG_OUT)) {
2070 int dev_sata = phy->phy_type & PORT_TYPE_SATA;
2072 mvs_do_release_task(mvi, phy_no, NULL);
2073 phy->phy_event |= PHY_PLUG_OUT;
2074 MVS_CHIP_DISP->clear_srs_irq(mvi, 0, 1);
2075 mvs_handle_event(mvi,
2076 (void *)(unsigned long)phy_no,
2078 ready = mvs_is_phy_ready(mvi, phy_no);
2080 mv_dprintk("phy%d Unplug Notice\n",
2082 mvi->id * mvi->chip->n_phy);
2083 if (ready || dev_sata) {
2084 if (MVS_CHIP_DISP->stp_reset)
2085 MVS_CHIP_DISP->stp_reset(mvi,
2088 MVS_CHIP_DISP->phy_reset(mvi,
2095 if (phy->irq_status & PHYEV_COMWAKE) {
2096 tmp = MVS_CHIP_DISP->read_port_irq_mask(mvi, phy_no);
2097 MVS_CHIP_DISP->write_port_irq_mask(mvi, phy_no,
2098 tmp | PHYEV_SIG_FIS);
2099 if (phy->timer.function == NULL) {
2100 phy->timer.data = (unsigned long)phy;
2101 phy->timer.function = mvs_sig_time_out;
2102 phy->timer.expires = jiffies + 10*HZ;
2103 add_timer(&phy->timer);
2106 if (phy->irq_status & (PHYEV_SIG_FIS | PHYEV_ID_DONE)) {
2107 phy->phy_status = mvs_is_phy_ready(mvi, phy_no);
2108 mv_dprintk("notify plug in on phy[%d]\n", phy_no);
2109 if (phy->phy_status) {
2111 MVS_CHIP_DISP->detect_porttype(mvi, phy_no);
2112 if (phy->phy_type & PORT_TYPE_SATA) {
2113 tmp = MVS_CHIP_DISP->read_port_irq_mask(
2115 tmp &= ~PHYEV_SIG_FIS;
2116 MVS_CHIP_DISP->write_port_irq_mask(mvi,
2119 mvs_update_phyinfo(mvi, phy_no, 0);
2120 if (phy->phy_type & PORT_TYPE_SAS) {
2121 MVS_CHIP_DISP->phy_reset(mvi, phy_no, 2);
2125 mvs_bytes_dmaed(mvi, phy_no);
2126 /* whether driver is going to handle hot plug */
2127 if (phy->phy_event & PHY_PLUG_OUT) {
2128 mvs_port_notify_formed(sas_phy, 0);
2129 phy->phy_event &= ~PHY_PLUG_OUT;
2132 mv_dprintk("plugin interrupt but phy%d is gone\n",
2133 phy_no + mvi->id*mvi->chip->n_phy);
2135 } else if (phy->irq_status & PHYEV_BROAD_CH) {
2136 mv_dprintk("port %d broadcast change.\n",
2137 phy_no + mvi->id*mvi->chip->n_phy);
2138 /* exception for Samsung disk drive*/
2140 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
2142 MVS_CHIP_DISP->write_port_irq_stat(mvi, phy_no, phy->irq_status);
2145 int mvs_int_rx(struct mvs_info *mvi, bool self_clear)
2147 u32 rx_prod_idx, rx_desc;
2150 /* the first dword in the RX ring is special: it contains
2151 * a mirror of the hardware's RX producer index, so that
2152 * we don't have to stall the CPU reading that register.
2153 * The actual RX ring is offset by one dword, due to this.
2155 rx_prod_idx = mvi->rx_cons;
2156 mvi->rx_cons = le32_to_cpu(mvi->rx[0]);
2157 if (mvi->rx_cons == 0xfff) /* h/w hasn't touched RX ring yet */
2160 /* The CMPL_Q may come late, read from register and try again
2161 * note: if coalescing is enabled,
2162 * it will need to read from register every time for sure
2164 if (unlikely(mvi->rx_cons == rx_prod_idx))
2165 mvi->rx_cons = MVS_CHIP_DISP->rx_update(mvi) & RX_RING_SZ_MASK;
2167 if (mvi->rx_cons == rx_prod_idx)
2170 while (mvi->rx_cons != rx_prod_idx) {
2171 /* increment our internal RX consumer pointer */
2172 rx_prod_idx = (rx_prod_idx + 1) & (MVS_RX_RING_SZ - 1);
2173 rx_desc = le32_to_cpu(mvi->rx[rx_prod_idx + 1]);
2175 if (likely(rx_desc & RXQ_DONE))
2176 mvs_slot_complete(mvi, rx_desc, 0);
2177 if (rx_desc & RXQ_ATTN) {
2179 } else if (rx_desc & RXQ_ERR) {
2180 if (!(rx_desc & RXQ_DONE))
2181 mvs_slot_complete(mvi, rx_desc, 0);
2182 } else if (rx_desc & RXQ_SLOT_RESET) {
2183 mvs_slot_free(mvi, rx_desc);
2187 if (attn && self_clear)
2188 MVS_CHIP_DISP->int_full(mvi);