1 Signed-off-by: David Daney <ddaney@caviumnetworks.com>
3 arch/mips/include/asm/octeon/cvmx-mdio.h | 577 +++++++++++++++++++++
4 drivers/net/Kconfig | 8 +
5 drivers/net/Makefile | 1 +
6 drivers/net/octeon/Makefile | 11 +
7 drivers/net/octeon/cvmx-mgmt-port.c | 818 ++++++++++++++++++++++++++++++
8 drivers/net/octeon/cvmx-mgmt-port.h | 168 ++++++
9 drivers/net/octeon/octeon-mgmt-port.c | 389 ++++++++++++++
10 7 files changed, 1972 insertions(+), 0 deletions(-)
11 create mode 100644 arch/mips/include/asm/octeon/cvmx-mdio.h
12 create mode 100644 drivers/net/octeon/Makefile
13 create mode 100644 drivers/net/octeon/cvmx-mgmt-port.c
14 create mode 100644 drivers/net/octeon/cvmx-mgmt-port.h
15 create mode 100644 drivers/net/octeon/octeon-mgmt-port.c
18 +++ b/arch/mips/include/asm/octeon/cvmx-mdio.h
20 +/***********************license start***************
21 + * Author: Cavium Networks
23 + * Contact: support@caviumnetworks.com
24 + * This file is part of the OCTEON SDK
26 + * Copyright (c) 2003-2008 Cavium Networks
28 + * This file is free software; you can redistribute it and/or modify
29 + * it under the terms of the GNU General Public License, Version 2, as
30 + * published by the Free Software Foundation.
32 + * This file is distributed in the hope that it will be useful, but
33 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
34 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
35 + * NONINFRINGEMENT. See the GNU General Public License for more
38 + * You should have received a copy of the GNU General Public License
39 + * along with this file; if not, write to the Free Software
40 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41 + * or visit http://www.gnu.org/licenses/.
43 + * This file may also be available under a different license from Cavium.
44 + * Contact Cavium Networks for more information
45 + ***********************license end**************************************/
49 + * Interface to the SMI/MDIO hardware, including support for both IEEE 802.3
50 + * clause 22 and clause 45 operations.
54 +#ifndef __CVMX_MIO_H__
55 +#define __CVMX_MIO_H__
57 +#include "cvmx-smix-defs.h"
60 + * PHY register 0 from the 802.3 spec
62 +#define CVMX_MDIO_PHY_REG_CONTROL 0
63 +union cvmx_mdio_phy_reg_control {
67 + uint16_t loopback:1;
68 + uint16_t speed_lsb:1;
69 + uint16_t autoneg_enable:1;
70 + uint16_t power_down:1;
72 + uint16_t restart_autoneg:1;
74 + uint16_t collision_test:1;
75 + uint16_t speed_msb:1;
76 + uint16_t unidirectional_enable:1;
77 + uint16_t reserved_0_4:5;
82 + * PHY register 1 from the 802.3 spec
84 +#define CVMX_MDIO_PHY_REG_STATUS 1
85 +union cvmx_mdio_phy_reg_status {
88 + uint16_t capable_100base_t4:1;
89 + uint16_t capable_100base_x_full:1;
90 + uint16_t capable_100base_x_half:1;
91 + uint16_t capable_10_full:1;
92 + uint16_t capable_10_half:1;
93 + uint16_t capable_100base_t2_full:1;
94 + uint16_t capable_100base_t2_half:1;
95 + uint16_t capable_extended_status:1;
96 + uint16_t capable_unidirectional:1;
97 + uint16_t capable_mf_preamble_suppression:1;
98 + uint16_t autoneg_complete:1;
99 + uint16_t remote_fault:1;
100 + uint16_t capable_autoneg:1;
101 + uint16_t link_status:1;
102 + uint16_t jabber_detect:1;
103 + uint16_t capable_extended_registers:1;
109 + * PHY register 2 from the 802.3 spec
111 +#define CVMX_MDIO_PHY_REG_ID1 2
112 +union cvmx_mdio_phy_reg_id1 {
115 + uint16_t oui_bits_3_18;
120 + * PHY register 3 from the 802.3 spec
122 +#define CVMX_MDIO_PHY_REG_ID2 3
123 +union cvmx_mdio_phy_reg_id2 {
126 + uint16_t oui_bits_19_24:6;
128 + uint16_t revision:4;
133 + * PHY register 4 from the 802.3 spec
135 +#define CVMX_MDIO_PHY_REG_AUTONEG_ADVER 4
136 +union cvmx_mdio_phy_reg_autoneg_adver {
139 + uint16_t next_page:1;
140 + uint16_t reserved_14:1;
141 + uint16_t remote_fault:1;
142 + uint16_t reserved_12:1;
143 + uint16_t asymmetric_pause:1;
145 + uint16_t advert_100base_t4:1;
146 + uint16_t advert_100base_tx_full:1;
147 + uint16_t advert_100base_tx_half:1;
148 + uint16_t advert_10base_tx_full:1;
149 + uint16_t advert_10base_tx_half:1;
150 + uint16_t selector:5;
155 + * PHY register 5 from the 802.3 spec
157 +#define CVMX_MDIO_PHY_REG_LINK_PARTNER_ABILITY 5
158 +union cvmx_mdio_phy_reg_link_partner_ability {
161 + uint16_t next_page:1;
163 + uint16_t remote_fault:1;
164 + uint16_t reserved_12:1;
165 + uint16_t asymmetric_pause:1;
167 + uint16_t advert_100base_t4:1;
168 + uint16_t advert_100base_tx_full:1;
169 + uint16_t advert_100base_tx_half:1;
170 + uint16_t advert_10base_tx_full:1;
171 + uint16_t advert_10base_tx_half:1;
172 + uint16_t selector:5;
177 + * PHY register 6 from the 802.3 spec
179 +#define CVMX_MDIO_PHY_REG_AUTONEG_EXPANSION 6
180 +union cvmx_mdio_phy_reg_autoneg_expansion {
183 + uint16_t reserved_5_15:11;
184 + uint16_t parallel_detection_fault:1;
185 + uint16_t link_partner_next_page_capable:1;
186 + uint16_t local_next_page_capable:1;
187 + uint16_t page_received:1;
188 + uint16_t link_partner_autoneg_capable:1;
194 + * PHY register 9 from the 802.3 spec
196 +#define CVMX_MDIO_PHY_REG_CONTROL_1000 9
197 +union cvmx_mdio_phy_reg_control_1000 {
200 + uint16_t test_mode:3;
201 + uint16_t manual_master_slave:1;
203 + uint16_t port_type:1;
204 + uint16_t advert_1000base_t_full:1;
205 + uint16_t advert_1000base_t_half:1;
206 + uint16_t reserved_0_7:8;
211 + * PHY register 10 from the 802.3 spec
213 +#define CVMX_MDIO_PHY_REG_STATUS_1000 10
214 +union cvmx_mdio_phy_reg_status_1000 {
217 + uint16_t master_slave_fault:1;
218 + uint16_t is_master:1;
219 + uint16_t local_receiver_ok:1;
220 + uint16_t remote_receiver_ok:1;
221 + uint16_t remote_capable_1000base_t_full:1;
222 + uint16_t remote_capable_1000base_t_half:1;
223 + uint16_t reserved_8_9:2;
224 + uint16_t idle_error_count:8;
229 + * PHY register 15 from the 802.3 spec
231 +#define CVMX_MDIO_PHY_REG_EXTENDED_STATUS 15
232 +union cvmx_mdio_phy_reg_extended_status {
235 + uint16_t capable_1000base_x_full:1;
236 + uint16_t capable_1000base_x_half:1;
237 + uint16_t capable_1000base_t_full:1;
238 + uint16_t capable_1000base_t_half:1;
239 + uint16_t reserved_0_11:12;
244 + * PHY register 13 from the 802.3 spec
246 +#define CVMX_MDIO_PHY_REG_MMD_CONTROL 13
247 +union cvmx_mdio_phy_reg_mmd_control {
250 + uint16_t function:2;
251 + uint16_t reserved_5_13:9;
257 + * PHY register 14 from the 802.3 spec
259 +#define CVMX_MDIO_PHY_REG_MMD_ADDRESS_DATA 14
260 +union cvmx_mdio_phy_reg_mmd_address_data {
263 + uint16_t address_data:16;
267 +/* Operating request encodings. */
268 +#define MDIO_CLAUSE_22_WRITE 0
269 +#define MDIO_CLAUSE_22_READ 1
271 +#define MDIO_CLAUSE_45_ADDRESS 0
272 +#define MDIO_CLAUSE_45_WRITE 1
273 +#define MDIO_CLAUSE_45_READ_INC 2
274 +#define MDIO_CLAUSE_45_READ 3
276 +/* MMD identifiers, mostly for accessing devices withing XENPAK modules. */
277 +#define CVMX_MMD_DEVICE_PMA_PMD 1
278 +#define CVMX_MMD_DEVICE_WIS 2
279 +#define CVMX_MMD_DEVICE_PCS 3
280 +#define CVMX_MMD_DEVICE_PHY_XS 4
281 +#define CVMX_MMD_DEVICE_DTS_XS 5
282 +#define CVMX_MMD_DEVICE_TC 6
283 +#define CVMX_MMD_DEVICE_CL22_EXT 29
284 +#define CVMX_MMD_DEVICE_VENDOR_1 30
285 +#define CVMX_MMD_DEVICE_VENDOR_2 31
288 + * Perform an MII read. This function is used to read PHY
289 + * registers controlling auto negotiation.
291 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
292 + * support multiple busses.
293 + * @phy_id: The MII phy id
294 + * @location: Register location to read
296 + * Returns Result from the read or -1 on failure
298 +static inline int cvmx_mdio_read(int bus_id, int phy_id, int location)
300 + union cvmx_smix_cmd smi_cmd;
301 + union cvmx_smix_rd_dat smi_rd;
302 + int timeout = 1000;
305 + smi_cmd.s.phy_op = MDIO_CLAUSE_22_READ;
306 + smi_cmd.s.phy_adr = phy_id;
307 + smi_cmd.s.reg_adr = location;
308 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
312 + smi_rd.u64 = cvmx_read_csr(CVMX_SMIX_RD_DAT(bus_id));
313 + } while (smi_rd.s.pending && timeout--);
316 + return smi_rd.s.dat;
322 + * Perform an MII write. This function is used to write PHY
323 + * registers controlling auto negotiation.
325 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
326 + * support multiple busses.
327 + * @phy_id: The MII phy id
328 + * @location: Register location to write
329 + * @val: Value to write
331 + * Returns -1 on error
334 +static inline int cvmx_mdio_write(int bus_id, int phy_id, int location, int val)
336 + union cvmx_smix_cmd smi_cmd;
337 + union cvmx_smix_wr_dat smi_wr;
338 + int timeout = 1000;
341 + smi_wr.s.dat = val;
342 + cvmx_write_csr(CVMX_SMIX_WR_DAT(bus_id), smi_wr.u64);
345 + smi_cmd.s.phy_op = MDIO_CLAUSE_22_WRITE;
346 + smi_cmd.s.phy_adr = phy_id;
347 + smi_cmd.s.reg_adr = location;
348 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
352 + smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id));
353 + } while (smi_wr.s.pending && --timeout);
361 + * Perform an IEEE 802.3 clause 45 MII read using clause 22 operations. This
362 + * function is used to read PHY registers controlling auto negotiation.
364 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
365 + * support multiple busses.
366 + * @phy_id: The MII phy id
367 + * @device: MDIO Managable Device (MMD) id
368 + * @location: Register location to read
370 + * Returns Result from the read or -1 on failure
373 +static inline int cvmx_mdio_45_via_22_read(int bus_id, int phy_id, int device,
376 + union cvmx_mdio_phy_reg_mmd_control mmd_control;
379 + * a) To Register 13, write the Function field to 00 (address)
380 + * and DEVAD field to the device address value for the
383 + mmd_control.u16 = 0;
384 + mmd_control.s.function = MDIO_CLAUSE_45_ADDRESS;
385 + mmd_control.s.devad = device;
386 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_CONTROL,
390 + * b) To Register 14, write the desired address value to the
391 + * MMD's address register;
393 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_ADDRESS_DATA,
397 + * c) To Register 13, write the Function field to 01 (Data, no
398 + * post increment) and DEVAD field to the same device
399 + * address value for the desired MMD;
401 + mmd_control.u16 = 0;
402 + mmd_control.s.function = MDIO_CLAUSE_45_READ;
403 + mmd_control.s.devad = device;
404 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_CONTROL,
408 + * d) From Register 14, read the content of the MMD's selected
411 + return cvmx_mdio_read(bus_id, phy_id,
412 + CVMX_MDIO_PHY_REG_MMD_ADDRESS_DATA);
416 + * Perform an IEEE 802.3 clause 45 MII write using clause 22
417 + * operations. This function is used to write PHY registers
418 + * controlling auto negotiation.
420 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
421 + * support multiple busses.
422 + * @phy_id: The MII phy id
423 + * @device: MDIO Managable Device (MMD) id
424 + * @location: Register location to write
425 + * @val: Value to write
427 + * Returns -1 on error
430 +static inline int cvmx_mdio_45_via_22_write(int bus_id, int phy_id, int device,
431 + int location, int val)
433 + union cvmx_mdio_phy_reg_mmd_control mmd_control;
436 + * a) To Register 13, write the Function field to 00 (address)
437 + * and DEVAD field to the device address value for the
440 + mmd_control.u16 = 0;
441 + mmd_control.s.function = MDIO_CLAUSE_45_ADDRESS;
442 + mmd_control.s.devad = device;
443 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_CONTROL,
447 + * b) To Register 14, write the desired address value to the
448 + * MMD's address register;
450 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_ADDRESS_DATA,
454 + * c) To Register 13, write the Function field to 01 (Data, no
455 + * post increment) and DEVAD field to the same device
456 + * address value for the desired MMD;
458 + mmd_control.u16 = 0;
459 + mmd_control.s.function = MDIO_CLAUSE_45_READ;
460 + mmd_control.s.devad = device;
461 + cvmx_mdio_write(bus_id, phy_id, CVMX_MDIO_PHY_REG_MMD_CONTROL,
465 + * d) To Register 14, write the content of the MMD's selected
468 + return cvmx_mdio_write(bus_id, phy_id,
469 + CVMX_MDIO_PHY_REG_MMD_ADDRESS_DATA, val);
475 + * Perform an IEEE 802.3 clause 45 MII read. This function is used to read PHY
476 + * registers controlling auto negotiation.
478 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
479 + * support multiple busses.
480 + * @phy_id: The MII phy id
481 + * @device: MDIO Managable Device (MMD) id
482 + * @location: Register location to read
484 + * Returns Result from the read or -1 on failure
487 +static inline int cvmx_mdio_45_read(int bus_id, int phy_id, int device,
490 + union cvmx_smix_cmd smi_cmd;
491 + union cvmx_smix_rd_dat smi_rd;
492 + union cvmx_smix_wr_dat smi_wr;
493 + int timeout = 1000;
496 + smi_wr.s.dat = location;
497 + cvmx_write_csr(CVMX_SMIX_WR_DAT(bus_id), smi_wr.u64);
500 + smi_cmd.s.phy_op = MDIO_CLAUSE_45_ADDRESS;
501 + smi_cmd.s.phy_adr = phy_id;
502 + smi_cmd.s.reg_adr = device;
503 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
507 + smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id));
508 + } while (smi_wr.s.pending && --timeout);
513 + smi_cmd.s.phy_op = MDIO_CLAUSE_45_READ;
514 + smi_cmd.s.phy_adr = phy_id;
515 + smi_cmd.s.reg_adr = device;
516 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
520 + smi_rd.u64 = cvmx_read_csr(CVMX_SMIX_RD_DAT(bus_id));
521 + } while (smi_rd.s.pending && timeout--);
524 + cvmx_dprintf("cvmx_mdio_45_read: bus_id %d phy_id %2d "
525 + "device %2d register %2d TIME OUT\n",
526 + bus_id, phy_id, device, location);
529 + return smi_rd.s.dat;
531 + cvmx_dprintf("cvmx_mdio_45_read: bus_id %d phy_id %2d "
532 + "device %2d register %2d INVALID READ\n",
533 + bus_id, phy_id, device, location);
539 + * Perform an IEEE 802.3 clause 45 MII write. This function is used to
540 + * write PHY registers controlling auto negotiation.
542 + * @bus_id: MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
543 + * support multiple busses.
544 + * @phy_id: The MII phy id
545 + * @device: MDIO Managable Device (MMD) id
546 + * @location: Register location to write
547 + * @val: Value to write
549 + * Returns -1 on error
552 +static inline int cvmx_mdio_45_write(int bus_id, int phy_id, int device,
553 + int location, int val)
555 + union cvmx_smix_cmd smi_cmd;
556 + union cvmx_smix_wr_dat smi_wr;
557 + int timeout = 1000;
560 + smi_wr.s.dat = location;
561 + cvmx_write_csr(CVMX_SMIX_WR_DAT(bus_id), smi_wr.u64);
564 + smi_cmd.s.phy_op = MDIO_CLAUSE_45_ADDRESS;
565 + smi_cmd.s.phy_adr = phy_id;
566 + smi_cmd.s.reg_adr = device;
567 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
571 + smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id));
572 + } while (smi_wr.s.pending && --timeout);
577 + smi_wr.s.dat = val;
578 + cvmx_write_csr(CVMX_SMIX_WR_DAT(bus_id), smi_wr.u64);
581 + smi_cmd.s.phy_op = MDIO_CLAUSE_45_WRITE;
582 + smi_cmd.s.phy_adr = phy_id;
583 + smi_cmd.s.reg_adr = device;
584 + cvmx_write_csr(CVMX_SMIX_CMD(bus_id), smi_cmd.u64);
588 + smi_wr.u64 = cvmx_read_csr(CVMX_SMIX_WR_DAT(bus_id));
589 + } while (smi_wr.s.pending && --timeout);
597 --- a/drivers/net/Kconfig
598 +++ b/drivers/net/Kconfig
599 @@ -2035,6 +2035,14 @@ config ATL2
600 To compile this driver as a module, choose M here. The module
604 + tristate "OCTEON Management port ethernet driver (CN5XXX)"
605 + depends on CPU_CAVIUM_OCTEON
608 + This option enables the ethernet driver for the management port on
609 + CN52XX, CN57XX, CN56XX, CN55XX, and CN54XX chips.
611 source "drivers/net/fs_enet/Kconfig"
614 --- a/drivers/net/Makefile
615 +++ b/drivers/net/Makefile
616 @@ -234,6 +234,7 @@ pasemi_mac_driver-objs := pasemi_mac.o p
617 obj-$(CONFIG_MLX4_CORE) += mlx4/
618 obj-$(CONFIG_ENC28J60) += enc28j60.o
619 obj-$(CONFIG_ETHOC) += ethoc.o
620 +obj-$(CONFIG_OCTEON_MGMT) += octeon/
622 obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o
625 +++ b/drivers/net/octeon/Makefile
627 +# Makefile for the Cavium OCTEON Ethernet drivers.
629 +# This file is subject to the terms and conditions of the GNU General Public
630 +# License. See the file "COPYING" in the main directory of this archive
633 +# Copyright (C) 2008 Cavium Networks
635 +obj-$(CONFIG_OCTEON_MGMT) += octeon_mgmt.o
637 +octeon_mgmt-objs := octeon-mgmt-port.o cvmx-mgmt-port.o
638 \ No newline at end of file
640 +++ b/drivers/net/octeon/cvmx-mgmt-port.c
642 +/***********************license start***************
643 + * Author: Cavium Networks
645 + * Contact: support@caviumnetworks.com
646 + * This file is part of the OCTEON SDK
648 + * Copyright (c) 2003-2008 Cavium Networks
650 + * This file is free software; you can redistribute it and/or modify
651 + * it under the terms of the GNU General Public License, Version 2, as
652 + * published by the Free Software Foundation.
654 + * This file is distributed in the hope that it will be useful, but
655 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
656 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
657 + * NONINFRINGEMENT. See the GNU General Public License for more
660 + * You should have received a copy of the GNU General Public License
661 + * along with this file; if not, write to the Free Software
662 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
663 + * or visit http://www.gnu.org/licenses/.
665 + * This file may also be available under a different license from Cavium.
666 + * Contact Cavium Networks for more information
667 + ***********************license end**************************************/
671 + * Support functions for managing the MII management port
675 +#include <asm/octeon/octeon.h>
676 +#include <asm/octeon/cvmx-spinlock.h>
677 +#include <asm/octeon/cvmx-bootmem.h>
678 +#include <asm/octeon/cvmx-mdio.h>
680 +#include <asm/octeon/cvmx-mixx-defs.h>
681 +#include <asm/octeon/cvmx-agl-defs.h>
683 +#include "cvmx-mgmt-port.h"
685 +#define CVMX_MGMT_PORT_NUM_PORTS 2
686 +/* Number of TX ring buffer entries and buffers */
687 +#define CVMX_MGMT_PORT_NUM_TX_BUFFERS 16
688 +/* Number of RX ring buffer entries and buffers */
689 +#define CVMX_MGMT_PORT_NUM_RX_BUFFERS 128
691 +#define CVMX_MGMT_PORT_TX_BUFFER_SIZE 12288
692 +#define CVMX_MGMT_PORT_RX_BUFFER_SIZE 1536
695 + * Format of the TX/RX ring buffer entries
697 +union cvmx_mgmt_port_ring_entry {
700 + uint64_t reserved_62_63:2;
701 + /* Length of the buffer/packet in bytes */
703 + /* The RX error code */
705 + /* Physical address of the buffer */
711 + * Per port state required for each mgmt port
713 +struct cvmx_mgmt_port_state {
714 + /* Used for exclusive access to this structure */
715 + cvmx_spinlock_t lock;
716 + /* Where the next TX will write in the tx_ring and tx_buffers */
717 + int tx_write_index;
718 + /* Where the next RX will be in the rx_ring and rx_buffers */
720 + /* The SMI/MDIO PHY address */
722 + /* Our MAC address */
724 + union cvmx_mgmt_port_ring_entry tx_ring[CVMX_MGMT_PORT_NUM_TX_BUFFERS];
725 + union cvmx_mgmt_port_ring_entry rx_ring[CVMX_MGMT_PORT_NUM_RX_BUFFERS];
726 + char tx_buffers[CVMX_MGMT_PORT_NUM_TX_BUFFERS]
727 + [CVMX_MGMT_PORT_TX_BUFFER_SIZE];
728 + char rx_buffers[CVMX_MGMT_PORT_NUM_RX_BUFFERS]
729 + [CVMX_MGMT_PORT_RX_BUFFER_SIZE];
733 + * Pointers to each mgmt port's state
735 +struct cvmx_mgmt_port_state *cvmx_mgmt_port_state_ptr;
738 + * Return the number of management ports supported by this chip
740 + * Returns Number of ports
742 +int __cvmx_mgmt_port_num_ports(void)
744 + if (OCTEON_IS_MODEL(OCTEON_CN56XX))
746 + else if (OCTEON_IS_MODEL(OCTEON_CN52XX))
753 + * Called to initialize a management port for use. Multiple calls
754 + * to this function accross applications is safe.
756 + * @port: Port to initialize
758 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
760 +enum cvmx_mgmt_port_result cvmx_mgmt_port_initialize(int port)
762 + char *alloc_name = "cvmx_mgmt_port";
763 + union cvmx_mixx_oring1 oring1;
764 + union cvmx_mixx_ctl mix_ctl;
766 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
767 + return CVMX_MGMT_PORT_INVALID_PARAM;
769 + cvmx_mgmt_port_state_ptr =
770 + cvmx_bootmem_alloc_named(CVMX_MGMT_PORT_NUM_PORTS *
771 + sizeof(struct cvmx_mgmt_port_state), 128,
773 + if (cvmx_mgmt_port_state_ptr) {
774 + memset(cvmx_mgmt_port_state_ptr, 0,
775 + CVMX_MGMT_PORT_NUM_PORTS *
776 + sizeof(struct cvmx_mgmt_port_state));
778 + struct cvmx_bootmem_named_block_desc *block_desc =
779 + cvmx_bootmem_find_named_block(alloc_name);
781 + cvmx_mgmt_port_state_ptr =
782 + cvmx_phys_to_ptr(block_desc->base_addr);
784 + cvmx_dprintf("ERROR: cvmx_mgmt_port_initialize: "
785 + "Unable to get named block %s.\n",
787 + return CVMX_MGMT_PORT_NO_MEMORY;
792 + * Reset the MIX block if the previous user had a different TX
795 + mix_ctl.u64 = cvmx_read_csr(CVMX_MIXX_CTL(port));
796 + if (!mix_ctl.s.reset) {
797 + oring1.u64 = cvmx_read_csr(CVMX_MIXX_ORING1(port));
798 + if (oring1.s.osize != CVMX_MGMT_PORT_NUM_TX_BUFFERS) {
799 + mix_ctl.u64 = cvmx_read_csr(CVMX_MIXX_CTL(port));
801 + cvmx_write_csr(CVMX_MIXX_CTL(port), mix_ctl.u64);
804 + cvmx_read_csr(CVMX_MIXX_CTL(port));
805 + } while (mix_ctl.s.busy);
806 + mix_ctl.s.reset = 1;
807 + cvmx_write_csr(CVMX_MIXX_CTL(port), mix_ctl.u64);
808 + cvmx_read_csr(CVMX_MIXX_CTL(port));
809 + memset(cvmx_mgmt_port_state_ptr + port, 0,
810 + sizeof(struct cvmx_mgmt_port_state));
814 + if (cvmx_mgmt_port_state_ptr[port].tx_ring[0].u64 == 0) {
815 + struct cvmx_mgmt_port_state *state =
816 + cvmx_mgmt_port_state_ptr + port;
818 + union cvmx_mixx_bist mix_bist;
819 + union cvmx_agl_gmx_bist agl_gmx_bist;
820 + union cvmx_mixx_oring1 oring1;
821 + union cvmx_mixx_iring1 iring1;
822 + union cvmx_mixx_ctl mix_ctl;
824 + /* Make sure BIST passed */
825 + mix_bist.u64 = cvmx_read_csr(CVMX_MIXX_BIST(port));
827 + cvmx_dprintf("WARNING: cvmx_mgmt_port_initialize: "
828 + "Managment port MIX failed BIST "
830 + (unsigned long long)mix_bist.u64);
832 + agl_gmx_bist.u64 = cvmx_read_csr(CVMX_AGL_GMX_BIST);
833 + if (agl_gmx_bist.u64)
834 + cvmx_dprintf("WARNING: cvmx_mgmt_port_initialize: "
835 + "Managment port AGL failed BIST "
837 + (unsigned long long)agl_gmx_bist.u64);
839 + /* Clear all state information */
840 + memset(state, 0, sizeof(*state));
842 + /* Take the control logic out of reset */
843 + mix_ctl.u64 = cvmx_read_csr(CVMX_MIXX_CTL(port));
844 + mix_ctl.s.reset = 0;
845 + cvmx_write_csr(CVMX_MIXX_CTL(port), mix_ctl.u64);
847 + /* Set the PHY address */
848 + if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
849 + state->phy_id = -1;
851 + /* Will need to be change to match the board */
852 + state->phy_id = port;
854 + /* Create a default MAC address */
855 + state->mac = 0x000000dead000000ull;
856 + state->mac += 0xffffff & CAST64(state);
858 + /* Setup the TX ring */
859 + for (i = 0; i < CVMX_MGMT_PORT_NUM_TX_BUFFERS; i++) {
860 + state->tx_ring[i].s.len = CVMX_MGMT_PORT_TX_BUFFER_SIZE;
861 + state->tx_ring[i].s.addr =
862 + cvmx_ptr_to_phys(state->tx_buffers[i]);
865 + /* Tell the HW where the TX ring is */
867 + oring1.s.obase = cvmx_ptr_to_phys(state->tx_ring) >> 3;
868 + oring1.s.osize = CVMX_MGMT_PORT_NUM_TX_BUFFERS;
870 + cvmx_write_csr(CVMX_MIXX_ORING1(port), oring1.u64);
872 + /* Setup the RX ring */
873 + for (i = 0; i < CVMX_MGMT_PORT_NUM_RX_BUFFERS; i++) {
874 + /* This size is -8 due to an errata for CN56XX pass 1 */
875 + state->rx_ring[i].s.len =
876 + CVMX_MGMT_PORT_RX_BUFFER_SIZE - 8;
877 + state->rx_ring[i].s.addr =
878 + cvmx_ptr_to_phys(state->rx_buffers[i]);
881 + /* Tell the HW where the RX ring is */
883 + iring1.s.ibase = cvmx_ptr_to_phys(state->rx_ring) >> 3;
884 + iring1.s.isize = CVMX_MGMT_PORT_NUM_RX_BUFFERS;
886 + cvmx_write_csr(CVMX_MIXX_IRING1(port), iring1.u64);
887 + cvmx_write_csr(CVMX_MIXX_IRING2(port),
888 + CVMX_MGMT_PORT_NUM_RX_BUFFERS);
890 + /* Disable the external input/output */
891 + cvmx_mgmt_port_disable(port);
893 + /* Set the MAC address filtering up */
894 + cvmx_mgmt_port_set_mac(port, state->mac);
897 + * Set the default max size to an MTU of 1500 with L2
900 + cvmx_mgmt_port_set_max_packet_size(port, 1518);
903 + * Enable the port HW. Packets are not allowed until
904 + * cvmx_mgmt_port_enable() is called.
907 + /* Strip the ending CRC */
908 + mix_ctl.s.crc_strip = 1;
909 + /* Enable the port */
911 + /* Arbitration mode */
912 + mix_ctl.s.nbtarb = 0;
913 + /* MII CB-request FIFO programmable high watermark */
914 + mix_ctl.s.mrq_hwm = 1;
915 + cvmx_write_csr(CVMX_MIXX_CTL(port), mix_ctl.u64);
917 + if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
918 + || OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_X)) {
920 + * Force compensation values, as they are not
921 + * determined properly by HW.
923 + union cvmx_agl_gmx_drv_ctl drv_ctl;
925 + drv_ctl.u64 = cvmx_read_csr(CVMX_AGL_GMX_DRV_CTL);
927 + drv_ctl.s.byp_en1 = 1;
928 + drv_ctl.s.nctl1 = 6;
929 + drv_ctl.s.pctl1 = 6;
931 + drv_ctl.s.byp_en = 1;
932 + drv_ctl.s.nctl = 6;
933 + drv_ctl.s.pctl = 6;
935 + cvmx_write_csr(CVMX_AGL_GMX_DRV_CTL, drv_ctl.u64);
938 + return CVMX_MGMT_PORT_SUCCESS;
942 + * Shutdown a management port. This currently disables packet IO
943 + * but leaves all hardware and buffers. Another application can then
944 + * call initialize() without redoing the hardware setup.
946 + * @port: Management port
948 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
950 +enum cvmx_mgmt_port_result cvmx_mgmt_port_shutdown(int port)
952 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
953 + return CVMX_MGMT_PORT_INVALID_PARAM;
955 + /* Stop packets from comming in */
956 + cvmx_mgmt_port_disable(port);
959 + * We don't free any memory so the next intialize can reuse
962 + return CVMX_MGMT_PORT_SUCCESS;
966 + * Enable packet IO on a management port
968 + * @port: Management port
970 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
972 +enum cvmx_mgmt_port_result cvmx_mgmt_port_enable(int port)
974 + struct cvmx_mgmt_port_state *state;
975 + union cvmx_agl_gmx_prtx_cfg agl_gmx_prtx;
976 + union cvmx_agl_gmx_inf_mode agl_gmx_inf_mode;
977 + union cvmx_agl_gmx_rxx_frm_ctl rxx_frm_ctl;
979 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
980 + return CVMX_MGMT_PORT_INVALID_PARAM;
982 + state = cvmx_mgmt_port_state_ptr + port;
984 + cvmx_spinlock_lock(&state->lock);
986 + rxx_frm_ctl.u64 = 0;
987 + rxx_frm_ctl.s.pre_align = 1;
989 + * When set, disables the length check for non-min sized pkts
990 + * with padding in the client data.
992 + rxx_frm_ctl.s.pad_len = 1;
993 + /* When set, disables the length check for VLAN pkts */
994 + rxx_frm_ctl.s.vlan_len = 1;
995 + /* When set, PREAMBLE checking is less strict */
996 + rxx_frm_ctl.s.pre_free = 1;
997 + /* Control Pause Frames can match station SMAC */
998 + rxx_frm_ctl.s.ctl_smac = 0;
999 + /* Control Pause Frames can match globally assign Multicast address */
1000 + rxx_frm_ctl.s.ctl_mcst = 1;
1001 + /* Forward pause information to TX block */
1002 + rxx_frm_ctl.s.ctl_bck = 1;
1003 + /* Drop Control Pause Frames */
1004 + rxx_frm_ctl.s.ctl_drp = 1;
1005 + /* Strip off the preamble */
1006 + rxx_frm_ctl.s.pre_strp = 1;
1008 + * This port is configured to send PREAMBLE+SFD to begin every
1009 + * frame. GMX checks that the PREAMBLE is sent correctly.
1011 + rxx_frm_ctl.s.pre_chk = 1;
1012 + cvmx_write_csr(CVMX_AGL_GMX_RXX_FRM_CTL(port), rxx_frm_ctl.u64);
1014 + /* Enable the AGL block */
1015 + agl_gmx_inf_mode.u64 = 0;
1016 + agl_gmx_inf_mode.s.en = 1;
1017 + cvmx_write_csr(CVMX_AGL_GMX_INF_MODE, agl_gmx_inf_mode.u64);
1019 + /* Configure the port duplex and enables */
1020 + agl_gmx_prtx.u64 = cvmx_read_csr(CVMX_AGL_GMX_PRTX_CFG(port));
1021 + agl_gmx_prtx.s.tx_en = 1;
1022 + agl_gmx_prtx.s.rx_en = 1;
1023 + if (cvmx_mgmt_port_get_link(port) < 0)
1024 + agl_gmx_prtx.s.duplex = 0;
1026 + agl_gmx_prtx.s.duplex = 1;
1027 + agl_gmx_prtx.s.en = 1;
1028 + cvmx_write_csr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64);
1030 + cvmx_spinlock_unlock(&state->lock);
1031 + return CVMX_MGMT_PORT_SUCCESS;
1035 + * Disable packet IO on a management port
1037 + * @port: Management port
1039 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1041 +enum cvmx_mgmt_port_result cvmx_mgmt_port_disable(int port)
1043 + struct cvmx_mgmt_port_state *state;
1044 + union cvmx_agl_gmx_prtx_cfg agl_gmx_prtx;
1046 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1047 + return CVMX_MGMT_PORT_INVALID_PARAM;
1049 + state = cvmx_mgmt_port_state_ptr + port;
1051 + cvmx_spinlock_lock(&state->lock);
1053 + agl_gmx_prtx.u64 = cvmx_read_csr(CVMX_AGL_GMX_PRTX_CFG(port));
1054 + agl_gmx_prtx.s.en = 0;
1055 + cvmx_write_csr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64);
1057 + cvmx_spinlock_unlock(&state->lock);
1058 + return CVMX_MGMT_PORT_SUCCESS;
1062 + * Send a packet out the management port. The packet is copied so
1063 + * the input buffer isn't used after this call.
1065 + * @port: Management port
1066 + * @packet_len: Length of the packet to send. It does not include the final CRC
1067 + * @buffer: Packet data
1069 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1071 +enum cvmx_mgmt_port_result cvmx_mgmt_port_send(int port, int packet_len,
1074 + struct cvmx_mgmt_port_state *state;
1075 + union cvmx_mixx_oring2 mix_oring2;
1077 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1078 + return CVMX_MGMT_PORT_INVALID_PARAM;
1080 + /* Max sure the packet size is valid */
1081 + if ((packet_len < 1) || (packet_len > CVMX_MGMT_PORT_TX_BUFFER_SIZE))
1082 + return CVMX_MGMT_PORT_INVALID_PARAM;
1084 + if (buffer == NULL)
1085 + return CVMX_MGMT_PORT_INVALID_PARAM;
1087 + state = cvmx_mgmt_port_state_ptr + port;
1089 + cvmx_spinlock_lock(&state->lock);
1091 + mix_oring2.u64 = cvmx_read_csr(CVMX_MIXX_ORING2(port));
1092 + if (mix_oring2.s.odbell >= CVMX_MGMT_PORT_NUM_TX_BUFFERS - 1) {
1093 + /* No room for another packet */
1094 + cvmx_spinlock_unlock(&state->lock);
1095 + return CVMX_MGMT_PORT_NO_MEMORY;
1097 + /* Copy the packet into the output buffer */
1098 + memcpy(state->tx_buffers[state->tx_write_index], buffer,
1100 + /* Insert the source MAC */
1101 + memcpy(state->tx_buffers[state->tx_write_index] + 6,
1102 + ((char *)&state->mac) + 2, 6);
1103 + /* Update the TX ring buffer entry size */
1104 + state->tx_ring[state->tx_write_index].s.len = packet_len;
1105 + /* Increment our TX index */
1106 + state->tx_write_index =
1107 + (state->tx_write_index + 1) % CVMX_MGMT_PORT_NUM_TX_BUFFERS;
1108 + /* Ring the doorbell, send ing the packet */
1110 + cvmx_write_csr(CVMX_MIXX_ORING2(port), 1);
1111 + if (cvmx_read_csr(CVMX_MIXX_ORCNT(port)))
1112 + cvmx_write_csr(CVMX_MIXX_ORCNT(port),
1113 + cvmx_read_csr(CVMX_MIXX_ORCNT(port)));
1115 + cvmx_spinlock_unlock(&state->lock);
1116 + return CVMX_MGMT_PORT_SUCCESS;
1121 + * Receive a packet from the management port.
1123 + * @port: Management port
1124 + * @buffer_len: Size of the buffer to receive the packet into
1125 + * @buffer: Buffer to receive the packet into
1127 + * Returns The size of the packet, or a negative erorr code on failure. Zero
1128 + * means that no packets were available.
1130 +int cvmx_mgmt_port_receive(int port, int buffer_len, void *buffer)
1132 + union cvmx_mixx_ircnt mix_ircnt;
1133 + struct cvmx_mgmt_port_state *state;
1136 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1137 + return CVMX_MGMT_PORT_INVALID_PARAM;
1139 + /* Max sure the buffer size is valid */
1140 + if (buffer_len < 1)
1141 + return CVMX_MGMT_PORT_INVALID_PARAM;
1143 + if (buffer == NULL)
1144 + return CVMX_MGMT_PORT_INVALID_PARAM;
1146 + state = cvmx_mgmt_port_state_ptr + port;
1148 + cvmx_spinlock_lock(&state->lock);
1150 + /* Find out how many RX packets are pending */
1151 + mix_ircnt.u64 = cvmx_read_csr(CVMX_MIXX_IRCNT(port));
1152 + if (mix_ircnt.s.ircnt) {
1153 + void *source = state->rx_buffers[state->rx_read_index];
1154 + uint64_t *zero_check = source;
1156 + * CN56XX pass 1 has an errata where packets might
1157 + * start 8 bytes into the buffer instead of at their
1158 + * correct location. If the first 8 bytes is zero we
1159 + * assume this has happened.
1161 + if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X)
1162 + && (*zero_check == 0))
1164 + /* Start off with zero bytes received */
1167 + * While the completion code signals more data, copy
1168 + * the buffers into the user's data.
1170 + while (state->rx_ring[state->rx_read_index].s.code == 16) {
1171 + /* Only copy what will fit in the user's buffer */
1172 + int length = state->rx_ring[state->rx_read_index].s.len;
1173 + if (length > buffer_len)
1174 + length = buffer_len;
1175 + memcpy(buffer, source, length);
1177 + * Reduce the size of the buffer to the
1178 + * remaining space. If we run out we will
1179 + * signal an error when the code 15 buffer
1183 + buffer_len -= length;
1186 + * Update this buffer for reuse in future
1187 + * receives. This size is -8 due to an errata
1188 + * for CN56XX pass 1.
1190 + state->rx_ring[state->rx_read_index].s.code = 0;
1191 + state->rx_ring[state->rx_read_index].s.len =
1192 + CVMX_MGMT_PORT_RX_BUFFER_SIZE - 8;
1193 + state->rx_read_index =
1194 + (state->rx_read_index +
1195 + 1) % CVMX_MGMT_PORT_NUM_RX_BUFFERS;
1197 + * Zero the beginning of the buffer for use by
1198 + * the errata check.
1202 + /* Increment the number of RX buffers */
1203 + cvmx_write_csr(CVMX_MIXX_IRING2(port), 1);
1204 + source = state->rx_buffers[state->rx_read_index];
1205 + zero_check = source;
1208 + /* Check for the final good completion code */
1209 + if (state->rx_ring[state->rx_read_index].s.code == 15) {
1211 + state->rx_ring[state->rx_read_index].s.len) {
1213 + state->rx_ring[state->rx_read_index].s.len;
1214 + memcpy(buffer, source, length);
1217 + /* Not enough room for the packet */
1218 + cvmx_dprintf("ERROR: cvmx_mgmt_port_receive: "
1219 + "Packet (%d) larger than "
1220 + "supplied buffer (%d)\n",
1221 + state->rx_ring[state->rx_read_index].s.len,
1223 + result = CVMX_MGMT_PORT_NO_MEMORY;
1226 + union cvmx_agl_gmx_prtx_cfg agl_gmx_prtx;
1227 + cvmx_dprintf("ERROR: cvmx_mgmt_port_receive: Receive "
1228 + "error code %d. Packet dropped(Len %d)\n",
1229 + state->rx_ring[state->rx_read_index].s.code,
1230 + state->rx_ring[state->rx_read_index].s.len +
1232 + result = -state->rx_ring[state->rx_read_index].s.code;
1234 + /* Check to see if we need to change the duplex. */
1235 + agl_gmx_prtx.u64 =
1236 + cvmx_read_csr(CVMX_AGL_GMX_PRTX_CFG(port));
1237 + if (cvmx_mgmt_port_get_link(port) < 0)
1238 + agl_gmx_prtx.s.duplex = 0;
1240 + agl_gmx_prtx.s.duplex = 1;
1241 + cvmx_write_csr(CVMX_AGL_GMX_PRTX_CFG(port),
1242 + agl_gmx_prtx.u64);
1246 + * Clean out the ring buffer entry. This size is -8
1247 + * due to an errata for CN56XX pass 1.
1249 + state->rx_ring[state->rx_read_index].s.code = 0;
1250 + state->rx_ring[state->rx_read_index].s.len =
1251 + CVMX_MGMT_PORT_RX_BUFFER_SIZE - 8;
1252 + state->rx_read_index =
1253 + (state->rx_read_index + 1) % CVMX_MGMT_PORT_NUM_RX_BUFFERS;
1255 + * Zero the beginning of the buffer for use by the
1260 + /* Increment the number of RX buffers */
1261 + cvmx_write_csr(CVMX_MIXX_IRING2(port), 1);
1262 + /* Decrement the pending RX count */
1263 + cvmx_write_csr(CVMX_MIXX_IRCNT(port), 1);
1265 + /* No packets available */
1268 + cvmx_spinlock_unlock(&state->lock);
1273 + * Get the management port link status:
1274 + * 100 = 100Mbps, full duplex
1275 + * 10 = 10Mbps, full duplex
1277 + * -10 = 10Mpbs, half duplex
1278 + * -100 = 100Mbps, half duplex
1280 + * @port: Management port
1284 +int cvmx_mgmt_port_get_link(int port)
1286 + struct cvmx_mgmt_port_state *state;
1290 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1291 + return CVMX_MGMT_PORT_INVALID_PARAM;
1293 + state = cvmx_mgmt_port_state_ptr + port;
1295 + /* Assume 100Mbps if we don't know the PHY address */
1296 + if (state->phy_id == -1)
1299 + /* Read the PHY state */
1301 + cvmx_mdio_read(state->phy_id >> 8, state->phy_id & 0xff, 17);
1303 + /* Only return a link if the PHY has finished auto negotiation
1304 + and set the resolved bit (bit 11) */
1305 + if (!(phy_status & (1 << 11)))
1308 + /* Create multiple factor to represent duplex */
1309 + if ((phy_status >> 13) & 1)
1314 + /* Speed is encoded on bits 15-14 */
1315 + switch ((phy_status >> 14) & 3) {
1316 + case 0: /* 10 Mbps */
1317 + return 10 * duplex;
1318 + case 1: /* 100 Mbps */
1319 + return 100 * duplex;
1326 + * Set the MAC address for a management port
1328 + * @port: Management port
1329 + * @mac: New MAC address. The lower 6 bytes are used.
1331 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1333 +enum cvmx_mgmt_port_result cvmx_mgmt_port_set_mac(int port, uint64_t mac)
1335 + struct cvmx_mgmt_port_state *state;
1336 + union cvmx_agl_gmx_rxx_adr_ctl agl_gmx_rxx_adr_ctl;
1338 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1339 + return CVMX_MGMT_PORT_INVALID_PARAM;
1341 + state = cvmx_mgmt_port_state_ptr + port;
1343 + cvmx_spinlock_lock(&state->lock);
1345 + agl_gmx_rxx_adr_ctl.u64 = 0;
1346 + /* Only accept matching MAC addresses */
1347 + agl_gmx_rxx_adr_ctl.s.cam_mode = 1;
1348 + /* Drop multicast */
1349 + agl_gmx_rxx_adr_ctl.s.mcst = 0;
1350 + /* Allow broadcast */
1351 + agl_gmx_rxx_adr_ctl.s.bcst = 1;
1352 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CTL(port), agl_gmx_rxx_adr_ctl.u64);
1354 + /* Only using one of the CAMs */
1355 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM0(port), (mac >> 40) & 0xff);
1356 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM1(port), (mac >> 32) & 0xff);
1357 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM2(port), (mac >> 24) & 0xff);
1358 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM3(port), (mac >> 16) & 0xff);
1359 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM4(port), (mac >> 8) & 0xff);
1360 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM5(port), (mac >> 0) & 0xff);
1361 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM_EN(port), 1);
1364 + cvmx_spinlock_unlock(&state->lock);
1365 + return CVMX_MGMT_PORT_SUCCESS;
1369 + * Get the MAC address for a management port
1371 + * @port: Management port
1373 + * Returns MAC address
1375 +uint64_t cvmx_mgmt_port_get_mac(int port)
1377 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1378 + return CVMX_MGMT_PORT_INVALID_PARAM;
1380 + return cvmx_mgmt_port_state_ptr[port].mac;
1384 + * Set the multicast list.
1386 + * @port: Management port
1387 + * @flags: Interface flags
1391 +void cvmx_mgmt_port_set_multicast_list(int port, int flags)
1393 + struct cvmx_mgmt_port_state *state;
1394 + union cvmx_agl_gmx_rxx_adr_ctl agl_gmx_rxx_adr_ctl;
1396 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1399 + state = cvmx_mgmt_port_state_ptr + port;
1401 + cvmx_spinlock_lock(&state->lock);
1403 + agl_gmx_rxx_adr_ctl.u64 = cvmx_read_csr(CVMX_AGL_GMX_RXX_ADR_CTL(port));
1405 + /* Allow broadcast MAC addresses */
1406 + if (!agl_gmx_rxx_adr_ctl.s.bcst)
1407 + agl_gmx_rxx_adr_ctl.s.bcst = 1;
1409 + if ((flags & CVMX_IFF_ALLMULTI) || (flags & CVMX_IFF_PROMISC))
1410 + /* Force accept multicast packets */
1411 + agl_gmx_rxx_adr_ctl.s.mcst = 2;
1413 + /* Force reject multicast packets */
1414 + agl_gmx_rxx_adr_ctl.s.mcst = 1;
1416 + if (flags & CVMX_IFF_PROMISC)
1418 + * Reject matches if promisc. Since CAM is shut off,
1419 + * should accept everything.
1421 + agl_gmx_rxx_adr_ctl.s.cam_mode = 0;
1423 + /* Filter packets based on the CAM */
1424 + agl_gmx_rxx_adr_ctl.s.cam_mode = 1;
1426 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CTL(port), agl_gmx_rxx_adr_ctl.u64);
1428 + if (flags & CVMX_IFF_PROMISC)
1429 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM_EN(port), 0);
1431 + cvmx_write_csr(CVMX_AGL_GMX_RXX_ADR_CAM_EN(port), 1);
1433 + cvmx_spinlock_unlock(&state->lock);
1437 + * Set the maximum packet allowed in. Size is specified
1438 + * including L2 but without FCS. A normal MTU would corespond
1439 + * to 1514 assuming the standard 14 byte L2 header.
1441 + * @port: Management port
1442 + * @size_without_fcs:
1443 + * Size in bytes without FCS
1445 +void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs)
1447 + struct cvmx_mgmt_port_state *state;
1449 + if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports()))
1452 + state = cvmx_mgmt_port_state_ptr + port;
1454 + cvmx_spinlock_lock(&state->lock);
1455 + cvmx_write_csr(CVMX_AGL_GMX_RXX_FRM_MAX(port), size_without_fcs);
1456 + cvmx_write_csr(CVMX_AGL_GMX_RXX_JABBER(port),
1457 + (size_without_fcs + 7) & 0xfff8);
1458 + cvmx_spinlock_unlock(&state->lock);
1461 +++ b/drivers/net/octeon/cvmx-mgmt-port.h
1463 +/***********************license start***************
1464 + * Author: Cavium Networks
1466 + * Contact: support@caviumnetworks.com
1467 + * This file is part of the OCTEON SDK
1469 + * Copyright (c) 2003-2008 Cavium Networks
1471 + * This file is free software; you can redistribute it and/or modify
1472 + * it under the terms of the GNU General Public License, Version 2, as
1473 + * published by the Free Software Foundation.
1475 + * This file is distributed in the hope that it will be useful, but
1476 + * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1477 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1478 + * NONINFRINGEMENT. See the GNU General Public License for more
1481 + * You should have received a copy of the GNU General Public License
1482 + * along with this file; if not, write to the Free Software
1483 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1484 + * or visit http://www.gnu.org/licenses/.
1486 + * This file may also be available under a different license from Cavium.
1487 + * Contact Cavium Networks for more information
1488 + ***********************license end**************************************/
1492 + * Support functions for managing the MII management port
1496 +#ifndef __CVMX_MGMT_PORT_H__
1497 +#define __CVMX_MGMT_PORT_H__
1499 +enum cvmx_mgmt_port_result {
1500 + CVMX_MGMT_PORT_SUCCESS = 0,
1501 + CVMX_MGMT_PORT_NO_MEMORY = -1,
1502 + CVMX_MGMT_PORT_INVALID_PARAM = -2,
1505 +/* Enumeration of Net Device interface flags. */
1506 +enum cvmx_mgmt_port_netdevice_flags {
1507 + CVMX_IFF_PROMISC = 0x100, /* receive all packets */
1508 + CVMX_IFF_ALLMULTI = 0x200, /* receive all multicast packets */
1512 + * Called to initialize a management port for use. Multiple calls
1513 + * to this function accross applications is safe.
1515 + * @port: Port to initialize
1517 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1519 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_initialize(int port);
1522 + * Shutdown a management port. This currently disables packet IO
1523 + * but leaves all hardware and buffers. Another application can then
1524 + * call initialize() without redoing the hardware setup.
1526 + * @port: Management port
1528 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1530 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_shutdown(int port);
1533 + * Enable packet IO on a management port
1535 + * @port: Management port
1537 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1539 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_enable(int port);
1542 + * Disable packet IO on a management port
1544 + * @port: Management port
1546 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1548 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_disable(int port);
1551 + * Send a packet out the management port. The packet is copied so
1552 + * the input buffer isn't used after this call.
1554 + * @port: Management port
1555 + * @packet_len: Length of the packet to send. It does not include the final CRC
1556 + * @buffer: Packet data
1558 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1560 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_send(int port, int packet_len,
1564 + * Receive a packet from the management port.
1566 + * @port: Management port
1567 + * @buffer_len: Size of the buffer to receive the packet into
1568 + * @buffer: Buffer to receive the packet into
1570 + * Returns The size of the packet, or a negative erorr code on failure. Zero
1571 + * means that no packets were available.
1573 +extern int cvmx_mgmt_port_receive(int port, int buffer_len, void *buffer);
1576 + * Get the management port link status:
1577 + * 100 = 100Mbps, full duplex
1578 + * 10 = 10Mbps, full duplex
1580 + * -10 = 10Mpbs, half duplex
1581 + * -100 = 100Mbps, half duplex
1583 + * @port: Management port
1587 +extern int cvmx_mgmt_port_get_link(int port);
1590 + * Set the MAC address for a management port
1592 + * @port: Management port
1593 + * @mac: New MAC address. The lower 6 bytes are used.
1595 + * Returns CVMX_MGMT_PORT_SUCCESS or an error code
1597 +extern enum cvmx_mgmt_port_result cvmx_mgmt_port_set_mac(int port,
1601 + * Get the MAC address for a management port
1603 + * @port: Management port
1605 + * Returns MAC address
1607 +extern uint64_t cvmx_mgmt_port_get_mac(int port);
1610 + * Set the multicast list.
1612 + * @port: Management port
1613 + * @flags: Interface flags
1617 +extern void cvmx_mgmt_port_set_multicast_list(int port, int flags);
1620 + * Set the maximum packet allowed in. Size is specified
1621 + * including L2 but without FCS. A normal MTU would corespond
1622 + * to 1514 assuming the standard 14 byte L2 header.
1624 + * @port: Management port
1625 + * @size_without_crc:
1626 + * Size in bytes without FCS
1628 +extern void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs);
1630 +#endif /* __CVMX_MGMT_PORT_H__ */
1632 +++ b/drivers/net/octeon/octeon-mgmt-port.c
1635 + * Octeon Management Port Ethernet Driver
1637 + * This file is subject to the terms and conditions of the GNU General Public
1638 + * License. See the file "COPYING" in the main directory of this archive
1639 + * for more details.
1641 + * Copyright (C) 2007, 2008 Cavium Networks
1643 +#include <linux/module.h>
1644 +#include <linux/kernel.h>
1645 +#include <linux/netdevice.h>
1646 +#include <linux/etherdevice.h>
1647 +#include <linux/ip.h>
1648 +#include <linux/string.h>
1649 +#include <linux/delay.h>
1651 +#include <asm/octeon/octeon.h>
1652 +#include <asm/octeon/cvmx-mixx-defs.h>
1653 +#include <asm/octeon/cvmx-agl-defs.h>
1655 +#include "cvmx-mgmt-port.h"
1657 +static struct net_device *global_dev[2] = { NULL, NULL };
1659 +#define DEBUGPRINT(format, ...) do {if (printk_ratelimit()) \
1660 + printk(format, ##__VA_ARGS__); \
1664 + * This is the definition of the Ethernet driver's private
1665 + * driver state stored in dev->priv.
1667 +struct device_private {
1669 + struct net_device_stats stats; /* Device statistics */
1676 + * @param skb Packet to send
1677 + * @param dev Device info structure
1678 + * @return Always returns zero
1680 +static int packet_transmit(struct sk_buff *skb, struct net_device *dev)
1683 + struct device_private *priv = netdev_priv(dev);
1684 + enum cvmx_mgmt_port_result result;
1685 + local_irq_save(flags);
1686 + result = cvmx_mgmt_port_send(priv->port, skb->len, skb->data);
1687 + local_irq_restore(flags);
1688 + if (result == CVMX_MGMT_PORT_SUCCESS) {
1689 + priv->stats.tx_packets++;
1690 + priv->stats.tx_bytes += skb->len;
1692 + /* DEBUGPRINT("ERROR: cvmx_mgmt_port_send() failed with %d\n",
1695 + priv->stats.tx_dropped++;
1697 + dev_kfree_skb(skb);
1703 + * Interrupt handler. The interrupt occurs whenever the POW
1704 + * transitions from 0->1 packets in our group.
1711 +static irqreturn_t do_interrupt(int cpl, void *dev_id)
1714 + struct sk_buff *skb;
1716 + char packet[2048];
1717 + struct net_device *dev = (struct net_device *) dev_id;
1718 + struct device_private *priv = netdev_priv(dev);
1721 + local_irq_save(flags);
1722 + result = cvmx_mgmt_port_receive(priv->port, sizeof(packet),
1724 + local_irq_restore(flags);
1726 + /* Silently drop packets if we aren't up */
1727 + if ((dev->flags & IFF_UP) == 0)
1731 + skb = dev_alloc_skb(result);
1733 + memcpy(skb_put(skb, result), packet, result);
1734 + skb->protocol = eth_type_trans(skb, dev);
1736 + skb->ip_summed = CHECKSUM_NONE;
1737 + priv->stats.rx_bytes += skb->len;
1738 + priv->stats.rx_packets++;
1741 + DEBUGPRINT("%s: Failed to allocate skbuff, "
1742 + "packet dropped\n",
1744 + priv->stats.rx_dropped++;
1746 + } else if (result < 0) {
1747 + DEBUGPRINT("%s: Receive error code %d, packet "
1749 + dev->name, result);
1750 + priv->stats.rx_errors++;
1752 + } while (result != 0);
1754 + /* Clear any pending interrupts */
1755 + cvmx_write_csr(CVMX_MIXX_ISR(priv->port),
1756 + cvmx_read_csr(CVMX_MIXX_ISR(priv->port)));
1757 + cvmx_read_csr(CVMX_MIXX_ISR(priv->port));
1759 + return IRQ_HANDLED;
1763 +#ifdef CONFIG_NET_POLL_CONTROLLER
1765 + * This is called when the kernel needs to manually poll the
1766 + * device. For Octeon, this is simply calling the interrupt
1767 + * handler. We actually poll all the devices, not just the
1770 + * @param dev Device to poll. Unused
1772 +static void device_poll_controller(struct net_device *dev)
1774 + do_interrupt(0, dev);
1780 + * Open a device for use. Device should be able to send and
1781 + * receive packets after this is called.
1783 + * @param dev Device to bring up
1784 + * @return Zero on success
1786 +static int device_open(struct net_device *dev)
1788 + /* Clear the statistics whenever the interface is brought up */
1789 + struct device_private *priv = netdev_priv(dev);
1790 + memset(&priv->stats, 0, sizeof(priv->stats));
1791 + cvmx_mgmt_port_enable(priv->port);
1797 + * Stop an ethernet device. No more packets should be
1798 + * received from this device.
1800 + * @param dev Device to bring down
1801 + * @return Zero on success
1803 +static int device_close(struct net_device *dev)
1805 + struct device_private *priv = netdev_priv(dev);
1806 + cvmx_mgmt_port_disable(priv->port);
1812 + * Get the low level ethernet statistics
1814 + * @param dev Device to get the statistics from
1815 + * @return Pointer to the statistics
1817 +static struct net_device_stats *device_get_stats(struct net_device *dev)
1819 + struct device_private *priv = netdev_priv(dev);
1820 + return &priv->stats;
1824 + * Set the multicast list. Currently unimplemented.
1826 + * @param dev Device to work on
1828 +static void ethernet_mgmt_port_set_multicast_list(struct net_device *dev)
1830 + struct device_private *priv = netdev_priv(dev);
1831 + int port = priv->port;
1833 + if (OCTEON_IS_MODEL(OCTEON_CN52XX))
1837 + if (port < num_ports)
1838 + cvmx_mgmt_port_set_multicast_list(port, dev->flags);
1842 + * Set the hardware MAC address for a management port device
1844 + * @param dev Device to change the MAC address for
1845 + * @param addr Address structure to change it too. MAC address is addr + 2.
1846 + * @return Zero on success
1848 +static int ethernet_mgmt_port_set_mac_address(struct net_device *dev,
1851 + struct device_private *priv = netdev_priv(dev);
1852 + union cvmx_agl_gmx_prtx_cfg agl_gmx_cfg;
1853 + int port = priv->port;
1856 + if (OCTEON_IS_MODEL(OCTEON_CN52XX))
1861 + memcpy(dev->dev_addr, addr + 2, 6);
1863 + if (port < num_ports) {
1865 + uint8_t *ptr = addr;
1867 + for (i = 0; i < 6; i++)
1868 + mac = (mac<<8) | (uint64_t)(ptr[i+2]);
1870 + agl_gmx_cfg.u64 = cvmx_read_csr(CVMX_AGL_GMX_PRTX_CFG(port));
1871 + cvmx_mgmt_port_set_mac(port, mac);
1872 + ethernet_mgmt_port_set_multicast_list(dev);
1873 + cvmx_write_csr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_cfg.u64);
1879 + * Per network device initialization
1881 + * @param dev Device to initialize
1882 + * @return Zero on success
1884 +static int device_init(struct net_device *dev)
1886 + struct device_private *priv = netdev_priv(dev);
1887 + uint64_t mac = cvmx_mgmt_port_get_mac(priv->port);
1889 + dev->hard_start_xmit = packet_transmit;
1890 + dev->get_stats = device_get_stats;
1891 + dev->open = device_open;
1892 + dev->stop = device_close;
1893 +#ifdef CONFIG_NET_POLL_CONTROLLER
1894 + dev->poll_controller = device_poll_controller;
1896 + dev->dev_addr[0] = (mac >> 40) & 0xff;
1897 + dev->dev_addr[1] = (mac >> 32) & 0xff;
1898 + dev->dev_addr[2] = (mac >> 24) & 0xff;
1899 + dev->dev_addr[3] = (mac >> 16) & 0xff;
1900 + dev->dev_addr[4] = (mac >> 8) & 0xff;
1901 + dev->dev_addr[5] = (mac >> 0) & 0xff;
1907 + * Module/ driver initialization. Creates the linux network
1910 + * @return Zero on success
1912 +static int __init ethernet_mgmt_port_init(void)
1914 + struct net_device *dev;
1915 + struct device_private *priv;
1916 + union cvmx_mixx_irhwm mix_irhwm;
1917 + union cvmx_mixx_intena mix_intena;
1921 + if (!OCTEON_IS_MODEL(OCTEON_CN56XX) && !OCTEON_IS_MODEL(OCTEON_CN52XX))
1924 + if (OCTEON_IS_MODEL(OCTEON_CN52XX))
1929 + printk("Octeon management port ethernet driver\n");
1931 + for (port = 0; port < num_ports; port++) {
1932 + if (cvmx_mgmt_port_initialize(port) != CVMX_MGMT_PORT_SUCCESS) {
1933 + pr_err("ERROR: cvmx_mgmt_port_initialize(%d) "
1934 + "failed\n", port);
1938 + /* Setup is complete, create the virtual ethernet devices */
1939 + dev = alloc_etherdev(sizeof(struct device_private));
1940 + if (dev == NULL) {
1941 + pr_err("ERROR: Failed to allocate ethernet device\n");
1945 + dev->init = device_init;
1946 + strcpy(dev->name, "mgmt%d");
1948 + /* Initialize the device private structure. */
1949 + priv = netdev_priv(dev);
1950 + memset(priv, 0, sizeof(struct device_private));
1951 + priv->port = port;
1953 + if (register_netdev(dev) < 0) {
1954 + pr_err("ERROR: Failed to register ethernet device\n");
1959 + /* Clear any pending interrupts */
1960 + cvmx_write_csr(CVMX_MIXX_ISR(priv->port),
1961 + cvmx_read_csr(CVMX_MIXX_ISR(priv->port)));
1963 + /* Register an IRQ hander for to receive interrupts */
1965 + (priv->port == 0) ? OCTEON_IRQ_MII0 : OCTEON_IRQ_MII1;
1966 + if (request_irq(dev->irq, do_interrupt, IRQF_SHARED, dev->name,
1968 + pr_err("ethernet-mgmt: Failed to assign "
1969 + "interrupt %d\n", dev->irq);
1971 + /* Interrupt every single RX packet */
1972 + mix_irhwm.u64 = 0;
1973 + mix_irhwm.s.irhwm = 0;
1974 + cvmx_write_csr(CVMX_MIXX_IRHWM(priv->port), mix_irhwm.u64);
1976 + /* Enable receive interrupts */
1977 + mix_intena.u64 = 0;
1978 + mix_intena.s.ithena = 1;
1979 + cvmx_write_csr(CVMX_MIXX_INTENA(priv->port), mix_intena.u64);
1981 + global_dev[priv->port] = dev;
1983 + dev->set_mac_address = ethernet_mgmt_port_set_mac_address;
1984 + dev->set_multicast_list = ethernet_mgmt_port_set_multicast_list;
1991 + * Module / driver shutdown
1993 + * @return Zero on success
1995 +static void __exit ethernet_mgmt_port_cleanup(void)
1998 + for (port = 0; port < 2; port++) {
1999 + if (global_dev[port]) {
2000 + struct device_private *priv =
2001 + netdev_priv(global_dev[port]);
2002 + /* Disable interrupt */
2003 + cvmx_write_csr(CVMX_MIXX_IRHWM(priv->port), 0);
2004 + cvmx_write_csr(CVMX_MIXX_INTENA(priv->port), 0);
2005 + cvmx_mgmt_port_shutdown(priv->port);
2007 + /* Free the interrupt handler */
2008 + free_irq(global_dev[port]->irq, global_dev[port]);
2010 + /* Free the ethernet devices */
2011 + unregister_netdev(global_dev[port]);
2012 + kfree(global_dev[port]);
2013 + global_dev[port] = NULL;
2018 +MODULE_LICENSE("GPL");
2019 +MODULE_AUTHOR("Cavium Networks <support@caviumnetworks.com>");
2020 +MODULE_DESCRIPTION("Cavium Networks Octeon management port ethernet driver.");
2021 +module_init(ethernet_mgmt_port_init);
2022 +module_exit(ethernet_mgmt_port_cleanup);