net/fm10k: replace license text with SPDX tag
[dpdk.git] / drivers / net / fm10k / base / fm10k_api.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2013 - 2015 Intel Corporation
3  */
4
5 #include "fm10k_api.h"
6 #include "fm10k_common.h"
7
8 /**
9  *  fm10k_set_mac_type - Sets MAC type
10  *  @hw: pointer to the HW structure
11  *
12  *  This function sets the mac type of the adapter based on the
13  *  vendor ID and device ID stored in the hw structure.
14  **/
15 s32 fm10k_set_mac_type(struct fm10k_hw *hw)
16 {
17         s32 ret_val = FM10K_SUCCESS;
18
19         DEBUGFUNC("fm10k_set_mac_type");
20
21         if (hw->vendor_id != FM10K_INTEL_VENDOR_ID) {
22                 ERROR_REPORT2(FM10K_ERROR_UNSUPPORTED,
23                              "Unsupported vendor id: %x\n", hw->vendor_id);
24                 return FM10K_ERR_DEVICE_NOT_SUPPORTED;
25         }
26
27         switch (hw->device_id) {
28         case FM10K_DEV_ID_PF:
29 #ifdef BOULDER_RAPIDS_HW
30         case FM10K_DEV_ID_SDI_FM10420_QDA2:
31 #endif /* BOULDER_RAPIDS_HW */
32 #ifdef ATWOOD_CHANNEL_HW
33         case FM10K_DEV_ID_SDI_FM10420_DA2:
34 #endif /* ATWOOD_CHANNEL_HW */
35                 hw->mac.type = fm10k_mac_pf;
36                 break;
37         case FM10K_DEV_ID_VF:
38                 hw->mac.type = fm10k_mac_vf;
39                 break;
40         default:
41                 ret_val = FM10K_ERR_DEVICE_NOT_SUPPORTED;
42                 ERROR_REPORT2(FM10K_ERROR_UNSUPPORTED,
43                              "Unsupported device id: %x\n",
44                              hw->device_id);
45                 break;
46         }
47
48         DEBUGOUT2("fm10k_set_mac_type found mac: %d, returns: %d\n",
49                   hw->mac.type, ret_val);
50
51         return ret_val;
52 }
53
54 /**
55  *  fm10k_init_shared_code - Initialize the shared code
56  *  @hw: pointer to hardware structure
57  *
58  *  This will assign function pointers and assign the MAC type and PHY code.
59  *  Does not touch the hardware. This function must be called prior to any
60  *  other function in the shared code. The fm10k_hw structure should be
61  *  memset to 0 prior to calling this function.  The following fields in
62  *  hw structure should be filled in prior to calling this function:
63  *  hw_addr, back, device_id, vendor_id, subsystem_device_id,
64  *  subsystem_vendor_id, and revision_id
65  **/
66 s32 fm10k_init_shared_code(struct fm10k_hw *hw)
67 {
68         s32 status;
69
70         DEBUGFUNC("fm10k_init_shared_code");
71
72         /* Set the mac type */
73         fm10k_set_mac_type(hw);
74
75         switch (hw->mac.type) {
76         case fm10k_mac_pf:
77                 status = fm10k_init_ops_pf(hw);
78                 break;
79         case fm10k_mac_vf:
80                 status = fm10k_init_ops_vf(hw);
81                 break;
82         default:
83                 status = FM10K_ERR_DEVICE_NOT_SUPPORTED;
84                 break;
85         }
86
87         return status;
88 }
89
90 #define fm10k_call_func(hw, func, params, error) \
91                  ((func) ? (func params) : (error))
92
93 /**
94  *  fm10k_reset_hw - Reset the hardware to known good state
95  *  @hw: pointer to hardware structure
96  *
97  *  This function should return the hardware to a state similar to the
98  *  one it is in after being powered on.
99  **/
100 s32 fm10k_reset_hw(struct fm10k_hw *hw)
101 {
102         return fm10k_call_func(hw, hw->mac.ops.reset_hw, (hw),
103                                FM10K_NOT_IMPLEMENTED);
104 }
105
106 /**
107  *  fm10k_init_hw - Initialize the hardware
108  *  @hw: pointer to hardware structure
109  *
110  *  Initialize the hardware by resetting and then starting the hardware
111  **/
112 s32 fm10k_init_hw(struct fm10k_hw *hw)
113 {
114         return fm10k_call_func(hw, hw->mac.ops.init_hw, (hw),
115                                FM10K_NOT_IMPLEMENTED);
116 }
117
118 /**
119  *  fm10k_stop_hw - Prepares hardware to shutdown Rx/Tx
120  *  @hw: pointer to hardware structure
121  *
122  *  Disables Rx/Tx queues and disables the DMA engine.
123  **/
124 s32 fm10k_stop_hw(struct fm10k_hw *hw)
125 {
126         return fm10k_call_func(hw, hw->mac.ops.stop_hw, (hw),
127                                FM10K_NOT_IMPLEMENTED);
128 }
129
130 /**
131  *  fm10k_start_hw - Prepares hardware for Rx/Tx
132  *  @hw: pointer to hardware structure
133  *
134  *  This function sets the flags indicating that the hardware is ready to
135  *  begin operation.
136  **/
137 s32 fm10k_start_hw(struct fm10k_hw *hw)
138 {
139         return fm10k_call_func(hw, hw->mac.ops.start_hw, (hw),
140                                FM10K_NOT_IMPLEMENTED);
141 }
142
143 /**
144  *  fm10k_get_bus_info - Set PCI bus info
145  *  @hw: pointer to hardware structure
146  *
147  *  Sets the PCI bus info (speed, width, type) within the fm10k_hw structure
148  **/
149 s32 fm10k_get_bus_info(struct fm10k_hw *hw)
150 {
151         return fm10k_call_func(hw, hw->mac.ops.get_bus_info, (hw),
152                                FM10K_NOT_IMPLEMENTED);
153 }
154
155 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
156 /**
157  *  fm10k_is_slot_appropriate - Indicate appropriate slot for this SKU
158  *  @hw: pointer to hardware structure
159  *
160  *  Looks at the PCIe bus info to confirm whether or not this slot can support
161  *  the necessary bandwidth for this device.
162  **/
163 bool fm10k_is_slot_appropriate(struct fm10k_hw *hw)
164 {
165         if (hw->mac.ops.is_slot_appropriate)
166                 return hw->mac.ops.is_slot_appropriate(hw);
167         return true;
168 }
169
170 #endif
171 /**
172  *  fm10k_update_vlan - Clear VLAN ID to VLAN filter table
173  *  @hw: pointer to hardware structure
174  *  @vid: VLAN ID to add to table
175  *  @idx: Index indicating VF ID or PF ID in table
176  *  @set: Indicates if this is a set or clear operation
177  *
178  *  This function adds or removes the corresponding VLAN ID from the VLAN
179  *  filter table for the corresponding function.
180  **/
181 s32 fm10k_update_vlan(struct fm10k_hw *hw, u32 vid, u8 idx, bool set)
182 {
183         return fm10k_call_func(hw, hw->mac.ops.update_vlan, (hw, vid, idx, set),
184                                FM10K_NOT_IMPLEMENTED);
185 }
186
187 /**
188  *  fm10k_read_mac_addr - Reads MAC address
189  *  @hw: pointer to hardware structure
190  *
191  *  Reads the MAC address out of the interface and stores it in the HW
192  *  structures.
193  **/
194 s32 fm10k_read_mac_addr(struct fm10k_hw *hw)
195 {
196         return fm10k_call_func(hw, hw->mac.ops.read_mac_addr, (hw),
197                                FM10K_NOT_IMPLEMENTED);
198 }
199
200 /**
201  *  fm10k_update_hw_stats - Update hw statistics
202  *  @hw: pointer to hardware structure
203  *
204  *  This function updates statistics that are related to hardware.
205  * */
206 void fm10k_update_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
207 {
208         if (hw->mac.ops.update_hw_stats)
209                 hw->mac.ops.update_hw_stats(hw, stats);
210 }
211
212 /**
213  *  fm10k_rebind_hw_stats - Reset base for hw statistics
214  *  @hw: pointer to hardware structure
215  *
216  *  This function resets the base for statistics that are related to hardware.
217  * */
218 void fm10k_rebind_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
219 {
220         if (hw->mac.ops.rebind_hw_stats)
221                 hw->mac.ops.rebind_hw_stats(hw, stats);
222 }
223
224 /**
225  *  fm10k_configure_dglort_map - Configures GLORT entry and queues
226  *  @hw: pointer to hardware structure
227  *  @dglort: pointer to dglort configuration structure
228  *
229  *  Reads the configuration structure contained in dglort_cfg and uses
230  *  that information to then populate a DGLORTMAP/DEC entry and the queues
231  *  to which it has been assigned.
232  **/
233 s32 fm10k_configure_dglort_map(struct fm10k_hw *hw,
234                                struct fm10k_dglort_cfg *dglort)
235 {
236         return fm10k_call_func(hw, hw->mac.ops.configure_dglort_map,
237                                (hw, dglort), FM10K_NOT_IMPLEMENTED);
238 }
239
240 /**
241  *  fm10k_set_dma_mask - Configures PhyAddrSpace to limit DMA to system
242  *  @hw: pointer to hardware structure
243  *  @dma_mask: 64 bit DMA mask required for platform
244  *
245  *  This function configures the endpoint to limit the access to memory
246  *  beyond what is physically in the system.
247  **/
248 void fm10k_set_dma_mask(struct fm10k_hw *hw, u64 dma_mask)
249 {
250         if (hw->mac.ops.set_dma_mask)
251                 hw->mac.ops.set_dma_mask(hw, dma_mask);
252 }
253
254 /**
255  *  fm10k_get_fault - Record a fault in one of the interface units
256  *  @hw: pointer to hardware structure
257  *  @type: pointer to fault type register offset
258  *  @fault: pointer to memory location to record the fault
259  *
260  *  Record the fault register contents to the fault data structure and
261  *  clear the entry from the register.
262  *
263  *  Returns ERR_PARAM if invalid register is specified or no error is present.
264  **/
265 s32 fm10k_get_fault(struct fm10k_hw *hw, int type, struct fm10k_fault *fault)
266 {
267         return fm10k_call_func(hw, hw->mac.ops.get_fault, (hw, type, fault),
268                                FM10K_NOT_IMPLEMENTED);
269 }
270
271 /**
272  *  fm10k_update_uc_addr - Update device unicast address
273  *  @hw: pointer to the HW structure
274  *  @lport: logical port ID to update - unused
275  *  @mac: MAC address to add/remove from table
276  *  @vid: VLAN ID to add/remove from table
277  *  @add: Indicates if this is an add or remove operation
278  *  @flags: flags field to indicate add and secure - unused
279  *
280  *  This function is used to add or remove unicast MAC addresses
281  **/
282 s32 fm10k_update_uc_addr(struct fm10k_hw *hw, u16 lport,
283                           const u8 *mac, u16 vid, bool add, u8 flags)
284 {
285         return fm10k_call_func(hw, hw->mac.ops.update_uc_addr,
286                                (hw, lport, mac, vid, add, flags),
287                                FM10K_NOT_IMPLEMENTED);
288 }
289
290 /**
291  *  fm10k_update_mc_addr - Update device multicast address
292  *  @hw: pointer to the HW structure
293  *  @lport: logical port ID to update - unused
294  *  @mac: MAC address to add/remove from table
295  *  @vid: VLAN ID to add/remove from table
296  *  @add: Indicates if this is an add or remove operation
297  *
298  *  This function is used to add or remove multicast MAC addresses
299  **/
300 s32 fm10k_update_mc_addr(struct fm10k_hw *hw, u16 lport,
301                          const u8 *mac, u16 vid, bool add)
302 {
303         return fm10k_call_func(hw, hw->mac.ops.update_mc_addr,
304                                (hw, lport, mac, vid, add),
305                                FM10K_NOT_IMPLEMENTED);
306 }
307
308 /**
309  *  fm10k_adjust_systime - Adjust systime frequency
310  *  @hw: pointer to hardware structure
311  *  @ppb: adjustment rate in parts per billion
312  *
313  *  This function is meant to update the frequency of the clock represented
314  *  by the SYSTIME register.
315  **/
316 s32 fm10k_adjust_systime(struct fm10k_hw *hw, s32 ppb)
317 {
318         return fm10k_call_func(hw, hw->mac.ops.adjust_systime,
319                                (hw, ppb), FM10K_NOT_IMPLEMENTED);
320 }
321
322 /**
323  *  fm10k_notify_offset - Notify switch of change in PTP offset
324  *  @hw: pointer to hardware structure
325  *  @offset: 64bit unsigned offset from hardware SYSTIME value
326  *
327  *  This function is meant to notify switch of change in the PTP offset for
328  *  the hardware SYSTIME registers.
329  **/
330 s32 fm10k_notify_offset(struct fm10k_hw *hw, u64 offset)
331 {
332         return fm10k_call_func(hw, hw->mac.ops.notify_offset,
333                                (hw, offset), FM10K_NOT_IMPLEMENTED);
334 }