Deleted Added
full compact
if_mxge.c (188531) if_mxge.c (188736)
1/******************************************************************************
2
1/******************************************************************************
2
3Copyright (c) 2006-2008, Myricom Inc.
3Copyright (c) 2006-2009, Myricom Inc.
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11

--- 11 unchanged lines hidden (view full) ---

23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26POSSIBILITY OF SUCH DAMAGE.
27
28***************************************************************************/
29
30#include <sys/cdefs.h>
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11

--- 11 unchanged lines hidden (view full) ---

23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26POSSIBILITY OF SUCH DAMAGE.
27
28***************************************************************************/
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/mxge/if_mxge.c 188531 2009-02-12 18:33:56Z rdivacky $");
31__FBSDID("$FreeBSD: head/sys/dev/mxge/if_mxge.c 188736 2009-02-17 22:15:58Z gallatin $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/linker.h>
36#include <sys/firmware.h>
37#include <sys/endian.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>

--- 97 unchanged lines hidden (view full) ---

137static int mxge_send_cmd(mxge_softc_t *sc, uint32_t cmd, mxge_cmd_t *data);
138static int mxge_close(mxge_softc_t *sc);
139static int mxge_open(mxge_softc_t *sc);
140static void mxge_tick(void *arg);
141
142static int
143mxge_probe(device_t dev)
144{
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/linker.h>
36#include <sys/firmware.h>
37#include <sys/endian.h>
38#include <sys/sockio.h>
39#include <sys/mbuf.h>

--- 97 unchanged lines hidden (view full) ---

137static int mxge_send_cmd(mxge_softc_t *sc, uint32_t cmd, mxge_cmd_t *data);
138static int mxge_close(mxge_softc_t *sc);
139static int mxge_open(mxge_softc_t *sc);
140static void mxge_tick(void *arg);
141
142static int
143mxge_probe(device_t dev)
144{
145 if ((pci_get_vendor(dev) == MXGE_PCI_VENDOR_MYRICOM) &&
146 ((pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E) ||
147 (pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E_9))) {
148 device_set_desc(dev, "Myri10G-PCIE-8A");
149 return 0;
150 }
151 return ENXIO;
145 int rev;
146
147
148 if ((pci_get_vendor(dev) == MXGE_PCI_VENDOR_MYRICOM) &&
149 ((pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E) ||
150 (pci_get_device(dev) == MXGE_PCI_DEVICE_Z8E_9))) {
151 rev = pci_get_revid(dev);
152 switch (rev) {
153 case MXGE_PCI_REV_Z8E:
154 device_set_desc(dev, "Myri10G-PCIE-8A");
155 break;
156 case MXGE_PCI_REV_Z8ES:
157 device_set_desc(dev, "Myri10G-PCIE-8B");
158 break;
159 default:
160 device_set_desc(dev, "Myri10G-PCIE-8??");
161 device_printf(dev, "Unrecognized rev %d NIC\n",
162 rev);
163 break;
164 }
165 return 0;
166 }
167 return ENXIO;
152}
153
154static void
155mxge_enable_wc(mxge_softc_t *sc)
156{
157#if defined(__i386) || defined(__amd64)
158 vm_offset_t len;
159 int err;

--- 2340 unchanged lines hidden (view full) ---

2500 mtx_lock(&ss->tx.mtx);
2501 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2502 ss->tx.wake++;
2503 mxge_start_locked(ss);
2504 mtx_unlock(&ss->tx.mtx);
2505 }
2506}
2507
168}
169
170static void
171mxge_enable_wc(mxge_softc_t *sc)
172{
173#if defined(__i386) || defined(__amd64)
174 vm_offset_t len;
175 int err;

--- 2340 unchanged lines hidden (view full) ---

2516 mtx_lock(&ss->tx.mtx);
2517 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2518 ss->tx.wake++;
2519 mxge_start_locked(ss);
2520 mtx_unlock(&ss->tx.mtx);
2521 }
2522}
2523
2508static struct mxge_media_type mxge_media_types[] =
2524static struct mxge_media_type mxge_xfp_media_types[] =
2509{
2510 {IFM_10G_CX4, 0x7f, "10GBASE-CX4 (module)"},
2511 {IFM_10G_SR, (1 << 7), "10GBASE-SR"},
2512 {IFM_10G_LR, (1 << 6), "10GBASE-LR"},
2513 {0, (1 << 5), "10GBASE-ER"},
2525{
2526 {IFM_10G_CX4, 0x7f, "10GBASE-CX4 (module)"},
2527 {IFM_10G_SR, (1 << 7), "10GBASE-SR"},
2528 {IFM_10G_LR, (1 << 6), "10GBASE-LR"},
2529 {0, (1 << 5), "10GBASE-ER"},
2514 {0, (1 << 4), "10GBASE-LRM"},
2530 {IFM_10G_LRM, (1 << 4), "10GBASE-LRM"},
2515 {0, (1 << 3), "10GBASE-SW"},
2516 {0, (1 << 2), "10GBASE-LW"},
2517 {0, (1 << 1), "10GBASE-EW"},
2518 {0, (1 << 0), "Reserved"}
2519};
2531 {0, (1 << 3), "10GBASE-SW"},
2532 {0, (1 << 2), "10GBASE-LW"},
2533 {0, (1 << 1), "10GBASE-EW"},
2534 {0, (1 << 0), "Reserved"}
2535};
2536static struct mxge_media_type mxge_sfp_media_types[] =
2537{
2538 {0, (1 << 0), "Reserved"},
2539 {IFM_10G_LRM, (1 << 6), "10GBASE-LRM"},
2540 {IFM_10G_LR, (1 << 5), "10GBASE-LR"},
2541 {IFM_10G_SR, (1 << 4), "10GBASE-SR"}
2542};
2520
2521static void
2522mxge_set_media(mxge_softc_t *sc, int type)
2523{
2524 sc->media_flags |= type;
2525 ifmedia_add(&sc->media, sc->media_flags, 0, NULL);
2526 ifmedia_set(&sc->media, sc->media_flags);
2527}

--- 6 unchanged lines hidden (view full) ---

2534 * several milliseconds, so it is run via the watchdog routine, rather
2535 * than in the interrupt handler itself. This need only be done
2536 * once, not each time the link is up.
2537 */
2538static void
2539mxge_media_probe(mxge_softc_t *sc)
2540{
2541 mxge_cmd_t cmd;
2543
2544static void
2545mxge_set_media(mxge_softc_t *sc, int type)
2546{
2547 sc->media_flags |= type;
2548 ifmedia_add(&sc->media, sc->media_flags, 0, NULL);
2549 ifmedia_set(&sc->media, sc->media_flags);
2550}

--- 6 unchanged lines hidden (view full) ---

2557 * several milliseconds, so it is run via the watchdog routine, rather
2558 * than in the interrupt handler itself. This need only be done
2559 * once, not each time the link is up.
2560 */
2561static void
2562mxge_media_probe(mxge_softc_t *sc)
2563{
2564 mxge_cmd_t cmd;
2565 char *cage_type;
2542 char *ptr;
2566 char *ptr;
2543 int i, err, ms;
2567 struct mxge_media_type *mxge_media_types = NULL;
2568 int i, err, ms, mxge_media_type_entries;
2569 uint32_t byte;
2544
2545 sc->need_media_probe = 0;
2546
2547 /* if we've already set a media type, we're done */
2548 if (sc->media_flags != (IFM_ETHER | IFM_AUTO))
2549 return;
2550
2551 /*

--- 11 unchanged lines hidden (view full) ---

2563 ptr = index(ptr, '-');
2564 if (ptr == NULL) {
2565 device_printf(sc->dev,
2566 "only %d dashes in PC?!?\n", i);
2567 return;
2568 }
2569 }
2570 if (*ptr == 'C') {
2570
2571 sc->need_media_probe = 0;
2572
2573 /* if we've already set a media type, we're done */
2574 if (sc->media_flags != (IFM_ETHER | IFM_AUTO))
2575 return;
2576
2577 /*

--- 11 unchanged lines hidden (view full) ---

2589 ptr = index(ptr, '-');
2590 if (ptr == NULL) {
2591 device_printf(sc->dev,
2592 "only %d dashes in PC?!?\n", i);
2593 return;
2594 }
2595 }
2596 if (*ptr == 'C') {
2597 /* -C is CX4 */
2571 mxge_set_media(sc, IFM_10G_CX4);
2572 return;
2573 }
2574 else if (*ptr == 'Q') {
2598 mxge_set_media(sc, IFM_10G_CX4);
2599 return;
2600 }
2601 else if (*ptr == 'Q') {
2602 /* -Q is Quad Ribbon Fiber */
2575 device_printf(sc->dev, "Quad Ribbon Fiber Media\n");
2576 /* FreeBSD has no media type for Quad ribbon fiber */
2577 return;
2578 }
2579
2603 device_printf(sc->dev, "Quad Ribbon Fiber Media\n");
2604 /* FreeBSD has no media type for Quad ribbon fiber */
2605 return;
2606 }
2607
2580 if (*ptr != 'R') {
2608 if (*ptr == 'R') {
2609 /* -R is XFP */
2610 mxge_media_types = mxge_xfp_media_types;
2611 mxge_media_type_entries =
2612 sizeof (mxge_xfp_media_types) /
2613 sizeof (mxge_xfp_media_types[0]);
2614 byte = MXGE_XFP_COMPLIANCE_BYTE;
2615 cage_type = "XFP";
2616 }
2617
2618 if (*ptr == 'S' || *(ptr +1) == 'S') {
2619 /* -S or -2S is SFP+ */
2620 mxge_media_types = mxge_sfp_media_types;
2621 mxge_media_type_entries =
2622 sizeof (mxge_sfp_media_types) /
2623 sizeof (mxge_sfp_media_types[0]);
2624 cage_type = "SFP+";
2625 byte = 3;
2626 }
2627
2628 if (mxge_media_types == NULL) {
2581 device_printf(sc->dev, "Unknown media type: %c\n", *ptr);
2582 return;
2583 }
2584
2585 /*
2586 * At this point we know the NIC has an XFP cage, so now we
2587 * try to determine what is in the cage by using the
2588 * firmware's XFP I2C commands to read the XFP 10GbE compilance
2589 * register. We read just one byte, which may take over
2590 * a millisecond
2591 */
2592
2593 cmd.data0 = 0; /* just fetch 1 byte, not all 256 */
2629 device_printf(sc->dev, "Unknown media type: %c\n", *ptr);
2630 return;
2631 }
2632
2633 /*
2634 * At this point we know the NIC has an XFP cage, so now we
2635 * try to determine what is in the cage by using the
2636 * firmware's XFP I2C commands to read the XFP 10GbE compilance
2637 * register. We read just one byte, which may take over
2638 * a millisecond
2639 */
2640
2641 cmd.data0 = 0; /* just fetch 1 byte, not all 256 */
2594 cmd.data1 = MXGE_XFP_COMPLIANCE_BYTE; /* the byte we want */
2595 err = mxge_send_cmd(sc, MXGEFW_CMD_XFP_I2C_READ, &cmd);
2596 if (err == MXGEFW_CMD_ERROR_XFP_FAILURE) {
2642 cmd.data1 = byte;
2643 err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_READ, &cmd);
2644 if (err == MXGEFW_CMD_ERROR_I2C_FAILURE) {
2597 device_printf(sc->dev, "failed to read XFP\n");
2598 }
2645 device_printf(sc->dev, "failed to read XFP\n");
2646 }
2599 if (err == MXGEFW_CMD_ERROR_XFP_ABSENT) {
2600 device_printf(sc->dev, "Type R with no XFP!?!?\n");
2647 if (err == MXGEFW_CMD_ERROR_I2C_ABSENT) {
2648 device_printf(sc->dev, "Type R/S with no XFP!?!?\n");
2601 }
2602 if (err != MXGEFW_CMD_OK) {
2603 return;
2604 }
2605
2606 /* now we wait for the data to be cached */
2649 }
2650 if (err != MXGEFW_CMD_OK) {
2651 return;
2652 }
2653
2654 /* now we wait for the data to be cached */
2607 cmd.data0 = MXGE_XFP_COMPLIANCE_BYTE;
2608 err = mxge_send_cmd(sc, MXGEFW_CMD_XFP_BYTE, &cmd);
2655 cmd.data0 = byte;
2656 err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
2609 for (ms = 0; (err == EBUSY) && (ms < 50); ms++) {
2610 DELAY(1000);
2657 for (ms = 0; (err == EBUSY) && (ms < 50); ms++) {
2658 DELAY(1000);
2611 cmd.data0 = MXGE_XFP_COMPLIANCE_BYTE;
2612 err = mxge_send_cmd(sc, MXGEFW_CMD_XFP_BYTE, &cmd);
2659 cmd.data0 = byte;
2660 err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
2613 }
2614 if (err != MXGEFW_CMD_OK) {
2661 }
2662 if (err != MXGEFW_CMD_OK) {
2615 device_printf(sc->dev, "failed to read XFP (%d, %dms)\n",
2616 err, ms);
2663 device_printf(sc->dev, "failed to read %s (%d, %dms)\n",
2664 cage_type, err, ms);
2617 return;
2618 }
2619
2620 if (cmd.data0 == mxge_media_types[0].bitmask) {
2621 if (mxge_verbose)
2665 return;
2666 }
2667
2668 if (cmd.data0 == mxge_media_types[0].bitmask) {
2669 if (mxge_verbose)
2622 device_printf(sc->dev, "XFP:%s\n",
2670 device_printf(sc->dev, "%s:%s\n", cage_type,
2623 mxge_media_types[0].name);
2624 mxge_set_media(sc, IFM_10G_CX4);
2625 return;
2626 }
2671 mxge_media_types[0].name);
2672 mxge_set_media(sc, IFM_10G_CX4);
2673 return;
2674 }
2627 for (i = 1;
2628 i < sizeof (mxge_media_types) / sizeof (mxge_media_types[0]);
2629 i++) {
2675 for (i = 1; i < mxge_media_type_entries; i++) {
2630 if (cmd.data0 & mxge_media_types[i].bitmask) {
2631 if (mxge_verbose)
2676 if (cmd.data0 & mxge_media_types[i].bitmask) {
2677 if (mxge_verbose)
2632 device_printf(sc->dev, "XFP:%s\n",
2678 device_printf(sc->dev, "%s:%s\n",
2679 cage_type,
2633 mxge_media_types[i].name);
2634
2635 mxge_set_media(sc, mxge_media_types[i].flag);
2636 return;
2637 }
2638 }
2680 mxge_media_types[i].name);
2681
2682 mxge_set_media(sc, mxge_media_types[i].flag);
2683 return;
2684 }
2685 }
2639 device_printf(sc->dev, "XFP media 0x%x unknown\n", cmd.data0);
2686 device_printf(sc->dev, "%s media 0x%x unknown\n", cage_type,
2687 cmd.data0);
2640
2641 return;
2642}
2643
2644static void
2645mxge_intr(void *arg)
2646{
2647 struct mxge_slice_state *ss = arg;

--- 1688 unchanged lines hidden ---
2688
2689 return;
2690}
2691
2692static void
2693mxge_intr(void *arg)
2694{
2695 struct mxge_slice_state *ss = arg;

--- 1688 unchanged lines hidden ---