28 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/netdevice.h>
34 #include <linux/slab.h>
59 #if defined(CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS) \
60 && CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS
67 "\tNumber of packet buffers to allocate and store in the\n"
68 "\tFPA. By default, 1024 packet buffers are used unless\n"
69 "\tCONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS is defined.");
74 "\tPOW group to receive packets from. All ethernet hardware\n"
75 "\twill be configured to send incomming packets to this POW\n"
76 "\tgroup. Also any other software can submit packets to this\n"
77 "\tgroup for the kernel to process.");
82 "\tPOW group to send packets to other software on. This\n"
83 "\tcontrols the creation of the virtual device pow0.\n"
84 "\talways_use_pow also depends on this value.");
89 "\tWhen set, always send to the pow group. This will cause\n"
90 "\tpackets sent to real ethernet devices to be sent to the\n"
91 "\tPOW group instead of the hardware. Unless some other\n"
92 "\tapplication changes the config, packets will still be\n"
93 "\treceived from the low level hardware. Use this option\n"
94 "\tto allow a CVMX app to intercept all packets from the\n"
95 "\tlinux kernel. You must specify pow_send_group along with\n"
101 "\tComma separated list of ethernet devices that should use the\n"
102 "\tPOW for transmit instead of the actual ethernet hardware. This\n"
103 "\tis a per port version of always_use_pow. always_use_pow takes\n"
104 "\tprecedence over this list. For example, setting this to\n"
105 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n"
106 "\tusing the pow_send_group.");
111 "\t\tThe maximum number of CPUs to use for packet reception.\n"
112 "\t\tUse -1 to use all available CPUs.");
154 &cvm_oct_rx_refill_work,
HZ);
157 static void cvm_oct_periodic_worker(
struct work_struct *work)
164 priv->
poll(cvm_oct_device[priv->
port]);
172 static __devinit void cvm_oct_configure_common_hw(
void)
199 cvmx_wqe_t *work = work_queue_entry;
201 int segments = work->word2.s.bufs;
206 cvmx_phys_to_ptr(segment_ptr.
s.addr - 8);
208 cvmx_fpa_free(cvm_oct_get_buffer_ptr(segment_ptr),
212 segment_ptr = next_ptr;
235 memset(&rx_status, 0,
sizeof(rx_status));
236 memset(&tx_status, 0,
sizeof(tx_status));
238 cvmx_pip_get_port_status(priv->
port, 1, &rx_status);
239 cvmx_pko_get_port_status(priv->
port, 1, &tx_status);
273 static int cvm_oct_common_change_mtu(
struct net_device *dev,
int new_mtu)
278 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
288 if ((new_mtu + 14 + 4 + vlan_bytes < 64)
289 || (new_mtu + 14 + 4 + vlan_bytes > 65392)) {
290 pr_err(
"MTU must be between %d and %d.\n",
291 64 - 14 - 4 - vlan_bytes, 65392 - 14 - 4 - vlan_bytes);
300 int max_packet = new_mtu + 14 + 4 + vlan_bytes;
314 frm_len_chk.s.minlen = 64;
324 cvmx_write_csr(CVMX_GMXX_RXX_JABBER(index,
interface),
325 (max_packet + 7) & ~7
u);
334 static void cvm_oct_common_set_multicast_list(
struct net_device *dev)
367 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index,
interface));
368 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index,
interface),
369 gmx_cfg.u64 & ~1ull);
371 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CTL(index,
interface),
374 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
377 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
380 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index,
interface),
392 static int cvm_oct_set_mac_filter(
struct net_device *dev)
405 for (i = 0; i < 6; i++)
406 mac = (mac << 8) | (
uint64_t)ptr[i];
409 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index,
interface));
410 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index,
interface),
411 gmx_cfg.u64 & ~1ull);
413 cvmx_write_csr(CVMX_GMXX_SMACX(index,
interface), mac);
414 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM0(index,
interface),
416 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM1(index,
interface),
418 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM2(index,
interface),
420 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM3(index,
interface),
422 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM4(index,
interface),
424 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM5(index,
interface),
426 cvm_oct_common_set_multicast_list(dev);
427 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index,
interface),
433 static int cvm_oct_common_set_mac_address(
struct net_device *dev,
void *
addr)
439 return cvm_oct_set_mac_filter(dev);
456 if (mac && is_valid_ether_addr(mac)) {
460 eth_hw_addr_random(dev);
471 if (priv->
queue != -1) {
482 cvm_oct_set_mac_filter(dev);
507 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
508 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
510 .ndo_change_mtu = cvm_oct_common_change_mtu,
511 .ndo_get_stats = cvm_oct_common_get_stats,
512 #ifdef CONFIG_NET_POLL_CONTROLLER
522 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
523 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
525 .ndo_change_mtu = cvm_oct_common_change_mtu,
526 .ndo_get_stats = cvm_oct_common_get_stats,
527 #ifdef CONFIG_NET_POLL_CONTROLLER
537 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
538 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
540 .ndo_change_mtu = cvm_oct_common_change_mtu,
541 .ndo_get_stats = cvm_oct_common_get_stats,
542 #ifdef CONFIG_NET_POLL_CONTROLLER
550 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
551 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
553 .ndo_change_mtu = cvm_oct_common_change_mtu,
554 .ndo_get_stats = cvm_oct_common_get_stats,
555 #ifdef CONFIG_NET_POLL_CONTROLLER
565 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
566 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
568 .ndo_change_mtu = cvm_oct_common_change_mtu,
569 .ndo_get_stats = cvm_oct_common_get_stats,
570 #ifdef CONFIG_NET_POLL_CONTROLLER
577 .ndo_set_rx_mode = cvm_oct_common_set_multicast_list,
578 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
580 .ndo_change_mtu = cvm_oct_common_change_mtu,
581 .ndo_get_stats = cvm_oct_common_get_stats,
582 #ifdef CONFIG_NET_POLL_CONTROLLER
612 ni = cvm_oct_of_get_child(pip, interface);
616 np = cvm_oct_of_get_child(ni, port);
633 pip = pdev->
dev.of_node;
635 pr_err(
"Error: No 'pip' in /aliases\n");
640 if (cvm_oct_poll_queue ==
NULL) {
641 pr_err(
"octeon-ethernet: Cannot create workqueue");
645 cvm_oct_configure_common_hw();
651 for (interface = 0;
interface < num_interfaces; interface++) {
669 memset(cvm_oct_device, 0,
sizeof(cvm_oct_device));
682 pr_info(
"\tConfiguring device for POW only access\n");
693 for (qos = 0; qos < 16; qos++)
697 pr_err(
"Failed to register ethernet device for POW\n");
701 pr_info(
"%s: POW send group %d, receive group %d\n",
706 pr_err(
"Failed to allocate ethernet device for POW\n");
711 for (interface = 0;
interface < num_interfaces; interface++) {
720 port_index++, port++) {
725 pr_err(
"Failed to allocate ethernet device for port %d\n", port);
730 priv = netdev_priv(dev);
731 priv->
of_node = cvm_oct_node_for_port(pip, interface, port_index);
734 cvm_oct_periodic_worker);
737 priv->
queue = cvmx_pko_get_base_queue(priv->
port);
738 priv->
fau = fau - cvmx_pko_get_num_queues(port) * 4;
739 for (qos = 0; qos < 16; qos++)
741 for (qos = 0; qos < cvmx_pko_get_num_queues(port);
743 cvmx_fau_atomic_write32(priv->
fau + qos * 4, 0);
745 switch (priv->
imode) {
788 pr_err(
"Failed to register ethernet device "
789 "for interface %d, port %d\n",
790 interface, priv->
port);
793 cvm_oct_device[priv->
port] =
dev;
795 cvmx_pko_get_num_queues(priv->
port) *
838 if (cvm_oct_device[port]) {
869 .compatible =
"cavium,octeon-3860-pip",
876 .probe = cvm_oct_probe,
880 .name = KBUILD_MODNAME,
881 .of_match_table = cvm_oct_match,