Deleted Added
full compact
sfxge_port.c (264772) sfxge_port.c (272325)
1/*-
2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
3 * All rights reserved.
4 *
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
3 * All rights reserved.
4 *
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/sfxge/sfxge_port.c 264772 2014-04-22 20:19:09Z gnn $");
31__FBSDID("$FreeBSD: head/sys/dev/sfxge/sfxge_port.c 272325 2014-09-30 20:18:10Z gnn $");
32
33#include <sys/types.h>
34#include <sys/limits.h>
35#include <net/ethernet.h>
36#include <net/if_dl.h>
37
38#include "common/efx.h"
39

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

69 EFSYS_PROBE1(wait, unsigned int, count);
70
71 /* Synchronize the DMA memory for reading */
72 bus_dmamap_sync(esmp->esm_tag, esmp->esm_map,
73 BUS_DMASYNC_POSTREAD);
74
75 /* Try to update the cached counters */
76 if ((rc = efx_mac_stats_update(sc->enp, esmp,
32
33#include <sys/types.h>
34#include <sys/limits.h>
35#include <net/ethernet.h>
36#include <net/if_dl.h>
37
38#include "common/efx.h"
39

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

69 EFSYS_PROBE1(wait, unsigned int, count);
70
71 /* Synchronize the DMA memory for reading */
72 bus_dmamap_sync(esmp->esm_tag, esmp->esm_map,
73 BUS_DMASYNC_POSTREAD);
74
75 /* Try to update the cached counters */
76 if ((rc = efx_mac_stats_update(sc->enp, esmp,
77 port->mac_stats.decode_buf, NULL)) != EAGAIN)
77 port->mac_stats.decode_buf, NULL)) != EAGAIN)
78 goto out;
79
80 DELAY(100);
81 }
82
83 rc = ETIMEDOUT;
84out:
85 mtx_unlock(&port->lock);
78 goto out;
79
80 DELAY(100);
81 }
82
83 rc = ETIMEDOUT;
84out:
85 mtx_unlock(&port->lock);
86 return rc;
86 return (rc);
87}
88
89static int
90sfxge_mac_stat_handler(SYSCTL_HANDLER_ARGS)
91{
92 struct sfxge_softc *sc = arg1;
93 unsigned int id = arg2;
94 int rc;
95
96 if ((rc = sfxge_mac_stat_update(sc)) != 0)
87}
88
89static int
90sfxge_mac_stat_handler(SYSCTL_HANDLER_ARGS)
91{
92 struct sfxge_softc *sc = arg1;
93 unsigned int id = arg2;
94 int rc;
95
96 if ((rc = sfxge_mac_stat_update(sc)) != 0)
97 return rc;
97 return (rc);
98
98
99 return SYSCTL_OUT(req,
99 return (SYSCTL_OUT(req,
100 (uint64_t *)sc->port.mac_stats.decode_buf + id,
100 (uint64_t *)sc->port.mac_stats.decode_buf + id,
101 sizeof(uint64_t));
101 sizeof(uint64_t)));
102}
103
104static void
105sfxge_mac_stat_init(struct sfxge_softc *sc)
106{
107 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
108 struct sysctl_oid_list *stat_list;
109 unsigned int id;

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

125#ifdef SFXGE_HAVE_PAUSE_MEDIAOPTS
126
127static unsigned int
128sfxge_port_wanted_fc(struct sfxge_softc *sc)
129{
130 struct ifmedia_entry *ifm = sc->media.ifm_cur;
131
132 if (ifm->ifm_media == (IFM_ETHER | IFM_AUTO))
102}
103
104static void
105sfxge_mac_stat_init(struct sfxge_softc *sc)
106{
107 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
108 struct sysctl_oid_list *stat_list;
109 unsigned int id;

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

125#ifdef SFXGE_HAVE_PAUSE_MEDIAOPTS
126
127static unsigned int
128sfxge_port_wanted_fc(struct sfxge_softc *sc)
129{
130 struct ifmedia_entry *ifm = sc->media.ifm_cur;
131
132 if (ifm->ifm_media == (IFM_ETHER | IFM_AUTO))
133 return EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
134 return ((ifm->ifm_media & IFM_ETH_RXPAUSE) ? EFX_FCNTL_RESPOND : 0) |
135 ((ifm->ifm_media & IFM_ETH_TXPAUSE) ? EFX_FCNTL_GENERATE : 0);
133 return (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE);
134 return (((ifm->ifm_media & IFM_ETH_RXPAUSE) ? EFX_FCNTL_RESPOND : 0) |
135 ((ifm->ifm_media & IFM_ETH_TXPAUSE) ? EFX_FCNTL_GENERATE : 0));
136}
137
138static unsigned int
139sfxge_port_link_fc_ifm(struct sfxge_softc *sc)
140{
141 unsigned int wanted_fc, link_fc;
142
143 efx_mac_fcntl_get(sc->enp, &wanted_fc, &link_fc);
144 return ((link_fc & EFX_FCNTL_RESPOND) ? IFM_ETH_RXPAUSE : 0) |
145 ((link_fc & EFX_FCNTL_GENERATE) ? IFM_ETH_TXPAUSE : 0);
146}
147
148#else /* !SFXGE_HAVE_PAUSE_MEDIAOPTS */
149
150static unsigned int
151sfxge_port_wanted_fc(struct sfxge_softc *sc)
152{
136}
137
138static unsigned int
139sfxge_port_link_fc_ifm(struct sfxge_softc *sc)
140{
141 unsigned int wanted_fc, link_fc;
142
143 efx_mac_fcntl_get(sc->enp, &wanted_fc, &link_fc);
144 return ((link_fc & EFX_FCNTL_RESPOND) ? IFM_ETH_RXPAUSE : 0) |
145 ((link_fc & EFX_FCNTL_GENERATE) ? IFM_ETH_TXPAUSE : 0);
146}
147
148#else /* !SFXGE_HAVE_PAUSE_MEDIAOPTS */
149
150static unsigned int
151sfxge_port_wanted_fc(struct sfxge_softc *sc)
152{
153 return sc->port.wanted_fc;
153 return (sc->port.wanted_fc);
154}
155
156static unsigned int
157sfxge_port_link_fc_ifm(struct sfxge_softc *sc)
158{
154}
155
156static unsigned int
157sfxge_port_link_fc_ifm(struct sfxge_softc *sc)
158{
159 return 0;
159 return (0);
160}
161
162static int
163sfxge_port_wanted_fc_handler(SYSCTL_HANDLER_ARGS)
164{
165 struct sfxge_softc *sc;
166 struct sfxge_port *port;
167 unsigned int fcntl;
168 int error;
169
170 sc = arg1;
171 port = &sc->port;
172
173 mtx_lock(&port->lock);
174
160}
161
162static int
163sfxge_port_wanted_fc_handler(SYSCTL_HANDLER_ARGS)
164{
165 struct sfxge_softc *sc;
166 struct sfxge_port *port;
167 unsigned int fcntl;
168 int error;
169
170 sc = arg1;
171 port = &sc->port;
172
173 mtx_lock(&port->lock);
174
175 if (req->newptr) {
175 if (req->newptr != NULL) {
176 if ((error = SYSCTL_IN(req, &fcntl, sizeof(fcntl))) != 0)
177 goto out;
178
179 if (port->wanted_fc == fcntl)
180 goto out;
181
182 port->wanted_fc = fcntl;
183

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

230 [EFX_LINK_10000FDX] = MIN(IF_Gbps(10ULL), ULONG_MAX),
231};
232
233void
234sfxge_mac_link_update(struct sfxge_softc *sc, efx_link_mode_t mode)
235{
236 struct sfxge_port *port;
237 int link_state;
176 if ((error = SYSCTL_IN(req, &fcntl, sizeof(fcntl))) != 0)
177 goto out;
178
179 if (port->wanted_fc == fcntl)
180 goto out;
181
182 port->wanted_fc = fcntl;
183

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

230 [EFX_LINK_10000FDX] = MIN(IF_Gbps(10ULL), ULONG_MAX),
231};
232
233void
234sfxge_mac_link_update(struct sfxge_softc *sc, efx_link_mode_t mode)
235{
236 struct sfxge_port *port;
237 int link_state;
238
238
239 port = &sc->port;
240
241 if (port->link_mode == mode)
242 return;
243
244 port->link_mode = mode;
245
246 /* Push link state update to the OS */

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

284 struct sockaddr_dl *sa;
285 efx_nic_t *enp = sc->enp;
286 unsigned int index;
287 int rc;
288
289 /* Set promisc-unicast and broadcast filter bits */
290 if ((rc = efx_mac_filter_set(enp, !!(ifp->if_flags & IFF_PROMISC),
291 B_TRUE)) != 0)
239 port = &sc->port;
240
241 if (port->link_mode == mode)
242 return;
243
244 port->link_mode = mode;
245
246 /* Push link state update to the OS */

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

284 struct sockaddr_dl *sa;
285 efx_nic_t *enp = sc->enp;
286 unsigned int index;
287 int rc;
288
289 /* Set promisc-unicast and broadcast filter bits */
290 if ((rc = efx_mac_filter_set(enp, !!(ifp->if_flags & IFF_PROMISC),
291 B_TRUE)) != 0)
292 return rc;
292 return (rc);
293
294 /* Set multicast hash filter */
295 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) {
296 for (index = 0; index < EFX_MAC_HASH_BITS; index++)
297 bucket[index] = 1;
298 } else {
299 /* Broadcast frames also go through the multicast
300 * filter, and the broadcast address hashes to

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

306 if (ifma->ifma_addr->sa_family == AF_LINK) {
307 sa = (struct sockaddr_dl *)ifma->ifma_addr;
308 index = ether_crc32_le(LLADDR(sa), 6) & 0xff;
309 bucket[index] = 1;
310 }
311 }
312 if_maddr_runlock(ifp);
313 }
293
294 /* Set multicast hash filter */
295 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) {
296 for (index = 0; index < EFX_MAC_HASH_BITS; index++)
297 bucket[index] = 1;
298 } else {
299 /* Broadcast frames also go through the multicast
300 * filter, and the broadcast address hashes to

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

306 if (ifma->ifma_addr->sa_family == AF_LINK) {
307 sa = (struct sockaddr_dl *)ifma->ifma_addr;
308 index = ether_crc32_le(LLADDR(sa), 6) & 0xff;
309 bucket[index] = 1;
310 }
311 }
312 if_maddr_runlock(ifp);
313 }
314 return efx_mac_hash_set(enp, bucket);
314 return (efx_mac_hash_set(enp, bucket));
315}
316
317int
318sfxge_mac_filter_set(struct sfxge_softc *sc)
319{
320 struct sfxge_port *port = &sc->port;
321 int rc;
322

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

331 * lock is held in sleeping thread. Both problems are repeatable
332 * on LAG with LACP proto bring up.
333 */
334 if (port->init_state == SFXGE_PORT_STARTED)
335 rc = sfxge_mac_filter_set_locked(sc);
336 else
337 rc = 0;
338 mtx_unlock(&port->lock);
315}
316
317int
318sfxge_mac_filter_set(struct sfxge_softc *sc)
319{
320 struct sfxge_port *port = &sc->port;
321 int rc;
322

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

331 * lock is held in sleeping thread. Both problems are repeatable
332 * on LAG with LACP proto bring up.
333 */
334 if (port->init_state == SFXGE_PORT_STARTED)
335 rc = sfxge_mac_filter_set_locked(sc);
336 else
337 rc = 0;
338 mtx_unlock(&port->lock);
339 return rc;
339 return (rc);
340}
341
342void
343sfxge_port_stop(struct sfxge_softc *sc)
344{
345 struct sfxge_port *port;
346 efx_nic_t *enp;
347

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

408 if_addr_runlock(ifp);
409 if ((rc = efx_mac_addr_set(enp, mac_addr)) != 0)
410 goto fail;
411
412 sfxge_mac_filter_set_locked(sc);
413
414 /* Update MAC stats by DMA every second */
415 if ((rc = efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf,
340}
341
342void
343sfxge_port_stop(struct sfxge_softc *sc)
344{
345 struct sfxge_port *port;
346 efx_nic_t *enp;
347

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

408 if_addr_runlock(ifp);
409 if ((rc = efx_mac_addr_set(enp, mac_addr)) != 0)
410 goto fail;
411
412 sfxge_mac_filter_set_locked(sc);
413
414 /* Update MAC stats by DMA every second */
415 if ((rc = efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf,
416 1000, B_FALSE)) != 0)
416 1000, B_FALSE)) != 0)
417 goto fail2;
418
419 if ((rc = efx_mac_drain(enp, B_FALSE)) != 0)
420 goto fail3;
421
422 if ((rc = efx_phy_adv_cap_set(sc->enp, sc->media.ifm_cur->ifm_data))
423 != 0)
424 goto fail4;

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

430 sfxge_mac_poll_work(sc, 0);
431
432 return (0);
433
434fail4:
435 (void)efx_mac_drain(enp, B_TRUE);
436fail3:
437 (void)efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf,
417 goto fail2;
418
419 if ((rc = efx_mac_drain(enp, B_FALSE)) != 0)
420 goto fail3;
421
422 if ((rc = efx_phy_adv_cap_set(sc->enp, sc->media.ifm_cur->ifm_data))
423 != 0)
424 goto fail4;

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

430 sfxge_mac_poll_work(sc, 0);
431
432 return (0);
433
434fail4:
435 (void)efx_mac_drain(enp, B_TRUE);
436fail3:
437 (void)efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf,
438 0, B_FALSE);
438 0, B_FALSE);
439fail2:
440 efx_port_fini(sc->enp);
441fail:
442 mtx_unlock(&port->lock);
443
444 return (rc);
445}
446

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

483 goto out;
484
485 DELAY(100);
486 }
487
488 rc = ETIMEDOUT;
489out:
490 mtx_unlock(&port->lock);
439fail2:
440 efx_port_fini(sc->enp);
441fail:
442 mtx_unlock(&port->lock);
443
444 return (rc);
445}
446

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

483 goto out;
484
485 DELAY(100);
486 }
487
488 rc = ETIMEDOUT;
489out:
490 mtx_unlock(&port->lock);
491 return rc;
491 return (rc);
492}
493
494static int
495sfxge_phy_stat_handler(SYSCTL_HANDLER_ARGS)
496{
497 struct sfxge_softc *sc = arg1;
498 unsigned int id = arg2;
499 int rc;
500
501 if ((rc = sfxge_phy_stat_update(sc)) != 0)
492}
493
494static int
495sfxge_phy_stat_handler(SYSCTL_HANDLER_ARGS)
496{
497 struct sfxge_softc *sc = arg1;
498 unsigned int id = arg2;
499 int rc;
500
501 if ((rc = sfxge_phy_stat_update(sc)) != 0)
502 return rc;
502 return (rc);
503
503
504 return SYSCTL_OUT(req,
504 return (SYSCTL_OUT(req,
505 (uint32_t *)sc->port.phy_stats.decode_buf + id,
505 (uint32_t *)sc->port.phy_stats.decode_buf + id,
506 sizeof(uint32_t));
506 sizeof(uint32_t)));
507}
508
509static void
510sfxge_phy_stat_init(struct sfxge_softc *sc)
511{
512 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
513 struct sysctl_oid_list *stat_list;
514 unsigned int id;

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

614
615fail2:
616 free(port->mac_stats.decode_buf, M_SFXGE);
617 sfxge_dma_free(phy_stats_buf);
618fail:
619 free(port->phy_stats.decode_buf, M_SFXGE);
620 (void)mtx_destroy(&port->lock);
621 port->sc = NULL;
507}
508
509static void
510sfxge_phy_stat_init(struct sfxge_softc *sc)
511{
512 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
513 struct sysctl_oid_list *stat_list;
514 unsigned int id;

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

614
615fail2:
616 free(port->mac_stats.decode_buf, M_SFXGE);
617 sfxge_dma_free(phy_stats_buf);
618fail:
619 free(port->phy_stats.decode_buf, M_SFXGE);
620 (void)mtx_destroy(&port->lock);
621 port->sc = NULL;
622 return rc;
622 return (rc);
623}
624
625static int sfxge_link_mode[EFX_PHY_MEDIA_NTYPES][EFX_LINK_NMODES] = {
626 [EFX_PHY_MEDIA_CX4] = {
627 [EFX_LINK_10000FDX] = IFM_ETHER | IFM_FDX | IFM_10G_CX4,
628 },
629 [EFX_PHY_MEDIA_KX4] = {
630 [EFX_LINK_10000FDX] = IFM_ETHER | IFM_FDX | IFM_10G_KX4,

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

692 }
693
694 rc = efx_mac_fcntl_set(sc->enp, sfxge_port_wanted_fc(sc), B_TRUE);
695 if (rc != 0)
696 goto out;
697
698 rc = efx_phy_adv_cap_set(sc->enp, ifm->ifm_data);
699out:
623}
624
625static int sfxge_link_mode[EFX_PHY_MEDIA_NTYPES][EFX_LINK_NMODES] = {
626 [EFX_PHY_MEDIA_CX4] = {
627 [EFX_LINK_10000FDX] = IFM_ETHER | IFM_FDX | IFM_10G_CX4,
628 },
629 [EFX_PHY_MEDIA_KX4] = {
630 [EFX_LINK_10000FDX] = IFM_ETHER | IFM_FDX | IFM_10G_KX4,

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

692 }
693
694 rc = efx_mac_fcntl_set(sc->enp, sfxge_port_wanted_fc(sc), B_TRUE);
695 if (rc != 0)
696 goto out;
697
698 rc = efx_phy_adv_cap_set(sc->enp, ifm->ifm_data);
699out:
700 sx_xunlock(&sc->softc_lock);
700 sx_xunlock(&sc->softc_lock);
701
701
702 return rc;
702 return (rc);
703}
704
705int sfxge_port_ifmedia_init(struct sfxge_softc *sc)
706{
707 efx_phy_media_type_t medium_type;
708 uint32_t cap_mask, mode_cap_mask;
709 efx_link_mode_t mode;
710 int mode_ifm, best_mode_ifm = 0;

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

783 if (cap_mask & (1 << EFX_PHY_CAP_AN)) {
784 /* Add autoselect mode. */
785 mode_ifm = IFM_ETHER | IFM_AUTO;
786 ifmedia_add(&sc->media, mode_ifm,
787 cap_mask & ~(1 << EFX_PHY_CAP_ASYM), NULL);
788 best_mode_ifm = mode_ifm;
789 }
790
703}
704
705int sfxge_port_ifmedia_init(struct sfxge_softc *sc)
706{
707 efx_phy_media_type_t medium_type;
708 uint32_t cap_mask, mode_cap_mask;
709 efx_link_mode_t mode;
710 int mode_ifm, best_mode_ifm = 0;

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

783 if (cap_mask & (1 << EFX_PHY_CAP_AN)) {
784 /* Add autoselect mode. */
785 mode_ifm = IFM_ETHER | IFM_AUTO;
786 ifmedia_add(&sc->media, mode_ifm,
787 cap_mask & ~(1 << EFX_PHY_CAP_ASYM), NULL);
788 best_mode_ifm = mode_ifm;
789 }
790
791 if (best_mode_ifm)
791 if (best_mode_ifm != 0)
792 ifmedia_set(&sc->media, best_mode_ifm);
793
794 /* Now discard port state until interface is started. */
795 efx_port_fini(sc->enp);
796out2:
797 efx_nic_fini(sc->enp);
798out:
792 ifmedia_set(&sc->media, best_mode_ifm);
793
794 /* Now discard port state until interface is started. */
795 efx_port_fini(sc->enp);
796out2:
797 efx_nic_fini(sc->enp);
798out:
799 return rc;
799 return (rc);
800}
800}