1ffd8b1fd81e4338f85ad7551dae48c0a165f0f2
[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 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
36 {
37         s32 status;
38
39         DEBUGFUNC("txgbe_init_shared_code");
40
41         /*
42          * Set the mac type
43          */
44         txgbe_set_mac_type(hw);
45
46         switch (hw->mac.type) {
47         case txgbe_mac_raptor:
48                 status = txgbe_init_ops_pf(hw);
49                 break;
50         default:
51                 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
52                 break;
53         }
54         hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
55
56         hw->bus.set_lan_id(hw);
57
58         return status;
59 }
60
61 /**
62  *  txgbe_set_mac_type - Sets MAC type
63  *  @hw: pointer to the HW structure
64  *
65  *  This function sets the mac type of the adapter based on the
66  *  vendor ID and device ID stored in the hw structure.
67  **/
68 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
69 {
70         s32 err = 0;
71
72         DEBUGFUNC("txgbe_set_mac_type");
73
74         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
75                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
76                 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
77         }
78
79         switch (hw->device_id) {
80         case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
81                 hw->phy.media_type = txgbe_media_type_backplane;
82                 hw->mac.type = txgbe_mac_raptor;
83                 break;
84         case TXGBE_DEV_ID_RAPTOR_XAUI:
85         case TXGBE_DEV_ID_RAPTOR_SGMII:
86                 hw->phy.media_type = txgbe_media_type_copper;
87                 hw->mac.type = txgbe_mac_raptor;
88                 break;
89         case TXGBE_DEV_ID_RAPTOR_SFP:
90         case TXGBE_DEV_ID_WX1820_SFP:
91                 hw->phy.media_type = txgbe_media_type_fiber;
92                 hw->mac.type = txgbe_mac_raptor;
93                 break;
94         case TXGBE_DEV_ID_RAPTOR_QSFP:
95                 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
96                 hw->mac.type = txgbe_mac_raptor;
97                 break;
98         case TXGBE_DEV_ID_RAPTOR_VF:
99         case TXGBE_DEV_ID_RAPTOR_VF_HV:
100                 hw->phy.media_type = txgbe_media_type_virtual;
101                 hw->mac.type = txgbe_mac_raptor_vf;
102                 break;
103         default:
104                 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
105                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
106                 break;
107         }
108
109         DEBUGOUT("found mac: %d media: %d, returns: %d\n",
110                   hw->mac.type, hw->phy.media_type, err);
111         return err;
112 }
113
114 /**
115  *  txgbe_init_ops_pf - Inits func ptrs and MAC type
116  *  @hw: pointer to hardware structure
117  *
118  *  Initialize the function pointers and assign the MAC type.
119  *  Does not touch the hardware.
120  **/
121 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
122 {
123         struct txgbe_bus_info *bus = &hw->bus;
124         struct txgbe_mac_info *mac = &hw->mac;
125
126         DEBUGFUNC("txgbe_init_ops_pf");
127
128         /* BUS */
129         bus->set_lan_id = txgbe_set_lan_id_multi_port;
130
131         mac->num_rar_entries    = TXGBE_RAPTOR_RAR_ENTRIES;
132
133         return 0;
134 }