File Index
Files and directories
Sign in
FILE

rnpgbe_chip.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_chip.c C
  1// SPDX-License-Identifier: GPL-2.0
  2/* Copyright(c) 2020 - 2025 Mucse Corporation. */
  3
  4#include <linux/pci.h>
  5#include <linux/errno.h>
  6#include <linux/etherdevice.h>
  7
  8#include "rnpgbe.h"
  9#include "rnpgbe_hw.h"
 10#include "rnpgbe_mbx.h"
 11#include "rnpgbe_mbx_fw.h"
 12
 13/**
 14 * rnpgbe_get_permanent_mac - Get permanent mac
 15 * @hw: hw information structure
 16 * @perm_addr: pointer to store perm_addr
 17 *
 18 * rnpgbe_get_permanent_mac tries to get mac from hw
 19 *
 20 * Return: 0 on success, negative errno on failure
 21 **/
 22int rnpgbe_get_permanent_mac(struct mucse_hw *hw, u8 *perm_addr)
 23{
 24	struct device *dev = &hw->pdev->dev;
 25	int err;
 26
 27	err = mucse_mbx_get_macaddr(hw, hw->pfvfnum, perm_addr, hw->port);
 28	if (err) {
 29		dev_err(dev, "Failed to get MAC from FW %d\n", err);
 30		return err;
 31	}
 32
 33	if (!is_valid_ether_addr(perm_addr)) {
 34		dev_err(dev, "Failed to get valid MAC from FW\n");
 35		return -EINVAL;
 36	}
 37
 38	return 0;
 39}
 40
 41/**
 42 * rnpgbe_reset_hw - Do a hardware reset
 43 * @hw: hw information structure
 44 *
 45 * rnpgbe_reset_hw calls fw to do a hardware
 46 * reset, and cleans some regs to default.
 47 *
 48 * Return: 0 on success, negative errno on failure
 49 **/
 50int rnpgbe_reset_hw(struct mucse_hw *hw)
 51{
 52	mucse_hw_wr32(hw, RNPGBE_DMA_AXI_EN, 0);
 53	return mucse_mbx_reset_hw(hw);
 54}
 55
 56/**
 57 * rnpgbe_send_notify - Echo fw status
 58 * @hw: hw information structure
 59 * @enable: true or false status
 60 * @mode: status mode
 61 *
 62 * Return: 0 on success, negative errno on failure
 63 **/
 64int rnpgbe_send_notify(struct mucse_hw *hw,
 65		       bool enable,
 66		       int mode)
 67{
 68	int err;
 69	/* Keep switch struct to support more modes in the future */
 70	switch (mode) {
 71	case mucse_fw_powerup:
 72		err = mucse_mbx_powerup(hw, enable);
 73		break;
 74	default:
 75		err = -EINVAL;
 76	}
 77
 78	return err;
 79}
 80
 81/**
 82 * rnpgbe_init_n500 - Setup n500 hw info
 83 * @hw: hw information structure
 84 *
 85 * rnpgbe_init_n500 initializes all private
 86 * structure for n500
 87 **/
 88static void rnpgbe_init_n500(struct mucse_hw *hw)
 89{
 90	struct mucse_mbx_info *mbx = &hw->mbx;
 91
 92	mbx->fwpf_ctrl_base = MUCSE_N500_FWPF_CTRL_BASE;
 93	mbx->fwpf_shm_base = MUCSE_N500_FWPF_SHM_BASE;
 94}
 95
 96/**
 97 * rnpgbe_init_n210 - Setup n210 hw info
 98 * @hw: hw information structure
 99 *
100 * rnpgbe_init_n210 initializes all private
101 * structure for n210
102 **/
103static void rnpgbe_init_n210(struct mucse_hw *hw)
104{
105	struct mucse_mbx_info *mbx = &hw->mbx;
106
107	mbx->fwpf_ctrl_base = MUCSE_N210_FWPF_CTRL_BASE;
108	mbx->fwpf_shm_base = MUCSE_N210_FWPF_SHM_BASE;
109}
110
111/**
112 * rnpgbe_init_hw - Setup hw info according to board_type
113 * @hw: hw information structure
114 * @board_type: board type
115 *
116 * rnpgbe_init_hw initializes all hw data
117 *
118 * Return: 0 on success, -EINVAL on failure
119 **/
120int rnpgbe_init_hw(struct mucse_hw *hw, int board_type)
121{
122	struct mucse_mbx_info *mbx = &hw->mbx;
123
124	hw->port = 0;
125
126	mbx->pf2fw_mbx_ctrl = MUCSE_GBE_PFFW_MBX_CTRL_OFFSET;
127	mbx->fwpf_mbx_mask = MUCSE_GBE_FWPF_MBX_MASK_OFFSET;
128
129	switch (board_type) {
130	case board_n500:
131		rnpgbe_init_n500(hw);
132		break;
133	case board_n210:
134		rnpgbe_init_n210(hw);
135		break;
136	default:
137		return -EINVAL;
138	}
139	/* init_params with mbx base */
140	mucse_init_mbx_params_pf(hw);
141
142	return 0;
143}
~/ Read-only file preview.