1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013 - 2015 Intel Corporation
6 #include "fm10k_common.h"
9 * fm10k_set_mac_type - Sets MAC type
10 * @hw: pointer to the HW structure
12 * This function sets the mac type of the adapter based on the
13 * vendor ID and device ID stored in the hw structure.
15 s32 fm10k_set_mac_type(struct fm10k_hw *hw)
17 s32 ret_val = FM10K_SUCCESS;
19 DEBUGFUNC("fm10k_set_mac_type");
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;
27 switch (hw->device_id) {
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;
38 hw->mac.type = fm10k_mac_vf;
41 ret_val = FM10K_ERR_DEVICE_NOT_SUPPORTED;
42 ERROR_REPORT2(FM10K_ERROR_UNSUPPORTED,
43 "Unsupported device id: %x\n",
48 DEBUGOUT2("fm10k_set_mac_type found mac: %d, returns: %d\n",
49 hw->mac.type, ret_val);
55 * fm10k_init_shared_code - Initialize the shared code
56 * @hw: pointer to hardware structure
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
66 s32 fm10k_init_shared_code(struct fm10k_hw *hw)
70 DEBUGFUNC("fm10k_init_shared_code");
72 /* Set the mac type */
73 fm10k_set_mac_type(hw);
75 switch (hw->mac.type) {
77 status = fm10k_init_ops_pf(hw);
80 status = fm10k_init_ops_vf(hw);
83 status = FM10K_ERR_DEVICE_NOT_SUPPORTED;
90 #define fm10k_call_func(hw, func, params, error) \
91 ((func) ? (func params) : (error))
94 * fm10k_reset_hw - Reset the hardware to known good state
95 * @hw: pointer to hardware structure
97 * This function should return the hardware to a state similar to the
98 * one it is in after being powered on.
100 s32 fm10k_reset_hw(struct fm10k_hw *hw)
102 return fm10k_call_func(hw, hw->mac.ops.reset_hw, (hw),
103 FM10K_NOT_IMPLEMENTED);
107 * fm10k_init_hw - Initialize the hardware
108 * @hw: pointer to hardware structure
110 * Initialize the hardware by resetting and then starting the hardware
112 s32 fm10k_init_hw(struct fm10k_hw *hw)
114 return fm10k_call_func(hw, hw->mac.ops.init_hw, (hw),
115 FM10K_NOT_IMPLEMENTED);
119 * fm10k_stop_hw - Prepares hardware to shutdown Rx/Tx
120 * @hw: pointer to hardware structure
122 * Disables Rx/Tx queues and disables the DMA engine.
124 s32 fm10k_stop_hw(struct fm10k_hw *hw)
126 return fm10k_call_func(hw, hw->mac.ops.stop_hw, (hw),
127 FM10K_NOT_IMPLEMENTED);
131 * fm10k_start_hw - Prepares hardware for Rx/Tx
132 * @hw: pointer to hardware structure
134 * This function sets the flags indicating that the hardware is ready to
137 s32 fm10k_start_hw(struct fm10k_hw *hw)
139 return fm10k_call_func(hw, hw->mac.ops.start_hw, (hw),
140 FM10K_NOT_IMPLEMENTED);
144 * fm10k_get_bus_info - Set PCI bus info
145 * @hw: pointer to hardware structure
147 * Sets the PCI bus info (speed, width, type) within the fm10k_hw structure
149 s32 fm10k_get_bus_info(struct fm10k_hw *hw)
151 return fm10k_call_func(hw, hw->mac.ops.get_bus_info, (hw),
152 FM10K_NOT_IMPLEMENTED);
155 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
157 * fm10k_is_slot_appropriate - Indicate appropriate slot for this SKU
158 * @hw: pointer to hardware structure
160 * Looks at the PCIe bus info to confirm whether or not this slot can support
161 * the necessary bandwidth for this device.
163 bool fm10k_is_slot_appropriate(struct fm10k_hw *hw)
165 if (hw->mac.ops.is_slot_appropriate)
166 return hw->mac.ops.is_slot_appropriate(hw);
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
178 * This function adds or removes the corresponding VLAN ID from the VLAN
179 * filter table for the corresponding function.
181 s32 fm10k_update_vlan(struct fm10k_hw *hw, u32 vid, u8 idx, bool set)
183 return fm10k_call_func(hw, hw->mac.ops.update_vlan, (hw, vid, idx, set),
184 FM10K_NOT_IMPLEMENTED);
188 * fm10k_read_mac_addr - Reads MAC address
189 * @hw: pointer to hardware structure
191 * Reads the MAC address out of the interface and stores it in the HW
194 s32 fm10k_read_mac_addr(struct fm10k_hw *hw)
196 return fm10k_call_func(hw, hw->mac.ops.read_mac_addr, (hw),
197 FM10K_NOT_IMPLEMENTED);
201 * fm10k_update_hw_stats - Update hw statistics
202 * @hw: pointer to hardware structure
204 * This function updates statistics that are related to hardware.
206 void fm10k_update_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
208 if (hw->mac.ops.update_hw_stats)
209 hw->mac.ops.update_hw_stats(hw, stats);
213 * fm10k_rebind_hw_stats - Reset base for hw statistics
214 * @hw: pointer to hardware structure
216 * This function resets the base for statistics that are related to hardware.
218 void fm10k_rebind_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
220 if (hw->mac.ops.rebind_hw_stats)
221 hw->mac.ops.rebind_hw_stats(hw, stats);
225 * fm10k_configure_dglort_map - Configures GLORT entry and queues
226 * @hw: pointer to hardware structure
227 * @dglort: pointer to dglort configuration structure
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.
233 s32 fm10k_configure_dglort_map(struct fm10k_hw *hw,
234 struct fm10k_dglort_cfg *dglort)
236 return fm10k_call_func(hw, hw->mac.ops.configure_dglort_map,
237 (hw, dglort), FM10K_NOT_IMPLEMENTED);
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
245 * This function configures the endpoint to limit the access to memory
246 * beyond what is physically in the system.
248 void fm10k_set_dma_mask(struct fm10k_hw *hw, u64 dma_mask)
250 if (hw->mac.ops.set_dma_mask)
251 hw->mac.ops.set_dma_mask(hw, dma_mask);
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
260 * Record the fault register contents to the fault data structure and
261 * clear the entry from the register.
263 * Returns ERR_PARAM if invalid register is specified or no error is present.
265 s32 fm10k_get_fault(struct fm10k_hw *hw, int type, struct fm10k_fault *fault)
267 return fm10k_call_func(hw, hw->mac.ops.get_fault, (hw, type, fault),
268 FM10K_NOT_IMPLEMENTED);
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
280 * This function is used to add or remove unicast MAC addresses
282 s32 fm10k_update_uc_addr(struct fm10k_hw *hw, u16 lport,
283 const u8 *mac, u16 vid, bool add, u8 flags)
285 return fm10k_call_func(hw, hw->mac.ops.update_uc_addr,
286 (hw, lport, mac, vid, add, flags),
287 FM10K_NOT_IMPLEMENTED);
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
298 * This function is used to add or remove multicast MAC addresses
300 s32 fm10k_update_mc_addr(struct fm10k_hw *hw, u16 lport,
301 const u8 *mac, u16 vid, bool add)
303 return fm10k_call_func(hw, hw->mac.ops.update_mc_addr,
304 (hw, lport, mac, vid, add),
305 FM10K_NOT_IMPLEMENTED);
309 * fm10k_adjust_systime - Adjust systime frequency
310 * @hw: pointer to hardware structure
311 * @ppb: adjustment rate in parts per billion
313 * This function is meant to update the frequency of the clock represented
314 * by the SYSTIME register.
316 s32 fm10k_adjust_systime(struct fm10k_hw *hw, s32 ppb)
318 return fm10k_call_func(hw, hw->mac.ops.adjust_systime,
319 (hw, ppb), FM10K_NOT_IMPLEMENTED);
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
327 * This function is meant to notify switch of change in the PTP offset for
328 * the hardware SYSTIME registers.
330 s32 fm10k_notify_offset(struct fm10k_hw *hw, u64 offset)
332 return fm10k_call_func(hw, hw->mac.ops.notify_offset,
333 (hw, offset), FM10K_NOT_IMPLEMENTED);