Deleted Added
full compact
sfp.c (270287) sfp.c (270822)
1/*-
2 * Copyright (c) 2014 Alexander V. Chernikov. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

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

20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#ifndef lint
27static const char rcsid[] =
1/*-
2 * Copyright (c) 2014 Alexander V. Chernikov. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

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

20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#ifndef lint
27static const char rcsid[] =
28 "$FreeBSD: head/sbin/ifconfig/sfp.c 270287 2014-08-21 17:54:42Z melifaro $";
28 "$FreeBSD: head/sbin/ifconfig/sfp.c 270822 2014-08-29 18:02:58Z melifaro $";
29#endif /* not lint */
30
31#include <sys/types.h>
32#include <sys/param.h>
33#include <sys/ioctl.h>
34#include <sys/socket.h>
35
36#include <net/if.h>

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

619{
620 char xbuf[2];
621
622 memset(xbuf, 0, sizeof(xbuf));
623 ii->f(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan -1) * 2, 2, xbuf);
624 convert_sff_power(ii, buf, size, xbuf);
625}
626
29#endif /* not lint */
30
31#include <sys/types.h>
32#include <sys/param.h>
33#include <sys/ioctl.h>
34#include <sys/socket.h>
35
36#include <net/if.h>

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

619{
620 char xbuf[2];
621
622 memset(xbuf, 0, sizeof(xbuf));
623 ii->f(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan -1) * 2, 2, xbuf);
624 convert_sff_power(ii, buf, size, xbuf);
625}
626
627/* Intel ixgbe-specific structures and handlers */
628struct ixgbe_i2c_req {
629 uint8_t dev_addr;
630 uint8_t offset;
631 uint8_t len;
632 uint8_t data[8];
633};
634#define SIOCGI2C SIOCGIFGENERIC
635
627/* Generic handler */
636static int
628static int
637read_i2c_ixgbe(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
629read_i2c_generic(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
638 caddr_t buf)
639{
630 caddr_t buf)
631{
640 struct ixgbe_i2c_req ixreq;
641 int i;
632 struct ifi2creq req;
633 int i, l;
642
643 if (ii->error != 0)
644 return (ii->error);
645
634
635 if (ii->error != 0)
636 return (ii->error);
637
646 ii->ifr->ifr_data = (caddr_t)&ixreq;
638 ii->ifr->ifr_data = (caddr_t)&req;
647
639
648 memset(&ixreq, 0, sizeof(ixreq));
649 ixreq.dev_addr = addr;
640 i = 0;
641 l = 0;
642 memset(&req, 0, sizeof(req));
643 req.dev_addr = addr;
644 req.offset = off;
645 req.len = len;
650
646
651 for (i = 0; i < len; i += 1) {
652 ixreq.offset = off + i;
653 ixreq.len = 1;
654 ixreq.data[0] = '\0';
655
647 while (len > 0) {
648 l = (len > sizeof(req.data)) ? sizeof(req.data) : len;
649 req.len = l;
656 if (ioctl(ii->s, SIOCGI2C, ii->ifr) != 0) {
657 ii->error = errno;
658 return (errno);
659 }
650 if (ioctl(ii->s, SIOCGI2C, ii->ifr) != 0) {
651 ii->error = errno;
652 return (errno);
653 }
660 memcpy(&buf[i], ixreq.data, 1);
654
655 memcpy(&buf[i], req.data, l);
656 len -= l;
657 i += l;
658 req.offset += l;
661 }
662
663 return (0);
664}
665
659 }
660
661 return (0);
662}
663
666/* Generic handler */
667static int
668read_i2c_generic(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
669 caddr_t buf)
670{
671
672 ii->error = EINVAL;
673 return (-1);
674}
675
676static void
677print_qsfp_status(struct i2c_info *ii, int verbose)
678{
679 char buf[80], buf2[40], buf3[40];
680 uint8_t diag_type;
681 int i;
682
683 /* Read diagnostic monitoring type */

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

761 }
762}
763
764void
765sfp_status(int s, struct ifreq *ifr, int verbose)
766{
767 struct i2c_info ii;
768
664static void
665print_qsfp_status(struct i2c_info *ii, int verbose)
666{
667 char buf[80], buf2[40], buf3[40];
668 uint8_t diag_type;
669 int i;
670
671 /* Read diagnostic monitoring type */

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

749 }
750}
751
752void
753sfp_status(int s, struct ifreq *ifr, int verbose)
754{
755 struct i2c_info ii;
756
757 memset(&ii, 0, sizeof(ii));
769 /* Prepare necessary into to pass to NIC handler */
770 ii.s = s;
771 ii.ifr = ifr;
772
773 /*
774 * Check if we have i2c support for particular driver.
775 * TODO: Determine driver by original name.
776 */
758 /* Prepare necessary into to pass to NIC handler */
759 ii.s = s;
760 ii.ifr = ifr;
761
762 /*
763 * Check if we have i2c support for particular driver.
764 * TODO: Determine driver by original name.
765 */
777 memset(&ii, 0, sizeof(ii));
778 if (strncmp(ifr->ifr_name, "ix", 2) == 0) {
766 if (strncmp(ifr->ifr_name, "ix", 2) == 0) {
779 ii.f = read_i2c_ixgbe;
767 ii.f = read_i2c_generic;
780 print_sfp_status(&ii, verbose);
781 } else if (strncmp(ifr->ifr_name, "cxl", 3) == 0) {
782 ii.port_id = atoi(&ifr->ifr_name[3]);
783 ii.f = read_i2c_generic;
784 ii.cfd = -1;
785 print_qsfp_status(&ii, verbose);
786 } else
787 return;
788}
789
768 print_sfp_status(&ii, verbose);
769 } else if (strncmp(ifr->ifr_name, "cxl", 3) == 0) {
770 ii.port_id = atoi(&ifr->ifr_name[3]);
771 ii.f = read_i2c_generic;
772 ii.cfd = -1;
773 print_qsfp_status(&ii, verbose);
774 } else
775 return;
776}
777