xref: /f-stack/dpdk/drivers/net/fm10k/base/fm10k_api.c (revision 4418919f)
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  **/
fm10k_set_mac_type(struct fm10k_hw * hw)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  **/
fm10k_init_shared_code(struct fm10k_hw * hw)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  **/
fm10k_reset_hw(struct fm10k_hw * hw)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  **/
fm10k_init_hw(struct fm10k_hw * hw)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  **/
fm10k_stop_hw(struct fm10k_hw * hw)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  **/
fm10k_start_hw(struct fm10k_hw * hw)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  **/
fm10k_get_bus_info(struct fm10k_hw * hw)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  **/
fm10k_is_slot_appropriate(struct fm10k_hw * hw)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  **/
fm10k_update_vlan(struct fm10k_hw * hw,u32 vid,u8 idx,bool set)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  **/
fm10k_read_mac_addr(struct fm10k_hw * hw)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  * */
fm10k_update_hw_stats(struct fm10k_hw * hw,struct fm10k_hw_stats * stats)206 void fm10k_update_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
207 {
208 	switch (hw->mac.type) {
209 	case fm10k_mac_pf:
210 		return fm10k_update_hw_stats_pf(hw, stats);
211 	case fm10k_mac_vf:
212 		return fm10k_update_hw_stats_vf(hw, stats);
213 	default:
214 		break;
215 	}
216 }
217 
218 /**
219  *  fm10k_rebind_hw_stats - Reset base for hw statistics
220  *  @hw: pointer to hardware structure
221  *
222  *  This function resets the base for statistics that are related to hardware.
223  * */
fm10k_rebind_hw_stats(struct fm10k_hw * hw,struct fm10k_hw_stats * stats)224 void fm10k_rebind_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
225 {
226 	switch (hw->mac.type) {
227 	case fm10k_mac_pf:
228 		return fm10k_rebind_hw_stats_pf(hw, stats);
229 	case fm10k_mac_vf:
230 		return fm10k_rebind_hw_stats_vf(hw, stats);
231 	default:
232 		break;
233 	}
234 }
235 
236 /**
237  *  fm10k_configure_dglort_map - Configures GLORT entry and queues
238  *  @hw: pointer to hardware structure
239  *  @dglort: pointer to dglort configuration structure
240  *
241  *  Reads the configuration structure contained in dglort_cfg and uses
242  *  that information to then populate a DGLORTMAP/DEC entry and the queues
243  *  to which it has been assigned.
244  **/
fm10k_configure_dglort_map(struct fm10k_hw * hw,struct fm10k_dglort_cfg * dglort)245 s32 fm10k_configure_dglort_map(struct fm10k_hw *hw,
246 			       struct fm10k_dglort_cfg *dglort)
247 {
248 	return fm10k_call_func(hw, hw->mac.ops.configure_dglort_map,
249 			       (hw, dglort), FM10K_NOT_IMPLEMENTED);
250 }
251 
252 /**
253  *  fm10k_set_dma_mask - Configures PhyAddrSpace to limit DMA to system
254  *  @hw: pointer to hardware structure
255  *  @dma_mask: 64 bit DMA mask required for platform
256  *
257  *  This function configures the endpoint to limit the access to memory
258  *  beyond what is physically in the system.
259  **/
fm10k_set_dma_mask(struct fm10k_hw * hw,u64 dma_mask)260 void fm10k_set_dma_mask(struct fm10k_hw *hw, u64 dma_mask)
261 {
262 	if (hw->mac.ops.set_dma_mask)
263 		hw->mac.ops.set_dma_mask(hw, dma_mask);
264 }
265 
266 /**
267  *  fm10k_get_fault - Record a fault in one of the interface units
268  *  @hw: pointer to hardware structure
269  *  @type: pointer to fault type register offset
270  *  @fault: pointer to memory location to record the fault
271  *
272  *  Record the fault register contents to the fault data structure and
273  *  clear the entry from the register.
274  *
275  *  Returns ERR_PARAM if invalid register is specified or no error is present.
276  **/
fm10k_get_fault(struct fm10k_hw * hw,int type,struct fm10k_fault * fault)277 s32 fm10k_get_fault(struct fm10k_hw *hw, int type, struct fm10k_fault *fault)
278 {
279 	return fm10k_call_func(hw, hw->mac.ops.get_fault, (hw, type, fault),
280 			       FM10K_NOT_IMPLEMENTED);
281 }
282 
283 /**
284  *  fm10k_update_uc_addr - Update device unicast address
285  *  @hw: pointer to the HW structure
286  *  @lport: logical port ID to update - unused
287  *  @mac: MAC address to add/remove from table
288  *  @vid: VLAN ID to add/remove from table
289  *  @add: Indicates if this is an add or remove operation
290  *  @flags: flags field to indicate add and secure - unused
291  *
292  *  This function is used to add or remove unicast MAC addresses
293  **/
fm10k_update_uc_addr(struct fm10k_hw * hw,u16 lport,const u8 * mac,u16 vid,bool add,u8 flags)294 s32 fm10k_update_uc_addr(struct fm10k_hw *hw, u16 lport,
295 			  const u8 *mac, u16 vid, bool add, u8 flags)
296 {
297 	return fm10k_call_func(hw, hw->mac.ops.update_uc_addr,
298 			       (hw, lport, mac, vid, add, flags),
299 			       FM10K_NOT_IMPLEMENTED);
300 }
301 
302 /**
303  *  fm10k_update_mc_addr - Update device multicast address
304  *  @hw: pointer to the HW structure
305  *  @lport: logical port ID to update - unused
306  *  @mac: MAC address to add/remove from table
307  *  @vid: VLAN ID to add/remove from table
308  *  @add: Indicates if this is an add or remove operation
309  *
310  *  This function is used to add or remove multicast MAC addresses
311  **/
fm10k_update_mc_addr(struct fm10k_hw * hw,u16 lport,const u8 * mac,u16 vid,bool add)312 s32 fm10k_update_mc_addr(struct fm10k_hw *hw, u16 lport,
313 			 const u8 *mac, u16 vid, bool add)
314 {
315 	return fm10k_call_func(hw, hw->mac.ops.update_mc_addr,
316 			       (hw, lport, mac, vid, add),
317 			       FM10K_NOT_IMPLEMENTED);
318 }
319 
320 /**
321  *  fm10k_adjust_systime - Adjust systime frequency
322  *  @hw: pointer to hardware structure
323  *  @ppb: adjustment rate in parts per billion
324  *
325  *  This function is meant to update the frequency of the clock represented
326  *  by the SYSTIME register.
327  **/
fm10k_adjust_systime(struct fm10k_hw * hw,s32 ppb)328 s32 fm10k_adjust_systime(struct fm10k_hw *hw, s32 ppb)
329 {
330 	return fm10k_call_func(hw, hw->mac.ops.adjust_systime,
331 			       (hw, ppb), FM10K_NOT_IMPLEMENTED);
332 }
333 
334 /**
335  *  fm10k_notify_offset - Notify switch of change in PTP offset
336  *  @hw: pointer to hardware structure
337  *  @offset: 64bit unsigned offset from hardware SYSTIME value
338  *
339  *  This function is meant to notify switch of change in the PTP offset for
340  *  the hardware SYSTIME registers.
341  **/
fm10k_notify_offset(struct fm10k_hw * hw,u64 offset)342 s32 fm10k_notify_offset(struct fm10k_hw *hw, u64 offset)
343 {
344 	return fm10k_call_func(hw, hw->mac.ops.notify_offset,
345 			       (hw, offset), FM10K_NOT_IMPLEMENTED);
346 }
347