59 u32 val = t3_read_reg(adapter, reg);
61 if (!!(val & mask) == polarity) {
88 t3_write_reg(adapter, p->
reg_addr + offset, p->
val);
106 u32 v = t3_read_reg(adapter, addr) & ~mask;
108 t3_write_reg(adapter, addr, v | val);
109 t3_read_reg(adapter, addr);
124 static void t3_read_indirect(
struct adapter *adap,
unsigned int addr_reg,
125 unsigned int data_reg,
u32 *vals,
126 unsigned int nregs,
unsigned int start_idx)
129 t3_write_reg(adap, addr_reg, start_idx);
130 *vals++ = t3_read_reg(adap, data_reg);
148 static const int shift[] = { 0, 0, 16, 24 };
149 static const int step[] = { 0, 32, 16, 8 };
151 unsigned int size64 = mc7->
size / 8;
154 if (start >= size64 || start + n > size64)
157 start *= (8 << mc7->
width);
162 for (i = (1 << mc7->
width) - 1; i >= 0; --
i) {
169 while ((val &
F_BUSY) && attempts--)
170 val = t3_read_reg(adap,
176 if (mc7->
width == 0) {
177 val64 = t3_read_reg(adap,
180 val64 |= (
u64) val << 32;
183 val >>= shift[mc7->
width];
184 val64 |= (
u64) val << (step[mc7->
width] * i);
204 #define MDIO_ATTEMPTS 20
209 static int t3_mi1_read(
struct net_device *
dev,
int phy_addr,
int mmd_addr,
228 static int t3_mi1_write(
struct net_device *
dev,
int phy_addr,
int mmd_addr,
246 static const struct mdio_ops mi1_mdio_ops = {
248 .write = t3_mi1_write,
256 static int mi1_wr_addr(
struct adapter *adapter,
int phy_addr,
int mmd_addr,
272 static int mi1_ext_read(
struct net_device *dev,
int phy_addr,
int mmd_addr,
276 struct adapter *adapter = pi->
adapter;
280 ret = mi1_wr_addr(adapter, phy_addr, mmd_addr, reg_addr);
292 static int mi1_ext_write(
struct net_device *dev,
int phy_addr,
int mmd_addr,
296 struct adapter *adapter = pi->
adapter;
300 ret = mi1_wr_addr(adapter, phy_addr, mmd_addr, reg_addr);
311 static const struct mdio_ops mi1_mdio_ext_ops = {
312 .read = mi1_ext_read,
313 .write = mi1_ext_write,
334 ret = t3_mdio_read(phy, mmd, reg, &val);
337 ret = t3_mdio_write(phy, mmd, reg, val |
set);
363 err = t3_mdio_read(phy, mmd,
MDIO_CTRL1, &ctl);
369 }
while (ctl && --wait);
385 unsigned int val = 0;
427 unsigned int val = 0;
508 &mi1_mdio_ops,
"Chelsio PE9000"},
512 &mi1_mdio_ops,
"Chelsio T302"},
517 &mi1_mdio_ext_ops,
"Chelsio T310"},
523 &mi1_mdio_ext_ops,
"Chelsio T320"},
530 &mi1_mdio_ext_ops,
"Chelsio T310" },
535 &mi1_mdio_ext_ops,
"Chelsio N320E-G2" },
566 #define VPD_ENTRY(name, len) \
567 u8 name##_kword[2]; u8 name##_len; u8 name##_data[len]
598 #define EEPROM_MAX_POLL 40
599 #define EEPROM_STAT_ADDR 0x4000
600 #define VPD_BASE 0xc00
618 unsigned int base = adapter->
params.pci.vpd_cap_addr;
629 if (!(val & PCI_VPD_ADDR_F)) {
630 CH_ERR(adapter,
"reading EEPROM address 0x%x failed\n", addr);
651 unsigned int base = adapter->
params.pci.vpd_cap_addr;
665 if (val & PCI_VPD_ADDR_F) {
666 CH_ERR(adapter,
"write to EEPROM address 0x%x failed\n", addr);
691 static int get_vpd_params(
struct adapter *adapter,
struct vpd_params *
p)
705 for (i = 0; i <
sizeof(
vpd); i += 4) {
720 if (adapter->
params.rev == 0 && !
vpd.port0_data[0]) {
721 p->
port_type[0] = uses_xaui(adapter) ? 1 : 2;
722 p->
port_type[1] = uses_xaui(adapter) ? 6 : 2;
730 for (i = 0; i < 6; i++)
766 static int sf1_read(
struct adapter *adapter,
unsigned int byte_cnt,
int cont,
771 if (!byte_cnt || byte_cnt > 4)
793 static int sf1_write(
struct adapter *adapter,
unsigned int byte_cnt,
int cont,
796 if (!byte_cnt || byte_cnt > 4)
814 static int flash_wait_op(
struct adapter *adapter,
int attempts,
int delay)
820 if ((ret = sf1_write(adapter, 1, 1,
SF_RD_STATUS)) != 0 ||
821 (ret = sf1_read(adapter, 1, 0, &status)) != 0)
845 static int t3_read_flash(
struct adapter *adapter,
unsigned int addr,
846 unsigned int nwords,
u32 *
data,
int byte_oriented)
850 if (addr + nwords *
sizeof(
u32) >
SF_SIZE || (addr & 3))
855 if ((ret = sf1_write(adapter, 4, 1, addr)) != 0 ||
856 (ret = sf1_read(adapter, 1, 1, data)) != 0)
859 for (; nwords; nwords--, data++) {
860 ret = sf1_read(adapter, 4, nwords > 1, data);
864 *data =
htonl(*data);
879 static int t3_write_flash(
struct adapter *adapter,
unsigned int addr,
880 unsigned int n,
const u8 *data)
886 if (addr + n >
SF_SIZE || offset + n > 256)
891 if ((ret = sf1_write(adapter, 1, 0,
SF_WR_ENABLE)) != 0 ||
892 (ret = sf1_write(adapter, 4, 1, val)) != 0)
895 for (left = n;
left; left -=
c) {
897 for (val = 0, i = 0; i <
c; ++
i)
898 val = (val << 8) + *data++;
900 ret = sf1_write(adapter, c, c != left, val);
904 if ((ret = flash_wait_op(adapter, 5, 1)) != 0)
908 ret = t3_read_flash(adapter, addr & ~0xff,
ARRAY_SIZE(buf), buf, 1);
912 if (
memcmp(data - n, (
u8 *) buf + offset, n))
966 CH_ERR(adapter,
"found wrong TP version (%u.%u), "
967 "driver compiled for version %d.%d\n", major, minor,
991 for (csum = 0, i = 0; i < size /
sizeof(
csum); i++)
993 if (csum != 0xffffffff) {
994 CH_ERR(adapter,
"corrupted protocol SRAM image, checksum %u\n",
1016 return t3_read_flash(adapter,
FW_VERS_ADDR, 1, vers, 0);
1044 CH_WARN(adapter,
"found old FW minor version(%u.%u), "
1045 "driver compiled for version %u.%u\n", major, minor,
1048 CH_WARN(adapter,
"found newer FW version(%u.%u), "
1049 "driver compiled for version %u.%u\n", major, minor,
1064 static int t3_flash_erase_sectors(
struct adapter *adapter,
int start,
int end)
1066 while (start <= end) {
1069 if ((ret = sf1_write(adapter, 1, 0,
SF_WR_ENABLE)) != 0 ||
1070 (ret = sf1_write(adapter, 4, 0,
1072 (ret = flash_wait_op(adapter, 5, 500)) != 0)
1102 for (csum = 0, i = 0; i < size /
sizeof(
csum); i++)
1103 csum +=
ntohl(p[i]);
1104 if (csum != 0xffffffff) {
1105 CH_ERR(adapter,
"corrupted firmware image, checksum %u\n",
1110 ret = t3_flash_erase_sectors(adapter, fw_sector, fw_sector);
1116 unsigned int chunk_size =
min(size, 256
U);
1118 ret = t3_write_flash(adapter, addr, chunk_size, fw_data);
1123 fw_data += chunk_size;
1127 ret = t3_write_flash(adapter,
FW_VERS_ADDR, 4, fw_data);
1130 CH_ERR(adapter,
"firmware download failed, error %d\n", ret);
1134 #define CIM_CTL_BASE 0x2000
1147 unsigned int n,
unsigned int *valp)
1154 for ( ; !ret && n--; addr += 4) {
1164 static void t3_gate_rx_traffic(
struct cmac *
mac,
u32 *rx_cfg,
1165 u32 *rx_hash_high,
u32 *rx_hash_low)
1186 static void t3_open_rx_traffic(
struct cmac *
mac,
u32 rx_cfg,
1187 u32 rx_hash_high,
u32 rx_hash_low)
1209 struct port_info *pi = adap2pinfo(adapter, port_id);
1214 phy->
ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc);
1216 if (!lc->
link_ok && link_ok) {
1217 u32 rx_cfg, rx_hash_high, rx_hash_low;
1221 t3_gate_rx_traffic(mac, &rx_cfg, &rx_hash_high, &rx_hash_low);
1227 mac->
stats.link_faults++;
1230 t3_open_rx_traffic(mac, rx_cfg, rx_hash_high, rx_hash_low);
1239 duplex == lc->
duplex && fc == lc->
fc)
1243 uses_xaui(adapter)) {
1265 struct port_info *pi = adap2pinfo(adapter, port_id);
1270 u32 rx_cfg, rx_hash_high, rx_hash_low;
1272 t3_gate_rx_traffic(mac, &rx_cfg, &rx_hash_high, &rx_hash_low);
1274 if (adapter->
params.rev > 0 && uses_xaui(adapter))
1280 t3_open_rx_traffic(mac, rx_cfg, rx_hash_high, rx_hash_low);
1282 link_fault = t3_read_reg(adapter,
1291 phy->
ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc);
1302 mac->
stats.link_faults++;
1346 lc->
fc = (
unsigned char)fc;
1352 phy->
ops->autoneg_enable(phy);
1355 lc->
fc = (
unsigned char)fc;
1356 phy->
ops->reset(phy, 0);
1398 static int t3_handle_intr_status(
struct adapter *adapter,
unsigned int reg,
1401 unsigned long *
stats)
1404 unsigned int status = t3_read_reg(adapter, reg) &
mask;
1406 for (; acts->
mask; ++acts) {
1407 if (!(status & acts->
mask))
1412 acts->
msg, status & acts->
mask);
1413 status &= ~acts->
mask;
1414 }
else if (acts->
msg)
1415 CH_WARN(adapter,
"%s (0x%x)\n",
1416 acts->
msg, status & acts->
mask);
1421 t3_write_reg(adapter, reg, status);
1425 #define SGE_INTR_MASK (F_RSPQDISABLED | \
1426 F_UC_REQ_FRAMINGERROR | F_R_REQ_FRAMINGERROR | \
1427 F_CPPARITYERROR | F_OCPARITYERROR | F_RCPARITYERROR | \
1428 F_IRPARITYERROR | V_ITPARITYERROR(M_ITPARITYERROR) | \
1429 V_FLPARITYERROR(M_FLPARITYERROR) | F_LODRBPARITYERROR | \
1430 F_HIDRBPARITYERROR | F_LORCQPARITYERROR | \
1431 F_HIRCQPARITYERROR | F_LOPRIORITYDBFULL | \
1432 F_HIPRIORITYDBFULL | F_LOPRIORITYDBEMPTY | \
1433 F_HIPRIORITYDBEMPTY | F_HIPIODRBDROPERR | \
1435 #define MC5_INTR_MASK (F_PARITYERR | F_ACTRGNFULL | F_UNKNOWNCMD | \
1436 F_REQQPARERR | F_DISPQPARERR | F_DELACTEMPTY | \
1438 #define MC7_INTR_MASK (F_AE | F_UE | F_CE | V_PE(M_PE))
1439 #define XGM_INTR_MASK (V_TXFIFO_PRTY_ERR(M_TXFIFO_PRTY_ERR) | \
1440 V_RXFIFO_PRTY_ERR(M_RXFIFO_PRTY_ERR) | \
1442 #define PCIX_INTR_MASK (F_MSTDETPARERR | F_SIGTARABT | F_RCVTARABT | \
1443 F_RCVMSTABT | F_SIGSYSERR | F_DETPARERR | \
1444 F_SPLCMPDIS | F_UNXSPLCMP | F_RCVSPLCMPERR | \
1445 F_DETCORECCERR | F_DETUNCECCERR | F_PIOPARERR | \
1446 V_WFPARERR(M_WFPARERR) | V_RFPARERR(M_RFPARERR) | \
1447 V_CFPARERR(M_CFPARERR) )
1448 #define PCIE_INTR_MASK (F_UNXSPLCPLERRR | F_UNXSPLCPLERRC | F_PCIE_PIOPARERR |\
1449 F_PCIE_WFPARERR | F_PCIE_RFPARERR | F_PCIE_CFPARERR | \
1451 F_RETRYBUFPARERR | F_RETRYLUTPARERR | F_RXPARERR | \
1452 F_TXPARERR | V_BISTERR(M_BISTERR))
1453 #define ULPRX_INTR_MASK (F_PARERRDATA | F_PARERRPCMD | F_ARBPF1PERR | \
1454 F_ARBPF0PERR | F_ARBFPERR | F_PCMDMUXPERR | \
1455 F_DATASELFRAMEERR1 | F_DATASELFRAMEERR0)
1456 #define ULPTX_INTR_MASK 0xfc
1457 #define CPLSW_INTR_MASK (F_CIM_OP_MAP_PERR | F_TP_FRAMING_ERROR | \
1458 F_SGE_FRAMING_ERROR | F_CIM_FRAMING_ERROR | \
1459 F_ZERO_SWITCH_ERROR)
1460 #define CIM_INTR_MASK (F_BLKWRPLINT | F_BLKRDPLINT | F_BLKWRCTLINT | \
1461 F_BLKRDCTLINT | F_BLKWRFLASHINT | F_BLKRDFLASHINT | \
1462 F_SGLWRFLASHINT | F_WRBLKFLASHINT | F_BLKWRBOOTINT | \
1463 F_FLASHRANGEINT | F_SDRAMRANGEINT | F_RSVDSPACEINT | \
1464 F_DRAMPARERR | F_ICACHEPARERR | F_DCACHEPARERR | \
1465 F_OBQSGEPARERR | F_OBQULPHIPARERR | F_OBQULPLOPARERR | \
1466 F_IBQSGELOPARERR | F_IBQSGEHIPARERR | F_IBQULPPARERR | \
1467 F_IBQTPPARERR | F_ITAGPARERR | F_DTAGPARERR)
1468 #define PMTX_INTR_MASK (F_ZERO_C_CMD_ERROR | ICSPI_FRM_ERR | OESPI_FRM_ERR | \
1469 V_ICSPI_PAR_ERROR(M_ICSPI_PAR_ERROR) | \
1470 V_OESPI_PAR_ERROR(M_OESPI_PAR_ERROR))
1471 #define PMRX_INTR_MASK (F_ZERO_E_CMD_ERROR | IESPI_FRM_ERR | OCSPI_FRM_ERR | \
1472 V_IESPI_PAR_ERROR(M_IESPI_PAR_ERROR) | \
1473 V_OCSPI_PAR_ERROR(M_OCSPI_PAR_ERROR))
1474 #define MPS_INTR_MASK (V_TX0TPPARERRENB(M_TX0TPPARERRENB) | \
1475 V_TX1TPPARERRENB(M_TX1TPPARERRENB) | \
1476 V_RXTPPARERRENB(M_RXTPPARERRENB) | \
1477 V_MCAPARERRENB(M_MCAPARERRENB))
1478 #define XGM_EXTRA_INTR_MASK (F_LINKFAULTCHANGE)
1479 #define PL_INTR_MASK (F_T3DBG | F_XGMAC0_0 | F_XGMAC0_1 | F_MC5A | F_PM1_TX | \
1480 F_PM1_RX | F_ULP2_TX | F_ULP2_RX | F_TP1 | F_CIM | \
1481 F_MC7_CM | F_MC7_PMTX | F_MC7_PMRX | F_SGE3 | F_PCIM0 | \
1482 F_MPS0 | F_CPL_SWITCH)
1486 static void pci_intr_handler(
struct adapter *adapter)
1488 static const struct intr_info pcix1_intr_info[] = {
1490 {
F_SIGTARABT,
"PCI signaled target abort", -1, 1},
1491 {
F_RCVTARABT,
"PCI received target abort", -1, 1},
1492 {
F_RCVMSTABT,
"PCI received master abort", -1, 1},
1493 {
F_SIGSYSERR,
"PCI signaled system error", -1, 1},
1494 {
F_DETPARERR,
"PCI detected parity error", -1, 1},
1495 {
F_SPLCMPDIS,
"PCI split completion discarded", -1, 1},
1496 {
F_UNXSPLCMP,
"PCI unexpected split completion error", -1, 1},
1502 {
F_PIOPARERR,
"PCI PIO FIFO parity error", -1, 1},
1522 static void pcie_intr_handler(
struct adapter *adapter)
1524 static const struct intr_info pcie_intr_info[] = {
1525 {
F_PEXERR,
"PCI PEX error", -1, 1},
1527 "PCI unexpected split completion DMA read error", -1, 1},
1529 "PCI unexpected split completion DMA command error", -1, 1},
1535 "PCI MSI-X table/PBA parity error", -1, 1},
1545 CH_ALERT(adapter,
"PEX error code 0x%x\n",
1556 static void tp_intr_handler(
struct adapter *adapter)
1558 static const struct intr_info tp_intr_info[] = {
1559 {0xffffff,
"TP parity error", -1, 1},
1560 {0x1000000,
"TP out of Rx pages", -1, 1},
1561 {0x2000000,
"TP out of Tx pages", -1, 1},
1565 static const struct intr_info tp_intr_info_t3c[] = {
1566 {0x1fffffff,
"TP parity error", -1, 1},
1574 tp_intr_info : tp_intr_info_t3c,
NULL))
1581 static void cim_intr_handler(
struct adapter *adapter)
1583 static const struct intr_info cim_intr_info[] = {
1612 cim_intr_info,
NULL))
1619 static void ulprx_intr_handler(
struct adapter *adapter)
1621 static const struct intr_info ulprx_intr_info[] = {
1626 {
F_ARBFPERR,
"ULP RX ArbF parity error", -1, 1},
1634 ulprx_intr_info,
NULL))
1641 static void ulptx_intr_handler(
struct adapter *adapter)
1643 static const struct intr_info ulptx_intr_info[] = {
1648 {0xfc,
"ULP TX parity error", -1, 1},
1657 #define ICSPI_FRM_ERR (F_ICSPI0_FIFO2X_RX_FRAMING_ERROR | \
1658 F_ICSPI1_FIFO2X_RX_FRAMING_ERROR | F_ICSPI0_RX_FRAMING_ERROR | \
1659 F_ICSPI1_RX_FRAMING_ERROR | F_ICSPI0_TX_FRAMING_ERROR | \
1660 F_ICSPI1_TX_FRAMING_ERROR)
1661 #define OESPI_FRM_ERR (F_OESPI0_RX_FRAMING_ERROR | \
1662 F_OESPI1_RX_FRAMING_ERROR | F_OESPI0_TX_FRAMING_ERROR | \
1663 F_OESPI1_TX_FRAMING_ERROR | F_OESPI0_OFIFO2X_TX_FRAMING_ERROR | \
1664 F_OESPI1_OFIFO2X_TX_FRAMING_ERROR)
1669 static void pmtx_intr_handler(
struct adapter *adapter)
1671 static const struct intr_info pmtx_intr_info[] = {
1676 "PMTX ispi parity error", -1, 1},
1678 "PMTX ospi parity error", -1, 1},
1683 pmtx_intr_info,
NULL))
1687 #define IESPI_FRM_ERR (F_IESPI0_FIFO2X_RX_FRAMING_ERROR | \
1688 F_IESPI1_FIFO2X_RX_FRAMING_ERROR | F_IESPI0_RX_FRAMING_ERROR | \
1689 F_IESPI1_RX_FRAMING_ERROR | F_IESPI0_TX_FRAMING_ERROR | \
1690 F_IESPI1_TX_FRAMING_ERROR)
1691 #define OCSPI_FRM_ERR (F_OCSPI0_RX_FRAMING_ERROR | \
1692 F_OCSPI1_RX_FRAMING_ERROR | F_OCSPI0_TX_FRAMING_ERROR | \
1693 F_OCSPI1_TX_FRAMING_ERROR | F_OCSPI0_OFIFO2X_TX_FRAMING_ERROR | \
1694 F_OCSPI1_OFIFO2X_TX_FRAMING_ERROR)
1699 static void pmrx_intr_handler(
struct adapter *adapter)
1701 static const struct intr_info pmrx_intr_info[] = {
1706 "PMRX ispi parity error", -1, 1},
1708 "PMRX ospi parity error", -1, 1},
1713 pmrx_intr_info,
NULL))
1720 static void cplsw_intr_handler(
struct adapter *adapter)
1722 static const struct intr_info cplsw_intr_info[] = {
1733 cplsw_intr_info,
NULL))
1740 static void mps_intr_handler(
struct adapter *adapter)
1742 static const struct intr_info mps_intr_info[] = {
1743 {0x1ff,
"MPS parity error", -1, 1},
1748 mps_intr_info,
NULL))
1752 #define MC7_INTR_FATAL (F_UE | V_PE(M_PE) | F_AE)
1757 static void mc7_intr_handler(
struct mc7 *
mc7)
1759 struct adapter *adapter = mc7->
adapter;
1763 mc7->
stats.corr_err++;
1764 CH_WARN(adapter,
"%s MC7 correctable error at addr 0x%x, "
1765 "data 0x%x 0x%x 0x%x\n", mc7->
name,
1773 mc7->
stats.uncorr_err++;
1774 CH_ALERT(adapter,
"%s MC7 uncorrectable error at addr 0x%x, "
1775 "data 0x%x 0x%x 0x%x\n", mc7->
name,
1783 mc7->
stats.parity_err++;
1784 CH_ALERT(adapter,
"%s MC7 parity error 0x%x\n",
1791 if (adapter->
params.rev > 0)
1792 addr = t3_read_reg(adapter,
1794 mc7->
stats.addr_err++;
1795 CH_ALERT(adapter,
"%s MC7 address error: 0x%x\n",
1805 #define XGM_INTR_FATAL (V_TXFIFO_PRTY_ERR(M_TXFIFO_PRTY_ERR) | \
1806 V_RXFIFO_PRTY_ERR(M_RXFIFO_PRTY_ERR))
1810 static int mac_intr_handler(
struct adapter *adap,
unsigned int idx)
1812 struct cmac *
mac = &adap2pinfo(adap, idx)->
mac;
1823 mac->
stats.tx_fifo_parity_err++;
1824 CH_ALERT(adap,
"port%d: MAC TX FIFO parity error\n", idx);
1827 mac->
stats.rx_fifo_parity_err++;
1828 CH_ALERT(adap,
"port%d: MAC RX FIFO parity error\n", idx);
1831 mac->
stats.tx_fifo_urun++;
1833 mac->
stats.rx_fifo_ovfl++;
1835 mac->
stats.serdes_signal_loss++;
1837 mac->
stats.xaui_pcs_ctc_err++;
1839 mac->
stats.xaui_pcs_align_change++;
1844 mac->
stats.link_faults++;
1864 struct port_info *p = adap2pinfo(adapter, i);
1869 if (cause & (1 <<
adapter_info(adapter)->gpio_intr[i])) {
1870 int phy_cause = p->
phy.ops->intr_handler(&p->
phy);
1875 p->
phy.fifo_errors++;
1896 if (is_pcie(adapter))
1897 pcie_intr_handler(adapter);
1899 pci_intr_handler(adapter);
1904 mc7_intr_handler(&adapter->
pmrx);
1906 mc7_intr_handler(&adapter->
pmtx);
1908 mc7_intr_handler(&adapter->
cm);
1910 cim_intr_handler(adapter);
1912 tp_intr_handler(adapter);
1914 ulprx_intr_handler(adapter);
1916 ulptx_intr_handler(adapter);
1918 pmrx_intr_handler(adapter);
1920 pmtx_intr_handler(adapter);
1922 cplsw_intr_handler(adapter);
1924 mps_intr_handler(adapter);
1928 mac_intr_handler(adapter, 0);
1930 mac_intr_handler(adapter, 1);
1940 static unsigned int calc_gpio_intr(
struct adapter *adap)
1942 unsigned int i, gpi_intr = 0;
1980 adapter->params.rev >=
T3_REV_C ? 0x2bfffff : 0x3bfffff);
1982 if (adapter->params.rev > 0) {
1995 if (is_pcie(adapter))
2025 static const unsigned int cause_reg_addr[] = {
2047 t3_port_intr_clear(adapter, i);
2050 t3_write_reg(adapter, cause_reg_addr[i], 0xffffffff);
2052 if (is_pcie(adapter))
2060 struct port_info *pi = adap2pinfo(adapter, idx);
2068 struct port_info *pi = adap2pinfo(adapter, idx);
2084 struct cphy *
phy = &adap2pinfo(adapter, idx)->phy;
2088 phy->
ops->intr_enable(phy);
2101 struct cphy *
phy = &adap2pinfo(adapter, idx)->phy;
2105 phy->
ops->intr_disable(phy);
2116 static void t3_port_intr_clear(
struct adapter *adapter,
int idx)
2118 struct cphy *
phy = &adap2pinfo(adapter, idx)->phy;
2122 phy->
ops->intr_clear(phy);
2125 #define SG_CONTEXT_CMD_ATTEMPTS 100
2136 static int t3_sge_write_context(
struct adapter *adapter,
unsigned int id,
2173 static int clear_sge_ctxt(
struct adapter *adap,
unsigned int id,
2214 if (base_addr & 0xfff)
2231 return t3_sge_write_context(adapter,
id,
F_EGRESS);
2251 int gts_enable,
u64 base_addr,
unsigned int size,
2252 unsigned int bsize,
unsigned int cong_thres,
int gen,
2255 if (base_addr & 0xfff)
2272 return t3_sge_write_context(adapter,
id,
F_FREELIST);
2291 int irq_vec_idx,
u64 base_addr,
unsigned int size,
2292 unsigned int fl_thres,
int gen,
unsigned int cidx)
2294 unsigned int intr = 0;
2296 if (base_addr & 0xfff)
2306 if (irq_vec_idx >= 0)
2311 return t3_sge_write_context(adapter,
id,
F_RESPONSEQ);
2330 unsigned int size,
int rspq,
int ovfl_mode,
2331 unsigned int credits,
unsigned int credit_thres)
2333 if (base_addr & 0xfff)
2348 return t3_sge_write_context(adapter,
id,
F_CQ);
2459 unsigned int credits)
2473 if (op >= 2 && op < 7) {
2474 if (adapter->
params.rev > 0)
2480 F_CONTEXT_CMD_BUSY, 0,
2503 int i,
j, cpu_idx = 0, q_idx = 0;
2509 for (j = 0; j < 2; ++
j) {
2510 val |= (cpus[cpu_idx++] & 0x3f) << (8 * j);
2511 if (cpus[cpu_idx] == 0xff)
2520 (i << 16) | rspq[q_idx++]);
2521 if (rspq[q_idx] == 0xffff)
2537 if (is_offload(adap) || !enable)
2551 static inline unsigned int pm_num_pages(
unsigned int mem_size,
2552 unsigned int pg_size)
2554 unsigned int n = mem_size / pg_size;
2559 #define mem_region(adap, start, size, reg) \
2560 t3_write_reg((adap), A_ ## reg, (start)); \
2571 static void partition_mem(
struct adapter *adap,
const struct tp_params *p)
2573 unsigned int m, pstructs, tids = t3_mc5_size(&adap->
mc5);
2574 unsigned int timers = 0, timers_shift = 22;
2576 if (adap->
params.rev > 0) {
2577 if (tids <= 16 * 1024) {
2580 }
else if (tids <= 64 * 1024) {
2583 }
else if (tids <= 256 * 1024) {
2605 pstructs -= pstructs % 24;
2609 mem_region(adap, m, (64 << 10) * 64, SG_EGR_CNTX_BADDR);
2610 mem_region(adap, m, (64 << 10) * 64, SG_CQ_CONTEXT_BADDR);
2612 m += ((p->
ntimer_qs - 1) << timers_shift) + (1 << 22);
2613 mem_region(adap, m, pstructs * 64, TP_CMM_MM_BASE);
2614 mem_region(adap, m, 64 * (pstructs / 24), TP_CMM_MM_PS_FLST_BASE);
2618 m = (m + 4095) & ~0xfff;
2622 tids = (p->
cm_size - m - (3 << 20)) / 3072 - 32;
2623 m = t3_mc5_size(&adap->
mc5) - adap->
params.mc5.nservers -
2626 adap->
params.mc5.nservers += m - tids;
2629 static inline void tp_wr_indirect(
struct adapter *adap,
unsigned int addr,
2636 static void tp_config(
struct adapter *adap,
const struct tp_params *p)
2666 if (adap->
params.rev > 0) {
2687 #define TP_TMR_RES 50
2690 #define TP_DACK_TIMER 50
2691 #define TP_RTO_MIN 250
2701 static void tp_set_timers(
struct adapter *adap,
unsigned int core_clk)
2703 unsigned int tre = fls(core_clk / (1000000 /
TP_TMR_RES)) - 1;
2704 unsigned int dack_re = fls(core_clk / 5000) - 1;
2705 unsigned int tstamp_re = fls(core_clk / 1000);
2706 unsigned int tps = core_clk >> tre;
2722 #define SECONDS * tps
2745 static int t3_tp_set_coalescing_size(
struct adapter *adap,
2746 unsigned int size,
int psh)
2776 static void t3_tp_set_max_rxsize(
struct adapter *adap,
unsigned int size)
2782 static void init_mtus(
unsigned short mtus[])
2810 static void init_cong_ctrl(
unsigned short *
a,
unsigned short *
b)
2812 a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
2837 b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
2840 b[13] = b[14] = b[15] = b[16] = 3;
2841 b[17] = b[18] = b[19] = b[20] = b[21] = 4;
2842 b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
2848 #define CC_MIN_INCR 2U
2864 unsigned short beta[NCCTRL_WIN],
unsigned short mtu_cap)
2866 static const unsigned int avg_pkts[
NCCTRL_WIN] = {
2867 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
2868 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
2869 28672, 40960, 57344, 81920, 114688, 163840, 229376
2874 for (i = 0; i <
NMTUS; ++
i) {
2875 unsigned int mtu =
min(mtus[i], mtu_cap);
2876 unsigned int log2 = fls(mtu);
2878 if (!(mtu & ((1 << log2) >> 2)))
2881 (i << 24) | (log2 << 16) | mtu);
2886 inc =
max(((mtu - 40) *
alpha[w]) / avg_pkts[w],
2890 (w << 16) | (beta[w] << 13) | inc);
2905 sizeof(*tps) /
sizeof(
u32), 0);
2908 #define ulp_region(adap, name, start, len) \
2909 t3_write_reg((adap), A_ULPRX_ ## name ## _LLIMIT, (start)); \
2910 t3_write_reg((adap), A_ULPRX_ ## name ## _ULIMIT, \
2911 (start) + (len) - 1); \
2914 #define ulptx_region(adap, name, start, len) \
2915 t3_write_reg((adap), A_ULPTX_ ## name ## _LLIMIT, (start)); \
2916 t3_write_reg((adap), A_ULPTX_ ## name ## _ULIMIT, \
2917 (start) + (len) - 1)
2919 static void ulp_config(
struct adapter *adap,
const struct tp_params *p)
2967 key[0] = tp->
sport | (tp->
sip << 16);
2968 key[1] = (tp->
sip >> 16) | (tp->
dport << 16);
2978 key[3] |= (1 << 29);
2980 key[3] |= (1 << 28);
2983 tp_wr_indirect(adapter, addr++, key[0]);
2984 tp_wr_indirect(adapter, addr++, mask[0]);
2985 tp_wr_indirect(adapter, addr++, key[1]);
2986 tp_wr_indirect(adapter, addr++, mask[1]);
2987 tp_wr_indirect(adapter, addr++, key[2]);
2988 tp_wr_indirect(adapter, addr++, mask[2]);
2989 tp_wr_indirect(adapter, addr++, key[3]);
2990 tp_wr_indirect(adapter, addr, mask[3]);
3005 unsigned int clk = adap->
params.vpd.cclk * 1000;
3006 unsigned int selected_cpt = 0, selected_bpt = 0;
3010 for (cpt = 1; cpt <= 255; cpt++) {
3012 bpt = (kbps + tps / 2) / tps;
3013 if (bpt > 0 && bpt <= 255) {
3015 delta = v >= kbps ? v - kbps : kbps -
v;
3016 if (delta <= mindelta) {
3021 }
else if (selected_cpt)
3031 v = (v & 0xffff) | (selected_cpt << 16) | (selected_bpt << 24);
3033 v = (v & 0xffff0000) | selected_cpt | (selected_bpt << 8);
3038 static int tp_init(
struct adapter *adap,
const struct tp_params *p)
3045 if (is_offload(adap)) {
3046 tp_set_timers(adap, adap->
params.vpd.cclk * 1000);
3051 CH_ERR(adap,
"TP initialization timed out\n");
3063 static void chan_init_hw(
struct adapter *adap,
unsigned int chan_map)
3067 if (chan_map != 3) {
3074 chan_map == 1 ? 0xffffffff : 0);
3087 for (i = 0; i < 16; i++)
3089 (i << 16) | 0x1010);
3093 static int calibrate_xgm(
struct adapter *adapter)
3095 if (uses_xaui(adapter)) {
3098 for (i = 0; i < 5; ++
i) {
3109 CH_ERR(adapter,
"MAC calibration failed\n");
3120 static void calibrate_xgm_t3b(
struct adapter *adapter)
3122 if (!uses_xaui(adapter)) {
3150 static int wrreg_wait(
struct adapter *adapter,
unsigned int addr,
u32 val)
3152 t3_write_reg(adapter, addr, val);
3153 t3_read_reg(adapter, addr);
3154 if (!(t3_read_reg(adapter, addr) & F_BUSY))
3156 CH_ERR(adapter,
"write to MC7 register 0x%x timed out\n", addr);
3160 static int mc7_init(
struct mc7 *
mc7,
unsigned int mc7_clock,
int mem_type)
3162 static const unsigned int mc7_mode[] = {
3163 0x632, 0x642, 0x652, 0x432, 0x442
3166 {12, 3, 4, {20, 28, 34, 52, 0}, 15, 6, 4},
3167 {12, 4, 5, {20, 28, 34, 52, 0}, 16, 7, 4},
3168 {12, 5, 6, {20, 28, 34, 52, 0}, 17, 8, 4},
3169 {9, 3, 4, {15, 21, 26, 39, 0}, 12, 6, 4},
3170 {9, 4, 5, {15, 21, 26, 39, 0}, 13, 7, 4}
3174 unsigned int width, density, slow, attempts;
3175 struct adapter *adapter = mc7->
adapter;
3184 density =
G_DEN(val);
3196 CH_ERR(adapter,
"%s MC7 calibration timed out\n",
3234 mc7_mode[mem_type]) ||
3240 mc7_clock = mc7_clock * 7812 + mc7_clock / 2;
3241 mc7_clock /= 1000000;
3251 (mc7->
size << width) - 1);
3259 }
while ((val & F_BUSY) && --attempts);
3261 CH_ERR(adapter,
"%s MC7 BIST timed out\n", mc7->
name);
3273 static void config_pcie(
struct adapter *adap)
3275 static const u16 ack_lat[4][6] = {
3276 {237, 416, 559, 1071, 2095, 4143},
3277 {128, 217, 289, 545, 1057, 2081},
3278 {73, 118, 154, 282, 538, 1050},
3279 {67, 107, 86, 150, 278, 534}
3281 static const u16 rpl_tmr[4][6] = {
3282 {711, 1248, 1677, 3213, 6285, 12429},
3283 {384, 651, 867, 1635, 3171, 6243},
3284 {219, 354, 462, 846, 1614, 3150},
3285 {201, 321, 258, 450, 834, 1602}
3289 unsigned int log2_width, pldsize;
3290 unsigned int fst_trn_rx, fst_trn_tx, acklat, rpllmt;
3295 pci_read_config_word(adap->
pdev, 0x2, &devid);
3296 if (devid == 0x37) {
3306 fst_trn_rx = adap->
params.rev == 0 ? fst_trn_tx :
3308 log2_width = fls(adap->
params.pci.width) - 1;
3309 acklat = ack_lat[log2_width][pldsize];
3311 acklat += fst_trn_tx * 4;
3312 rpllmt = rpl_tmr[log2_width][pldsize] + fst_trn_rx * 4;
3314 if (adap->
params.rev == 0)
3344 if (adapter->
params.rev > 0)
3345 calibrate_xgm_t3b(adapter);
3346 else if (calibrate_xgm(adapter))
3350 partition_mem(adapter, &adapter->
params.tp);
3356 adapter->
params.mc5.nfilters,
3357 adapter->
params.mc5.nroutes))
3360 for (i = 0; i < 32; i++)
3361 if (clear_sge_ctxt(adapter, i,
F_CQ))
3365 if (tp_init(adapter, &adapter->
params.tp))
3368 t3_tp_set_coalescing_size(adapter,
3371 t3_tp_set_max_rxsize(adapter,
3372 min(adapter->
params.sge.max_pkt_size, 16384
U));
3373 ulp_config(adapter, &adapter->
params.tp);
3375 if (is_pcie(adapter))
3376 config_pcie(adapter);
3388 chan_init_hw(adapter, adapter->
params.chan_map);
3404 CH_ERR(adapter,
"uP initialization timed out\n");
3421 static void get_pci_mode(
struct adapter *adapter,
struct pci_params *p)
3423 static unsigned short speed_map[] = { 33, 66, 100, 133 };
3426 if (pci_is_pcie(adapter->
pdev)) {
3431 p->
width = (val >> 4) & 0x3f;
3441 else if (pci_mode < 4)
3443 else if (pci_mode < 8)
3481 static unsigned int mc7_calc_size(
u32 cfg)
3483 unsigned int width =
G_WIDTH(cfg);
3485 unsigned int org = !!(cfg &
F_ORG) + 1;
3486 unsigned int density =
G_DEN(cfg);
3487 unsigned int MBs = ((256 << density) * banks) / (org <<
width);
3492 static void mc7_prep(
struct adapter *adapter,
struct mc7 *mc7,
3493 unsigned int base_addr,
const char *
name)
3505 static void mac_prep(
struct cmac *
mac,
struct adapter *adapter,
int index)
3510 pci_read_config_word(adapter->
pdev, 0x2, &devid);
3512 if (devid == 0x37 && !adapter->
params.vpd.xauicfg[1])
3517 if (adapter->
params.rev == 0 && uses_xaui(adapter)) {
3519 is_10G(adapter) ? 0x2901c04 : 0x2301c04);
3525 static void early_hw_init(
struct adapter *adapter,
3530 mi1_init(adapter, ai);
3538 if (adapter->
params.rev == 0 || !uses_xaui(adapter))
3559 int i, save_and_restore_pcie =
3563 if (save_and_restore_pcie)
3571 for (i = 0; i < 10; i++) {
3573 pci_read_config_word(adapter->
pdev, 0x00, &devid);
3574 if (devid == 0x1425)
3578 if (devid != 0x1425)
3581 if (save_and_restore_pcie)
3586 static int init_parity(
struct adapter *adap)
3593 for (err = i = 0; !err && i < 16; i++)
3594 err = clear_sge_ctxt(adap, i,
F_EGRESS);
3595 for (i = 0xfff0; !err && i <= 0xffff; i++)
3596 err = clear_sge_ctxt(adap, i,
F_EGRESS);
3603 for (i = 0; i < 4; i++)
3625 unsigned int i,
j = -1;
3627 get_pci_mode(adapter, &adapter->
params.pci);
3629 adapter->
params.info = ai;
3641 adapter->
params.linkpoll_period = 10;
3642 adapter->
params.stats_update_period =
is_10G(adapter) ?
3644 adapter->
params.pci.vpd_cap_addr =
3646 ret = get_vpd_params(adapter, &adapter->
params.vpd);
3655 if (adapter->
params.vpd.mclk) {
3673 adapter->
params.rev > 0 ? 12 : 6;
3676 adapter->
params.offload = t3_mc7_size(&adapter->
pmrx) &&
3677 t3_mc7_size(&adapter->
pmtx) &&
3678 t3_mc7_size(&adapter->
cm);
3680 if (is_offload(adapter)) {
3682 adapter->
params.mc5.nfilters = adapter->
params.rev > 0 ?
3684 adapter->
params.mc5.nroutes = 0;
3687 init_mtus(adapter->
params.mtus);
3688 init_cong_ctrl(adapter->
params.a_wnd, adapter->
params.b_wnd);
3691 early_hw_init(adapter, ai);
3692 ret = init_parity(adapter);
3699 struct port_info *p = adap2pinfo(adapter, i);
3701 while (!adapter->
params.vpd.port_type[++j])
3704 pti = &port_types[adapter->
params.vpd.port_type[
j]];
3706 CH_ALERT(adapter,
"Invalid port type index %d\n",
3707 adapter->
params.vpd.port_type[j]);
3711 p->
phy.mdio.dev = adapter->
port[
i];
3716 mac_prep(&p->
mac, adapter, j);
3724 hw_addr[5] = adapter->
params.vpd.eth_base[5] +
i;
3731 p->
phy.ops->power_down(&p->
phy, 1);
3739 adapter->
params.linkpoll_period > 10)
3740 adapter->
params.linkpoll_period = 10;
3755 unsigned int i,
j = -1;
3758 early_hw_init(adapter, ai);
3759 ret = init_parity(adapter);
3765 struct port_info *p = adap2pinfo(adapter, i);
3767 while (!adapter->
params.vpd.port_type[++j])
3770 pti = &port_types[adapter->
params.vpd.port_type[
j]];
3774 p->
phy.ops->power_down(&p->
phy, 1);