alpha: fix several security issues
[linux/fpc-iii.git] / drivers / scsi / mvsas / mv_64xx.c
blob13c960481391e8590d0b7b2e3163f58022ca424f
1 /*
2 * Marvell 88SE64xx hardware specific
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
13 * License.
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
23 * USA
26 #include "mv_sas.h"
27 #include "mv_64xx.h"
28 #include "mv_chips.h"
30 static void mvs_64xx_detect_porttype(struct mvs_info *mvi, int i)
32 void __iomem *regs = mvi->regs;
33 u32 reg;
34 struct mvs_phy *phy = &mvi->phy[i];
36 /* TODO check & save device type */
37 reg = mr32(MVS_GBL_PORT_TYPE);
38 phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
39 if (reg & MODE_SAS_SATA & (1 << i))
40 phy->phy_type |= PORT_TYPE_SAS;
41 else
42 phy->phy_type |= PORT_TYPE_SATA;
45 static void __devinit mvs_64xx_enable_xmt(struct mvs_info *mvi, int phy_id)
47 void __iomem *regs = mvi->regs;
48 u32 tmp;
50 tmp = mr32(MVS_PCS);
51 if (mvi->chip->n_phy <= 4)
52 tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT);
53 else
54 tmp |= 1 << (phy_id + PCS_EN_PORT_XMT_SHIFT2);
55 mw32(MVS_PCS, tmp);
58 static void __devinit mvs_64xx_phy_hacks(struct mvs_info *mvi)
60 void __iomem *regs = mvi->regs;
62 mvs_phy_hacks(mvi);
64 if (!(mvi->flags & MVF_FLAG_SOC)) {
65 /* TEST - for phy decoding error, adjust voltage levels */
66 mw32(MVS_P0_VSR_ADDR + 0, 0x8);
67 mw32(MVS_P0_VSR_DATA + 0, 0x2F0);
69 mw32(MVS_P0_VSR_ADDR + 8, 0x8);
70 mw32(MVS_P0_VSR_DATA + 8, 0x2F0);
72 mw32(MVS_P0_VSR_ADDR + 16, 0x8);
73 mw32(MVS_P0_VSR_DATA + 16, 0x2F0);
75 mw32(MVS_P0_VSR_ADDR + 24, 0x8);
76 mw32(MVS_P0_VSR_DATA + 24, 0x2F0);
77 } else {
78 int i;
79 /* disable auto port detection */
80 mw32(MVS_GBL_PORT_TYPE, 0);
81 for (i = 0; i < mvi->chip->n_phy; i++) {
82 mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE7);
83 mvs_write_port_vsr_data(mvi, i, 0x90000000);
84 mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE9);
85 mvs_write_port_vsr_data(mvi, i, 0x50f2);
86 mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE11);
87 mvs_write_port_vsr_data(mvi, i, 0x0e);
92 static void mvs_64xx_stp_reset(struct mvs_info *mvi, u32 phy_id)
94 void __iomem *regs = mvi->regs;
95 u32 reg, tmp;
97 if (!(mvi->flags & MVF_FLAG_SOC)) {
98 if (phy_id < 4)
99 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &reg);
100 else
101 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &reg);
103 } else
104 reg = mr32(MVS_PHY_CTL);
106 tmp = reg;
107 if (phy_id < 4)
108 tmp |= (1U << phy_id) << PCTL_LINK_OFFS;
109 else
110 tmp |= (1U << (phy_id - 4)) << PCTL_LINK_OFFS;
112 if (!(mvi->flags & MVF_FLAG_SOC)) {
113 if (phy_id < 4) {
114 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
115 mdelay(10);
116 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, reg);
117 } else {
118 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
119 mdelay(10);
120 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, reg);
122 } else {
123 mw32(MVS_PHY_CTL, tmp);
124 mdelay(10);
125 mw32(MVS_PHY_CTL, reg);
129 static void mvs_64xx_phy_reset(struct mvs_info *mvi, u32 phy_id, int hard)
131 u32 tmp;
132 tmp = mvs_read_port_irq_stat(mvi, phy_id);
133 tmp &= ~PHYEV_RDY_CH;
134 mvs_write_port_irq_stat(mvi, phy_id, tmp);
135 tmp = mvs_read_phy_ctl(mvi, phy_id);
136 if (hard == 1)
137 tmp |= PHY_RST_HARD;
138 else if (hard == 0)
139 tmp |= PHY_RST;
140 mvs_write_phy_ctl(mvi, phy_id, tmp);
141 if (hard) {
142 do {
143 tmp = mvs_read_phy_ctl(mvi, phy_id);
144 } while (tmp & PHY_RST_HARD);
148 void mvs_64xx_clear_srs_irq(struct mvs_info *mvi, u8 reg_set, u8 clear_all)
150 void __iomem *regs = mvi->regs;
151 u32 tmp;
152 if (clear_all) {
153 tmp = mr32(MVS_INT_STAT_SRS_0);
154 if (tmp) {
155 printk(KERN_DEBUG "check SRS 0 %08X.\n", tmp);
156 mw32(MVS_INT_STAT_SRS_0, tmp);
158 } else {
159 tmp = mr32(MVS_INT_STAT_SRS_0);
160 if (tmp & (1 << (reg_set % 32))) {
161 printk(KERN_DEBUG "register set 0x%x was stopped.\n",
162 reg_set);
163 mw32(MVS_INT_STAT_SRS_0, 1 << (reg_set % 32));
168 static int __devinit mvs_64xx_chip_reset(struct mvs_info *mvi)
170 void __iomem *regs = mvi->regs;
171 u32 tmp;
172 int i;
174 /* make sure interrupts are masked immediately (paranoia) */
175 mw32(MVS_GBL_CTL, 0);
176 tmp = mr32(MVS_GBL_CTL);
178 /* Reset Controller */
179 if (!(tmp & HBA_RST)) {
180 if (mvi->flags & MVF_PHY_PWR_FIX) {
181 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp);
182 tmp &= ~PCTL_PWR_OFF;
183 tmp |= PCTL_PHY_DSBL;
184 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
186 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp);
187 tmp &= ~PCTL_PWR_OFF;
188 tmp |= PCTL_PHY_DSBL;
189 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
193 /* make sure interrupts are masked immediately (paranoia) */
194 mw32(MVS_GBL_CTL, 0);
195 tmp = mr32(MVS_GBL_CTL);
197 /* Reset Controller */
198 if (!(tmp & HBA_RST)) {
199 /* global reset, incl. COMRESET/H_RESET_N (self-clearing) */
200 mw32_f(MVS_GBL_CTL, HBA_RST);
203 /* wait for reset to finish; timeout is just a guess */
204 i = 1000;
205 while (i-- > 0) {
206 msleep(10);
208 if (!(mr32(MVS_GBL_CTL) & HBA_RST))
209 break;
211 if (mr32(MVS_GBL_CTL) & HBA_RST) {
212 dev_printk(KERN_ERR, mvi->dev, "HBA reset failed\n");
213 return -EBUSY;
215 return 0;
218 static void mvs_64xx_phy_disable(struct mvs_info *mvi, u32 phy_id)
220 void __iomem *regs = mvi->regs;
221 u32 tmp;
222 if (!(mvi->flags & MVF_FLAG_SOC)) {
223 u32 offs;
224 if (phy_id < 4)
225 offs = PCR_PHY_CTL;
226 else {
227 offs = PCR_PHY_CTL2;
228 phy_id -= 4;
230 pci_read_config_dword(mvi->pdev, offs, &tmp);
231 tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id);
232 pci_write_config_dword(mvi->pdev, offs, tmp);
233 } else {
234 tmp = mr32(MVS_PHY_CTL);
235 tmp |= 1U << (PCTL_PHY_DSBL_OFFS + phy_id);
236 mw32(MVS_PHY_CTL, tmp);
240 static void mvs_64xx_phy_enable(struct mvs_info *mvi, u32 phy_id)
242 void __iomem *regs = mvi->regs;
243 u32 tmp;
244 if (!(mvi->flags & MVF_FLAG_SOC)) {
245 u32 offs;
246 if (phy_id < 4)
247 offs = PCR_PHY_CTL;
248 else {
249 offs = PCR_PHY_CTL2;
250 phy_id -= 4;
252 pci_read_config_dword(mvi->pdev, offs, &tmp);
253 tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id));
254 pci_write_config_dword(mvi->pdev, offs, tmp);
255 } else {
256 tmp = mr32(MVS_PHY_CTL);
257 tmp &= ~(1U << (PCTL_PHY_DSBL_OFFS + phy_id));
258 mw32(MVS_PHY_CTL, tmp);
262 static int __devinit mvs_64xx_init(struct mvs_info *mvi)
264 void __iomem *regs = mvi->regs;
265 int i;
266 u32 tmp, cctl;
268 if (mvi->pdev && mvi->pdev->revision == 0)
269 mvi->flags |= MVF_PHY_PWR_FIX;
270 if (!(mvi->flags & MVF_FLAG_SOC)) {
271 mvs_show_pcie_usage(mvi);
272 tmp = mvs_64xx_chip_reset(mvi);
273 if (tmp)
274 return tmp;
275 } else {
276 tmp = mr32(MVS_PHY_CTL);
277 tmp &= ~PCTL_PWR_OFF;
278 tmp |= PCTL_PHY_DSBL;
279 mw32(MVS_PHY_CTL, tmp);
282 /* Init Chip */
283 /* make sure RST is set; HBA_RST /should/ have done that for us */
284 cctl = mr32(MVS_CTL) & 0xFFFF;
285 if (cctl & CCTL_RST)
286 cctl &= ~CCTL_RST;
287 else
288 mw32_f(MVS_CTL, cctl | CCTL_RST);
290 if (!(mvi->flags & MVF_FLAG_SOC)) {
291 /* write to device control _AND_ device status register */
292 pci_read_config_dword(mvi->pdev, PCR_DEV_CTRL, &tmp);
293 tmp &= ~PRD_REQ_MASK;
294 tmp |= PRD_REQ_SIZE;
295 pci_write_config_dword(mvi->pdev, PCR_DEV_CTRL, tmp);
297 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL, &tmp);
298 tmp &= ~PCTL_PWR_OFF;
299 tmp &= ~PCTL_PHY_DSBL;
300 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL, tmp);
302 pci_read_config_dword(mvi->pdev, PCR_PHY_CTL2, &tmp);
303 tmp &= PCTL_PWR_OFF;
304 tmp &= ~PCTL_PHY_DSBL;
305 pci_write_config_dword(mvi->pdev, PCR_PHY_CTL2, tmp);
306 } else {
307 tmp = mr32(MVS_PHY_CTL);
308 tmp &= ~PCTL_PWR_OFF;
309 tmp |= PCTL_COM_ON;
310 tmp &= ~PCTL_PHY_DSBL;
311 tmp |= PCTL_LINK_RST;
312 mw32(MVS_PHY_CTL, tmp);
313 msleep(100);
314 tmp &= ~PCTL_LINK_RST;
315 mw32(MVS_PHY_CTL, tmp);
316 msleep(100);
319 /* reset control */
320 mw32(MVS_PCS, 0); /* MVS_PCS */
321 /* init phys */
322 mvs_64xx_phy_hacks(mvi);
324 /* enable auto port detection */
325 mw32(MVS_GBL_PORT_TYPE, MODE_AUTO_DET_EN);
327 mw32(MVS_CMD_LIST_LO, mvi->slot_dma);
328 mw32(MVS_CMD_LIST_HI, (mvi->slot_dma >> 16) >> 16);
330 mw32(MVS_RX_FIS_LO, mvi->rx_fis_dma);
331 mw32(MVS_RX_FIS_HI, (mvi->rx_fis_dma >> 16) >> 16);
333 mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ);
334 mw32(MVS_TX_LO, mvi->tx_dma);
335 mw32(MVS_TX_HI, (mvi->tx_dma >> 16) >> 16);
337 mw32(MVS_RX_CFG, MVS_RX_RING_SZ);
338 mw32(MVS_RX_LO, mvi->rx_dma);
339 mw32(MVS_RX_HI, (mvi->rx_dma >> 16) >> 16);
341 for (i = 0; i < mvi->chip->n_phy; i++) {
342 /* set phy local SAS address */
343 /* should set little endian SAS address to 64xx chip */
344 mvs_set_sas_addr(mvi, i, PHYR_ADDR_LO, PHYR_ADDR_HI,
345 cpu_to_be64(mvi->phy[i].dev_sas_addr));
347 mvs_64xx_enable_xmt(mvi, i);
349 mvs_64xx_phy_reset(mvi, i, 1);
350 msleep(500);
351 mvs_64xx_detect_porttype(mvi, i);
353 if (mvi->flags & MVF_FLAG_SOC) {
354 /* set select registers */
355 writel(0x0E008000, regs + 0x000);
356 writel(0x59000008, regs + 0x004);
357 writel(0x20, regs + 0x008);
358 writel(0x20, regs + 0x00c);
359 writel(0x20, regs + 0x010);
360 writel(0x20, regs + 0x014);
361 writel(0x20, regs + 0x018);
362 writel(0x20, regs + 0x01c);
364 for (i = 0; i < mvi->chip->n_phy; i++) {
365 /* clear phy int status */
366 tmp = mvs_read_port_irq_stat(mvi, i);
367 tmp &= ~PHYEV_SIG_FIS;
368 mvs_write_port_irq_stat(mvi, i, tmp);
370 /* set phy int mask */
371 tmp = PHYEV_RDY_CH | PHYEV_BROAD_CH | PHYEV_UNASSOC_FIS |
372 PHYEV_ID_DONE | PHYEV_DCDR_ERR | PHYEV_CRC_ERR |
373 PHYEV_DEC_ERR;
374 mvs_write_port_irq_mask(mvi, i, tmp);
376 msleep(100);
377 mvs_update_phyinfo(mvi, i, 1);
380 /* FIXME: update wide port bitmaps */
382 /* little endian for open address and command table, etc. */
384 * it seems that ( from the spec ) turning on big-endian won't
385 * do us any good on big-endian machines, need further confirmation
387 cctl = mr32(MVS_CTL);
388 cctl |= CCTL_ENDIAN_CMD;
389 cctl |= CCTL_ENDIAN_DATA;
390 cctl &= ~CCTL_ENDIAN_OPEN;
391 cctl |= CCTL_ENDIAN_RSP;
392 mw32_f(MVS_CTL, cctl);
394 /* reset CMD queue */
395 tmp = mr32(MVS_PCS);
396 tmp |= PCS_CMD_RST;
397 mw32(MVS_PCS, tmp);
398 /* interrupt coalescing may cause missing HW interrput in some case,
399 * and the max count is 0x1ff, while our max slot is 0x200,
400 * it will make count 0.
402 tmp = 0;
403 mw32(MVS_INT_COAL, tmp);
405 tmp = 0x100;
406 mw32(MVS_INT_COAL_TMOUT, tmp);
408 /* ladies and gentlemen, start your engines */
409 mw32(MVS_TX_CFG, 0);
410 mw32(MVS_TX_CFG, MVS_CHIP_SLOT_SZ | TX_EN);
411 mw32(MVS_RX_CFG, MVS_RX_RING_SZ | RX_EN);
412 /* enable CMD/CMPL_Q/RESP mode */
413 mw32(MVS_PCS, PCS_SATA_RETRY | PCS_FIS_RX_EN |
414 PCS_CMD_EN | PCS_CMD_STOP_ERR);
416 /* enable completion queue interrupt */
417 tmp = (CINT_PORT_MASK | CINT_DONE | CINT_MEM | CINT_SRS | CINT_CI_STOP |
418 CINT_DMA_PCIE);
420 mw32(MVS_INT_MASK, tmp);
422 /* Enable SRS interrupt */
423 mw32(MVS_INT_MASK_SRS_0, 0xFFFF);
425 return 0;
428 static int mvs_64xx_ioremap(struct mvs_info *mvi)
430 if (!mvs_ioremap(mvi, 4, 2))
431 return 0;
432 return -1;
435 static void mvs_64xx_iounmap(struct mvs_info *mvi)
437 mvs_iounmap(mvi->regs);
438 mvs_iounmap(mvi->regs_ex);
441 static void mvs_64xx_interrupt_enable(struct mvs_info *mvi)
443 void __iomem *regs = mvi->regs;
444 u32 tmp;
446 tmp = mr32(MVS_GBL_CTL);
447 mw32(MVS_GBL_CTL, tmp | INT_EN);
450 static void mvs_64xx_interrupt_disable(struct mvs_info *mvi)
452 void __iomem *regs = mvi->regs;
453 u32 tmp;
455 tmp = mr32(MVS_GBL_CTL);
456 mw32(MVS_GBL_CTL, tmp & ~INT_EN);
459 static u32 mvs_64xx_isr_status(struct mvs_info *mvi, int irq)
461 void __iomem *regs = mvi->regs;
462 u32 stat;
464 if (!(mvi->flags & MVF_FLAG_SOC)) {
465 stat = mr32(MVS_GBL_INT_STAT);
467 if (stat == 0 || stat == 0xffffffff)
468 return 0;
469 } else
470 stat = 1;
471 return stat;
474 static irqreturn_t mvs_64xx_isr(struct mvs_info *mvi, int irq, u32 stat)
476 void __iomem *regs = mvi->regs;
478 /* clear CMD_CMPLT ASAP */
479 mw32_f(MVS_INT_STAT, CINT_DONE);
480 #ifndef MVS_USE_TASKLET
481 spin_lock(&mvi->lock);
482 #endif
483 mvs_int_full(mvi);
484 #ifndef MVS_USE_TASKLET
485 spin_unlock(&mvi->lock);
486 #endif
487 return IRQ_HANDLED;
490 static void mvs_64xx_command_active(struct mvs_info *mvi, u32 slot_idx)
492 u32 tmp;
493 mvs_cw32(mvi, 0x40 + (slot_idx >> 3), 1 << (slot_idx % 32));
494 mvs_cw32(mvi, 0x00 + (slot_idx >> 3), 1 << (slot_idx % 32));
495 do {
496 tmp = mvs_cr32(mvi, 0x00 + (slot_idx >> 3));
497 } while (tmp & 1 << (slot_idx % 32));
498 do {
499 tmp = mvs_cr32(mvi, 0x40 + (slot_idx >> 3));
500 } while (tmp & 1 << (slot_idx % 32));
503 static void mvs_64xx_issue_stop(struct mvs_info *mvi, enum mvs_port_type type,
504 u32 tfs)
506 void __iomem *regs = mvi->regs;
507 u32 tmp;
509 if (type == PORT_TYPE_SATA) {
510 tmp = mr32(MVS_INT_STAT_SRS_0) | (1U << tfs);
511 mw32(MVS_INT_STAT_SRS_0, tmp);
513 mw32(MVS_INT_STAT, CINT_CI_STOP);
514 tmp = mr32(MVS_PCS) | 0xFF00;
515 mw32(MVS_PCS, tmp);
518 static void mvs_64xx_free_reg_set(struct mvs_info *mvi, u8 *tfs)
520 void __iomem *regs = mvi->regs;
521 u32 tmp, offs;
523 if (*tfs == MVS_ID_NOT_MAPPED)
524 return;
526 offs = 1U << ((*tfs & 0x0f) + PCS_EN_SATA_REG_SHIFT);
527 if (*tfs < 16) {
528 tmp = mr32(MVS_PCS);
529 mw32(MVS_PCS, tmp & ~offs);
530 } else {
531 tmp = mr32(MVS_CTL);
532 mw32(MVS_CTL, tmp & ~offs);
535 tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << *tfs);
536 if (tmp)
537 mw32(MVS_INT_STAT_SRS_0, tmp);
539 *tfs = MVS_ID_NOT_MAPPED;
540 return;
543 static u8 mvs_64xx_assign_reg_set(struct mvs_info *mvi, u8 *tfs)
545 int i;
546 u32 tmp, offs;
547 void __iomem *regs = mvi->regs;
549 if (*tfs != MVS_ID_NOT_MAPPED)
550 return 0;
552 tmp = mr32(MVS_PCS);
554 for (i = 0; i < mvi->chip->srs_sz; i++) {
555 if (i == 16)
556 tmp = mr32(MVS_CTL);
557 offs = 1U << ((i & 0x0f) + PCS_EN_SATA_REG_SHIFT);
558 if (!(tmp & offs)) {
559 *tfs = i;
561 if (i < 16)
562 mw32(MVS_PCS, tmp | offs);
563 else
564 mw32(MVS_CTL, tmp | offs);
565 tmp = mr32(MVS_INT_STAT_SRS_0) & (1U << i);
566 if (tmp)
567 mw32(MVS_INT_STAT_SRS_0, tmp);
568 return 0;
571 return MVS_ID_NOT_MAPPED;
574 void mvs_64xx_make_prd(struct scatterlist *scatter, int nr, void *prd)
576 int i;
577 struct scatterlist *sg;
578 struct mvs_prd *buf_prd = prd;
579 for_each_sg(scatter, sg, nr, i) {
580 buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
581 buf_prd->len = cpu_to_le32(sg_dma_len(sg));
582 buf_prd++;
586 static int mvs_64xx_oob_done(struct mvs_info *mvi, int i)
588 u32 phy_st;
589 mvs_write_port_cfg_addr(mvi, i,
590 PHYR_PHY_STAT);
591 phy_st = mvs_read_port_cfg_data(mvi, i);
592 if (phy_st & PHY_OOB_DTCTD)
593 return 1;
594 return 0;
597 static void mvs_64xx_fix_phy_info(struct mvs_info *mvi, int i,
598 struct sas_identify_frame *id)
601 struct mvs_phy *phy = &mvi->phy[i];
602 struct asd_sas_phy *sas_phy = &phy->sas_phy;
604 sas_phy->linkrate =
605 (phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
606 PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET;
608 phy->minimum_linkrate =
609 (phy->phy_status &
610 PHY_MIN_SPP_PHYS_LINK_RATE_MASK) >> 8;
611 phy->maximum_linkrate =
612 (phy->phy_status &
613 PHY_MAX_SPP_PHYS_LINK_RATE_MASK) >> 12;
615 mvs_write_port_cfg_addr(mvi, i, PHYR_IDENTIFY);
616 phy->dev_info = mvs_read_port_cfg_data(mvi, i);
618 mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_DEV_INFO);
619 phy->att_dev_info = mvs_read_port_cfg_data(mvi, i);
621 mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_HI);
622 phy->att_dev_sas_addr =
623 (u64) mvs_read_port_cfg_data(mvi, i) << 32;
624 mvs_write_port_cfg_addr(mvi, i, PHYR_ATT_ADDR_LO);
625 phy->att_dev_sas_addr |= mvs_read_port_cfg_data(mvi, i);
626 phy->att_dev_sas_addr = SAS_ADDR(&phy->att_dev_sas_addr);
629 static void mvs_64xx_phy_work_around(struct mvs_info *mvi, int i)
631 u32 tmp;
632 struct mvs_phy *phy = &mvi->phy[i];
633 /* workaround for HW phy decoding error on 1.5g disk drive */
634 mvs_write_port_vsr_addr(mvi, i, VSR_PHY_MODE6);
635 tmp = mvs_read_port_vsr_data(mvi, i);
636 if (((phy->phy_status & PHY_NEG_SPP_PHYS_LINK_RATE_MASK) >>
637 PHY_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET) ==
638 SAS_LINK_RATE_1_5_GBPS)
639 tmp &= ~PHY_MODE6_LATECLK;
640 else
641 tmp |= PHY_MODE6_LATECLK;
642 mvs_write_port_vsr_data(mvi, i, tmp);
645 void mvs_64xx_phy_set_link_rate(struct mvs_info *mvi, u32 phy_id,
646 struct sas_phy_linkrates *rates)
648 u32 lrmin = 0, lrmax = 0;
649 u32 tmp;
651 tmp = mvs_read_phy_ctl(mvi, phy_id);
652 lrmin = (rates->minimum_linkrate << 8);
653 lrmax = (rates->maximum_linkrate << 12);
655 if (lrmin) {
656 tmp &= ~(0xf << 8);
657 tmp |= lrmin;
659 if (lrmax) {
660 tmp &= ~(0xf << 12);
661 tmp |= lrmax;
663 mvs_write_phy_ctl(mvi, phy_id, tmp);
664 mvs_64xx_phy_reset(mvi, phy_id, 1);
667 static void mvs_64xx_clear_active_cmds(struct mvs_info *mvi)
669 u32 tmp;
670 void __iomem *regs = mvi->regs;
671 tmp = mr32(MVS_PCS);
672 mw32(MVS_PCS, tmp & 0xFFFF);
673 mw32(MVS_PCS, tmp);
674 tmp = mr32(MVS_CTL);
675 mw32(MVS_CTL, tmp & 0xFFFF);
676 mw32(MVS_CTL, tmp);
680 u32 mvs_64xx_spi_read_data(struct mvs_info *mvi)
682 void __iomem *regs = mvi->regs_ex;
683 return ior32(SPI_DATA_REG_64XX);
686 void mvs_64xx_spi_write_data(struct mvs_info *mvi, u32 data)
688 void __iomem *regs = mvi->regs_ex;
689 iow32(SPI_DATA_REG_64XX, data);
693 int mvs_64xx_spi_buildcmd(struct mvs_info *mvi,
694 u32 *dwCmd,
695 u8 cmd,
696 u8 read,
697 u8 length,
698 u32 addr
701 u32 dwTmp;
703 dwTmp = ((u32)cmd << 24) | ((u32)length << 19);
704 if (read)
705 dwTmp |= 1U<<23;
707 if (addr != MV_MAX_U32) {
708 dwTmp |= 1U<<22;
709 dwTmp |= (addr & 0x0003FFFF);
712 *dwCmd = dwTmp;
713 return 0;
717 int mvs_64xx_spi_issuecmd(struct mvs_info *mvi, u32 cmd)
719 void __iomem *regs = mvi->regs_ex;
720 int retry;
722 for (retry = 0; retry < 1; retry++) {
723 iow32(SPI_CTRL_REG_64XX, SPI_CTRL_VENDOR_ENABLE);
724 iow32(SPI_CMD_REG_64XX, cmd);
725 iow32(SPI_CTRL_REG_64XX,
726 SPI_CTRL_VENDOR_ENABLE | SPI_CTRL_SPISTART);
729 return 0;
732 int mvs_64xx_spi_waitdataready(struct mvs_info *mvi, u32 timeout)
734 void __iomem *regs = mvi->regs_ex;
735 u32 i, dwTmp;
737 for (i = 0; i < timeout; i++) {
738 dwTmp = ior32(SPI_CTRL_REG_64XX);
739 if (!(dwTmp & SPI_CTRL_SPISTART))
740 return 0;
741 msleep(10);
744 return -1;
747 #ifndef DISABLE_HOTPLUG_DMA_FIX
748 void mvs_64xx_fix_dma(dma_addr_t buf_dma, int buf_len, int from, void *prd)
750 int i;
751 struct mvs_prd *buf_prd = prd;
752 buf_prd += from;
753 for (i = 0; i < MAX_SG_ENTRY - from; i++) {
754 buf_prd->addr = cpu_to_le64(buf_dma);
755 buf_prd->len = cpu_to_le32(buf_len);
756 ++buf_prd;
759 #endif
761 const struct mvs_dispatch mvs_64xx_dispatch = {
762 "mv64xx",
763 mvs_64xx_init,
764 NULL,
765 mvs_64xx_ioremap,
766 mvs_64xx_iounmap,
767 mvs_64xx_isr,
768 mvs_64xx_isr_status,
769 mvs_64xx_interrupt_enable,
770 mvs_64xx_interrupt_disable,
771 mvs_read_phy_ctl,
772 mvs_write_phy_ctl,
773 mvs_read_port_cfg_data,
774 mvs_write_port_cfg_data,
775 mvs_write_port_cfg_addr,
776 mvs_read_port_vsr_data,
777 mvs_write_port_vsr_data,
778 mvs_write_port_vsr_addr,
779 mvs_read_port_irq_stat,
780 mvs_write_port_irq_stat,
781 mvs_read_port_irq_mask,
782 mvs_write_port_irq_mask,
783 mvs_get_sas_addr,
784 mvs_64xx_command_active,
785 mvs_64xx_clear_srs_irq,
786 mvs_64xx_issue_stop,
787 mvs_start_delivery,
788 mvs_rx_update,
789 mvs_int_full,
790 mvs_64xx_assign_reg_set,
791 mvs_64xx_free_reg_set,
792 mvs_get_prd_size,
793 mvs_get_prd_count,
794 mvs_64xx_make_prd,
795 mvs_64xx_detect_porttype,
796 mvs_64xx_oob_done,
797 mvs_64xx_fix_phy_info,
798 mvs_64xx_phy_work_around,
799 mvs_64xx_phy_set_link_rate,
800 mvs_hw_max_link_rate,
801 mvs_64xx_phy_disable,
802 mvs_64xx_phy_enable,
803 mvs_64xx_phy_reset,
804 mvs_64xx_stp_reset,
805 mvs_64xx_clear_active_cmds,
806 mvs_64xx_spi_read_data,
807 mvs_64xx_spi_write_data,
808 mvs_64xx_spi_buildcmd,
809 mvs_64xx_spi_issuecmd,
810 mvs_64xx_spi_waitdataready,
811 #ifndef DISABLE_HOTPLUG_DMA_FIX
812 mvs_64xx_fix_dma,
813 #endif