1 /**********************************************************************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2007 Cavium Networks
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 **********************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/delay.h>
33 #include <linux/phy.h>
37 #include <asm/octeon/octeon.h>
39 #include "ethernet-defines.h"
40 #include "octeon-ethernet.h"
41 #include "ethernet-mem.h"
42 #include "ethernet-rx.h"
43 #include "ethernet-tx.h"
44 #include "ethernet-mdio.h"
45 #include "ethernet-util.h"
46 #include "ethernet-proc.h"
53 #include "cvmx-helper.h"
55 #include "cvmx-gmxx-defs.h"
56 #include "cvmx-smix-defs.h"
58 #if defined(CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS) \
59 && CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS
60 int num_packet_buffers = CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS;
62 int num_packet_buffers = 1024;
64 module_param(num_packet_buffers, int, 0444);
65 MODULE_PARM_DESC(num_packet_buffers, "\n"
66 "\tNumber of packet buffers to allocate and store in the\n"
67 "\tFPA. By default, 1024 packet buffers are used unless\n"
68 "\tCONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS is defined.");
70 int pow_receive_group = 15;
71 module_param(pow_receive_group, int, 0444);
72 MODULE_PARM_DESC(pow_receive_group, "\n"
73 "\tPOW group to receive packets from. All ethernet hardware\n"
74 "\twill be configured to send incomming packets to this POW\n"
75 "\tgroup. Also any other software can submit packets to this\n"
76 "\tgroup for the kernel to process.");
78 int pow_send_group = -1;
79 module_param(pow_send_group, int, 0644);
80 MODULE_PARM_DESC(pow_send_group, "\n"
81 "\tPOW group to send packets to other software on. This\n"
82 "\tcontrols the creation of the virtual device pow0.\n"
83 "\talways_use_pow also depends on this value.");
86 module_param(always_use_pow, int, 0444);
87 MODULE_PARM_DESC(always_use_pow, "\n"
88 "\tWhen set, always send to the pow group. This will cause\n"
89 "\tpackets sent to real ethernet devices to be sent to the\n"
90 "\tPOW group instead of the hardware. Unless some other\n"
91 "\tapplication changes the config, packets will still be\n"
92 "\treceived from the low level hardware. Use this option\n"
93 "\tto allow a CVMX app to intercept all packets from the\n"
94 "\tlinux kernel. You must specify pow_send_group along with\n"
97 char pow_send_list[128] = "";
98 module_param_string(pow_send_list, pow_send_list, sizeof(pow_send_list), 0444);
99 MODULE_PARM_DESC(pow_send_list, "\n"
100 "\tComma separated list of ethernet devices that should use the\n"
101 "\tPOW for transmit instead of the actual ethernet hardware. This\n"
102 "\tis a per port version of always_use_pow. always_use_pow takes\n"
103 "\tprecedence over this list. For example, setting this to\n"
104 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n"
105 "\tusing the pow_send_group.");
107 int max_rx_cpus = -1;
108 module_param(max_rx_cpus, int, 0444);
109 MODULE_PARM_DESC(max_rx_cpus, "\n"
110 "\t\tThe maximum number of CPUs to use for packet reception.\n"
111 "\t\tUse -1 to use all available CPUs.");
113 int rx_napi_weight = 32;
114 module_param(rx_napi_weight, int, 0444);
115 MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter.");
118 * The offset from mac_addr_base that should be used for the next port
119 * that is configured. By convention, if any mgmt ports exist on the
120 * chip, they get the first mac addresses, The ports controlled by
121 * this driver are numbered sequencially following any mgmt addresses
124 static unsigned int cvm_oct_mac_addr_offset;
127 * Periodic timer to check auto negotiation
129 static struct timer_list cvm_oct_poll_timer;
132 * Array of every ethernet device owned by this driver indexed by
133 * the ipd input port number.
135 struct net_device *cvm_oct_device[TOTAL_NUMBER_OF_PORTS];
138 * Periodic timer tick for slow management operations
140 * @arg: Device to check
142 static void cvm_do_timer(unsigned long arg)
145 if (port < CVMX_PIP_NUM_INPUT_PORTS) {
146 if (cvm_oct_device[port]) {
147 struct octeon_ethernet *priv = netdev_priv(cvm_oct_device[port]);
149 priv->poll(cvm_oct_device[port]);
150 cvm_oct_free_tx_skbs(priv);
151 cvm_oct_device[port]->netdev_ops->ndo_get_stats(cvm_oct_device[port]);
155 * Poll the next port in a 50th of a second. This
156 * spreads the polling of ports out a little bit.
158 mod_timer(&cvm_oct_poll_timer, jiffies + HZ/50);
162 * FPA 0 may have been drained, try to refill it if we
163 * need more than num_packet_buffers / 2, otherwise
164 * normal receive processing will refill it. If it
165 * were drained, no packets could be received so
166 * cvm_oct_napi_poll would never be invoked to do the
169 cvm_oct_rx_refill_pool(num_packet_buffers / 2);
171 * All ports have been polled. Start the next iteration through
172 * the ports in one second.
174 mod_timer(&cvm_oct_poll_timer, jiffies + HZ);
179 * Configure common hardware for all interfaces
181 static __init void cvm_oct_configure_common_hw(void)
185 cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE,
187 cvm_oct_mem_fill_fpa(CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE,
189 if (CVMX_FPA_OUTPUT_BUFFER_POOL != CVMX_FPA_PACKET_POOL)
190 cvm_oct_mem_fill_fpa(CVMX_FPA_OUTPUT_BUFFER_POOL,
191 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, 128);
194 cvmx_helper_setup_red(num_packet_buffers / 4,
195 num_packet_buffers / 8);
200 * Free a work queue entry received in a intercept callback.
203 * Work queue entry to free
204 * Returns Zero on success, Negative on failure.
206 int cvm_oct_free_work(void *work_queue_entry)
208 cvmx_wqe_t *work = work_queue_entry;
210 int segments = work->word2.s.bufs;
211 union cvmx_buf_ptr segment_ptr = work->packet_ptr;
214 union cvmx_buf_ptr next_ptr = *(union cvmx_buf_ptr *)
215 cvmx_phys_to_ptr(segment_ptr.s.addr - 8);
216 if (unlikely(!segment_ptr.s.i))
217 cvmx_fpa_free(cvm_oct_get_buffer_ptr(segment_ptr),
219 DONT_WRITEBACK(CVMX_FPA_PACKET_POOL_SIZE /
221 segment_ptr = next_ptr;
223 cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, DONT_WRITEBACK(1));
227 EXPORT_SYMBOL(cvm_oct_free_work);
230 * Get the low level ethernet statistics
232 * @dev: Device to get the statistics from
233 * Returns Pointer to the statistics
235 static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
237 cvmx_pip_port_status_t rx_status;
238 cvmx_pko_port_status_t tx_status;
239 struct octeon_ethernet *priv = netdev_priv(dev);
241 if (priv->port < CVMX_PIP_NUM_INPUT_PORTS) {
242 if (octeon_is_simulation()) {
243 /* The simulator doesn't support statistics */
244 memset(&rx_status, 0, sizeof(rx_status));
245 memset(&tx_status, 0, sizeof(tx_status));
247 cvmx_pip_get_port_status(priv->port, 1, &rx_status);
248 cvmx_pko_get_port_status(priv->port, 1, &tx_status);
251 priv->stats.rx_packets += rx_status.inb_packets;
252 priv->stats.tx_packets += tx_status.packets;
253 priv->stats.rx_bytes += rx_status.inb_octets;
254 priv->stats.tx_bytes += tx_status.octets;
255 priv->stats.multicast += rx_status.multicast_packets;
256 priv->stats.rx_crc_errors += rx_status.inb_errors;
257 priv->stats.rx_frame_errors += rx_status.fcs_align_err_packets;
260 * The drop counter must be incremented atomically
261 * since the RX tasklet also increments it.
264 atomic64_add(rx_status.dropped_packets,
265 (atomic64_t *)&priv->stats.rx_dropped);
267 atomic_add(rx_status.dropped_packets,
268 (atomic_t *)&priv->stats.rx_dropped);
276 * Change the link MTU. Unimplemented
278 * @dev: Device to change
279 * @new_mtu: The new MTU
281 * Returns Zero on success
283 static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu)
285 struct octeon_ethernet *priv = netdev_priv(dev);
286 int interface = INTERFACE(priv->port);
287 int index = INDEX(priv->port);
288 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
295 * Limit the MTU to make sure the ethernet packets are between
296 * 64 bytes and 65535 bytes.
298 if ((new_mtu + 14 + 4 + vlan_bytes < 64)
299 || (new_mtu + 14 + 4 + vlan_bytes > 65392)) {
300 pr_err("MTU must be between %d and %d.\n",
301 64 - 14 - 4 - vlan_bytes, 65392 - 14 - 4 - vlan_bytes);
307 && (cvmx_helper_interface_get_mode(interface) !=
308 CVMX_HELPER_INTERFACE_MODE_SPI)) {
309 /* Add ethernet header and FCS, and VLAN if configured. */
310 int max_packet = new_mtu + 14 + 4 + vlan_bytes;
312 if (OCTEON_IS_MODEL(OCTEON_CN3XXX)
313 || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
314 /* Signal errors on packets larger than the MTU */
315 cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX(index, interface),
319 * Set the hardware to truncate packets larger
320 * than the MTU and smaller the 64 bytes.
322 union cvmx_pip_frm_len_chkx frm_len_chk;
324 frm_len_chk.s.minlen = 64;
325 frm_len_chk.s.maxlen = max_packet;
326 cvmx_write_csr(CVMX_PIP_FRM_LEN_CHKX(interface),
330 * Set the hardware to truncate packets larger than
331 * the MTU. The jabber register must be set to a
332 * multiple of 8 bytes, so round up.
334 cvmx_write_csr(CVMX_GMXX_RXX_JABBER(index, interface),
335 (max_packet + 7) & ~7u);
341 * Set the multicast list. Currently unimplemented.
343 * @dev: Device to work on
345 static void cvm_oct_common_set_multicast_list(struct net_device *dev)
347 union cvmx_gmxx_prtx_cfg gmx_cfg;
348 struct octeon_ethernet *priv = netdev_priv(dev);
349 int interface = INTERFACE(priv->port);
350 int index = INDEX(priv->port);
353 && (cvmx_helper_interface_get_mode(interface) !=
354 CVMX_HELPER_INTERFACE_MODE_SPI)) {
355 union cvmx_gmxx_rxx_adr_ctl control;
357 control.s.bcst = 1; /* Allow broadcast MAC addresses */
359 if (dev->mc_list || (dev->flags & IFF_ALLMULTI) ||
360 (dev->flags & IFF_PROMISC))
361 /* Force accept multicast packets */
364 /* Force reject multicat packets */
367 if (dev->flags & IFF_PROMISC)
369 * Reject matches if promisc. Since CAM is
370 * shut off, should accept everything.
372 control.s.cam_mode = 0;
374 /* Filter packets based on the CAM */
375 control.s.cam_mode = 1;
378 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
379 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
380 gmx_cfg.u64 & ~1ull);
382 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CTL(index, interface),
384 if (dev->flags & IFF_PROMISC)
385 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
386 (index, interface), 0);
388 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
389 (index, interface), 1);
391 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
397 * Set the hardware MAC address for a device
399 * @dev: Device to change the MAC address for
400 * @addr: Address structure to change it too. MAC address is addr + 2.
401 * Returns Zero on success
403 static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
405 struct octeon_ethernet *priv = netdev_priv(dev);
406 union cvmx_gmxx_prtx_cfg gmx_cfg;
407 int interface = INTERFACE(priv->port);
408 int index = INDEX(priv->port);
410 memcpy(dev->dev_addr, addr + 2, 6);
413 && (cvmx_helper_interface_get_mode(interface) !=
414 CVMX_HELPER_INTERFACE_MODE_SPI)) {
418 for (i = 0; i < 6; i++)
419 mac = (mac << 8) | (uint64_t) (ptr[i + 2]);
422 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
423 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
424 gmx_cfg.u64 & ~1ull);
426 cvmx_write_csr(CVMX_GMXX_SMACX(index, interface), mac);
427 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM0(index, interface),
429 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM1(index, interface),
431 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM2(index, interface),
433 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM3(index, interface),
435 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM4(index, interface),
437 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM5(index, interface),
439 cvm_oct_common_set_multicast_list(dev);
440 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
447 * Per network device initialization
449 * @dev: Device to initialize
450 * Returns Zero on success
452 int cvm_oct_common_init(struct net_device *dev)
454 struct octeon_ethernet *priv = netdev_priv(dev);
456 u64 mac = ((u64)(octeon_bootinfo->mac_addr_base[0] & 0xff) << 40) |
457 ((u64)(octeon_bootinfo->mac_addr_base[1] & 0xff) << 32) |
458 ((u64)(octeon_bootinfo->mac_addr_base[2] & 0xff) << 24) |
459 ((u64)(octeon_bootinfo->mac_addr_base[3] & 0xff) << 16) |
460 ((u64)(octeon_bootinfo->mac_addr_base[4] & 0xff) << 8) |
461 (u64)(octeon_bootinfo->mac_addr_base[5] & 0xff);
463 mac += cvm_oct_mac_addr_offset;
464 sa.sa_data[0] = (mac >> 40) & 0xff;
465 sa.sa_data[1] = (mac >> 32) & 0xff;
466 sa.sa_data[2] = (mac >> 24) & 0xff;
467 sa.sa_data[3] = (mac >> 16) & 0xff;
468 sa.sa_data[4] = (mac >> 8) & 0xff;
469 sa.sa_data[5] = mac & 0xff;
471 if (cvm_oct_mac_addr_offset >= octeon_bootinfo->mac_addr_count)
472 printk(KERN_DEBUG "%s: Using MAC outside of the assigned range:"
473 " %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
474 sa.sa_data[0] & 0xff, sa.sa_data[1] & 0xff,
475 sa.sa_data[2] & 0xff, sa.sa_data[3] & 0xff,
476 sa.sa_data[4] & 0xff, sa.sa_data[5] & 0xff);
477 cvm_oct_mac_addr_offset++;
480 * Force the interface to use the POW send if always_use_pow
481 * was specified or it is in the pow send list.
483 if ((pow_send_group != -1)
484 && (always_use_pow || strstr(pow_send_list, dev->name)))
487 if (priv->queue != -1 && USE_HW_TCPUDP_CHECKSUM)
488 dev->features |= NETIF_F_IP_CSUM;
490 /* We do our own locking, Linux doesn't need to */
491 dev->features |= NETIF_F_LLTX;
492 SET_ETHTOOL_OPS(dev, &cvm_oct_ethtool_ops);
494 cvm_oct_phy_setup_device(dev);
495 dev->netdev_ops->ndo_set_mac_address(dev, &sa);
496 dev->netdev_ops->ndo_change_mtu(dev, dev->mtu);
499 * Zero out stats for port so we won't mistakenly show
500 * counters from the bootloader.
502 memset(dev->netdev_ops->ndo_get_stats(dev), 0,
503 sizeof(struct net_device_stats));
508 void cvm_oct_common_uninit(struct net_device *dev)
510 struct octeon_ethernet *priv = netdev_priv(dev);
513 phy_disconnect(priv->phydev);
516 static const struct net_device_ops cvm_oct_npi_netdev_ops = {
517 .ndo_init = cvm_oct_common_init,
518 .ndo_uninit = cvm_oct_common_uninit,
519 .ndo_start_xmit = cvm_oct_xmit,
520 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
521 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
522 .ndo_do_ioctl = cvm_oct_ioctl,
523 .ndo_change_mtu = cvm_oct_common_change_mtu,
524 .ndo_get_stats = cvm_oct_common_get_stats,
525 #ifdef CONFIG_NET_POLL_CONTROLLER
526 .ndo_poll_controller = cvm_oct_poll_controller,
529 static const struct net_device_ops cvm_oct_xaui_netdev_ops = {
530 .ndo_init = cvm_oct_xaui_init,
531 .ndo_uninit = cvm_oct_xaui_uninit,
532 .ndo_open = cvm_oct_xaui_open,
533 .ndo_stop = cvm_oct_xaui_stop,
534 .ndo_start_xmit = cvm_oct_xmit,
535 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
536 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
537 .ndo_do_ioctl = cvm_oct_ioctl,
538 .ndo_change_mtu = cvm_oct_common_change_mtu,
539 .ndo_get_stats = cvm_oct_common_get_stats,
540 #ifdef CONFIG_NET_POLL_CONTROLLER
541 .ndo_poll_controller = cvm_oct_poll_controller,
544 static const struct net_device_ops cvm_oct_sgmii_netdev_ops = {
545 .ndo_init = cvm_oct_sgmii_init,
546 .ndo_uninit = cvm_oct_sgmii_uninit,
547 .ndo_open = cvm_oct_sgmii_open,
548 .ndo_stop = cvm_oct_sgmii_stop,
549 .ndo_start_xmit = cvm_oct_xmit,
550 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
551 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
552 .ndo_do_ioctl = cvm_oct_ioctl,
553 .ndo_change_mtu = cvm_oct_common_change_mtu,
554 .ndo_get_stats = cvm_oct_common_get_stats,
555 #ifdef CONFIG_NET_POLL_CONTROLLER
556 .ndo_poll_controller = cvm_oct_poll_controller,
559 static const struct net_device_ops cvm_oct_spi_netdev_ops = {
560 .ndo_init = cvm_oct_spi_init,
561 .ndo_uninit = cvm_oct_spi_uninit,
562 .ndo_start_xmit = cvm_oct_xmit,
563 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
564 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
565 .ndo_do_ioctl = cvm_oct_ioctl,
566 .ndo_change_mtu = cvm_oct_common_change_mtu,
567 .ndo_get_stats = cvm_oct_common_get_stats,
568 #ifdef CONFIG_NET_POLL_CONTROLLER
569 .ndo_poll_controller = cvm_oct_poll_controller,
572 static const struct net_device_ops cvm_oct_rgmii_netdev_ops = {
573 .ndo_init = cvm_oct_rgmii_init,
574 .ndo_uninit = cvm_oct_rgmii_uninit,
575 .ndo_open = cvm_oct_rgmii_open,
576 .ndo_stop = cvm_oct_rgmii_stop,
577 .ndo_start_xmit = cvm_oct_xmit,
578 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
579 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
580 .ndo_do_ioctl = cvm_oct_ioctl,
581 .ndo_change_mtu = cvm_oct_common_change_mtu,
582 .ndo_get_stats = cvm_oct_common_get_stats,
583 #ifdef CONFIG_NET_POLL_CONTROLLER
584 .ndo_poll_controller = cvm_oct_poll_controller,
587 static const struct net_device_ops cvm_oct_pow_netdev_ops = {
588 .ndo_init = cvm_oct_common_init,
589 .ndo_start_xmit = cvm_oct_xmit_pow,
590 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
591 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
592 .ndo_do_ioctl = cvm_oct_ioctl,
593 .ndo_change_mtu = cvm_oct_common_change_mtu,
594 .ndo_get_stats = cvm_oct_common_get_stats,
595 #ifdef CONFIG_NET_POLL_CONTROLLER
596 .ndo_poll_controller = cvm_oct_poll_controller,
600 extern void octeon_mdiobus_force_mod_depencency(void);
603 * Module/ driver initialization. Creates the linux network
606 * Returns Zero on success
608 static int __init cvm_oct_init_module(void)
612 int fau = FAU_NUM_PACKET_BUFFERS_TO_FREE;
615 octeon_mdiobus_force_mod_depencency();
616 pr_notice("cavium-ethernet %s\n", OCTEON_ETHERNET_VERSION);
618 if (OCTEON_IS_MODEL(OCTEON_CN52XX))
619 cvm_oct_mac_addr_offset = 2; /* First two are the mgmt ports. */
620 else if (OCTEON_IS_MODEL(OCTEON_CN56XX))
621 cvm_oct_mac_addr_offset = 1; /* First one is the mgmt port. */
623 cvm_oct_mac_addr_offset = 0;
625 cvm_oct_proc_initialize();
626 cvm_oct_configure_common_hw();
628 cvmx_helper_initialize_packet_io_global();
630 /* Change the input group for all ports before input is enabled */
631 num_interfaces = cvmx_helper_get_number_of_interfaces();
632 for (interface = 0; interface < num_interfaces; interface++) {
633 int num_ports = cvmx_helper_ports_on_interface(interface);
636 for (port = cvmx_helper_get_ipd_port(interface, 0);
637 port < cvmx_helper_get_ipd_port(interface, num_ports);
639 union cvmx_pip_prt_tagx pip_prt_tagx;
641 cvmx_read_csr(CVMX_PIP_PRT_TAGX(port));
642 pip_prt_tagx.s.grp = pow_receive_group;
643 cvmx_write_csr(CVMX_PIP_PRT_TAGX(port),
648 cvmx_helper_ipd_and_packet_input_enable();
650 memset(cvm_oct_device, 0, sizeof(cvm_oct_device));
653 * Initialize the FAU used for counting packet buffers that
656 cvmx_fau_atomic_write32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
658 if ((pow_send_group != -1)) {
659 struct net_device *dev;
660 pr_info("\tConfiguring device for POW only access\n");
661 dev = alloc_etherdev(sizeof(struct octeon_ethernet));
663 /* Initialize the device private structure. */
664 struct octeon_ethernet *priv = netdev_priv(dev);
666 hrtimer_init(&priv->tx_restart_timer,
669 priv->tx_restart_timer.function = cvm_oct_restart_tx;
672 * Default for 10GE 5000nS enough time to
673 * transmit about 100 64byte packtes. 1GE
674 * interfaces will get 50000nS below.
676 priv->tx_restart_interval = ktime_set(0, 5000);
678 dev->netdev_ops = &cvm_oct_pow_netdev_ops;
679 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED;
680 priv->port = CVMX_PIP_NUM_INPUT_PORTS;
682 strcpy(dev->name, "pow%d");
683 for (qos = 0; qos < 16; qos++)
684 skb_queue_head_init(&priv->tx_free_list[qos]);
686 if (register_netdev(dev) < 0) {
687 pr_err("Failed to register ethernet device for POW\n");
690 cvm_oct_device[CVMX_PIP_NUM_INPUT_PORTS] = dev;
691 pr_info("%s: POW send group %d, receive group %d\n",
692 dev->name, pow_send_group,
696 pr_err("Failed to allocate ethernet device for POW\n");
700 num_interfaces = cvmx_helper_get_number_of_interfaces();
701 for (interface = 0; interface < num_interfaces; interface++) {
702 cvmx_helper_interface_mode_t imode =
703 cvmx_helper_interface_get_mode(interface);
704 int num_ports = cvmx_helper_ports_on_interface(interface);
707 for (port = cvmx_helper_get_ipd_port(interface, 0);
708 port < cvmx_helper_get_ipd_port(interface, num_ports);
710 struct octeon_ethernet *priv;
711 struct net_device *dev =
712 alloc_etherdev(sizeof(struct octeon_ethernet));
714 pr_err("Failed to allocate ethernet device for port %d\n", port);
718 /* Initialize the device private structure. */
719 priv = netdev_priv(dev);
720 memset(priv, 0, sizeof(struct octeon_ethernet));
724 priv->queue = cvmx_pko_get_base_queue(priv->port);
725 priv->fau = fau - cvmx_pko_get_num_queues(port) * 4;
726 for (qos = 0; qos < 16; qos++)
727 skb_queue_head_init(&priv->tx_free_list[qos]);
728 for (qos = 0; qos < cvmx_pko_get_num_queues(port);
730 cvmx_fau_atomic_write32(priv->fau + qos * 4, 0);
732 switch (priv->imode) {
734 /* These types don't support ports to IPD/PKO */
735 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
736 case CVMX_HELPER_INTERFACE_MODE_PCIE:
737 case CVMX_HELPER_INTERFACE_MODE_PICMG:
740 case CVMX_HELPER_INTERFACE_MODE_NPI:
741 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
742 strcpy(dev->name, "npi%d");
745 case CVMX_HELPER_INTERFACE_MODE_XAUI:
746 dev->netdev_ops = &cvm_oct_xaui_netdev_ops;
747 strcpy(dev->name, "xaui%d");
750 case CVMX_HELPER_INTERFACE_MODE_LOOP:
751 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
752 strcpy(dev->name, "loop%d");
755 case CVMX_HELPER_INTERFACE_MODE_SGMII:
756 dev->netdev_ops = &cvm_oct_sgmii_netdev_ops;
757 priv->tx_restart_interval = ktime_set(0, 50000);
758 strcpy(dev->name, "eth%d");
761 case CVMX_HELPER_INTERFACE_MODE_SPI:
762 dev->netdev_ops = &cvm_oct_spi_netdev_ops;
763 strcpy(dev->name, "spi%d");
766 case CVMX_HELPER_INTERFACE_MODE_RGMII:
767 case CVMX_HELPER_INTERFACE_MODE_GMII:
768 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops;
769 priv->tx_restart_interval = ktime_set(0, 50000);
770 strcpy(dev->name, "eth%d");
774 if (!dev->netdev_ops) {
776 } else if (register_netdev(dev) < 0) {
777 pr_err("Failed to register ethernet device "
778 "for interface %d, port %d\n",
779 interface, priv->port);
782 cvm_oct_device[priv->port] = dev;
784 cvmx_pko_get_num_queues(priv->port) *
790 cvm_oct_rx_initialize();
792 /* Enable the poll timer for checking RGMII status */
793 init_timer(&cvm_oct_poll_timer);
794 cvm_oct_poll_timer.data = 0;
795 cvm_oct_poll_timer.function = cvm_do_timer;
796 mod_timer(&cvm_oct_poll_timer, jiffies + HZ);
802 * Module / driver shutdown
804 * Returns Zero on success
806 static void __exit cvm_oct_cleanup_module(void)
810 /* Disable POW interrupt */
811 cvmx_write_csr(CVMX_POW_WQ_INT_THRX(pow_receive_group), 0);
815 /* Free the interrupt handler */
816 free_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group, cvm_oct_device);
818 del_timer(&cvm_oct_poll_timer);
819 cvm_oct_rx_shutdown();
822 /* Free the ethernet devices */
823 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
824 if (cvm_oct_device[port]) {
825 cvm_oct_tx_shutdown(cvm_oct_device[port]);
826 unregister_netdev(cvm_oct_device[port]);
827 kfree(cvm_oct_device[port]);
828 cvm_oct_device[port] = NULL;
833 cvm_oct_proc_shutdown();
837 /* Free the HW pools */
838 cvm_oct_mem_empty_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE,
840 cvm_oct_mem_empty_fpa(CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE,
842 if (CVMX_FPA_OUTPUT_BUFFER_POOL != CVMX_FPA_PACKET_POOL)
843 cvm_oct_mem_empty_fpa(CVMX_FPA_OUTPUT_BUFFER_POOL,
844 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, 128);
847 MODULE_LICENSE("GPL");
848 MODULE_AUTHOR("Cavium Networks <support@caviumnetworks.com>");
849 MODULE_DESCRIPTION("Cavium Networks Octeon ethernet driver.");
850 module_init(cvm_oct_init_module);
851 module_exit(cvm_oct_cleanup_module);