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 switch (hw->mac.type) {
210 return fm10k_update_hw_stats_pf(hw, stats);
212 return fm10k_update_hw_stats_vf(hw, stats);
219 * fm10k_rebind_hw_stats - Reset base for hw statistics
220 * @hw: pointer to hardware structure
222 * This function resets the base for statistics that are related to hardware.
224 void fm10k_rebind_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats)
226 switch (hw->mac.type) {
228 return fm10k_rebind_hw_stats_pf(hw, stats);
230 return fm10k_rebind_hw_stats_vf(hw, stats);
237 * fm10k_configure_dglort_map - Configures GLORT entry and queues
238 * @hw: pointer to hardware structure
239 * @dglort: pointer to dglort configuration structure
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.
245 s32 fm10k_configure_dglort_map(struct fm10k_hw *hw,
246 struct fm10k_dglort_cfg *dglort)
248 return fm10k_call_func(hw, hw->mac.ops.configure_dglort_map,
249 (hw, dglort), FM10K_NOT_IMPLEMENTED);
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
257 * This function configures the endpoint to limit the access to memory
258 * beyond what is physically in the system.
260 void fm10k_set_dma_mask(struct fm10k_hw *hw, u64 dma_mask)
262 if (hw->mac.ops.set_dma_mask)
263 hw->mac.ops.set_dma_mask(hw, dma_mask);
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
272 * Record the fault register contents to the fault data structure and
273 * clear the entry from the register.
275 * Returns ERR_PARAM if invalid register is specified or no error is present.
277 s32 fm10k_get_fault(struct fm10k_hw *hw, int type, struct fm10k_fault *fault)
279 return fm10k_call_func(hw, hw->mac.ops.get_fault, (hw, type, fault),
280 FM10K_NOT_IMPLEMENTED);
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
292 * This function is used to add or remove unicast MAC addresses
294 s32 fm10k_update_uc_addr(struct fm10k_hw *hw, u16 lport,
295 const u8 *mac, u16 vid, bool add, u8 flags)
297 return fm10k_call_func(hw, hw->mac.ops.update_uc_addr,
298 (hw, lport, mac, vid, add, flags),
299 FM10K_NOT_IMPLEMENTED);
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
310 * This function is used to add or remove multicast MAC addresses
312 s32 fm10k_update_mc_addr(struct fm10k_hw *hw, u16 lport,
313 const u8 *mac, u16 vid, bool add)
315 return fm10k_call_func(hw, hw->mac.ops.update_mc_addr,
316 (hw, lport, mac, vid, add),
317 FM10K_NOT_IMPLEMENTED);
321 * fm10k_adjust_systime - Adjust systime frequency
322 * @hw: pointer to hardware structure
323 * @ppb: adjustment rate in parts per billion
325 * This function is meant to update the frequency of the clock represented
326 * by the SYSTIME register.
328 s32 fm10k_adjust_systime(struct fm10k_hw *hw, s32 ppb)
330 return fm10k_call_func(hw, hw->mac.ops.adjust_systime,
331 (hw, ppb), FM10K_NOT_IMPLEMENTED);
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
339 * This function is meant to notify switch of change in the PTP offset for
340 * the hardware SYSTIME registers.
342 s32 fm10k_notify_offset(struct fm10k_hw *hw, u64 offset)
344 return fm10k_call_func(hw, hw->mac.ops.notify_offset,
345 (hw, offset), FM10K_NOT_IMPLEMENTED);