cvmx-mgmt-port.c (215990) | cvmx-mgmt-port.c (217214) |
---|---|
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: --- 98 unchanged lines hidden (view full) --- 107CVMX_SHARED cvmx_mgmt_port_state_t *cvmx_mgmt_port_state_ptr = NULL; 108 109 110/** 111 * Return the number of management ports supported by this chip 112 * 113 * @return Number of ports 114 */ | 1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: --- 98 unchanged lines hidden (view full) --- 107CVMX_SHARED cvmx_mgmt_port_state_t *cvmx_mgmt_port_state_ptr = NULL; 108 109 110/** 111 * Return the number of management ports supported by this chip 112 * 113 * @return Number of ports 114 */ |
115int __cvmx_mgmt_port_num_ports(void) | 115static int __cvmx_mgmt_port_num_ports(void) |
116{ 117 if (OCTEON_IS_MODEL(OCTEON_CN56XX)) 118 return 1; 119 else if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX)) 120 return 2; 121 else 122 return 0; 123} --- 425 unchanged lines hidden (view full) --- 549 cvmx_write_csr(CVMX_MIXX_ORCNT(port), cvmx_read_csr(CVMX_MIXX_ORCNT(port))); 550 551 cvmx_spinlock_unlock(&state->lock); 552 return CVMX_MGMT_PORT_SUCCESS; 553 } 554} 555 556 | 116{ 117 if (OCTEON_IS_MODEL(OCTEON_CN56XX)) 118 return 1; 119 else if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX)) 120 return 2; 121 else 122 return 0; 123} --- 425 unchanged lines hidden (view full) --- 549 cvmx_write_csr(CVMX_MIXX_ORCNT(port), cvmx_read_csr(CVMX_MIXX_ORCNT(port))); 550 551 cvmx_spinlock_unlock(&state->lock); 552 return CVMX_MGMT_PORT_SUCCESS; 553 } 554} 555 556 |
557#if defined(__FreeBSD__) |
|
557/** | 558/** |
559 * Send a packet out the management port. The packet is copied so 560 * the input mbuf isn't used after this call. 561 * 562 * @param port Management port 563 * @param m Packet mbuf (with pkthdr) 564 * 565 * @return CVMX_MGMT_PORT_SUCCESS or an error code 566 */ 567cvmx_mgmt_port_result_t cvmx_mgmt_port_sendm(int port, const struct mbuf *m) 568{ 569 cvmx_mgmt_port_state_t *state; 570 cvmx_mixx_oring2_t mix_oring2; 571 572 if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports())) 573 return CVMX_MGMT_PORT_INVALID_PARAM; 574 575 /* Max sure the packet size is valid */ 576 if ((m->m_pkthdr.len < 1) || (m->m_pkthdr.len > CVMX_MGMT_PORT_TX_BUFFER_SIZE)) 577 return CVMX_MGMT_PORT_INVALID_PARAM; 578 579 state = cvmx_mgmt_port_state_ptr + port; 580 581 cvmx_spinlock_lock(&state->lock); 582 583 mix_oring2.u64 = cvmx_read_csr(CVMX_MIXX_ORING2(port)); 584 if (mix_oring2.s.odbell >= CVMX_MGMT_PORT_NUM_TX_BUFFERS - 1) 585 { 586 /* No room for another packet */ 587 cvmx_spinlock_unlock(&state->lock); 588 return CVMX_MGMT_PORT_NO_MEMORY; 589 } 590 else 591 { 592 /* Copy the packet into the output buffer */ 593 m_copydata(m, 0, m->m_pkthdr.len, state->tx_buffers[state->tx_write_index]); 594 /* Update the TX ring buffer entry size */ 595 state->tx_ring[state->tx_write_index].s.len = m->m_pkthdr.len; 596 /* This code doesn't support TX timestamps */ 597 state->tx_ring[state->tx_write_index].s.tstamp = 0; 598 /* Increment our TX index */ 599 state->tx_write_index = (state->tx_write_index + 1) % CVMX_MGMT_PORT_NUM_TX_BUFFERS; 600 /* Ring the doorbell, sending the packet */ 601 CVMX_SYNCWS; 602 cvmx_write_csr(CVMX_MIXX_ORING2(port), 1); 603 if (cvmx_read_csr(CVMX_MIXX_ORCNT(port))) 604 cvmx_write_csr(CVMX_MIXX_ORCNT(port), cvmx_read_csr(CVMX_MIXX_ORCNT(port))); 605 606 cvmx_spinlock_unlock(&state->lock); 607 return CVMX_MGMT_PORT_SUCCESS; 608 } 609} 610#endif 611 612 613/** |
|
558 * Receive a packet from the management port. 559 * 560 * @param port Management port 561 * @param buffer_len Size of the buffer to receive the packet into 562 * @param buffer Buffer to receive the packet into 563 * 564 * @return The size of the packet, or a negative erorr code on failure. Zero 565 * means that no packets were available. 566 */ | 614 * Receive a packet from the management port. 615 * 616 * @param port Management port 617 * @param buffer_len Size of the buffer to receive the packet into 618 * @param buffer Buffer to receive the packet into 619 * 620 * @return The size of the packet, or a negative erorr code on failure. Zero 621 * means that no packets were available. 622 */ |
567int cvmx_mgmt_port_receive(int port, int buffer_len, void *buffer) | 623int cvmx_mgmt_port_receive(int port, int buffer_len, uint8_t *buffer) |
568{ 569 cvmx_mixx_ircnt_t mix_ircnt; 570 cvmx_mgmt_port_state_t *state; 571 int result; 572 573 if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports())) 574 return CVMX_MGMT_PORT_INVALID_PARAM; 575 --- 7 unchanged lines hidden (view full) --- 583 state = cvmx_mgmt_port_state_ptr + port; 584 585 cvmx_spinlock_lock(&state->lock); 586 587 /* Find out how many RX packets are pending */ 588 mix_ircnt.u64 = cvmx_read_csr(CVMX_MIXX_IRCNT(port)); 589 if (mix_ircnt.s.ircnt) 590 { | 624{ 625 cvmx_mixx_ircnt_t mix_ircnt; 626 cvmx_mgmt_port_state_t *state; 627 int result; 628 629 if ((port < 0) || (port >= __cvmx_mgmt_port_num_ports())) 630 return CVMX_MGMT_PORT_INVALID_PARAM; 631 --- 7 unchanged lines hidden (view full) --- 639 state = cvmx_mgmt_port_state_ptr + port; 640 641 cvmx_spinlock_lock(&state->lock); 642 643 /* Find out how many RX packets are pending */ 644 mix_ircnt.u64 = cvmx_read_csr(CVMX_MIXX_IRCNT(port)); 645 if (mix_ircnt.s.ircnt) 646 { |
591 void *source = state->rx_buffers[state->rx_read_index]; 592 uint64_t *zero_check = source; | 647 uint64_t *source = (void *)state->rx_buffers[state->rx_read_index]; 648 uint64_t *zero_check = source; |
593 /* CN56XX pass 1 has an errata where packets might start 8 bytes 594 into the buffer instead of at their correct lcoation. If the 595 first 8 bytes is zero we assume this has happened */ 596 if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X) && (*zero_check == 0)) | 649 /* CN56XX pass 1 has an errata where packets might start 8 bytes 650 into the buffer instead of at their correct lcoation. If the 651 first 8 bytes is zero we assume this has happened */ 652 if (OCTEON_IS_MODEL(OCTEON_CN56XX_PASS1_X) && (*zero_check == 0)) |
597 source += 8; | 653 source++; |
598 /* Start off with zero bytes received */ 599 result = 0; 600 /* While the completion code signals more data, copy the buffers 601 into the user's data */ 602 while (state->rx_ring[state->rx_read_index].s.code == 16) 603 { 604 /* Only copy what will fit in the user's buffer */ 605 int length = state->rx_ring[state->rx_read_index].s.len; --- 10 unchanged lines hidden (view full) --- 616 state->rx_ring[state->rx_read_index].s.code = 0; 617 state->rx_ring[state->rx_read_index].s.len = CVMX_MGMT_PORT_RX_BUFFER_SIZE - 8; 618 state->rx_read_index = (state->rx_read_index + 1) % CVMX_MGMT_PORT_NUM_RX_BUFFERS; 619 /* Zero the beginning of the buffer for use by the errata check */ 620 *zero_check = 0; 621 CVMX_SYNCWS; 622 /* Increment the number of RX buffers */ 623 cvmx_write_csr(CVMX_MIXX_IRING2(port), 1); | 654 /* Start off with zero bytes received */ 655 result = 0; 656 /* While the completion code signals more data, copy the buffers 657 into the user's data */ 658 while (state->rx_ring[state->rx_read_index].s.code == 16) 659 { 660 /* Only copy what will fit in the user's buffer */ 661 int length = state->rx_ring[state->rx_read_index].s.len; --- 10 unchanged lines hidden (view full) --- 672 state->rx_ring[state->rx_read_index].s.code = 0; 673 state->rx_ring[state->rx_read_index].s.len = CVMX_MGMT_PORT_RX_BUFFER_SIZE - 8; 674 state->rx_read_index = (state->rx_read_index + 1) % CVMX_MGMT_PORT_NUM_RX_BUFFERS; 675 /* Zero the beginning of the buffer for use by the errata check */ 676 *zero_check = 0; 677 CVMX_SYNCWS; 678 /* Increment the number of RX buffers */ 679 cvmx_write_csr(CVMX_MIXX_IRING2(port), 1); |
624 source = state->rx_buffers[state->rx_read_index]; | 680 source = (void *)state->rx_buffers[state->rx_read_index]; |
625 zero_check = source; 626 } 627 628 /* Check for the final good completion code */ 629 if (state->rx_ring[state->rx_read_index].s.code == 15) 630 { 631 if (buffer_len >= state->rx_ring[state->rx_read_index].s.len) 632 { --- 319 unchanged lines hidden --- | 681 zero_check = source; 682 } 683 684 /* Check for the final good completion code */ 685 if (state->rx_ring[state->rx_read_index].s.code == 15) 686 { 687 if (buffer_len >= state->rx_ring[state->rx_read_index].s.len) 688 { --- 319 unchanged lines hidden --- |