6478b6fbfe0d676d8231dc7c56d497aaca553579
[dpdk.git] / drivers / net / txgbe / base / txgbe_hw.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #include "txgbe_type.h"
6 #include "txgbe_hw.h"
7
8 #define TXGBE_RAPTOR_RAR_ENTRIES   128
9
10 /**
11  *  txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
12  *  @hw: pointer to the HW structure
13  *
14  *  Determines the LAN function id by reading memory-mapped registers and swaps
15  *  the port value if requested, and set MAC instance for devices.
16  **/
17 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
18 {
19         struct txgbe_bus_info *bus = &hw->bus;
20         u32 reg;
21
22         DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
23
24         reg = rd32(hw, TXGBE_PORTSTAT);
25         bus->lan_id = TXGBE_PORTSTAT_ID(reg);
26
27         /* check for single port */
28         reg = rd32(hw, TXGBE_PWR);
29         if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
30                 bus->func = 0;
31         else
32                 bus->func = bus->lan_id;
33 }
34
35 /**
36  *  txgbe_init_shared_code - Initialize the shared code
37  *  @hw: pointer to hardware structure
38  *
39  *  This will assign function pointers and assign the MAC type and PHY code.
40  *  Does not touch the hardware. This function must be called prior to any
41  *  other function in the shared code. The txgbe_hw structure should be
42  *  memset to 0 prior to calling this function.  The following fields in
43  *  hw structure should be filled in prior to calling this function:
44  *  hw_addr, back, device_id, vendor_id, subsystem_device_id,
45  *  subsystem_vendor_id, and revision_id
46  **/
47 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
48 {
49         s32 status;
50
51         DEBUGFUNC("txgbe_init_shared_code");
52
53         /*
54          * Set the mac type
55          */
56         txgbe_set_mac_type(hw);
57
58         txgbe_init_ops_dummy(hw);
59         switch (hw->mac.type) {
60         case txgbe_mac_raptor:
61                 status = txgbe_init_ops_pf(hw);
62                 break;
63         default:
64                 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
65                 break;
66         }
67         hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
68
69         hw->bus.set_lan_id(hw);
70
71         return status;
72 }
73
74 /**
75  *  txgbe_set_mac_type - Sets MAC type
76  *  @hw: pointer to the HW structure
77  *
78  *  This function sets the mac type of the adapter based on the
79  *  vendor ID and device ID stored in the hw structure.
80  **/
81 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
82 {
83         s32 err = 0;
84
85         DEBUGFUNC("txgbe_set_mac_type");
86
87         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
88                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
89                 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
90         }
91
92         switch (hw->device_id) {
93         case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
94                 hw->phy.media_type = txgbe_media_type_backplane;
95                 hw->mac.type = txgbe_mac_raptor;
96                 break;
97         case TXGBE_DEV_ID_RAPTOR_XAUI:
98         case TXGBE_DEV_ID_RAPTOR_SGMII:
99                 hw->phy.media_type = txgbe_media_type_copper;
100                 hw->mac.type = txgbe_mac_raptor;
101                 break;
102         case TXGBE_DEV_ID_RAPTOR_SFP:
103         case TXGBE_DEV_ID_WX1820_SFP:
104                 hw->phy.media_type = txgbe_media_type_fiber;
105                 hw->mac.type = txgbe_mac_raptor;
106                 break;
107         case TXGBE_DEV_ID_RAPTOR_QSFP:
108                 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
109                 hw->mac.type = txgbe_mac_raptor;
110                 break;
111         case TXGBE_DEV_ID_RAPTOR_VF:
112         case TXGBE_DEV_ID_RAPTOR_VF_HV:
113                 hw->phy.media_type = txgbe_media_type_virtual;
114                 hw->mac.type = txgbe_mac_raptor_vf;
115                 break;
116         default:
117                 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
118                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
119                 break;
120         }
121
122         DEBUGOUT("found mac: %d media: %d, returns: %d\n",
123                   hw->mac.type, hw->phy.media_type, err);
124         return err;
125 }
126
127 /**
128  *  txgbe_init_ops_pf - Inits func ptrs and MAC type
129  *  @hw: pointer to hardware structure
130  *
131  *  Initialize the function pointers and assign the MAC type.
132  *  Does not touch the hardware.
133  **/
134 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
135 {
136         struct txgbe_bus_info *bus = &hw->bus;
137         struct txgbe_mac_info *mac = &hw->mac;
138
139         DEBUGFUNC("txgbe_init_ops_pf");
140
141         /* BUS */
142         bus->set_lan_id = txgbe_set_lan_id_multi_port;
143
144         mac->num_rar_entries    = TXGBE_RAPTOR_RAR_ENTRIES;
145
146         return 0;
147 }