x86/ldt: Further fix FPU emulation
[linux/fpc-iii.git] / drivers / net / ethernet / intel / fm10k / fm10k_vf.c
blob94f0f6a146d96e7e57fe9bf647bf6ae480a727b4
1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21 #include "fm10k_vf.h"
23 /**
24 * fm10k_stop_hw_vf - Stop Tx/Rx units
25 * @hw: pointer to hardware structure
27 **/
28 static s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
30 u8 *perm_addr = hw->mac.perm_addr;
31 u32 bal = 0, bah = 0;
32 s32 err;
33 u16 i;
35 /* we need to disable the queues before taking further steps */
36 err = fm10k_stop_hw_generic(hw);
37 if (err)
38 return err;
40 /* If permanent address is set then we need to restore it */
41 if (is_valid_ether_addr(perm_addr)) {
42 bal = (((u32)perm_addr[3]) << 24) |
43 (((u32)perm_addr[4]) << 16) |
44 (((u32)perm_addr[5]) << 8);
45 bah = (((u32)0xFF) << 24) |
46 (((u32)perm_addr[0]) << 16) |
47 (((u32)perm_addr[1]) << 8) |
48 ((u32)perm_addr[2]);
51 /* The queues have already been disabled so we just need to
52 * update their base address registers
54 for (i = 0; i < hw->mac.max_queues; i++) {
55 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
56 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
57 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
58 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
61 return 0;
64 /**
65 * fm10k_reset_hw_vf - VF hardware reset
66 * @hw: pointer to hardware structure
68 * This function should return the hardware to a state similar to the
69 * one it is in after just being initialized.
70 **/
71 static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
73 s32 err;
75 /* shut down queues we own and reset DMA configuration */
76 err = fm10k_stop_hw_vf(hw);
77 if (err)
78 return err;
80 /* Inititate VF reset */
81 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
83 /* Flush write and allow 100us for reset to complete */
84 fm10k_write_flush(hw);
85 udelay(FM10K_RESET_TIMEOUT);
87 /* Clear reset bit and verify it was cleared */
88 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
89 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
90 err = FM10K_ERR_RESET_FAILED;
92 return err;
95 /**
96 * fm10k_init_hw_vf - VF hardware initialization
97 * @hw: pointer to hardware structure
99 **/
100 static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
102 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
103 s32 err;
104 u16 i;
106 /* assume we always have at least 1 queue */
107 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
108 /* verify the Descriptor cache offsets are increasing */
109 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
110 if (!tqdloc || (tqdloc == tqdloc0))
111 break;
113 /* check to verify the PF doesn't own any of our queues */
114 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
115 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
116 break;
119 /* shut down queues we own and reset DMA configuration */
120 err = fm10k_disable_queues_generic(hw, i);
121 if (err)
122 return err;
124 /* record maximum queue count */
125 hw->mac.max_queues = i;
127 /* fetch default VLAN */
128 hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
129 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
131 return 0;
135 * fm10k_is_slot_appropriate_vf - Indicate appropriate slot for this SKU
136 * @hw: pointer to hardware structure
138 * Looks at the PCIe bus info to confirm whether or not this slot can support
139 * the necessary bandwidth for this device. Since the VF has no control over
140 * the "slot" it is in, always indicate that the slot is appropriate.
142 static bool fm10k_is_slot_appropriate_vf(struct fm10k_hw *hw)
144 return true;
147 /* This structure defines the attibutes to be parsed below */
148 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
149 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
150 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
151 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
152 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
153 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
154 FM10K_TLV_ATTR_LAST
158 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
159 * @hw: pointer to hardware structure
160 * @vid: VLAN ID to add to table
161 * @vsi: Reserved, should always be 0
162 * @set: Indicates if this is a set or clear operation
164 * This function adds or removes the corresponding VLAN ID from the VLAN
165 * filter table for this VF.
167 static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
169 struct fm10k_mbx_info *mbx = &hw->mbx;
170 u32 msg[4];
172 /* verify the index is not set */
173 if (vsi)
174 return FM10K_ERR_PARAM;
176 /* verify upper 4 bits of vid and length are 0 */
177 if ((vid << 16 | vid) >> 28)
178 return FM10K_ERR_PARAM;
180 /* encode set bit into the VLAN ID */
181 if (!set)
182 vid |= FM10K_VLAN_CLEAR;
184 /* generate VLAN request */
185 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
186 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
188 /* load onto outgoing mailbox */
189 return mbx->ops.enqueue_tx(hw, mbx, msg);
193 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
194 * @hw: pointer to the HW structure
195 * @results: Attributes for message
196 * @mbx: unused mailbox data
198 * This function should determine the MAC address for the VF
200 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
201 struct fm10k_mbx_info *mbx)
203 u8 perm_addr[ETH_ALEN];
204 u16 vid;
205 s32 err;
207 /* record MAC address requested */
208 err = fm10k_tlv_attr_get_mac_vlan(
209 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
210 perm_addr, &vid);
211 if (err)
212 return err;
214 ether_addr_copy(hw->mac.perm_addr, perm_addr);
215 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
216 hw->mac.vlan_override = !!(vid & FM10K_VLAN_CLEAR);
218 return 0;
222 * fm10k_read_mac_addr_vf - Read device MAC address
223 * @hw: pointer to the HW structure
225 * This function should determine the MAC address for the VF
227 static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
229 u8 perm_addr[ETH_ALEN];
230 u32 base_addr;
232 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
234 /* last byte should be 0 */
235 if (base_addr << 24)
236 return FM10K_ERR_INVALID_MAC_ADDR;
238 perm_addr[3] = (u8)(base_addr >> 24);
239 perm_addr[4] = (u8)(base_addr >> 16);
240 perm_addr[5] = (u8)(base_addr >> 8);
242 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
244 /* first byte should be all 1's */
245 if ((~base_addr) >> 24)
246 return FM10K_ERR_INVALID_MAC_ADDR;
248 perm_addr[0] = (u8)(base_addr >> 16);
249 perm_addr[1] = (u8)(base_addr >> 8);
250 perm_addr[2] = (u8)(base_addr);
252 ether_addr_copy(hw->mac.perm_addr, perm_addr);
253 ether_addr_copy(hw->mac.addr, perm_addr);
255 return 0;
259 * fm10k_update_uc_addr_vf - Update device unicast addresses
260 * @hw: pointer to the HW structure
261 * @glort: unused
262 * @mac: MAC address to add/remove from table
263 * @vid: VLAN ID to add/remove from table
264 * @add: Indicates if this is an add or remove operation
265 * @flags: flags field to indicate add and secure - unused
267 * This function is used to add or remove unicast MAC addresses for
268 * the VF.
270 static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
271 const u8 *mac, u16 vid, bool add, u8 flags)
273 struct fm10k_mbx_info *mbx = &hw->mbx;
274 u32 msg[7];
276 /* verify VLAN ID is valid */
277 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
278 return FM10K_ERR_PARAM;
280 /* verify MAC address is valid */
281 if (!is_valid_ether_addr(mac))
282 return FM10K_ERR_PARAM;
284 /* verify we are not locked down on the MAC address */
285 if (is_valid_ether_addr(hw->mac.perm_addr) &&
286 memcmp(hw->mac.perm_addr, mac, ETH_ALEN))
287 return FM10K_ERR_PARAM;
289 /* add bit to notify us if this is a set or clear operation */
290 if (!add)
291 vid |= FM10K_VLAN_CLEAR;
293 /* generate VLAN request */
294 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
295 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
297 /* load onto outgoing mailbox */
298 return mbx->ops.enqueue_tx(hw, mbx, msg);
302 * fm10k_update_mc_addr_vf - Update device multicast addresses
303 * @hw: pointer to the HW structure
304 * @glort: unused
305 * @mac: MAC address to add/remove from table
306 * @vid: VLAN ID to add/remove from table
307 * @add: Indicates if this is an add or remove operation
309 * This function is used to add or remove multicast MAC addresses for
310 * the VF.
312 static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
313 const u8 *mac, u16 vid, bool add)
315 struct fm10k_mbx_info *mbx = &hw->mbx;
316 u32 msg[7];
318 /* verify VLAN ID is valid */
319 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
320 return FM10K_ERR_PARAM;
322 /* verify multicast address is valid */
323 if (!is_multicast_ether_addr(mac))
324 return FM10K_ERR_PARAM;
326 /* add bit to notify us if this is a set or clear operation */
327 if (!add)
328 vid |= FM10K_VLAN_CLEAR;
330 /* generate VLAN request */
331 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
332 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
333 mac, vid);
335 /* load onto outgoing mailbox */
336 return mbx->ops.enqueue_tx(hw, mbx, msg);
340 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
341 * @hw: pointer to hardware structure
343 * This function will issue a request to the PF to rescan our MSI-X table
344 * and to update the interrupt moderator linked list.
346 static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
348 struct fm10k_mbx_info *mbx = &hw->mbx;
349 u32 msg[1];
351 /* generate MSI-X request */
352 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
354 /* load onto outgoing mailbox */
355 mbx->ops.enqueue_tx(hw, mbx, msg);
358 /* This structure defines the attibutes to be parsed below */
359 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
360 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
361 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
362 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
363 FM10K_TLV_ATTR_LAST
367 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
368 * @hw: Pointer to hardware structure
369 * @results: pointer array containing parsed data
370 * @mbx: Pointer to mailbox information structure
372 * This handler is meant to capture the indication from the PF that we
373 * are ready to bring up the interface.
375 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
376 struct fm10k_mbx_info *mbx)
378 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
379 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
381 return 0;
385 * fm10k_update_lport_state_vf - Update device state in lower device
386 * @hw: pointer to the HW structure
387 * @glort: unused
388 * @count: number of logical ports to enable - unused (always 1)
389 * @enable: boolean value indicating if this is an enable or disable request
391 * Notify the lower device of a state change. If the lower device is
392 * enabled we can add filters, if it is disabled all filters for this
393 * logical port are flushed.
395 static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
396 u16 count, bool enable)
398 struct fm10k_mbx_info *mbx = &hw->mbx;
399 u32 msg[2];
401 /* reset glort mask 0 as we have to wait to be enabled */
402 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
404 /* generate port state request */
405 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
406 if (!enable)
407 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
409 /* load onto outgoing mailbox */
410 return mbx->ops.enqueue_tx(hw, mbx, msg);
414 * fm10k_update_xcast_mode_vf - Request update of multicast mode
415 * @hw: pointer to hardware structure
416 * @glort: unused
417 * @mode: integer value indicating mode being requested
419 * This function will attempt to request a higher mode for the port
420 * so that it can enable either multicast, multicast promiscuous, or
421 * promiscuous mode of operation.
423 static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
425 struct fm10k_mbx_info *mbx = &hw->mbx;
426 u32 msg[3];
428 if (mode > FM10K_XCAST_MODE_NONE)
429 return FM10K_ERR_PARAM;
430 /* generate message requesting to change xcast mode */
431 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
432 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
434 /* load onto outgoing mailbox */
435 return mbx->ops.enqueue_tx(hw, mbx, msg);
438 const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
439 FM10K_TLV_ATTR_U64(FM10K_1588_MSG_TIMESTAMP),
440 FM10K_TLV_ATTR_LAST
443 /* currently there is no shared 1588 timestamp handler */
446 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
447 * @hw: pointer to hardware structure
448 * @stats: pointer to statistics structure
450 * This function collects and aggregates per queue hardware statistics.
452 static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
453 struct fm10k_hw_stats *stats)
455 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
459 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
460 * @hw: pointer to hardware structure
461 * @stats: pointer to the stats structure to update
463 * This function resets the base for queue hardware statistics.
465 static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
466 struct fm10k_hw_stats *stats)
468 /* Unbind Queue Statistics */
469 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
471 /* Reinitialize bases for all stats */
472 fm10k_update_hw_stats_vf(hw, stats);
476 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
477 * @hw: pointer to hardware structure
478 * @dglort: pointer to dglort configuration structure
480 * Reads the configuration structure contained in dglort_cfg and uses
481 * that information to then populate a DGLORTMAP/DEC entry and the queues
482 * to which it has been assigned.
484 static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
485 struct fm10k_dglort_cfg *dglort)
487 /* verify the dglort pointer */
488 if (!dglort)
489 return FM10K_ERR_PARAM;
491 /* stub for now until we determine correct message for this */
493 return 0;
497 * fm10k_adjust_systime_vf - Adjust systime frequency
498 * @hw: pointer to hardware structure
499 * @ppb: adjustment rate in parts per billion
501 * This function takes an adjustment rate in parts per billion and will
502 * verify that this value is 0 as the VF cannot support adjusting the
503 * systime clock.
505 * If the ppb value is non-zero the return is ERR_PARAM else success
507 static s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
509 /* The VF cannot adjust the clock frequency, however it should
510 * already have a syntonic clock with whichever host interface is
511 * running as the master for the host interface clock domain so
512 * there should be not frequency adjustment necessary.
514 return ppb ? FM10K_ERR_PARAM : 0;
518 * fm10k_read_systime_vf - Reads value of systime registers
519 * @hw: pointer to the hardware structure
521 * Function reads the content of 2 registers, combined to represent a 64 bit
522 * value measured in nanoseconds. In order to guarantee the value is accurate
523 * we check the 32 most significant bits both before and after reading the
524 * 32 least significant bits to verify they didn't change as we were reading
525 * the registers.
527 static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
529 u32 systime_l, systime_h, systime_tmp;
531 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
533 do {
534 systime_tmp = systime_h;
535 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
536 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
537 } while (systime_tmp != systime_h);
539 return ((u64)systime_h << 32) | systime_l;
542 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
543 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
544 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
545 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
546 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
549 static struct fm10k_mac_ops mac_ops_vf = {
550 .get_bus_info = &fm10k_get_bus_info_generic,
551 .reset_hw = &fm10k_reset_hw_vf,
552 .init_hw = &fm10k_init_hw_vf,
553 .start_hw = &fm10k_start_hw_generic,
554 .stop_hw = &fm10k_stop_hw_vf,
555 .is_slot_appropriate = &fm10k_is_slot_appropriate_vf,
556 .update_vlan = &fm10k_update_vlan_vf,
557 .read_mac_addr = &fm10k_read_mac_addr_vf,
558 .update_uc_addr = &fm10k_update_uc_addr_vf,
559 .update_mc_addr = &fm10k_update_mc_addr_vf,
560 .update_xcast_mode = &fm10k_update_xcast_mode_vf,
561 .update_int_moderator = &fm10k_update_int_moderator_vf,
562 .update_lport_state = &fm10k_update_lport_state_vf,
563 .update_hw_stats = &fm10k_update_hw_stats_vf,
564 .rebind_hw_stats = &fm10k_rebind_hw_stats_vf,
565 .configure_dglort_map = &fm10k_configure_dglort_map_vf,
566 .get_host_state = &fm10k_get_host_state_generic,
567 .adjust_systime = &fm10k_adjust_systime_vf,
568 .read_systime = &fm10k_read_systime_vf,
571 static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
573 fm10k_get_invariants_generic(hw);
575 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
578 struct fm10k_info fm10k_vf_info = {
579 .mac = fm10k_mac_vf,
580 .get_invariants = &fm10k_get_invariants_vf,
581 .mac_ops = &mac_ops_vf,