1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2020 Advanced Micro Devices, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Contact Information : 28 * Rajesh Kumar <rajesh1.kumar@amd.com> 29 * Shreyank Amartya <Shreyank.Amartya@amd.com> 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 #include <sys/param.h> 36 #include <sys/bus.h> 37 #include <sys/kernel.h> 38 #include <sys/malloc.h> 39 #include <sys/module.h> 40 #include <sys/mutex.h> 41 #include <sys/rman.h> 42 #include <sys/socket.h> 43 #include <sys/sysctl.h> 44 #include <sys/systm.h> 45 46 #include <net/if.h> 47 #include <net/if_media.h> 48 49 #include <dev/mii/mii.h> 50 #include <dev/mii/miivar.h> 51 52 #include <dev/pci/pcireg.h> 53 #include <dev/pci/pcivar.h> 54 55 #include "xgbe.h" 56 #include "xgbe-common.h" 57 58 #include "miibus_if.h" 59 #include "ifdi_if.h" 60 #include "opt_inet.h" 61 #include "opt_inet6.h" 62 63 MALLOC_DEFINE(M_AXGBE, "axgbe", "axgbe data"); 64 65 extern struct if_txrx axgbe_txrx; 66 static int axgbe_sph_enable; 67 68 /* Function prototypes */ 69 static void *axgbe_register(device_t); 70 static int axgbe_if_attach_pre(if_ctx_t); 71 static int axgbe_if_attach_post(if_ctx_t); 72 static int axgbe_if_detach(if_ctx_t); 73 static void axgbe_if_stop(if_ctx_t); 74 static void axgbe_if_init(if_ctx_t); 75 76 /* Queue related routines */ 77 static int axgbe_if_tx_queues_alloc(if_ctx_t, caddr_t *, uint64_t *, int, int); 78 static int axgbe_if_rx_queues_alloc(if_ctx_t, caddr_t *, uint64_t *, int, int); 79 static int axgbe_alloc_channels(if_ctx_t); 80 static void axgbe_if_queues_free(if_ctx_t); 81 static int axgbe_if_tx_queue_intr_enable(if_ctx_t, uint16_t); 82 static int axgbe_if_rx_queue_intr_enable(if_ctx_t, uint16_t); 83 84 /* Interrupt related routines */ 85 static void axgbe_if_disable_intr(if_ctx_t); 86 static void axgbe_if_enable_intr(if_ctx_t); 87 static int axgbe_if_msix_intr_assign(if_ctx_t, int); 88 static void xgbe_free_intr(struct xgbe_prv_data *, struct resource *, void *, int); 89 90 /* Init and Iflib routines */ 91 static void axgbe_pci_init(struct xgbe_prv_data *); 92 static void axgbe_pci_stop(if_ctx_t); 93 static void xgbe_disable_rx_tx_int(struct xgbe_prv_data *, struct xgbe_channel *); 94 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *); 95 static int axgbe_if_mtu_set(if_ctx_t, uint32_t); 96 static void axgbe_if_update_admin_status(if_ctx_t); 97 static void axgbe_if_media_status(if_ctx_t, struct ifmediareq *); 98 static int axgbe_if_media_change(if_ctx_t); 99 static int axgbe_if_promisc_set(if_ctx_t, int); 100 static uint64_t axgbe_if_get_counter(if_ctx_t, ift_counter); 101 static void axgbe_if_vlan_register(if_ctx_t, uint16_t); 102 static void axgbe_if_vlan_unregister(if_ctx_t, uint16_t); 103 #if __FreeBSD_version >= 1300000 104 static bool axgbe_if_needs_restart(if_ctx_t, enum iflib_restart_event); 105 #endif 106 static void axgbe_set_counts(if_ctx_t); 107 static void axgbe_init_iflib_softc_ctx(struct axgbe_if_softc *); 108 109 /* MII interface registered functions */ 110 static int axgbe_miibus_readreg(device_t, int, int); 111 static int axgbe_miibus_writereg(device_t, int, int, int); 112 static void axgbe_miibus_statchg(device_t); 113 114 /* ISR routines */ 115 static int axgbe_dev_isr(void *); 116 static void axgbe_ecc_isr(void *); 117 static void axgbe_i2c_isr(void *); 118 static void axgbe_an_isr(void *); 119 static int axgbe_msix_que(void *); 120 121 /* Timer routines */ 122 static void xgbe_service(void *, int); 123 static void xgbe_service_timer(void *); 124 static void xgbe_init_timers(struct xgbe_prv_data *); 125 static void xgbe_stop_timers(struct xgbe_prv_data *); 126 127 /* Dump routines */ 128 static void xgbe_dump_prop_registers(struct xgbe_prv_data *); 129 130 /* 131 * Allocate only for MAC (BAR0) and PCS (BAR1) registers, and just point the 132 * MSI-X table bar (BAR5) to iflib. iflib will do the allocation for MSI-X 133 * table. 134 */ 135 static struct resource_spec axgbe_pci_mac_spec[] = { 136 { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE }, /* MAC regs */ 137 { SYS_RES_MEMORY, PCIR_BAR(1), RF_ACTIVE }, /* PCS regs */ 138 { -1, 0 } 139 }; 140 141 static pci_vendor_info_t axgbe_vendor_info_array[] = 142 { 143 PVID(0x1022, 0x1458, "AMD 10 Gigabit Ethernet Driver"), 144 PVID(0x1022, 0x1459, "AMD 10 Gigabit Ethernet Driver"), 145 PVID_END 146 }; 147 148 static struct xgbe_version_data xgbe_v2a = { 149 .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 150 .xpcs_access = XGBE_XPCS_ACCESS_V2, 151 .mmc_64bit = 1, 152 .tx_max_fifo_size = 229376, 153 .rx_max_fifo_size = 229376, 154 .tx_tstamp_workaround = 1, 155 .ecc_support = 1, 156 .i2c_support = 1, 157 .irq_reissue_support = 1, 158 .tx_desc_prefetch = 5, 159 .rx_desc_prefetch = 5, 160 .an_cdr_workaround = 1, 161 }; 162 163 static struct xgbe_version_data xgbe_v2b = { 164 .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 165 .xpcs_access = XGBE_XPCS_ACCESS_V2, 166 .mmc_64bit = 1, 167 .tx_max_fifo_size = 65536, 168 .rx_max_fifo_size = 65536, 169 .tx_tstamp_workaround = 1, 170 .ecc_support = 1, 171 .i2c_support = 1, 172 .irq_reissue_support = 1, 173 .tx_desc_prefetch = 5, 174 .rx_desc_prefetch = 5, 175 .an_cdr_workaround = 1, 176 }; 177 178 /* Device Interface */ 179 static device_method_t ax_methods[] = { 180 DEVMETHOD(device_register, axgbe_register), 181 DEVMETHOD(device_probe, iflib_device_probe), 182 DEVMETHOD(device_attach, iflib_device_attach), 183 DEVMETHOD(device_detach, iflib_device_detach), 184 185 /* MII interface */ 186 DEVMETHOD(miibus_readreg, axgbe_miibus_readreg), 187 DEVMETHOD(miibus_writereg, axgbe_miibus_writereg), 188 DEVMETHOD(miibus_statchg, axgbe_miibus_statchg), 189 190 DEVMETHOD_END 191 }; 192 193 static driver_t ax_driver = { 194 "ax", ax_methods, sizeof(struct axgbe_if_softc), 195 }; 196 197 devclass_t ax_devclass; 198 DRIVER_MODULE(axp, pci, ax_driver, ax_devclass, 0, 0); 199 DRIVER_MODULE(miibus, ax, miibus_driver, miibus_devclass, 0, 0); 200 IFLIB_PNP_INFO(pci, ax_driver, axgbe_vendor_info_array); 201 202 MODULE_DEPEND(ax, pci, 1, 1, 1); 203 MODULE_DEPEND(ax, ether, 1, 1, 1); 204 MODULE_DEPEND(ax, iflib, 1, 1, 1); 205 MODULE_DEPEND(ax, miibus, 1, 1, 1); 206 207 /* Iflib Interface */ 208 static device_method_t axgbe_if_methods[] = { 209 DEVMETHOD(ifdi_attach_pre, axgbe_if_attach_pre), 210 DEVMETHOD(ifdi_attach_post, axgbe_if_attach_post), 211 DEVMETHOD(ifdi_detach, axgbe_if_detach), 212 DEVMETHOD(ifdi_init, axgbe_if_init), 213 DEVMETHOD(ifdi_stop, axgbe_if_stop), 214 DEVMETHOD(ifdi_msix_intr_assign, axgbe_if_msix_intr_assign), 215 DEVMETHOD(ifdi_intr_enable, axgbe_if_enable_intr), 216 DEVMETHOD(ifdi_intr_disable, axgbe_if_disable_intr), 217 DEVMETHOD(ifdi_tx_queue_intr_enable, axgbe_if_tx_queue_intr_enable), 218 DEVMETHOD(ifdi_rx_queue_intr_enable, axgbe_if_rx_queue_intr_enable), 219 DEVMETHOD(ifdi_tx_queues_alloc, axgbe_if_tx_queues_alloc), 220 DEVMETHOD(ifdi_rx_queues_alloc, axgbe_if_rx_queues_alloc), 221 DEVMETHOD(ifdi_queues_free, axgbe_if_queues_free), 222 DEVMETHOD(ifdi_update_admin_status, axgbe_if_update_admin_status), 223 DEVMETHOD(ifdi_mtu_set, axgbe_if_mtu_set), 224 DEVMETHOD(ifdi_media_status, axgbe_if_media_status), 225 DEVMETHOD(ifdi_media_change, axgbe_if_media_change), 226 DEVMETHOD(ifdi_promisc_set, axgbe_if_promisc_set), 227 DEVMETHOD(ifdi_get_counter, axgbe_if_get_counter), 228 DEVMETHOD(ifdi_vlan_register, axgbe_if_vlan_register), 229 DEVMETHOD(ifdi_vlan_unregister, axgbe_if_vlan_unregister), 230 #if __FreeBSD_version >= 1300000 231 DEVMETHOD(ifdi_needs_restart, axgbe_if_needs_restart), 232 #endif 233 DEVMETHOD_END 234 }; 235 236 static driver_t axgbe_if_driver = { 237 "axgbe_if", axgbe_if_methods, sizeof(struct axgbe_if_softc) 238 }; 239 240 /* Iflib Shared Context */ 241 static struct if_shared_ctx axgbe_sctx_init = { 242 .isc_magic = IFLIB_MAGIC, 243 .isc_driver = &axgbe_if_driver, 244 .isc_q_align = PAGE_SIZE, 245 .isc_tx_maxsize = XGBE_TSO_MAX_SIZE + sizeof(struct ether_vlan_header), 246 .isc_tx_maxsegsize = PAGE_SIZE, 247 .isc_tso_maxsize = XGBE_TSO_MAX_SIZE + sizeof(struct ether_vlan_header), 248 .isc_tso_maxsegsize = PAGE_SIZE, 249 .isc_rx_maxsize = MJUM9BYTES, 250 .isc_rx_maxsegsize = MJUM9BYTES, 251 .isc_rx_nsegments = 1, 252 .isc_admin_intrcnt = 4, 253 254 .isc_vendor_info = axgbe_vendor_info_array, 255 .isc_driver_version = XGBE_DRV_VERSION, 256 257 .isc_ntxd_min = {XGBE_TX_DESC_CNT_MIN}, 258 .isc_ntxd_default = {XGBE_TX_DESC_CNT_DEFAULT}, 259 .isc_ntxd_max = {XGBE_TX_DESC_CNT_MAX}, 260 261 .isc_ntxqs = 1, 262 .isc_flags = IFLIB_TSO_INIT_IP | IFLIB_NEED_SCRATCH | 263 IFLIB_NEED_ZERO_CSUM | IFLIB_NEED_ETHER_PAD, 264 }; 265 266 static void * 267 axgbe_register(device_t dev) 268 { 269 int axgbe_nfl; 270 int axgbe_nrxqs; 271 int error, i; 272 char *value = NULL; 273 274 value = kern_getenv("dev.ax.sph_enable"); 275 if (value) { 276 axgbe_sph_enable = strtol(value, NULL, 10); 277 freeenv(value); 278 } else { 279 /* 280 * No tunable found, generate one with default values 281 * Note: only a reboot will reveal the new kenv 282 */ 283 error = kern_setenv("dev.ax.sph_enable", "1"); 284 if (error) { 285 printf("Error setting tunable, using default driver values\n"); 286 } 287 axgbe_sph_enable = 1; 288 } 289 290 if (!axgbe_sph_enable) { 291 axgbe_nfl = 1; 292 axgbe_nrxqs = 1; 293 } else { 294 axgbe_nfl = 2; 295 axgbe_nrxqs = 2; 296 } 297 298 axgbe_sctx_init.isc_nfl = axgbe_nfl; 299 axgbe_sctx_init.isc_nrxqs = axgbe_nrxqs; 300 301 for (i = 0 ; i < axgbe_nrxqs ; i++) { 302 axgbe_sctx_init.isc_nrxd_min[i] = XGBE_RX_DESC_CNT_MIN; 303 axgbe_sctx_init.isc_nrxd_default[i] = XGBE_RX_DESC_CNT_DEFAULT; 304 axgbe_sctx_init.isc_nrxd_max[i] = XGBE_RX_DESC_CNT_MAX; 305 } 306 307 return (&axgbe_sctx_init); 308 } 309 310 /* MII Interface Functions */ 311 static int 312 axgbe_miibus_readreg(device_t dev, int phy, int reg) 313 { 314 struct axgbe_if_softc *sc = iflib_get_softc(device_get_softc(dev)); 315 struct xgbe_prv_data *pdata = &sc->pdata; 316 int val; 317 318 axgbe_printf(3, "%s: phy %d reg %d\n", __func__, phy, reg); 319 320 val = xgbe_phy_mii_read(pdata, phy, reg); 321 322 axgbe_printf(2, "%s: val 0x%x\n", __func__, val); 323 return (val & 0xFFFF); 324 } 325 326 static int 327 axgbe_miibus_writereg(device_t dev, int phy, int reg, int val) 328 { 329 struct axgbe_if_softc *sc = iflib_get_softc(device_get_softc(dev)); 330 struct xgbe_prv_data *pdata = &sc->pdata; 331 332 axgbe_printf(3, "%s: phy %d reg %d val 0x%x\n", __func__, phy, reg, val); 333 334 xgbe_phy_mii_write(pdata, phy, reg, val); 335 336 return(0); 337 } 338 339 static void 340 axgbe_miibus_statchg(device_t dev) 341 { 342 struct axgbe_if_softc *sc = iflib_get_softc(device_get_softc(dev)); 343 struct xgbe_prv_data *pdata = &sc->pdata; 344 struct mii_data *mii = device_get_softc(pdata->axgbe_miibus); 345 struct ifnet *ifp = pdata->netdev; 346 int bmsr; 347 348 axgbe_printf(2, "%s: Link %d/%d\n", __func__, pdata->phy.link, 349 pdata->phy_link); 350 351 if (mii == NULL || ifp == NULL || 352 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 353 return; 354 355 if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 356 (IFM_ACTIVE | IFM_AVALID)) { 357 358 switch (IFM_SUBTYPE(mii->mii_media_active)) { 359 case IFM_10_T: 360 case IFM_100_TX: 361 pdata->phy.link = 1; 362 break; 363 case IFM_1000_T: 364 case IFM_1000_SX: 365 case IFM_2500_SX: 366 pdata->phy.link = 1; 367 break; 368 default: 369 pdata->phy.link = 0; 370 break; 371 } 372 } else 373 pdata->phy_link = 0; 374 375 bmsr = axgbe_miibus_readreg(pdata->dev, pdata->mdio_addr, MII_BMSR); 376 if (bmsr & BMSR_ANEG) { 377 378 axgbe_printf(2, "%s: Autoneg Done\n", __func__); 379 380 /* Raise AN Interrupt */ 381 XMDIO_WRITE(pdata, MDIO_MMD_AN, MDIO_AN_INTMASK, 382 XGBE_AN_CL73_INT_MASK); 383 } 384 } 385 386 static int 387 axgbe_if_attach_pre(if_ctx_t ctx) 388 { 389 struct axgbe_if_softc *sc; 390 struct xgbe_prv_data *pdata; 391 struct resource *mac_res[2]; 392 if_softc_ctx_t scctx; 393 if_shared_ctx_t sctx; 394 device_t dev; 395 unsigned int ma_lo, ma_hi; 396 unsigned int reg; 397 398 sc = iflib_get_softc(ctx); 399 sc->pdata.dev = dev = iflib_get_dev(ctx); 400 sc->sctx = sctx = iflib_get_sctx(ctx); 401 sc->scctx = scctx = iflib_get_softc_ctx(ctx); 402 sc->media = iflib_get_media(ctx); 403 sc->ctx = ctx; 404 sc->link_status = LINK_STATE_DOWN; 405 pdata = &sc->pdata; 406 pdata->netdev = iflib_get_ifp(ctx); 407 408 spin_lock_init(&pdata->xpcs_lock); 409 410 /* Initialize locks */ 411 mtx_init(&pdata->rss_mutex, "xgbe rss mutex lock", NULL, MTX_DEF); 412 mtx_init(&pdata->mdio_mutex, "xgbe MDIO mutex lock", NULL, MTX_SPIN); 413 414 /* Allocate VLAN bitmap */ 415 pdata->active_vlans = bit_alloc(VLAN_NVID, M_AXGBE, M_WAITOK|M_ZERO); 416 pdata->num_active_vlans = 0; 417 418 /* Get the version data */ 419 DBGPR("%s: Device ID: 0x%x\n", __func__, pci_get_device(dev)); 420 if (pci_get_device(dev) == 0x1458) 421 sc->pdata.vdata = &xgbe_v2a; 422 else if (pci_get_device(dev) == 0x1459) 423 sc->pdata.vdata = &xgbe_v2b; 424 425 /* PCI setup */ 426 if (bus_alloc_resources(dev, axgbe_pci_mac_spec, mac_res)) 427 return (ENXIO); 428 429 sc->pdata.xgmac_res = mac_res[0]; 430 sc->pdata.xpcs_res = mac_res[1]; 431 432 /* Set the PCS indirect addressing definition registers*/ 433 pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; 434 pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; 435 436 /* Configure the PCS indirect addressing support */ 437 reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); 438 pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); 439 pdata->xpcs_window <<= 6; 440 pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); 441 pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7); 442 pdata->xpcs_window_mask = pdata->xpcs_window_size - 1; 443 DBGPR("xpcs window def : %#010x\n", 444 pdata->xpcs_window_def_reg); 445 DBGPR("xpcs window sel : %#010x\n", 446 pdata->xpcs_window_sel_reg); 447 DBGPR("xpcs window : %#010x\n", 448 pdata->xpcs_window); 449 DBGPR("xpcs window size : %#010x\n", 450 pdata->xpcs_window_size); 451 DBGPR("xpcs window mask : %#010x\n", 452 pdata->xpcs_window_mask); 453 454 /* Enable all interrupts in the hardware */ 455 XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 456 457 /* Retrieve the MAC address */ 458 ma_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO); 459 ma_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI); 460 pdata->mac_addr[0] = ma_lo & 0xff; 461 pdata->mac_addr[1] = (ma_lo >> 8) & 0xff; 462 pdata->mac_addr[2] = (ma_lo >>16) & 0xff; 463 pdata->mac_addr[3] = (ma_lo >> 24) & 0xff; 464 pdata->mac_addr[4] = ma_hi & 0xff; 465 pdata->mac_addr[5] = (ma_hi >> 8) & 0xff; 466 if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID)) { 467 axgbe_error("Invalid mac address\n"); 468 return (EINVAL); 469 } 470 iflib_set_mac(ctx, pdata->mac_addr); 471 472 /* Clock settings */ 473 pdata->sysclk_rate = XGBE_V2_DMA_CLOCK_FREQ; 474 pdata->ptpclk_rate = XGBE_V2_PTP_CLOCK_FREQ; 475 476 /* Set the DMA coherency values */ 477 pdata->coherent = 1; 478 pdata->arcr = XGBE_DMA_PCI_ARCR; 479 pdata->awcr = XGBE_DMA_PCI_AWCR; 480 pdata->awarcr = XGBE_DMA_PCI_AWARCR; 481 482 /* Read the port property registers */ 483 pdata->pp0 = XP_IOREAD(pdata, XP_PROP_0); 484 pdata->pp1 = XP_IOREAD(pdata, XP_PROP_1); 485 pdata->pp2 = XP_IOREAD(pdata, XP_PROP_2); 486 pdata->pp3 = XP_IOREAD(pdata, XP_PROP_3); 487 pdata->pp4 = XP_IOREAD(pdata, XP_PROP_4); 488 DBGPR("port property 0 = %#010x\n", pdata->pp0); 489 DBGPR("port property 1 = %#010x\n", pdata->pp1); 490 DBGPR("port property 2 = %#010x\n", pdata->pp2); 491 DBGPR("port property 3 = %#010x\n", pdata->pp3); 492 DBGPR("port property 4 = %#010x\n", pdata->pp4); 493 494 /* Set the maximum channels and queues */ 495 pdata->tx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, 496 MAX_TX_DMA); 497 pdata->rx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, 498 MAX_RX_DMA); 499 pdata->tx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, 500 MAX_TX_QUEUES); 501 pdata->rx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, 502 MAX_RX_QUEUES); 503 DBGPR("max tx/rx channel count = %u/%u\n", 504 pdata->tx_max_channel_count, pdata->rx_max_channel_count); 505 DBGPR("max tx/rx hw queue count = %u/%u\n", 506 pdata->tx_max_q_count, pdata->rx_max_q_count); 507 508 axgbe_set_counts(ctx); 509 510 /* Set the maximum fifo amounts */ 511 pdata->tx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2, 512 TX_FIFO_SIZE); 513 pdata->tx_max_fifo_size *= 16384; 514 pdata->tx_max_fifo_size = min(pdata->tx_max_fifo_size, 515 pdata->vdata->tx_max_fifo_size); 516 pdata->rx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2, 517 RX_FIFO_SIZE); 518 pdata->rx_max_fifo_size *= 16384; 519 pdata->rx_max_fifo_size = min(pdata->rx_max_fifo_size, 520 pdata->vdata->rx_max_fifo_size); 521 DBGPR("max tx/rx max fifo size = %u/%u\n", 522 pdata->tx_max_fifo_size, pdata->rx_max_fifo_size); 523 524 /* Initialize IFLIB if_softc_ctx_t */ 525 axgbe_init_iflib_softc_ctx(sc); 526 527 /* Alloc channels */ 528 if (axgbe_alloc_channels(ctx)) { 529 axgbe_error("Unable to allocate channel memory\n"); 530 return (ENOMEM); 531 } 532 533 TASK_INIT(&pdata->service_work, 0, xgbe_service, pdata); 534 535 /* create the workqueue */ 536 pdata->dev_workqueue = taskqueue_create("axgbe", M_WAITOK, 537 taskqueue_thread_enqueue, &pdata->dev_workqueue); 538 taskqueue_start_threads(&pdata->dev_workqueue, 1, PI_NET, 539 "axgbe dev taskq"); 540 541 /* Init timers */ 542 xgbe_init_timers(pdata); 543 544 return (0); 545 } /* axgbe_if_attach_pre */ 546 547 static void 548 xgbe_init_all_fptrs(struct xgbe_prv_data *pdata) 549 { 550 xgbe_init_function_ptrs_dev(&pdata->hw_if); 551 xgbe_init_function_ptrs_phy(&pdata->phy_if); 552 xgbe_init_function_ptrs_i2c(&pdata->i2c_if); 553 xgbe_init_function_ptrs_desc(&pdata->desc_if); 554 555 pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if); 556 } 557 558 static void 559 axgbe_set_counts(if_ctx_t ctx) 560 { 561 struct axgbe_if_softc *sc = iflib_get_softc(ctx);; 562 struct xgbe_prv_data *pdata = &sc->pdata; 563 cpuset_t lcpus; 564 int cpu_count, err; 565 size_t len; 566 567 /* Set all function pointers */ 568 xgbe_init_all_fptrs(pdata); 569 570 /* Populate the hardware features */ 571 xgbe_get_all_hw_features(pdata); 572 573 if (!pdata->tx_max_channel_count) 574 pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt; 575 if (!pdata->rx_max_channel_count) 576 pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt; 577 578 if (!pdata->tx_max_q_count) 579 pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt; 580 if (!pdata->rx_max_q_count) 581 pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt; 582 583 /* 584 * Calculate the number of Tx and Rx rings to be created 585 * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set 586 * the number of Tx queues to the number of Tx channels 587 * enabled 588 * -Rx (DMA) Channels do not map 1-to-1 so use the actual 589 * number of Rx queues or maximum allowed 590 */ 591 592 /* Get cpu count from sysctl */ 593 len = sizeof(cpu_count); 594 err = kernel_sysctlbyname(curthread, "hw.ncpu", &cpu_count, &len, NULL, 595 0, NULL, 0); 596 if (err) { 597 axgbe_error("Unable to fetch number of cpus\n"); 598 cpu_count = 1; 599 } 600 601 if (bus_get_cpus(pdata->dev, INTR_CPUS, sizeof(lcpus), &lcpus) != 0) { 602 axgbe_error("Unable to fetch CPU list\n"); 603 /* TODO - handle CPU_COPY(&all_cpus, &lcpus); */ 604 } 605 606 DBGPR("ncpu %d intrcpu %d\n", cpu_count, CPU_COUNT(&lcpus)); 607 608 pdata->tx_ring_count = min(CPU_COUNT(&lcpus), pdata->hw_feat.tx_ch_cnt); 609 pdata->tx_ring_count = min(pdata->tx_ring_count, 610 pdata->tx_max_channel_count); 611 pdata->tx_ring_count = min(pdata->tx_ring_count, pdata->tx_max_q_count); 612 613 pdata->tx_q_count = pdata->tx_ring_count; 614 615 pdata->rx_ring_count = min(CPU_COUNT(&lcpus), pdata->hw_feat.rx_ch_cnt); 616 pdata->rx_ring_count = min(pdata->rx_ring_count, 617 pdata->rx_max_channel_count); 618 619 pdata->rx_q_count = min(pdata->hw_feat.rx_q_cnt, pdata->rx_max_q_count); 620 621 DBGPR("TX/RX max channel count = %u/%u\n", 622 pdata->tx_max_channel_count, pdata->rx_max_channel_count); 623 DBGPR("TX/RX max queue count = %u/%u\n", 624 pdata->tx_max_q_count, pdata->rx_max_q_count); 625 DBGPR("TX/RX DMA ring count = %u/%u\n", 626 pdata->tx_ring_count, pdata->rx_ring_count); 627 DBGPR("TX/RX hardware queue count = %u/%u\n", 628 pdata->tx_q_count, pdata->rx_q_count); 629 } /* axgbe_set_counts */ 630 631 static void 632 axgbe_init_iflib_softc_ctx(struct axgbe_if_softc *sc) 633 { 634 struct xgbe_prv_data *pdata = &sc->pdata; 635 if_softc_ctx_t scctx = sc->scctx; 636 if_shared_ctx_t sctx = sc->sctx; 637 int i; 638 639 scctx->isc_nrxqsets = pdata->rx_q_count; 640 scctx->isc_ntxqsets = pdata->tx_q_count; 641 scctx->isc_msix_bar = pci_msix_table_bar(pdata->dev); 642 scctx->isc_tx_nsegments = 32; 643 644 for (i = 0; i < sctx->isc_ntxqs; i++) { 645 scctx->isc_txqsizes[i] = 646 roundup2(scctx->isc_ntxd[i] * sizeof(struct xgbe_ring_desc), 647 128); 648 scctx->isc_txd_size[i] = sizeof(struct xgbe_ring_desc); 649 } 650 651 for (i = 0; i < sctx->isc_nrxqs; i++) { 652 scctx->isc_rxqsizes[i] = 653 roundup2(scctx->isc_nrxd[i] * sizeof(struct xgbe_ring_desc), 654 128); 655 scctx->isc_rxd_size[i] = sizeof(struct xgbe_ring_desc); 656 } 657 658 scctx->isc_tx_tso_segments_max = 32; 659 scctx->isc_tx_tso_size_max = XGBE_TSO_MAX_SIZE; 660 scctx->isc_tx_tso_segsize_max = PAGE_SIZE; 661 662 /* 663 * Set capabilities 664 * 1) IFLIB automatically adds IFCAP_HWSTATS, so need to set explicitly 665 * 2) isc_tx_csum_flags is mandatory if IFCAP_TXCSUM (included in 666 * IFCAP_HWCSUM) is set 667 */ 668 scctx->isc_tx_csum_flags = (CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_SCTP | 669 CSUM_TCP_IPV6 | CSUM_UDP_IPV6 | CSUM_SCTP_IPV6 | 670 CSUM_TSO); 671 scctx->isc_capenable = (IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6 | 672 IFCAP_JUMBO_MTU | 673 IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWFILTER | 674 IFCAP_VLAN_HWCSUM | 675 IFCAP_TSO | IFCAP_VLAN_HWTSO); 676 scctx->isc_capabilities = scctx->isc_capenable; 677 678 /* 679 * Set rss_table_size alone when adding RSS support. rss_table_mask 680 * will be set by IFLIB based on rss_table_size 681 */ 682 scctx->isc_rss_table_size = XGBE_RSS_MAX_TABLE_SIZE; 683 684 scctx->isc_ntxqsets_max = XGBE_MAX_QUEUES; 685 scctx->isc_nrxqsets_max = XGBE_MAX_QUEUES; 686 687 scctx->isc_txrx = &axgbe_txrx; 688 } 689 690 static int 691 axgbe_alloc_channels(if_ctx_t ctx) 692 { 693 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 694 struct xgbe_prv_data *pdata = &sc->pdata; 695 struct xgbe_channel *channel; 696 int i, j, count; 697 698 DBGPR("%s: txqs %d rxqs %d\n", __func__, pdata->tx_ring_count, 699 pdata->rx_ring_count); 700 701 /* Iflibe sets based on isc_ntxqsets/nrxqsets */ 702 count = max_t(unsigned int, pdata->tx_ring_count, pdata->rx_ring_count); 703 704 /* Allocate channel memory */ 705 for (i = 0; i < count ; i++) { 706 channel = (struct xgbe_channel*)malloc(sizeof(struct xgbe_channel), 707 M_AXGBE, M_NOWAIT | M_ZERO); 708 709 if (channel == NULL) { 710 for (j = 0; j < i; j++) { 711 free(pdata->channel[j], M_AXGBE); 712 pdata->channel[j] = NULL; 713 } 714 return (ENOMEM); 715 } 716 717 pdata->channel[i] = channel; 718 } 719 720 pdata->total_channel_count = count; 721 DBGPR("Channel count set to: %u\n", pdata->total_channel_count); 722 723 for (i = 0; i < count; i++) { 724 725 channel = pdata->channel[i]; 726 snprintf(channel->name, sizeof(channel->name), "channel-%d",i); 727 728 channel->pdata = pdata; 729 channel->queue_index = i; 730 channel->dma_tag = rman_get_bustag(pdata->xgmac_res); 731 bus_space_subregion(channel->dma_tag, 732 rman_get_bushandle(pdata->xgmac_res), 733 DMA_CH_BASE + (DMA_CH_INC * i), DMA_CH_INC, 734 &channel->dma_handle); 735 channel->tx_ring = NULL; 736 channel->rx_ring = NULL; 737 } 738 739 return (0); 740 } /* axgbe_alloc_channels */ 741 742 static void 743 xgbe_service(void *ctx, int pending) 744 { 745 struct xgbe_prv_data *pdata = ctx; 746 struct axgbe_if_softc *sc = (struct axgbe_if_softc *)pdata; 747 bool prev_state = false; 748 749 /* Get previous link status */ 750 prev_state = pdata->phy.link; 751 752 pdata->phy_if.phy_status(pdata); 753 754 if (prev_state != pdata->phy.link) { 755 pdata->phy_link = pdata->phy.link; 756 axgbe_if_update_admin_status(sc->ctx); 757 } 758 759 callout_reset(&pdata->service_timer, 1*hz, xgbe_service_timer, pdata); 760 } 761 762 static void 763 xgbe_service_timer(void *data) 764 { 765 struct xgbe_prv_data *pdata = data; 766 767 taskqueue_enqueue(pdata->dev_workqueue, &pdata->service_work); 768 } 769 770 static void 771 xgbe_init_timers(struct xgbe_prv_data *pdata) 772 { 773 callout_init(&pdata->service_timer, 1); 774 } 775 776 static void 777 xgbe_start_timers(struct xgbe_prv_data *pdata) 778 { 779 callout_reset(&pdata->service_timer, 1*hz, xgbe_service_timer, pdata); 780 } 781 782 static void 783 xgbe_stop_timers(struct xgbe_prv_data *pdata) 784 { 785 callout_drain(&pdata->service_timer); 786 callout_stop(&pdata->service_timer); 787 } 788 789 static void 790 xgbe_dump_phy_registers(struct xgbe_prv_data *pdata) 791 { 792 axgbe_printf(1, "\n************* PHY Reg dump *********************\n"); 793 794 axgbe_printf(1, "PCS Control Reg (%#06x) = %#06x\n", MDIO_CTRL1, 795 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1)); 796 axgbe_printf(1, "PCS Status Reg (%#06x) = %#06x\n", MDIO_STAT1, 797 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1)); 798 axgbe_printf(1, "Phy Id (PHYS ID 1 %#06x)= %#06x\n", MDIO_DEVID1, 799 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_DEVID1)); 800 axgbe_printf(1, "Phy Id (PHYS ID 2 %#06x)= %#06x\n", MDIO_DEVID2, 801 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_DEVID2)); 802 axgbe_printf(1, "Devices in Package (%#06x)= %#06x\n", MDIO_DEVS1, 803 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_DEVS1)); 804 axgbe_printf(1, "Devices in Package (%#06x)= %#06x\n", MDIO_DEVS2, 805 XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_DEVS2)); 806 axgbe_printf(1, "Auto-Neg Control Reg (%#06x) = %#06x\n", MDIO_CTRL1, 807 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_CTRL1)); 808 axgbe_printf(1, "Auto-Neg Status Reg (%#06x) = %#06x\n", MDIO_STAT1, 809 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_STAT1)); 810 axgbe_printf(1, "Auto-Neg Ad Reg 1 (%#06x) = %#06x\n", 811 MDIO_AN_ADVERTISE, 812 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE)); 813 axgbe_printf(1, "Auto-Neg Ad Reg 2 (%#06x) = %#06x\n", 814 MDIO_AN_ADVERTISE + 1, 815 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1)); 816 axgbe_printf(1, "Auto-Neg Ad Reg 3 (%#06x) = %#06x\n", 817 MDIO_AN_ADVERTISE + 2, 818 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2)); 819 axgbe_printf(1, "Auto-Neg Completion Reg (%#06x) = %#06x\n", 820 MDIO_AN_COMP_STAT, 821 XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_COMP_STAT)); 822 823 axgbe_printf(1, "\n************************************************\n"); 824 } 825 826 static void 827 xgbe_dump_prop_registers(struct xgbe_prv_data *pdata) 828 { 829 int i; 830 831 axgbe_printf(1, "\n************* PROP Reg dump ********************\n"); 832 833 for (i = 0 ; i < 38 ; i++) { 834 axgbe_printf(1, "PROP Offset 0x%08x = %08x\n", 835 (XP_PROP_0 + (i * 4)), XP_IOREAD(pdata, 836 (XP_PROP_0 + (i * 4)))); 837 } 838 } 839 840 static void 841 xgbe_dump_dma_registers(struct xgbe_prv_data *pdata, int ch) 842 { 843 struct xgbe_channel *channel; 844 int i; 845 846 axgbe_printf(1, "\n************* DMA Reg dump *********************\n"); 847 848 axgbe_printf(1, "DMA MR Reg (%08x) = %08x\n", DMA_MR, 849 XGMAC_IOREAD(pdata, DMA_MR)); 850 axgbe_printf(1, "DMA SBMR Reg (%08x) = %08x\n", DMA_SBMR, 851 XGMAC_IOREAD(pdata, DMA_SBMR)); 852 axgbe_printf(1, "DMA ISR Reg (%08x) = %08x\n", DMA_ISR, 853 XGMAC_IOREAD(pdata, DMA_ISR)); 854 axgbe_printf(1, "DMA AXIARCR Reg (%08x) = %08x\n", DMA_AXIARCR, 855 XGMAC_IOREAD(pdata, DMA_AXIARCR)); 856 axgbe_printf(1, "DMA AXIAWCR Reg (%08x) = %08x\n", DMA_AXIAWCR, 857 XGMAC_IOREAD(pdata, DMA_AXIAWCR)); 858 axgbe_printf(1, "DMA AXIAWARCR Reg (%08x) = %08x\n", DMA_AXIAWARCR, 859 XGMAC_IOREAD(pdata, DMA_AXIAWARCR)); 860 axgbe_printf(1, "DMA DSR0 Reg (%08x) = %08x\n", DMA_DSR0, 861 XGMAC_IOREAD(pdata, DMA_DSR0)); 862 axgbe_printf(1, "DMA DSR1 Reg (%08x) = %08x\n", DMA_DSR1, 863 XGMAC_IOREAD(pdata, DMA_DSR1)); 864 axgbe_printf(1, "DMA DSR2 Reg (%08x) = %08x\n", DMA_DSR2, 865 XGMAC_IOREAD(pdata, DMA_DSR2)); 866 axgbe_printf(1, "DMA DSR3 Reg (%08x) = %08x\n", DMA_DSR3, 867 XGMAC_IOREAD(pdata, DMA_DSR3)); 868 axgbe_printf(1, "DMA DSR4 Reg (%08x) = %08x\n", DMA_DSR4, 869 XGMAC_IOREAD(pdata, DMA_DSR4)); 870 axgbe_printf(1, "DMA TXEDMACR Reg (%08x) = %08x\n", DMA_TXEDMACR, 871 XGMAC_IOREAD(pdata, DMA_TXEDMACR)); 872 axgbe_printf(1, "DMA RXEDMACR Reg (%08x) = %08x\n", DMA_RXEDMACR, 873 XGMAC_IOREAD(pdata, DMA_RXEDMACR)); 874 875 for (i = 0 ; i < 8 ; i++ ) { 876 877 if (ch >= 0) { 878 if (i != ch) 879 continue; 880 } 881 882 channel = pdata->channel[i]; 883 884 axgbe_printf(1, "\n************* DMA CH %d dump ****************\n", i); 885 886 axgbe_printf(1, "DMA_CH_CR Reg (%08x) = %08x\n", 887 DMA_CH_CR, XGMAC_DMA_IOREAD(channel, DMA_CH_CR)); 888 axgbe_printf(1, "DMA_CH_TCR Reg (%08x) = %08x\n", 889 DMA_CH_TCR, XGMAC_DMA_IOREAD(channel, DMA_CH_TCR)); 890 axgbe_printf(1, "DMA_CH_RCR Reg (%08x) = %08x\n", 891 DMA_CH_RCR, XGMAC_DMA_IOREAD(channel, DMA_CH_RCR)); 892 axgbe_printf(1, "DMA_CH_TDLR_HI Reg (%08x) = %08x\n", 893 DMA_CH_TDLR_HI, XGMAC_DMA_IOREAD(channel, DMA_CH_TDLR_HI)); 894 axgbe_printf(1, "DMA_CH_TDLR_LO Reg (%08x) = %08x\n", 895 DMA_CH_TDLR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_TDLR_LO)); 896 axgbe_printf(1, "DMA_CH_RDLR_HI Reg (%08x) = %08x\n", 897 DMA_CH_RDLR_HI, XGMAC_DMA_IOREAD(channel, DMA_CH_RDLR_HI)); 898 axgbe_printf(1, "DMA_CH_RDLR_LO Reg (%08x) = %08x\n", 899 DMA_CH_RDLR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_RDLR_LO)); 900 axgbe_printf(1, "DMA_CH_TDTR_LO Reg (%08x) = %08x\n", 901 DMA_CH_TDTR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_TDTR_LO)); 902 axgbe_printf(1, "DMA_CH_RDTR_LO Reg (%08x) = %08x\n", 903 DMA_CH_RDTR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_RDTR_LO)); 904 axgbe_printf(1, "DMA_CH_TDRLR Reg (%08x) = %08x\n", 905 DMA_CH_TDRLR, XGMAC_DMA_IOREAD(channel, DMA_CH_TDRLR)); 906 axgbe_printf(1, "DMA_CH_RDRLR Reg (%08x) = %08x\n", 907 DMA_CH_RDRLR, XGMAC_DMA_IOREAD(channel, DMA_CH_RDRLR)); 908 axgbe_printf(1, "DMA_CH_IER Reg (%08x) = %08x\n", 909 DMA_CH_IER, XGMAC_DMA_IOREAD(channel, DMA_CH_IER)); 910 axgbe_printf(1, "DMA_CH_RIWT Reg (%08x) = %08x\n", 911 DMA_CH_RIWT, XGMAC_DMA_IOREAD(channel, DMA_CH_RIWT)); 912 axgbe_printf(1, "DMA_CH_CATDR_LO Reg (%08x) = %08x\n", 913 DMA_CH_CATDR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_CATDR_LO)); 914 axgbe_printf(1, "DMA_CH_CARDR_LO Reg (%08x) = %08x\n", 915 DMA_CH_CARDR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_CARDR_LO)); 916 axgbe_printf(1, "DMA_CH_CATBR_HI Reg (%08x) = %08x\n", 917 DMA_CH_CATBR_HI, XGMAC_DMA_IOREAD(channel, DMA_CH_CATBR_HI)); 918 axgbe_printf(1, "DMA_CH_CATBR_LO Reg (%08x) = %08x\n", 919 DMA_CH_CATBR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_CATBR_LO)); 920 axgbe_printf(1, "DMA_CH_CARBR_HI Reg (%08x) = %08x\n", 921 DMA_CH_CARBR_HI, XGMAC_DMA_IOREAD(channel, DMA_CH_CARBR_HI)); 922 axgbe_printf(1, "DMA_CH_CARBR_LO Reg (%08x) = %08x\n", 923 DMA_CH_CARBR_LO, XGMAC_DMA_IOREAD(channel, DMA_CH_CARBR_LO)); 924 axgbe_printf(1, "DMA_CH_SR Reg (%08x) = %08x\n", 925 DMA_CH_SR, XGMAC_DMA_IOREAD(channel, DMA_CH_SR)); 926 axgbe_printf(1, "DMA_CH_DSR Reg (%08x) = %08x\n", 927 DMA_CH_DSR, XGMAC_DMA_IOREAD(channel, DMA_CH_DSR)); 928 axgbe_printf(1, "DMA_CH_DCFL Reg (%08x) = %08x\n", 929 DMA_CH_DCFL, XGMAC_DMA_IOREAD(channel, DMA_CH_DCFL)); 930 axgbe_printf(1, "DMA_CH_MFC Reg (%08x) = %08x\n", 931 DMA_CH_MFC, XGMAC_DMA_IOREAD(channel, DMA_CH_MFC)); 932 axgbe_printf(1, "DMA_CH_TDTRO Reg (%08x) = %08x\n", 933 DMA_CH_TDTRO, XGMAC_DMA_IOREAD(channel, DMA_CH_TDTRO)); 934 axgbe_printf(1, "DMA_CH_RDTRO Reg (%08x) = %08x\n", 935 DMA_CH_RDTRO, XGMAC_DMA_IOREAD(channel, DMA_CH_RDTRO)); 936 axgbe_printf(1, "DMA_CH_TDWRO Reg (%08x) = %08x\n", 937 DMA_CH_TDWRO, XGMAC_DMA_IOREAD(channel, DMA_CH_TDWRO)); 938 axgbe_printf(1, "DMA_CH_RDWRO Reg (%08x) = %08x\n", 939 DMA_CH_RDWRO, XGMAC_DMA_IOREAD(channel, DMA_CH_RDWRO)); 940 } 941 } 942 943 static void 944 xgbe_dump_mtl_registers(struct xgbe_prv_data *pdata) 945 { 946 int i; 947 948 axgbe_printf(1, "\n************* MTL Reg dump *********************\n"); 949 950 axgbe_printf(1, "MTL OMR Reg (%08x) = %08x\n", MTL_OMR, 951 XGMAC_IOREAD(pdata, MTL_OMR)); 952 axgbe_printf(1, "MTL FDCR Reg (%08x) = %08x\n", MTL_FDCR, 953 XGMAC_IOREAD(pdata, MTL_FDCR)); 954 axgbe_printf(1, "MTL FDSR Reg (%08x) = %08x\n", MTL_FDSR, 955 XGMAC_IOREAD(pdata, MTL_FDSR)); 956 axgbe_printf(1, "MTL FDDR Reg (%08x) = %08x\n", MTL_FDDR, 957 XGMAC_IOREAD(pdata, MTL_FDDR)); 958 axgbe_printf(1, "MTL ISR Reg (%08x) = %08x\n", MTL_ISR, 959 XGMAC_IOREAD(pdata, MTL_ISR)); 960 axgbe_printf(1, "MTL RQDCM0R Reg (%08x) = %08x\n", MTL_RQDCM0R, 961 XGMAC_IOREAD(pdata, MTL_RQDCM0R)); 962 axgbe_printf(1, "MTL RQDCM1R Reg (%08x) = %08x\n", MTL_RQDCM1R, 963 XGMAC_IOREAD(pdata, MTL_RQDCM1R)); 964 axgbe_printf(1, "MTL RQDCM2R Reg (%08x) = %08x\n", MTL_RQDCM2R, 965 XGMAC_IOREAD(pdata, MTL_RQDCM2R)); 966 axgbe_printf(1, "MTL TCPM0R Reg (%08x) = %08x\n", MTL_TCPM0R, 967 XGMAC_IOREAD(pdata, MTL_TCPM0R)); 968 axgbe_printf(1, "MTL TCPM1R Reg (%08x) = %08x\n", MTL_TCPM1R, 969 XGMAC_IOREAD(pdata, MTL_TCPM1R)); 970 971 for (i = 0 ; i < 8 ; i++ ) { 972 973 axgbe_printf(1, "\n************* MTL CH %d dump ****************\n", i); 974 975 axgbe_printf(1, "MTL_Q_TQOMR Reg (%08x) = %08x\n", 976 MTL_Q_TQOMR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TQOMR)); 977 axgbe_printf(1, "MTL_Q_TQUR Reg (%08x) = %08x\n", 978 MTL_Q_TQUR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TQUR)); 979 axgbe_printf(1, "MTL_Q_TQDR Reg (%08x) = %08x\n", 980 MTL_Q_TQDR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TQDR)); 981 axgbe_printf(1, "MTL_Q_TC0ETSCR Reg (%08x) = %08x\n", 982 MTL_Q_TC0ETSCR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TC0ETSCR)); 983 axgbe_printf(1, "MTL_Q_TC0ETSSR Reg (%08x) = %08x\n", 984 MTL_Q_TC0ETSSR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TC0ETSSR)); 985 axgbe_printf(1, "MTL_Q_TC0QWR Reg (%08x) = %08x\n", 986 MTL_Q_TC0QWR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_TC0QWR)); 987 988 axgbe_printf(1, "MTL_Q_RQOMR Reg (%08x) = %08x\n", 989 MTL_Q_RQOMR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_RQOMR)); 990 axgbe_printf(1, "MTL_Q_RQMPOCR Reg (%08x) = %08x\n", 991 MTL_Q_RQMPOCR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_RQMPOCR)); 992 axgbe_printf(1, "MTL_Q_RQDR Reg (%08x) = %08x\n", 993 MTL_Q_RQDR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_RQDR)); 994 axgbe_printf(1, "MTL_Q_RQCR Reg (%08x) = %08x\n", 995 MTL_Q_RQCR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_RQCR)); 996 axgbe_printf(1, "MTL_Q_RQFCR Reg (%08x) = %08x\n", 997 MTL_Q_RQFCR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_RQFCR)); 998 axgbe_printf(1, "MTL_Q_IER Reg (%08x) = %08x\n", 999 MTL_Q_IER, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_IER)); 1000 axgbe_printf(1, "MTL_Q_ISR Reg (%08x) = %08x\n", 1001 MTL_Q_ISR, XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR)); 1002 } 1003 } 1004 1005 static void 1006 xgbe_dump_mac_registers(struct xgbe_prv_data *pdata) 1007 { 1008 axgbe_printf(1, "\n************* MAC Reg dump **********************\n"); 1009 1010 axgbe_printf(1, "MAC TCR Reg (%08x) = %08x\n", MAC_TCR, 1011 XGMAC_IOREAD(pdata, MAC_TCR)); 1012 axgbe_printf(1, "MAC RCR Reg (%08x) = %08x\n", MAC_RCR, 1013 XGMAC_IOREAD(pdata, MAC_RCR)); 1014 axgbe_printf(1, "MAC PFR Reg (%08x) = %08x\n", MAC_PFR, 1015 XGMAC_IOREAD(pdata, MAC_PFR)); 1016 axgbe_printf(1, "MAC WTR Reg (%08x) = %08x\n", MAC_WTR, 1017 XGMAC_IOREAD(pdata, MAC_WTR)); 1018 axgbe_printf(1, "MAC HTR0 Reg (%08x) = %08x\n", MAC_HTR0, 1019 XGMAC_IOREAD(pdata, MAC_HTR0)); 1020 axgbe_printf(1, "MAC HTR1 Reg (%08x) = %08x\n", MAC_HTR1, 1021 XGMAC_IOREAD(pdata, MAC_HTR1)); 1022 axgbe_printf(1, "MAC HTR2 Reg (%08x) = %08x\n", MAC_HTR2, 1023 XGMAC_IOREAD(pdata, MAC_HTR2)); 1024 axgbe_printf(1, "MAC HTR3 Reg (%08x) = %08x\n", MAC_HTR3, 1025 XGMAC_IOREAD(pdata, MAC_HTR3)); 1026 axgbe_printf(1, "MAC HTR4 Reg (%08x) = %08x\n", MAC_HTR4, 1027 XGMAC_IOREAD(pdata, MAC_HTR4)); 1028 axgbe_printf(1, "MAC HTR5 Reg (%08x) = %08x\n", MAC_HTR5, 1029 XGMAC_IOREAD(pdata, MAC_HTR5)); 1030 axgbe_printf(1, "MAC HTR6 Reg (%08x) = %08x\n", MAC_HTR6, 1031 XGMAC_IOREAD(pdata, MAC_HTR6)); 1032 axgbe_printf(1, "MAC HTR7 Reg (%08x) = %08x\n", MAC_HTR7, 1033 XGMAC_IOREAD(pdata, MAC_HTR7)); 1034 axgbe_printf(1, "MAC VLANTR Reg (%08x) = %08x\n", MAC_VLANTR, 1035 XGMAC_IOREAD(pdata, MAC_VLANTR)); 1036 axgbe_printf(1, "MAC VLANHTR Reg (%08x) = %08x\n", MAC_VLANHTR, 1037 XGMAC_IOREAD(pdata, MAC_VLANHTR)); 1038 axgbe_printf(1, "MAC VLANIR Reg (%08x) = %08x\n", MAC_VLANIR, 1039 XGMAC_IOREAD(pdata, MAC_VLANIR)); 1040 axgbe_printf(1, "MAC IVLANIR Reg (%08x) = %08x\n", MAC_IVLANIR, 1041 XGMAC_IOREAD(pdata, MAC_IVLANIR)); 1042 axgbe_printf(1, "MAC RETMR Reg (%08x) = %08x\n", MAC_RETMR, 1043 XGMAC_IOREAD(pdata, MAC_RETMR)); 1044 axgbe_printf(1, "MAC Q0TFCR Reg (%08x) = %08x\n", MAC_Q0TFCR, 1045 XGMAC_IOREAD(pdata, MAC_Q0TFCR)); 1046 axgbe_printf(1, "MAC Q1TFCR Reg (%08x) = %08x\n", MAC_Q1TFCR, 1047 XGMAC_IOREAD(pdata, MAC_Q1TFCR)); 1048 axgbe_printf(1, "MAC Q2TFCR Reg (%08x) = %08x\n", MAC_Q2TFCR, 1049 XGMAC_IOREAD(pdata, MAC_Q2TFCR)); 1050 axgbe_printf(1, "MAC Q3TFCR Reg (%08x) = %08x\n", MAC_Q3TFCR, 1051 XGMAC_IOREAD(pdata, MAC_Q3TFCR)); 1052 axgbe_printf(1, "MAC Q4TFCR Reg (%08x) = %08x\n", MAC_Q4TFCR, 1053 XGMAC_IOREAD(pdata, MAC_Q4TFCR)); 1054 axgbe_printf(1, "MAC Q5TFCR Reg (%08x) = %08x\n", MAC_Q5TFCR, 1055 XGMAC_IOREAD(pdata, MAC_Q5TFCR)); 1056 axgbe_printf(1, "MAC Q6TFCR Reg (%08x) = %08x\n", MAC_Q6TFCR, 1057 XGMAC_IOREAD(pdata, MAC_Q6TFCR)); 1058 axgbe_printf(1, "MAC Q7TFCR Reg (%08x) = %08x\n", MAC_Q7TFCR, 1059 XGMAC_IOREAD(pdata, MAC_Q7TFCR)); 1060 axgbe_printf(1, "MAC RFCR Reg (%08x) = %08x\n", MAC_RFCR, 1061 XGMAC_IOREAD(pdata, MAC_RFCR)); 1062 axgbe_printf(1, "MAC RQC0R Reg (%08x) = %08x\n", MAC_RQC0R, 1063 XGMAC_IOREAD(pdata, MAC_RQC0R)); 1064 axgbe_printf(1, "MAC RQC1R Reg (%08x) = %08x\n", MAC_RQC1R, 1065 XGMAC_IOREAD(pdata, MAC_RQC1R)); 1066 axgbe_printf(1, "MAC RQC2R Reg (%08x) = %08x\n", MAC_RQC2R, 1067 XGMAC_IOREAD(pdata, MAC_RQC2R)); 1068 axgbe_printf(1, "MAC RQC3R Reg (%08x) = %08x\n", MAC_RQC3R, 1069 XGMAC_IOREAD(pdata, MAC_RQC3R)); 1070 axgbe_printf(1, "MAC ISR Reg (%08x) = %08x\n", MAC_ISR, 1071 XGMAC_IOREAD(pdata, MAC_ISR)); 1072 axgbe_printf(1, "MAC IER Reg (%08x) = %08x\n", MAC_IER, 1073 XGMAC_IOREAD(pdata, MAC_IER)); 1074 axgbe_printf(1, "MAC RTSR Reg (%08x) = %08x\n", MAC_RTSR, 1075 XGMAC_IOREAD(pdata, MAC_RTSR)); 1076 axgbe_printf(1, "MAC PMTCSR Reg (%08x) = %08x\n", MAC_PMTCSR, 1077 XGMAC_IOREAD(pdata, MAC_PMTCSR)); 1078 axgbe_printf(1, "MAC RWKPFR Reg (%08x) = %08x\n", MAC_RWKPFR, 1079 XGMAC_IOREAD(pdata, MAC_RWKPFR)); 1080 axgbe_printf(1, "MAC LPICSR Reg (%08x) = %08x\n", MAC_LPICSR, 1081 XGMAC_IOREAD(pdata, MAC_LPICSR)); 1082 axgbe_printf(1, "MAC LPITCR Reg (%08x) = %08x\n", MAC_LPITCR, 1083 XGMAC_IOREAD(pdata, MAC_LPITCR)); 1084 axgbe_printf(1, "MAC TIR Reg (%08x) = %08x\n", MAC_TIR, 1085 XGMAC_IOREAD(pdata, MAC_TIR)); 1086 axgbe_printf(1, "MAC VR Reg (%08x) = %08x\n", MAC_VR, 1087 XGMAC_IOREAD(pdata, MAC_VR)); 1088 axgbe_printf(1, "MAC DR Reg (%08x) = %08x\n", MAC_DR, 1089 XGMAC_IOREAD(pdata, MAC_DR)); 1090 axgbe_printf(1, "MAC HWF0R Reg (%08x) = %08x\n", MAC_HWF0R, 1091 XGMAC_IOREAD(pdata, MAC_HWF0R)); 1092 axgbe_printf(1, "MAC HWF1R Reg (%08x) = %08x\n", MAC_HWF1R, 1093 XGMAC_IOREAD(pdata, MAC_HWF1R)); 1094 axgbe_printf(1, "MAC HWF2R Reg (%08x) = %08x\n", MAC_HWF2R, 1095 XGMAC_IOREAD(pdata, MAC_HWF2R)); 1096 axgbe_printf(1, "MAC MDIOSCAR Reg (%08x) = %08x\n", MAC_MDIOSCAR, 1097 XGMAC_IOREAD(pdata, MAC_MDIOSCAR)); 1098 axgbe_printf(1, "MAC MDIOSCCDR Reg (%08x) = %08x\n", MAC_MDIOSCCDR, 1099 XGMAC_IOREAD(pdata, MAC_MDIOSCCDR)); 1100 axgbe_printf(1, "MAC MDIOISR Reg (%08x) = %08x\n", MAC_MDIOISR, 1101 XGMAC_IOREAD(pdata, MAC_MDIOISR)); 1102 axgbe_printf(1, "MAC MDIOIER Reg (%08x) = %08x\n", MAC_MDIOIER, 1103 XGMAC_IOREAD(pdata, MAC_MDIOIER)); 1104 axgbe_printf(1, "MAC MDIOCL22R Reg (%08x) = %08x\n", MAC_MDIOCL22R, 1105 XGMAC_IOREAD(pdata, MAC_MDIOCL22R)); 1106 axgbe_printf(1, "MAC GPIOCR Reg (%08x) = %08x\n", MAC_GPIOCR, 1107 XGMAC_IOREAD(pdata, MAC_GPIOCR)); 1108 axgbe_printf(1, "MAC GPIOSR Reg (%08x) = %08x\n", MAC_GPIOSR, 1109 XGMAC_IOREAD(pdata, MAC_GPIOSR)); 1110 axgbe_printf(1, "MAC MACA0HR Reg (%08x) = %08x\n", MAC_MACA0HR, 1111 XGMAC_IOREAD(pdata, MAC_MACA0HR)); 1112 axgbe_printf(1, "MAC MACA0LR Reg (%08x) = %08x\n", MAC_TCR, 1113 XGMAC_IOREAD(pdata, MAC_MACA0LR)); 1114 axgbe_printf(1, "MAC MACA1HR Reg (%08x) = %08x\n", MAC_MACA1HR, 1115 XGMAC_IOREAD(pdata, MAC_MACA1HR)); 1116 axgbe_printf(1, "MAC MACA1LR Reg (%08x) = %08x\n", MAC_MACA1LR, 1117 XGMAC_IOREAD(pdata, MAC_MACA1LR)); 1118 axgbe_printf(1, "MAC RSSCR Reg (%08x) = %08x\n", MAC_RSSCR, 1119 XGMAC_IOREAD(pdata, MAC_RSSCR)); 1120 axgbe_printf(1, "MAC RSSDR Reg (%08x) = %08x\n", MAC_RSSDR, 1121 XGMAC_IOREAD(pdata, MAC_RSSDR)); 1122 axgbe_printf(1, "MAC RSSAR Reg (%08x) = %08x\n", MAC_RSSAR, 1123 XGMAC_IOREAD(pdata, MAC_RSSAR)); 1124 axgbe_printf(1, "MAC TSCR Reg (%08x) = %08x\n", MAC_TSCR, 1125 XGMAC_IOREAD(pdata, MAC_TSCR)); 1126 axgbe_printf(1, "MAC SSIR Reg (%08x) = %08x\n", MAC_SSIR, 1127 XGMAC_IOREAD(pdata, MAC_SSIR)); 1128 axgbe_printf(1, "MAC STSR Reg (%08x) = %08x\n", MAC_STSR, 1129 XGMAC_IOREAD(pdata, MAC_STSR)); 1130 axgbe_printf(1, "MAC STNR Reg (%08x) = %08x\n", MAC_STNR, 1131 XGMAC_IOREAD(pdata, MAC_STNR)); 1132 axgbe_printf(1, "MAC STSUR Reg (%08x) = %08x\n", MAC_STSUR, 1133 XGMAC_IOREAD(pdata, MAC_STSUR)); 1134 axgbe_printf(1, "MAC STNUR Reg (%08x) = %08x\n", MAC_STNUR, 1135 XGMAC_IOREAD(pdata, MAC_STNUR)); 1136 axgbe_printf(1, "MAC TSAR Reg (%08x) = %08x\n", MAC_TSAR, 1137 XGMAC_IOREAD(pdata, MAC_TSAR)); 1138 axgbe_printf(1, "MAC TSSR Reg (%08x) = %08x\n", MAC_TSSR, 1139 XGMAC_IOREAD(pdata, MAC_TSSR)); 1140 axgbe_printf(1, "MAC TXSNR Reg (%08x) = %08x\n", MAC_TXSNR, 1141 XGMAC_IOREAD(pdata, MAC_TXSNR)); 1142 axgbe_printf(1, "MAC TXSSR Reg (%08x) = %08x\n", MAC_TXSSR, 1143 XGMAC_IOREAD(pdata, MAC_TXSSR)); 1144 } 1145 1146 static void 1147 xgbe_dump_rmon_counters(struct xgbe_prv_data *pdata) 1148 { 1149 struct xgbe_mmc_stats *stats = &pdata->mmc_stats; 1150 1151 axgbe_printf(1, "\n************* RMON counters dump ***************\n"); 1152 1153 pdata->hw_if.read_mmc_stats(pdata); 1154 1155 axgbe_printf(1, "rmon txoctetcount_gb (%08x) = %08lx\n", 1156 MMC_TXOCTETCOUNT_GB_LO, stats->txoctetcount_gb); 1157 axgbe_printf(1, "rmon txframecount_gb (%08x) = %08lx\n", 1158 MMC_TXFRAMECOUNT_GB_LO, stats->txframecount_gb); 1159 axgbe_printf(1, "rmon txbroadcastframes_g (%08x) = %08lx\n", 1160 MMC_TXBROADCASTFRAMES_G_LO, stats->txbroadcastframes_g); 1161 axgbe_printf(1, "rmon txmulticastframes_g (%08x) = %08lx\n", 1162 MMC_TXMULTICASTFRAMES_G_LO, stats->txmulticastframes_g); 1163 axgbe_printf(1, "rmon tx64octets_gb (%08x) = %08lx\n", 1164 MMC_TX64OCTETS_GB_LO, stats->tx64octets_gb); 1165 axgbe_printf(1, "rmon tx65to127octets_gb (%08x) = %08lx\n", 1166 MMC_TX65TO127OCTETS_GB_LO, stats->tx65to127octets_gb); 1167 axgbe_printf(1, "rmon tx128to255octets_gb (%08x) = %08lx\n", 1168 MMC_TX128TO255OCTETS_GB_LO, stats->tx128to255octets_gb); 1169 axgbe_printf(1, "rmon tx256to511octets_gb (%08x) = %08lx\n", 1170 MMC_TX256TO511OCTETS_GB_LO, stats->tx256to511octets_gb); 1171 axgbe_printf(1, "rmon tx512to1023octets_gb (%08x) = %08lx\n", 1172 MMC_TX512TO1023OCTETS_GB_LO, stats->tx512to1023octets_gb); 1173 axgbe_printf(1, "rmon tx1024tomaxoctets_gb (%08x) = %08lx\n", 1174 MMC_TX1024TOMAXOCTETS_GB_LO, stats->tx1024tomaxoctets_gb); 1175 axgbe_printf(1, "rmon txunicastframes_gb (%08x) = %08lx\n", 1176 MMC_TXUNICASTFRAMES_GB_LO, stats->txunicastframes_gb); 1177 axgbe_printf(1, "rmon txmulticastframes_gb (%08x) = %08lx\n", 1178 MMC_TXMULTICASTFRAMES_GB_LO, stats->txmulticastframes_gb); 1179 axgbe_printf(1, "rmon txbroadcastframes_gb (%08x) = %08lx\n", 1180 MMC_TXBROADCASTFRAMES_GB_LO, stats->txbroadcastframes_gb); 1181 axgbe_printf(1, "rmon txunderflowerror (%08x) = %08lx\n", 1182 MMC_TXUNDERFLOWERROR_LO, stats->txunderflowerror); 1183 axgbe_printf(1, "rmon txoctetcount_g (%08x) = %08lx\n", 1184 MMC_TXOCTETCOUNT_G_LO, stats->txoctetcount_g); 1185 axgbe_printf(1, "rmon txframecount_g (%08x) = %08lx\n", 1186 MMC_TXFRAMECOUNT_G_LO, stats->txframecount_g); 1187 axgbe_printf(1, "rmon txpauseframes (%08x) = %08lx\n", 1188 MMC_TXPAUSEFRAMES_LO, stats->txpauseframes); 1189 axgbe_printf(1, "rmon txvlanframes_g (%08x) = %08lx\n", 1190 MMC_TXVLANFRAMES_G_LO, stats->txvlanframes_g); 1191 axgbe_printf(1, "rmon rxframecount_gb (%08x) = %08lx\n", 1192 MMC_RXFRAMECOUNT_GB_LO, stats->rxframecount_gb); 1193 axgbe_printf(1, "rmon rxoctetcount_gb (%08x) = %08lx\n", 1194 MMC_RXOCTETCOUNT_GB_LO, stats->rxoctetcount_gb); 1195 axgbe_printf(1, "rmon rxoctetcount_g (%08x) = %08lx\n", 1196 MMC_RXOCTETCOUNT_G_LO, stats->rxoctetcount_g); 1197 axgbe_printf(1, "rmon rxbroadcastframes_g (%08x) = %08lx\n", 1198 MMC_RXBROADCASTFRAMES_G_LO, stats->rxbroadcastframes_g); 1199 axgbe_printf(1, "rmon rxmulticastframes_g (%08x) = %08lx\n", 1200 MMC_RXMULTICASTFRAMES_G_LO, stats->rxmulticastframes_g); 1201 axgbe_printf(1, "rmon rxcrcerror (%08x) = %08lx\n", 1202 MMC_RXCRCERROR_LO, stats->rxcrcerror); 1203 axgbe_printf(1, "rmon rxrunterror (%08x) = %08lx\n", 1204 MMC_RXRUNTERROR, stats->rxrunterror); 1205 axgbe_printf(1, "rmon rxjabbererror (%08x) = %08lx\n", 1206 MMC_RXJABBERERROR, stats->rxjabbererror); 1207 axgbe_printf(1, "rmon rxundersize_g (%08x) = %08lx\n", 1208 MMC_RXUNDERSIZE_G, stats->rxundersize_g); 1209 axgbe_printf(1, "rmon rxoversize_g (%08x) = %08lx\n", 1210 MMC_RXOVERSIZE_G, stats->rxoversize_g); 1211 axgbe_printf(1, "rmon rx64octets_gb (%08x) = %08lx\n", 1212 MMC_RX64OCTETS_GB_LO, stats->rx64octets_gb); 1213 axgbe_printf(1, "rmon rx65to127octets_gb (%08x) = %08lx\n", 1214 MMC_RX65TO127OCTETS_GB_LO, stats->rx65to127octets_gb); 1215 axgbe_printf(1, "rmon rx128to255octets_gb (%08x) = %08lx\n", 1216 MMC_RX128TO255OCTETS_GB_LO, stats->rx128to255octets_gb); 1217 axgbe_printf(1, "rmon rx256to511octets_gb (%08x) = %08lx\n", 1218 MMC_RX256TO511OCTETS_GB_LO, stats->rx256to511octets_gb); 1219 axgbe_printf(1, "rmon rx512to1023octets_gb (%08x) = %08lx\n", 1220 MMC_RX512TO1023OCTETS_GB_LO, stats->rx512to1023octets_gb); 1221 axgbe_printf(1, "rmon rx1024tomaxoctets_gb (%08x) = %08lx\n", 1222 MMC_RX1024TOMAXOCTETS_GB_LO, stats->rx1024tomaxoctets_gb); 1223 axgbe_printf(1, "rmon rxunicastframes_g (%08x) = %08lx\n", 1224 MMC_RXUNICASTFRAMES_G_LO, stats->rxunicastframes_g); 1225 axgbe_printf(1, "rmon rxlengtherror (%08x) = %08lx\n", 1226 MMC_RXLENGTHERROR_LO, stats->rxlengtherror); 1227 axgbe_printf(1, "rmon rxoutofrangetype (%08x) = %08lx\n", 1228 MMC_RXOUTOFRANGETYPE_LO, stats->rxoutofrangetype); 1229 axgbe_printf(1, "rmon rxpauseframes (%08x) = %08lx\n", 1230 MMC_RXPAUSEFRAMES_LO, stats->rxpauseframes); 1231 axgbe_printf(1, "rmon rxfifooverflow (%08x) = %08lx\n", 1232 MMC_RXFIFOOVERFLOW_LO, stats->rxfifooverflow); 1233 axgbe_printf(1, "rmon rxvlanframes_gb (%08x) = %08lx\n", 1234 MMC_RXVLANFRAMES_GB_LO, stats->rxvlanframes_gb); 1235 axgbe_printf(1, "rmon rxwatchdogerror (%08x) = %08lx\n", 1236 MMC_RXWATCHDOGERROR, stats->rxwatchdogerror); 1237 } 1238 1239 void 1240 xgbe_dump_i2c_registers(struct xgbe_prv_data *pdata) 1241 { 1242 axgbe_printf(1, "*************** I2C Registers **************\n"); 1243 axgbe_printf(1, " IC_CON : %010x\n", 1244 XI2C_IOREAD(pdata, 0x00)); 1245 axgbe_printf(1, " IC_TAR : %010x\n", 1246 XI2C_IOREAD(pdata, 0x04)); 1247 axgbe_printf(1, " IC_HS_MADDR : %010x\n", 1248 XI2C_IOREAD(pdata, 0x0c)); 1249 axgbe_printf(1, " IC_INTR_STAT : %010x\n", 1250 XI2C_IOREAD(pdata, 0x2c)); 1251 axgbe_printf(1, " IC_INTR_MASK : %010x\n", 1252 XI2C_IOREAD(pdata, 0x30)); 1253 axgbe_printf(1, " IC_RAW_INTR_STAT : %010x\n", 1254 XI2C_IOREAD(pdata, 0x34)); 1255 axgbe_printf(1, " IC_RX_TL : %010x\n", 1256 XI2C_IOREAD(pdata, 0x38)); 1257 axgbe_printf(1, " IC_TX_TL : %010x\n", 1258 XI2C_IOREAD(pdata, 0x3c)); 1259 axgbe_printf(1, " IC_ENABLE : %010x\n", 1260 XI2C_IOREAD(pdata, 0x6c)); 1261 axgbe_printf(1, " IC_STATUS : %010x\n", 1262 XI2C_IOREAD(pdata, 0x70)); 1263 axgbe_printf(1, " IC_TXFLR : %010x\n", 1264 XI2C_IOREAD(pdata, 0x74)); 1265 axgbe_printf(1, " IC_RXFLR : %010x\n", 1266 XI2C_IOREAD(pdata, 0x78)); 1267 axgbe_printf(1, " IC_ENABLE_STATUS : %010x\n", 1268 XI2C_IOREAD(pdata, 0x9c)); 1269 axgbe_printf(1, " IC_COMP_PARAM1 : %010x\n", 1270 XI2C_IOREAD(pdata, 0xf4)); 1271 } 1272 1273 static void 1274 xgbe_dump_active_vlans(struct xgbe_prv_data *pdata) 1275 { 1276 int i; 1277 1278 for(i=0 ; i<BITS_TO_LONGS(VLAN_NVID); i++) { 1279 if (i && (i%8 == 0)) 1280 axgbe_printf(1, "\n"); 1281 axgbe_printf(1, "vlans[%d]: 0x%08lx ", i, pdata->active_vlans[i]); 1282 } 1283 axgbe_printf(1, "\n"); 1284 } 1285 1286 static void 1287 xgbe_default_config(struct xgbe_prv_data *pdata) 1288 { 1289 pdata->blen = DMA_SBMR_BLEN_64; 1290 pdata->pbl = DMA_PBL_128; 1291 pdata->aal = 1; 1292 pdata->rd_osr_limit = 8; 1293 pdata->wr_osr_limit = 8; 1294 pdata->tx_sf_mode = MTL_TSF_ENABLE; 1295 pdata->tx_threshold = MTL_TX_THRESHOLD_64; 1296 pdata->tx_osp_mode = DMA_OSP_ENABLE; 1297 pdata->rx_sf_mode = MTL_RSF_DISABLE; 1298 pdata->rx_threshold = MTL_RX_THRESHOLD_64; 1299 pdata->pause_autoneg = 1; 1300 pdata->tx_pause = 1; 1301 pdata->rx_pause = 1; 1302 pdata->phy_speed = SPEED_UNKNOWN; 1303 pdata->power_down = 0; 1304 pdata->enable_rss = 1; 1305 } 1306 1307 static int 1308 axgbe_if_attach_post(if_ctx_t ctx) 1309 { 1310 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1311 struct xgbe_prv_data *pdata = &sc->pdata; 1312 struct ifnet *ifp = pdata->netdev; 1313 struct xgbe_phy_if *phy_if = &pdata->phy_if; 1314 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1315 if_softc_ctx_t scctx = sc->scctx; 1316 int i, ret; 1317 1318 /* set split header support based on tunable */ 1319 pdata->sph_enable = axgbe_sph_enable; 1320 1321 /* Initialize ECC timestamps */ 1322 pdata->tx_sec_period = ticks; 1323 pdata->tx_ded_period = ticks; 1324 pdata->rx_sec_period = ticks; 1325 pdata->rx_ded_period = ticks; 1326 pdata->desc_sec_period = ticks; 1327 pdata->desc_ded_period = ticks; 1328 1329 /* Reset the hardware */ 1330 ret = hw_if->exit(&sc->pdata); 1331 if (ret) 1332 axgbe_error("%s: exit error %d\n", __func__, ret); 1333 1334 /* Configure the defaults */ 1335 xgbe_default_config(pdata); 1336 1337 /* Set default max values if not provided */ 1338 if (!pdata->tx_max_fifo_size) 1339 pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size; 1340 if (!pdata->rx_max_fifo_size) 1341 pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size; 1342 1343 DBGPR("%s: tx fifo 0x%x rx fifo 0x%x\n", __func__, 1344 pdata->tx_max_fifo_size, pdata->rx_max_fifo_size); 1345 1346 /* Set and validate the number of descriptors for a ring */ 1347 MPASS(powerof2(XGBE_TX_DESC_CNT)); 1348 pdata->tx_desc_count = XGBE_TX_DESC_CNT; 1349 MPASS(powerof2(XGBE_RX_DESC_CNT)); 1350 pdata->rx_desc_count = XGBE_RX_DESC_CNT; 1351 1352 /* Adjust the number of queues based on interrupts assigned */ 1353 if (pdata->channel_irq_count) { 1354 pdata->tx_ring_count = min_t(unsigned int, pdata->tx_ring_count, 1355 pdata->channel_irq_count); 1356 pdata->rx_ring_count = min_t(unsigned int, pdata->rx_ring_count, 1357 pdata->channel_irq_count); 1358 1359 DBGPR("adjusted TX %u/%u RX %u/%u\n", 1360 pdata->tx_ring_count, pdata->tx_q_count, 1361 pdata->rx_ring_count, pdata->rx_q_count); 1362 } 1363 1364 /* Set channel count based on interrupts assigned */ 1365 pdata->channel_count = max_t(unsigned int, scctx->isc_ntxqsets, 1366 scctx->isc_nrxqsets); 1367 DBGPR("Channel count set to: %u\n", pdata->channel_count); 1368 1369 /* Get RSS key */ 1370 #ifdef RSS 1371 rss_getkey((uint8_t *)pdata->rss_key); 1372 #else 1373 arc4rand(&pdata->rss_key, ARRAY_SIZE(pdata->rss_key), 0); 1374 #endif 1375 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1); 1376 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1); 1377 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); 1378 1379 /* Initialize the PHY device */ 1380 pdata->sysctl_an_cdr_workaround = pdata->vdata->an_cdr_workaround; 1381 phy_if->phy_init(pdata); 1382 1383 /* Set the coalescing */ 1384 xgbe_init_rx_coalesce(&sc->pdata); 1385 xgbe_init_tx_coalesce(&sc->pdata); 1386 1387 ifmedia_add(sc->media, IFM_ETHER | IFM_10G_KR, 0, NULL); 1388 ifmedia_add(sc->media, IFM_ETHER | IFM_10G_T, 0, NULL); 1389 ifmedia_add(sc->media, IFM_ETHER | IFM_10G_SFI, 0, NULL); 1390 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_KX, 0, NULL); 1391 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_CX, 0, NULL); 1392 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_LX, 0, NULL); 1393 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_SX, 0, NULL); 1394 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_T, 0, NULL); 1395 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_SGMII, 0, NULL); 1396 ifmedia_add(sc->media, IFM_ETHER | IFM_100_TX, 0, NULL); 1397 ifmedia_add(sc->media, IFM_ETHER | IFM_100_SGMII, 0, NULL); 1398 ifmedia_add(sc->media, IFM_ETHER | IFM_AUTO, 0, NULL); 1399 ifmedia_set(sc->media, IFM_ETHER | IFM_AUTO); 1400 1401 /* Initialize the phy */ 1402 pdata->phy_link = -1; 1403 pdata->phy_speed = SPEED_UNKNOWN; 1404 ret = phy_if->phy_reset(pdata); 1405 if (ret) 1406 return (ret); 1407 1408 /* Calculate the Rx buffer size before allocating rings */ 1409 ret = xgbe_calc_rx_buf_size(pdata->netdev, if_getmtu(pdata->netdev)); 1410 pdata->rx_buf_size = ret; 1411 DBGPR("%s: rx_buf_size %d\n", __func__, ret); 1412 1413 /* Setup RSS lookup table */ 1414 for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++) 1415 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, 1416 i % pdata->rx_ring_count); 1417 1418 /* 1419 * Mark the device down until it is initialized, which happens 1420 * when the device is accessed first (for configuring the iface, 1421 * eg: setting IP) 1422 */ 1423 set_bit(XGBE_DOWN, &pdata->dev_state); 1424 1425 DBGPR("mtu %d\n", ifp->if_mtu); 1426 scctx->isc_max_frame_size = ifp->if_mtu + 18; 1427 scctx->isc_min_frame_size = XGMAC_MIN_PACKET; 1428 1429 axgbe_sysctl_init(pdata); 1430 1431 axgbe_pci_init(pdata); 1432 1433 return (0); 1434 } /* axgbe_if_attach_post */ 1435 1436 static void 1437 xgbe_free_intr(struct xgbe_prv_data *pdata, struct resource *res, void *tag, 1438 int rid) 1439 { 1440 if (tag) 1441 bus_teardown_intr(pdata->dev, res, tag); 1442 1443 if (res) 1444 bus_release_resource(pdata->dev, SYS_RES_IRQ, rid, res); 1445 } 1446 1447 static void 1448 axgbe_interrupts_free(if_ctx_t ctx) 1449 { 1450 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1451 struct xgbe_prv_data *pdata = &sc->pdata; 1452 if_softc_ctx_t scctx = sc->scctx; 1453 struct xgbe_channel *channel; 1454 struct if_irq irq; 1455 int i; 1456 1457 axgbe_printf(2, "%s: mode %d\n", __func__, scctx->isc_intr); 1458 1459 /* Free dev_irq */ 1460 iflib_irq_free(ctx, &pdata->dev_irq); 1461 1462 /* Free ecc_irq */ 1463 xgbe_free_intr(pdata, pdata->ecc_irq_res, pdata->ecc_irq_tag, 1464 pdata->ecc_rid); 1465 1466 /* Free i2c_irq */ 1467 xgbe_free_intr(pdata, pdata->i2c_irq_res, pdata->i2c_irq_tag, 1468 pdata->i2c_rid); 1469 1470 /* Free an_irq */ 1471 xgbe_free_intr(pdata, pdata->an_irq_res, pdata->an_irq_tag, 1472 pdata->an_rid); 1473 1474 for (i = 0; i < scctx->isc_nrxqsets; i++) { 1475 1476 channel = pdata->channel[i]; 1477 axgbe_printf(2, "%s: rid %d\n", __func__, channel->dma_irq_rid); 1478 irq.ii_res = channel->dma_irq_res; 1479 irq.ii_tag = channel->dma_irq_tag; 1480 iflib_irq_free(ctx, &irq); 1481 } 1482 } 1483 1484 static int 1485 axgbe_if_detach(if_ctx_t ctx) 1486 { 1487 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1488 struct xgbe_prv_data *pdata = &sc->pdata; 1489 struct xgbe_phy_if *phy_if = &pdata->phy_if; 1490 struct resource *mac_res[2]; 1491 1492 mac_res[0] = pdata->xgmac_res; 1493 mac_res[1] = pdata->xpcs_res; 1494 1495 phy_if->phy_exit(pdata); 1496 1497 /* Free Interrupts */ 1498 axgbe_interrupts_free(ctx); 1499 1500 /* Free workqueues */ 1501 taskqueue_free(pdata->dev_workqueue); 1502 1503 /* Release bus resources */ 1504 bus_release_resources(iflib_get_dev(ctx), axgbe_pci_mac_spec, mac_res); 1505 1506 /* Free VLAN bitmap */ 1507 free(pdata->active_vlans, M_AXGBE); 1508 1509 axgbe_sysctl_exit(pdata); 1510 1511 return (0); 1512 } /* axgbe_if_detach */ 1513 1514 static void 1515 axgbe_pci_init(struct xgbe_prv_data *pdata) 1516 { 1517 struct xgbe_phy_if *phy_if = &pdata->phy_if; 1518 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1519 int ret = 0; 1520 1521 if (!__predict_false((test_bit(XGBE_DOWN, &pdata->dev_state)))) { 1522 axgbe_printf(1, "%s: Starting when XGBE_UP\n", __func__); 1523 return; 1524 } 1525 1526 hw_if->init(pdata); 1527 1528 ret = phy_if->phy_start(pdata); 1529 if (ret) { 1530 axgbe_error("%s: phy start %d\n", __func__, ret); 1531 ret = hw_if->exit(pdata); 1532 if (ret) 1533 axgbe_error("%s: exit error %d\n", __func__, ret); 1534 return; 1535 } 1536 1537 hw_if->enable_tx(pdata); 1538 hw_if->enable_rx(pdata); 1539 1540 xgbe_start_timers(pdata); 1541 1542 clear_bit(XGBE_DOWN, &pdata->dev_state); 1543 1544 xgbe_dump_phy_registers(pdata); 1545 xgbe_dump_prop_registers(pdata); 1546 xgbe_dump_dma_registers(pdata, -1); 1547 xgbe_dump_mtl_registers(pdata); 1548 xgbe_dump_mac_registers(pdata); 1549 xgbe_dump_rmon_counters(pdata); 1550 } 1551 1552 static void 1553 axgbe_if_init(if_ctx_t ctx) 1554 { 1555 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1556 struct xgbe_prv_data *pdata = &sc->pdata; 1557 1558 axgbe_pci_init(pdata); 1559 } 1560 1561 static void 1562 axgbe_pci_stop(if_ctx_t ctx) 1563 { 1564 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1565 struct xgbe_prv_data *pdata = &sc->pdata; 1566 struct xgbe_phy_if *phy_if = &pdata->phy_if; 1567 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1568 int ret; 1569 1570 if (__predict_false(test_bit(XGBE_DOWN, &pdata->dev_state))) { 1571 axgbe_printf(1, "%s: Stopping when XGBE_DOWN\n", __func__); 1572 return; 1573 } 1574 1575 xgbe_stop_timers(pdata); 1576 taskqueue_drain_all(pdata->dev_workqueue); 1577 1578 hw_if->disable_tx(pdata); 1579 hw_if->disable_rx(pdata); 1580 1581 phy_if->phy_stop(pdata); 1582 1583 ret = hw_if->exit(pdata); 1584 if (ret) 1585 axgbe_error("%s: exit error %d\n", __func__, ret); 1586 1587 set_bit(XGBE_DOWN, &pdata->dev_state); 1588 } 1589 1590 static void 1591 axgbe_if_stop(if_ctx_t ctx) 1592 { 1593 axgbe_pci_stop(ctx); 1594 } 1595 1596 static void 1597 axgbe_if_disable_intr(if_ctx_t ctx) 1598 { 1599 /* TODO - implement */ 1600 } 1601 1602 static void 1603 axgbe_if_enable_intr(if_ctx_t ctx) 1604 { 1605 /* TODO - implement */ 1606 } 1607 1608 static int 1609 axgbe_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *va, uint64_t *pa, int ntxqs, 1610 int ntxqsets) 1611 { 1612 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1613 struct xgbe_prv_data *pdata = &sc->pdata; 1614 if_softc_ctx_t scctx = sc->scctx; 1615 struct xgbe_channel *channel; 1616 struct xgbe_ring *tx_ring; 1617 int i, j, k; 1618 1619 MPASS(scctx->isc_ntxqsets > 0); 1620 MPASS(scctx->isc_ntxqsets == ntxqsets); 1621 MPASS(ntxqs == 1); 1622 1623 axgbe_printf(1, "%s: txqsets %d/%d txqs %d\n", __func__, 1624 scctx->isc_ntxqsets, ntxqsets, ntxqs); 1625 1626 for (i = 0 ; i < ntxqsets; i++) { 1627 1628 channel = pdata->channel[i]; 1629 1630 tx_ring = (struct xgbe_ring*)malloc(ntxqs * 1631 sizeof(struct xgbe_ring), M_AXGBE, M_NOWAIT | M_ZERO); 1632 1633 if (tx_ring == NULL) { 1634 axgbe_error("Unable to allocate TX ring memory\n"); 1635 goto tx_ring_fail; 1636 } 1637 1638 channel->tx_ring = tx_ring; 1639 1640 for (j = 0; j < ntxqs; j++, tx_ring++) { 1641 tx_ring->rdata = 1642 (struct xgbe_ring_data*)malloc(scctx->isc_ntxd[j] * 1643 sizeof(struct xgbe_ring_data), M_AXGBE, M_NOWAIT); 1644 1645 /* Get the virtual & physical address of hw queues */ 1646 tx_ring->rdesc = (struct xgbe_ring_desc *)va[i*ntxqs + j]; 1647 tx_ring->rdesc_paddr = pa[i*ntxqs + j]; 1648 tx_ring->rdesc_count = scctx->isc_ntxd[j]; 1649 spin_lock_init(&tx_ring->lock); 1650 } 1651 } 1652 1653 axgbe_printf(1, "allocated for %d tx queues\n", scctx->isc_ntxqsets); 1654 1655 return (0); 1656 1657 tx_ring_fail: 1658 1659 for (j = 0; j < i ; j++) { 1660 1661 channel = pdata->channel[j]; 1662 1663 tx_ring = channel->tx_ring; 1664 for (k = 0; k < ntxqs ; k++, tx_ring++) { 1665 if (tx_ring && tx_ring->rdata) 1666 free(tx_ring->rdata, M_AXGBE); 1667 } 1668 free(channel->tx_ring, M_AXGBE); 1669 1670 channel->tx_ring = NULL; 1671 } 1672 1673 return (ENOMEM); 1674 1675 } /* axgbe_if_tx_queues_alloc */ 1676 1677 static int 1678 axgbe_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *va, uint64_t *pa, int nrxqs, 1679 int nrxqsets) 1680 { 1681 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1682 struct xgbe_prv_data *pdata = &sc->pdata; 1683 if_softc_ctx_t scctx = sc->scctx; 1684 struct xgbe_channel *channel; 1685 struct xgbe_ring *rx_ring; 1686 int i, j, k; 1687 1688 MPASS(scctx->isc_nrxqsets > 0); 1689 MPASS(scctx->isc_nrxqsets == nrxqsets); 1690 if (!pdata->sph_enable) { 1691 MPASS(nrxqs == 1); 1692 } else { 1693 MPASS(nrxqs == 2); 1694 } 1695 1696 axgbe_printf(1, "%s: rxqsets %d/%d rxqs %d\n", __func__, 1697 scctx->isc_nrxqsets, nrxqsets, nrxqs); 1698 1699 for (i = 0 ; i < nrxqsets; i++) { 1700 1701 channel = pdata->channel[i]; 1702 1703 rx_ring = (struct xgbe_ring*)malloc(nrxqs * 1704 sizeof(struct xgbe_ring), M_AXGBE, M_NOWAIT | M_ZERO); 1705 1706 if (rx_ring == NULL) { 1707 axgbe_error("Unable to allocate RX ring memory\n"); 1708 goto rx_ring_fail; 1709 } 1710 1711 channel->rx_ring = rx_ring; 1712 1713 for (j = 0; j < nrxqs; j++, rx_ring++) { 1714 rx_ring->rdata = 1715 (struct xgbe_ring_data*)malloc(scctx->isc_nrxd[j] * 1716 sizeof(struct xgbe_ring_data), M_AXGBE, M_NOWAIT); 1717 1718 /* Get the virtual and physical address of the hw queues */ 1719 rx_ring->rdesc = (struct xgbe_ring_desc *)va[i*nrxqs + j]; 1720 rx_ring->rdesc_paddr = pa[i*nrxqs + j]; 1721 rx_ring->rdesc_count = scctx->isc_nrxd[j]; 1722 spin_lock_init(&rx_ring->lock); 1723 } 1724 } 1725 1726 axgbe_printf(2, "allocated for %d rx queues\n", scctx->isc_nrxqsets); 1727 1728 return (0); 1729 1730 rx_ring_fail: 1731 1732 for (j = 0 ; j < i ; j++) { 1733 1734 channel = pdata->channel[j]; 1735 1736 rx_ring = channel->rx_ring; 1737 for (k = 0; k < nrxqs ; k++, rx_ring++) { 1738 if (rx_ring && rx_ring->rdata) 1739 free(rx_ring->rdata, M_AXGBE); 1740 } 1741 free(channel->rx_ring, M_AXGBE); 1742 1743 channel->rx_ring = NULL; 1744 } 1745 1746 return (ENOMEM); 1747 1748 } /* axgbe_if_rx_queues_alloc */ 1749 1750 static void 1751 axgbe_if_queues_free(if_ctx_t ctx) 1752 { 1753 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1754 struct xgbe_prv_data *pdata = &sc->pdata; 1755 if_softc_ctx_t scctx = sc->scctx; 1756 if_shared_ctx_t sctx = sc->sctx; 1757 struct xgbe_channel *channel; 1758 struct xgbe_ring *tx_ring; 1759 struct xgbe_ring *rx_ring; 1760 int i, j; 1761 1762 for (i = 0 ; i < scctx->isc_ntxqsets; i++) { 1763 1764 channel = pdata->channel[i]; 1765 1766 tx_ring = channel->tx_ring; 1767 for (j = 0; j < sctx->isc_ntxqs ; j++, tx_ring++) { 1768 if (tx_ring && tx_ring->rdata) 1769 free(tx_ring->rdata, M_AXGBE); 1770 } 1771 free(channel->tx_ring, M_AXGBE); 1772 channel->tx_ring = NULL; 1773 } 1774 1775 for (i = 0 ; i < scctx->isc_nrxqsets; i++) { 1776 1777 channel = pdata->channel[i]; 1778 1779 rx_ring = channel->rx_ring; 1780 for (j = 0; j < sctx->isc_nrxqs ; j++, rx_ring++) { 1781 if (rx_ring && rx_ring->rdata) 1782 free(rx_ring->rdata, M_AXGBE); 1783 } 1784 free(channel->rx_ring, M_AXGBE); 1785 channel->rx_ring = NULL; 1786 } 1787 1788 /* Free Channels */ 1789 for (i = 0; i < pdata->total_channel_count ; i++) { 1790 free(pdata->channel[i], M_AXGBE); 1791 pdata->channel[i] = NULL; 1792 } 1793 1794 pdata->total_channel_count = 0; 1795 pdata->channel_count = 0; 1796 } /* axgbe_if_queues_free */ 1797 1798 static void 1799 axgbe_if_vlan_register(if_ctx_t ctx, uint16_t vtag) 1800 { 1801 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1802 struct xgbe_prv_data *pdata = &sc->pdata; 1803 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1804 1805 if (!bit_test(pdata->active_vlans, vtag)) { 1806 axgbe_printf(0, "Registering VLAN %d\n", vtag); 1807 1808 bit_set(pdata->active_vlans, vtag); 1809 hw_if->update_vlan_hash_table(pdata); 1810 pdata->num_active_vlans++; 1811 1812 axgbe_printf(1, "Total active vlans: %d\n", 1813 pdata->num_active_vlans); 1814 } else 1815 axgbe_printf(0, "VLAN %d already registered\n", vtag); 1816 1817 xgbe_dump_active_vlans(pdata); 1818 } 1819 1820 static void 1821 axgbe_if_vlan_unregister(if_ctx_t ctx, uint16_t vtag) 1822 { 1823 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1824 struct xgbe_prv_data *pdata = &sc->pdata; 1825 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1826 1827 if (pdata->num_active_vlans == 0) { 1828 axgbe_printf(1, "No active VLANs to unregister\n"); 1829 return; 1830 } 1831 1832 if (bit_test(pdata->active_vlans, vtag)){ 1833 axgbe_printf(0, "Un-Registering VLAN %d\n", vtag); 1834 1835 bit_clear(pdata->active_vlans, vtag); 1836 hw_if->update_vlan_hash_table(pdata); 1837 pdata->num_active_vlans--; 1838 1839 axgbe_printf(1, "Total active vlans: %d\n", 1840 pdata->num_active_vlans); 1841 } else 1842 axgbe_printf(0, "VLAN %d already unregistered\n", vtag); 1843 1844 xgbe_dump_active_vlans(pdata); 1845 } 1846 1847 #if __FreeBSD_version >= 1300000 1848 static bool 1849 axgbe_if_needs_restart(if_ctx_t ctx __unused, enum iflib_restart_event event) 1850 { 1851 switch (event) { 1852 case IFLIB_RESTART_VLAN_CONFIG: 1853 default: 1854 return (true); 1855 } 1856 } 1857 #endif 1858 1859 static int 1860 axgbe_if_msix_intr_assign(if_ctx_t ctx, int msix) 1861 { 1862 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 1863 struct xgbe_prv_data *pdata = &sc->pdata; 1864 if_softc_ctx_t scctx = sc->scctx; 1865 struct xgbe_channel *channel; 1866 struct if_irq irq; 1867 int i, error, rid = 0, flags; 1868 char buf[16]; 1869 1870 MPASS(scctx->isc_intr != IFLIB_INTR_LEGACY); 1871 1872 pdata->isr_as_tasklet = 1; 1873 1874 if (scctx->isc_intr == IFLIB_INTR_MSI) { 1875 pdata->irq_count = 1; 1876 pdata->channel_irq_count = 1; 1877 return (0); 1878 } 1879 1880 axgbe_printf(1, "%s: msix %d txqsets %d rxqsets %d\n", __func__, msix, 1881 scctx->isc_ntxqsets, scctx->isc_nrxqsets); 1882 1883 flags = RF_ACTIVE; 1884 1885 /* DEV INTR SETUP */ 1886 rid++; 1887 error = iflib_irq_alloc_generic(ctx, &pdata->dev_irq, rid, 1888 IFLIB_INTR_ADMIN, axgbe_dev_isr, sc, 0, "dev_irq"); 1889 if (error) { 1890 axgbe_error("Failed to register device interrupt rid %d name %s\n", 1891 rid, "dev_irq"); 1892 return (error); 1893 } 1894 1895 /* ECC INTR SETUP */ 1896 rid++; 1897 pdata->ecc_rid = rid; 1898 pdata->ecc_irq_res = bus_alloc_resource_any(pdata->dev, SYS_RES_IRQ, 1899 &rid, flags); 1900 if (!pdata->ecc_irq_res) { 1901 axgbe_error("failed to allocate IRQ for rid %d, name %s.\n", 1902 rid, "ecc_irq"); 1903 return (ENOMEM); 1904 } 1905 1906 error = bus_setup_intr(pdata->dev, pdata->ecc_irq_res, INTR_MPSAFE | 1907 INTR_TYPE_NET, NULL, axgbe_ecc_isr, sc, &pdata->ecc_irq_tag); 1908 if (error) { 1909 axgbe_error("failed to setup interrupt for rid %d, name %s: %d\n", 1910 rid, "ecc_irq", error); 1911 return (error); 1912 } 1913 1914 /* I2C INTR SETUP */ 1915 rid++; 1916 pdata->i2c_rid = rid; 1917 pdata->i2c_irq_res = bus_alloc_resource_any(pdata->dev, SYS_RES_IRQ, 1918 &rid, flags); 1919 if (!pdata->i2c_irq_res) { 1920 axgbe_error("failed to allocate IRQ for rid %d, name %s.\n", 1921 rid, "i2c_irq"); 1922 return (ENOMEM); 1923 } 1924 1925 error = bus_setup_intr(pdata->dev, pdata->i2c_irq_res, INTR_MPSAFE | 1926 INTR_TYPE_NET, NULL, axgbe_i2c_isr, sc, &pdata->i2c_irq_tag); 1927 if (error) { 1928 axgbe_error("failed to setup interrupt for rid %d, name %s: %d\n", 1929 rid, "i2c_irq", error); 1930 return (error); 1931 } 1932 1933 /* AN INTR SETUP */ 1934 rid++; 1935 pdata->an_rid = rid; 1936 pdata->an_irq_res = bus_alloc_resource_any(pdata->dev, SYS_RES_IRQ, 1937 &rid, flags); 1938 if (!pdata->an_irq_res) { 1939 axgbe_error("failed to allocate IRQ for rid %d, name %s.\n", 1940 rid, "an_irq"); 1941 return (ENOMEM); 1942 } 1943 1944 error = bus_setup_intr(pdata->dev, pdata->an_irq_res, INTR_MPSAFE | 1945 INTR_TYPE_NET, NULL, axgbe_an_isr, sc, &pdata->an_irq_tag); 1946 if (error) { 1947 axgbe_error("failed to setup interrupt for rid %d, name %s: %d\n", 1948 rid, "an_irq", error); 1949 return (error); 1950 } 1951 1952 pdata->per_channel_irq = 1; 1953 pdata->channel_irq_mode = XGBE_IRQ_MODE_LEVEL; 1954 rid++; 1955 for (i = 0; i < scctx->isc_nrxqsets; i++, rid++) { 1956 1957 channel = pdata->channel[i]; 1958 1959 snprintf(buf, sizeof(buf), "rxq%d", i); 1960 error = iflib_irq_alloc_generic(ctx, &irq, rid, IFLIB_INTR_RXTX, 1961 axgbe_msix_que, channel, channel->queue_index, buf); 1962 1963 if (error) { 1964 axgbe_error("Failed to allocated que int %d err: %d\n", 1965 i, error); 1966 return (error); 1967 } 1968 1969 channel->dma_irq_rid = rid; 1970 channel->dma_irq_res = irq.ii_res; 1971 channel->dma_irq_tag = irq.ii_tag; 1972 axgbe_printf(1, "%s: channel count %d idx %d irq %d\n", 1973 __func__, scctx->isc_nrxqsets, i, rid); 1974 } 1975 pdata->irq_count = msix; 1976 pdata->channel_irq_count = scctx->isc_nrxqsets; 1977 1978 for (i = 0; i < scctx->isc_ntxqsets; i++) { 1979 1980 channel = pdata->channel[i]; 1981 1982 snprintf(buf, sizeof(buf), "txq%d", i); 1983 irq.ii_res = channel->dma_irq_res; 1984 iflib_softirq_alloc_generic(ctx, &irq, IFLIB_INTR_TX, channel, 1985 channel->queue_index, buf); 1986 } 1987 1988 return (0); 1989 } /* axgbe_if_msix_intr_assign */ 1990 1991 static int 1992 xgbe_enable_rx_tx_int(struct xgbe_prv_data *pdata, struct xgbe_channel *channel) 1993 { 1994 struct xgbe_hw_if *hw_if = &pdata->hw_if; 1995 enum xgbe_int int_id; 1996 1997 if (channel->tx_ring && channel->rx_ring) 1998 int_id = XGMAC_INT_DMA_CH_SR_TI_RI; 1999 else if (channel->tx_ring) 2000 int_id = XGMAC_INT_DMA_CH_SR_TI; 2001 else if (channel->rx_ring) 2002 int_id = XGMAC_INT_DMA_CH_SR_RI; 2003 else 2004 return (-1); 2005 2006 axgbe_printf(1, "%s channel: %d rx_tx interrupt enabled %d\n", 2007 __func__, channel->queue_index, int_id); 2008 return (hw_if->enable_int(channel, int_id)); 2009 } 2010 2011 static void 2012 xgbe_disable_rx_tx_int(struct xgbe_prv_data *pdata, struct xgbe_channel *channel) 2013 { 2014 struct xgbe_hw_if *hw_if = &pdata->hw_if; 2015 enum xgbe_int int_id; 2016 2017 if (channel->tx_ring && channel->rx_ring) 2018 int_id = XGMAC_INT_DMA_CH_SR_TI_RI; 2019 else if (channel->tx_ring) 2020 int_id = XGMAC_INT_DMA_CH_SR_TI; 2021 else if (channel->rx_ring) 2022 int_id = XGMAC_INT_DMA_CH_SR_RI; 2023 else 2024 return; 2025 2026 axgbe_printf(1, "%s channel: %d rx_tx interrupt disabled %d\n", 2027 __func__, channel->queue_index, int_id); 2028 hw_if->disable_int(channel, int_id); 2029 } 2030 2031 static void 2032 xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata) 2033 { 2034 unsigned int i; 2035 2036 for (i = 0; i < pdata->channel_count; i++) 2037 xgbe_disable_rx_tx_int(pdata, pdata->channel[i]); 2038 } 2039 2040 static int 2041 axgbe_msix_que(void *arg) 2042 { 2043 struct xgbe_channel *channel = (struct xgbe_channel *)arg; 2044 struct xgbe_prv_data *pdata = channel->pdata; 2045 unsigned int dma_ch_isr, dma_status; 2046 2047 axgbe_printf(1, "%s: Channel: %d SR 0x%04x DSR 0x%04x IER:0x%04x D_ISR:0x%04x M_ISR:0x%04x\n", 2048 __func__, channel->queue_index, 2049 XGMAC_DMA_IOREAD(channel, DMA_CH_SR), 2050 XGMAC_DMA_IOREAD(channel, DMA_CH_DSR), 2051 XGMAC_DMA_IOREAD(channel, DMA_CH_IER), 2052 XGMAC_IOREAD(pdata, DMA_ISR), 2053 XGMAC_IOREAD(pdata, MAC_ISR)); 2054 2055 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); 2056 2057 /* Disable Tx and Rx channel interrupts */ 2058 xgbe_disable_rx_tx_int(pdata, channel); 2059 2060 /* Clear the interrupts */ 2061 dma_status = 0; 2062 XGMAC_SET_BITS(dma_status, DMA_CH_SR, TI, 1); 2063 XGMAC_SET_BITS(dma_status, DMA_CH_SR, RI, 1); 2064 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_status); 2065 2066 return (FILTER_SCHEDULE_THREAD); 2067 } 2068 2069 static int 2070 axgbe_dev_isr(void *arg) 2071 { 2072 struct axgbe_if_softc *sc = (struct axgbe_if_softc *)arg; 2073 struct xgbe_prv_data *pdata = &sc->pdata; 2074 struct xgbe_channel *channel; 2075 struct xgbe_hw_if *hw_if = &pdata->hw_if; 2076 unsigned int i, dma_isr, dma_ch_isr; 2077 unsigned int mac_isr, mac_mdioisr; 2078 int ret = FILTER_HANDLED; 2079 2080 dma_isr = XGMAC_IOREAD(pdata, DMA_ISR); 2081 axgbe_printf(2, "%s DMA ISR: 0x%x\n", __func__, dma_isr); 2082 2083 if (!dma_isr) 2084 return (FILTER_HANDLED); 2085 2086 for (i = 0; i < pdata->channel_count; i++) { 2087 2088 if (!(dma_isr & (1 << i))) 2089 continue; 2090 2091 channel = pdata->channel[i]; 2092 2093 dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR); 2094 axgbe_printf(2, "%s: channel %d SR 0x%x DSR 0x%x\n", __func__, 2095 channel->queue_index, dma_ch_isr, XGMAC_DMA_IOREAD(channel, 2096 DMA_CH_DSR)); 2097 2098 /* 2099 * The TI or RI interrupt bits may still be set even if using 2100 * per channel DMA interrupts. Check to be sure those are not 2101 * enabled before using the private data napi structure. 2102 */ 2103 if (!pdata->per_channel_irq && 2104 (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, TI) || 2105 XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RI))) { 2106 2107 /* Disable Tx and Rx interrupts */ 2108 xgbe_disable_rx_tx_ints(pdata); 2109 } else { 2110 2111 /* 2112 * Don't clear Rx/Tx status if doing per channel DMA 2113 * interrupts, these will be cleared by the ISR for 2114 * per channel DMA interrupts 2115 */ 2116 XGMAC_SET_BITS(dma_ch_isr, DMA_CH_SR, TI, 0); 2117 XGMAC_SET_BITS(dma_ch_isr, DMA_CH_SR, RI, 0); 2118 } 2119 2120 if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, RBU)) 2121 pdata->ext_stats.rx_buffer_unavailable++; 2122 2123 /* Restart the device on a Fatal Bus Error */ 2124 if (XGMAC_GET_BITS(dma_ch_isr, DMA_CH_SR, FBE)) 2125 axgbe_error("%s: Fatal bus error reported 0x%x\n", 2126 __func__, dma_ch_isr); 2127 2128 /* Clear all interrupt signals */ 2129 XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr); 2130 2131 ret = FILTER_SCHEDULE_THREAD; 2132 } 2133 2134 if (XGMAC_GET_BITS(dma_isr, DMA_ISR, MACIS)) { 2135 2136 mac_isr = XGMAC_IOREAD(pdata, MAC_ISR); 2137 axgbe_printf(2, "%s MAC ISR: 0x%x\n", __func__, mac_isr); 2138 2139 if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCTXIS)) 2140 hw_if->tx_mmc_int(pdata); 2141 2142 if (XGMAC_GET_BITS(mac_isr, MAC_ISR, MMCRXIS)) 2143 hw_if->rx_mmc_int(pdata); 2144 2145 if (XGMAC_GET_BITS(mac_isr, MAC_ISR, SMI)) { 2146 mac_mdioisr = XGMAC_IOREAD(pdata, MAC_MDIOISR); 2147 2148 if (XGMAC_GET_BITS(mac_mdioisr, MAC_MDIOISR, 2149 SNGLCOMPINT)) 2150 wakeup_one(pdata); 2151 } 2152 2153 } 2154 2155 return (ret); 2156 } /* axgbe_dev_isr */ 2157 2158 static void 2159 axgbe_i2c_isr(void *arg) 2160 { 2161 struct axgbe_if_softc *sc = (struct axgbe_if_softc *)arg; 2162 2163 sc->pdata.i2c_if.i2c_isr(&sc->pdata); 2164 } 2165 2166 static void 2167 axgbe_ecc_isr(void *arg) 2168 { 2169 /* TODO - implement */ 2170 } 2171 2172 static void 2173 axgbe_an_isr(void *arg) 2174 { 2175 struct axgbe_if_softc *sc = (struct axgbe_if_softc *)arg; 2176 2177 sc->pdata.phy_if.an_isr(&sc->pdata); 2178 } 2179 2180 static int 2181 axgbe_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t qid) 2182 { 2183 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2184 struct xgbe_prv_data *pdata = &sc->pdata; 2185 int ret; 2186 2187 if (qid < pdata->tx_q_count) { 2188 ret = xgbe_enable_rx_tx_int(pdata, pdata->channel[qid]); 2189 if (ret) { 2190 axgbe_error("Enable TX INT failed\n"); 2191 return (ret); 2192 } 2193 } else 2194 axgbe_error("Queue ID exceed channel count\n"); 2195 2196 return (0); 2197 } 2198 2199 static int 2200 axgbe_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid) 2201 { 2202 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2203 struct xgbe_prv_data *pdata = &sc->pdata; 2204 int ret; 2205 2206 if (qid < pdata->rx_q_count) { 2207 ret = xgbe_enable_rx_tx_int(pdata, pdata->channel[qid]); 2208 if (ret) { 2209 axgbe_error("Enable RX INT failed\n"); 2210 return (ret); 2211 } 2212 } else 2213 axgbe_error("Queue ID exceed channel count\n"); 2214 2215 return (0); 2216 } 2217 2218 static void 2219 axgbe_if_update_admin_status(if_ctx_t ctx) 2220 { 2221 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2222 struct xgbe_prv_data *pdata = &sc->pdata; 2223 2224 axgbe_printf(1, "%s: phy_link %d status %d speed %d\n", __func__, 2225 pdata->phy_link, sc->link_status, pdata->phy.speed); 2226 2227 if (pdata->phy_link < 0) 2228 return; 2229 2230 if (pdata->phy_link) { 2231 if (sc->link_status == LINK_STATE_DOWN) { 2232 sc->link_status = LINK_STATE_UP; 2233 if (pdata->phy.speed & SPEED_10000) 2234 iflib_link_state_change(ctx, LINK_STATE_UP, 2235 IF_Gbps(10)); 2236 else if (pdata->phy.speed & SPEED_2500) 2237 iflib_link_state_change(ctx, LINK_STATE_UP, 2238 IF_Gbps(2.5)); 2239 else if (pdata->phy.speed & SPEED_1000) 2240 iflib_link_state_change(ctx, LINK_STATE_UP, 2241 IF_Gbps(1)); 2242 else if (pdata->phy.speed & SPEED_100) 2243 iflib_link_state_change(ctx, LINK_STATE_UP, 2244 IF_Mbps(100)); 2245 else if (pdata->phy.speed & SPEED_10) 2246 iflib_link_state_change(ctx, LINK_STATE_UP, 2247 IF_Mbps(10)); 2248 } 2249 } else { 2250 if (sc->link_status == LINK_STATE_UP) { 2251 sc->link_status = LINK_STATE_DOWN; 2252 iflib_link_state_change(ctx, LINK_STATE_DOWN, 0); 2253 } 2254 } 2255 } 2256 2257 static int 2258 axgbe_if_media_change(if_ctx_t ctx) 2259 { 2260 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2261 struct ifmedia *ifm = iflib_get_media(ctx); 2262 2263 sx_xlock(&sc->pdata.an_mutex); 2264 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 2265 return (EINVAL); 2266 2267 switch (IFM_SUBTYPE(ifm->ifm_media)) { 2268 case IFM_10G_KR: 2269 sc->pdata.phy.speed = SPEED_10000; 2270 sc->pdata.phy.autoneg = AUTONEG_DISABLE; 2271 break; 2272 case IFM_2500_KX: 2273 sc->pdata.phy.speed = SPEED_2500; 2274 sc->pdata.phy.autoneg = AUTONEG_DISABLE; 2275 break; 2276 case IFM_1000_KX: 2277 sc->pdata.phy.speed = SPEED_1000; 2278 sc->pdata.phy.autoneg = AUTONEG_DISABLE; 2279 break; 2280 case IFM_100_TX: 2281 sc->pdata.phy.speed = SPEED_100; 2282 sc->pdata.phy.autoneg = AUTONEG_DISABLE; 2283 break; 2284 case IFM_AUTO: 2285 sc->pdata.phy.autoneg = AUTONEG_ENABLE; 2286 break; 2287 } 2288 sx_xunlock(&sc->pdata.an_mutex); 2289 2290 return (-sc->pdata.phy_if.phy_config_aneg(&sc->pdata)); 2291 } 2292 2293 static int 2294 axgbe_if_promisc_set(if_ctx_t ctx, int flags) 2295 { 2296 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2297 struct xgbe_prv_data *pdata = &sc->pdata; 2298 struct ifnet *ifp = pdata->netdev; 2299 2300 axgbe_printf(1, "%s: MAC_PFR 0x%x drv_flags 0x%x if_flags 0x%x\n", 2301 __func__, XGMAC_IOREAD(pdata, MAC_PFR), ifp->if_drv_flags, ifp->if_flags); 2302 2303 if (ifp->if_flags & IFF_PPROMISC) { 2304 2305 axgbe_printf(1, "User requested to enter promisc mode\n"); 2306 2307 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == 1) { 2308 axgbe_printf(1, "Already in promisc mode\n"); 2309 return (0); 2310 } 2311 2312 axgbe_printf(1, "Entering promisc mode\n"); 2313 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1); 2314 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0); 2315 } else { 2316 2317 axgbe_printf(1, "User requested to leave promisc mode\n"); 2318 2319 if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == 0) { 2320 axgbe_printf(1, "Already not in promisc mode\n"); 2321 return (0); 2322 } 2323 2324 axgbe_printf(1, "Leaving promisc mode\n"); 2325 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0); 2326 XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1); 2327 } 2328 2329 return (0); 2330 } 2331 2332 static uint64_t 2333 axgbe_if_get_counter(if_ctx_t ctx, ift_counter cnt) 2334 { 2335 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2336 struct ifnet *ifp = iflib_get_ifp(ctx); 2337 struct xgbe_prv_data *pdata = &sc->pdata; 2338 struct xgbe_mmc_stats *pstats = &pdata->mmc_stats; 2339 2340 pdata->hw_if.read_mmc_stats(pdata); 2341 2342 switch(cnt) { 2343 case IFCOUNTER_IPACKETS: 2344 return (pstats->rxframecount_gb); 2345 case IFCOUNTER_IERRORS: 2346 return (pstats->rxframecount_gb - pstats->rxbroadcastframes_g - 2347 pstats->rxmulticastframes_g - pstats->rxunicastframes_g); 2348 case IFCOUNTER_OPACKETS: 2349 return (pstats->txframecount_gb); 2350 case IFCOUNTER_OERRORS: 2351 return (pstats->txframecount_gb - pstats->txframecount_g); 2352 case IFCOUNTER_IBYTES: 2353 return (pstats->rxoctetcount_gb); 2354 case IFCOUNTER_OBYTES: 2355 return (pstats->txoctetcount_gb); 2356 default: 2357 return (if_get_counter_default(ifp, cnt)); 2358 } 2359 } 2360 2361 static int 2362 axgbe_if_mtu_set(if_ctx_t ctx, uint32_t mtu) 2363 { 2364 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2365 struct xgbe_prv_data *pdata = &sc->pdata; 2366 int ret; 2367 2368 if (mtu > XGMAC_JUMBO_PACKET_MTU) 2369 return (EINVAL); 2370 2371 ret = xgbe_calc_rx_buf_size(pdata->netdev, mtu); 2372 pdata->rx_buf_size = ret; 2373 axgbe_printf(1, "%s: rx_buf_size %d\n", __func__, ret); 2374 2375 sc->scctx->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; 2376 return (0); 2377 } 2378 2379 static void 2380 axgbe_if_media_status(if_ctx_t ctx, struct ifmediareq * ifmr) 2381 { 2382 struct axgbe_if_softc *sc = iflib_get_softc(ctx); 2383 struct xgbe_prv_data *pdata = &sc->pdata; 2384 2385 ifmr->ifm_status = IFM_AVALID; 2386 if (!sc->pdata.phy.link) 2387 return; 2388 2389 ifmr->ifm_active = IFM_ETHER; 2390 ifmr->ifm_status |= IFM_ACTIVE; 2391 2392 axgbe_printf(1, "Speed 0x%x Mode %d\n", sc->pdata.phy.speed, 2393 pdata->phy_if.phy_impl.cur_mode(pdata)); 2394 pdata->phy_if.phy_impl.get_type(pdata, ifmr); 2395 2396 ifmr->ifm_active |= IFM_FDX; 2397 ifmr->ifm_active |= IFM_ETH_TXPAUSE; 2398 ifmr->ifm_active |= IFM_ETH_RXPAUSE; 2399 } 2400