Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2013 - 2019 Intel Corporation. */
3
4#include <linux/bitfield.h>
5#include "fm10k_vf.h"
6
7/**
8 * fm10k_stop_hw_vf - Stop Tx/Rx units
9 * @hw: pointer to hardware structure
10 *
11 **/
12static s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
13{
14 u8 *perm_addr = hw->mac.perm_addr;
15 u32 bal = 0, bah = 0, tdlen;
16 s32 err;
17 u16 i;
18
19 /* we need to disable the queues before taking further steps */
20 err = fm10k_stop_hw_generic(hw);
21 if (err && err != FM10K_ERR_REQUESTS_PENDING)
22 return err;
23
24 /* If permanent address is set then we need to restore it */
25 if (is_valid_ether_addr(perm_addr)) {
26 bal = (((u32)perm_addr[3]) << 24) |
27 (((u32)perm_addr[4]) << 16) |
28 (((u32)perm_addr[5]) << 8);
29 bah = (((u32)0xFF) << 24) |
30 (((u32)perm_addr[0]) << 16) |
31 (((u32)perm_addr[1]) << 8) |
32 ((u32)perm_addr[2]);
33 }
34
35 /* restore default itr_scale for next VF initialization */
36 tdlen = hw->mac.itr_scale << FM10K_TDLEN_ITR_SCALE_SHIFT;
37
38 /* The queues have already been disabled so we just need to
39 * update their base address registers
40 */
41 for (i = 0; i < hw->mac.max_queues; i++) {
42 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
43 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
44 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
45 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
46 /* Restore ITR scale in software-defined mechanism in TDLEN
47 * for next VF initialization. See definition of
48 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details on the use of
49 * TDLEN here.
50 */
51 fm10k_write_reg(hw, FM10K_TDLEN(i), tdlen);
52 }
53
54 return err;
55}
56
57/**
58 * fm10k_reset_hw_vf - VF hardware reset
59 * @hw: pointer to hardware structure
60 *
61 * This function should return the hardware to a state similar to the
62 * one it is in after just being initialized.
63 **/
64static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
65{
66 s32 err;
67
68 /* shut down queues we own and reset DMA configuration */
69 err = fm10k_stop_hw_vf(hw);
70 if (err == FM10K_ERR_REQUESTS_PENDING)
71 hw->mac.reset_while_pending++;
72 else if (err)
73 return err;
74
75 /* Inititate VF reset */
76 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
77
78 /* Flush write and allow 100us for reset to complete */
79 fm10k_write_flush(hw);
80 udelay(FM10K_RESET_TIMEOUT);
81
82 /* Clear reset bit and verify it was cleared */
83 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
84 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
85 return FM10K_ERR_RESET_FAILED;
86
87 return 0;
88}
89
90/**
91 * fm10k_init_hw_vf - VF hardware initialization
92 * @hw: pointer to hardware structure
93 *
94 **/
95static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
96{
97 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
98 s32 err;
99 u16 i;
100
101 /* verify we have at least 1 queue */
102 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(0)) ||
103 !~fm10k_read_reg(hw, FM10K_RXQCTL(0))) {
104 err = FM10K_ERR_NO_RESOURCES;
105 goto reset_max_queues;
106 }
107
108 /* determine how many queues we have */
109 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
110 /* verify the Descriptor cache offsets are increasing */
111 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
112 if (!tqdloc || (tqdloc == tqdloc0))
113 break;
114
115 /* check to verify the PF doesn't own any of our queues */
116 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
117 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
118 break;
119 }
120
121 /* shut down queues we own and reset DMA configuration */
122 err = fm10k_disable_queues_generic(hw, i);
123 if (err)
124 goto reset_max_queues;
125
126 /* record maximum queue count */
127 hw->mac.max_queues = i;
128
129 /* fetch default VLAN and ITR scale */
130 hw->mac.default_vid = FIELD_GET(FM10K_TXQCTL_VID_MASK,
131 fm10k_read_reg(hw, FM10K_TXQCTL(0)));
132 /* Read the ITR scale from TDLEN. See the definition of
133 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
134 * used here.
135 */
136 hw->mac.itr_scale = FIELD_GET(FM10K_TDLEN_ITR_SCALE_MASK,
137 fm10k_read_reg(hw, FM10K_TDLEN(0)));
138
139 return 0;
140
141reset_max_queues:
142 hw->mac.max_queues = 0;
143
144 return err;
145}
146
147/* This structure defines the attibutes to be parsed below */
148const 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
155};
156
157/**
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
163 *
164 * This function adds or removes the corresponding VLAN ID from the VLAN
165 * filter table for this VF.
166 **/
167static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
168{
169 struct fm10k_mbx_info *mbx = &hw->mbx;
170 u32 msg[4];
171
172 /* verify the index is not set */
173 if (vsi)
174 return FM10K_ERR_PARAM;
175
176 /* clever trick to verify reserved bits in both vid and length */
177 if ((vid << 16 | vid) >> 28)
178 return FM10K_ERR_PARAM;
179
180 /* encode set bit into the VLAN ID */
181 if (!set)
182 vid |= FM10K_VLAN_CLEAR;
183
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);
187
188 /* load onto outgoing mailbox */
189 return mbx->ops.enqueue_tx(hw, mbx, msg);
190}
191
192/**
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
197 *
198 * This function should determine the MAC address for the VF
199 **/
200s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
201 struct fm10k_mbx_info __always_unused *mbx)
202{
203 u8 perm_addr[ETH_ALEN];
204 u16 vid;
205 s32 err;
206
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;
213
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_OVERRIDE);
217
218 return 0;
219}
220
221/**
222 * fm10k_read_mac_addr_vf - Read device MAC address
223 * @hw: pointer to the HW structure
224 *
225 * This function should determine the MAC address for the VF
226 **/
227static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
228{
229 u8 perm_addr[ETH_ALEN];
230 u32 base_addr;
231
232 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
233
234 /* last byte should be 0 */
235 if (base_addr << 24)
236 return FM10K_ERR_INVALID_MAC_ADDR;
237
238 perm_addr[3] = (u8)(base_addr >> 24);
239 perm_addr[4] = (u8)(base_addr >> 16);
240 perm_addr[5] = (u8)(base_addr >> 8);
241
242 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
243
244 /* first byte should be all 1's */
245 if ((~base_addr) >> 24)
246 return FM10K_ERR_INVALID_MAC_ADDR;
247
248 perm_addr[0] = (u8)(base_addr >> 16);
249 perm_addr[1] = (u8)(base_addr >> 8);
250 perm_addr[2] = (u8)(base_addr);
251
252 ether_addr_copy(hw->mac.perm_addr, perm_addr);
253 ether_addr_copy(hw->mac.addr, perm_addr);
254
255 return 0;
256}
257
258/**
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
266 *
267 * This function is used to add or remove unicast MAC addresses for
268 * the VF.
269 **/
270static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw,
271 u16 __always_unused glort,
272 const u8 *mac, u16 vid, bool add,
273 u8 __always_unused flags)
274{
275 struct fm10k_mbx_info *mbx = &hw->mbx;
276 u32 msg[7];
277
278 /* verify VLAN ID is valid */
279 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
280 return FM10K_ERR_PARAM;
281
282 /* verify MAC address is valid */
283 if (!is_valid_ether_addr(mac))
284 return FM10K_ERR_PARAM;
285
286 /* verify we are not locked down on the MAC address */
287 if (is_valid_ether_addr(hw->mac.perm_addr) &&
288 !ether_addr_equal(hw->mac.perm_addr, mac))
289 return FM10K_ERR_PARAM;
290
291 /* add bit to notify us if this is a set or clear operation */
292 if (!add)
293 vid |= FM10K_VLAN_CLEAR;
294
295 /* generate VLAN request */
296 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
297 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
298
299 /* load onto outgoing mailbox */
300 return mbx->ops.enqueue_tx(hw, mbx, msg);
301}
302
303/**
304 * fm10k_update_mc_addr_vf - Update device multicast addresses
305 * @hw: pointer to the HW structure
306 * @glort: unused
307 * @mac: MAC address to add/remove from table
308 * @vid: VLAN ID to add/remove from table
309 * @add: Indicates if this is an add or remove operation
310 *
311 * This function is used to add or remove multicast MAC addresses for
312 * the VF.
313 **/
314static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw,
315 u16 __always_unused glort,
316 const u8 *mac, u16 vid, bool add)
317{
318 struct fm10k_mbx_info *mbx = &hw->mbx;
319 u32 msg[7];
320
321 /* verify VLAN ID is valid */
322 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
323 return FM10K_ERR_PARAM;
324
325 /* verify multicast address is valid */
326 if (!is_multicast_ether_addr(mac))
327 return FM10K_ERR_PARAM;
328
329 /* add bit to notify us if this is a set or clear operation */
330 if (!add)
331 vid |= FM10K_VLAN_CLEAR;
332
333 /* generate VLAN request */
334 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
335 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
336 mac, vid);
337
338 /* load onto outgoing mailbox */
339 return mbx->ops.enqueue_tx(hw, mbx, msg);
340}
341
342/**
343 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
344 * @hw: pointer to hardware structure
345 *
346 * This function will issue a request to the PF to rescan our MSI-X table
347 * and to update the interrupt moderator linked list.
348 **/
349static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
350{
351 struct fm10k_mbx_info *mbx = &hw->mbx;
352 u32 msg[1];
353
354 /* generate MSI-X request */
355 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
356
357 /* load onto outgoing mailbox */
358 mbx->ops.enqueue_tx(hw, mbx, msg);
359}
360
361/* This structure defines the attibutes to be parsed below */
362const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
363 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
364 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
365 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
366 FM10K_TLV_ATTR_LAST
367};
368
369/**
370 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
371 * @hw: Pointer to hardware structure
372 * @results: pointer array containing parsed data
373 * @mbx: Pointer to mailbox information structure
374 *
375 * This handler is meant to capture the indication from the PF that we
376 * are ready to bring up the interface.
377 **/
378s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
379 struct fm10k_mbx_info __always_unused *mbx)
380{
381 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
382 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
383
384 return 0;
385}
386
387/**
388 * fm10k_update_lport_state_vf - Update device state in lower device
389 * @hw: pointer to the HW structure
390 * @glort: unused
391 * @count: number of logical ports to enable - unused (always 1)
392 * @enable: boolean value indicating if this is an enable or disable request
393 *
394 * Notify the lower device of a state change. If the lower device is
395 * enabled we can add filters, if it is disabled all filters for this
396 * logical port are flushed.
397 **/
398static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw,
399 u16 __always_unused glort,
400 u16 __always_unused count, bool enable)
401{
402 struct fm10k_mbx_info *mbx = &hw->mbx;
403 u32 msg[2];
404
405 /* reset glort mask 0 as we have to wait to be enabled */
406 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
407
408 /* generate port state request */
409 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
410 if (!enable)
411 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
412
413 /* load onto outgoing mailbox */
414 return mbx->ops.enqueue_tx(hw, mbx, msg);
415}
416
417/**
418 * fm10k_update_xcast_mode_vf - Request update of multicast mode
419 * @hw: pointer to hardware structure
420 * @glort: unused
421 * @mode: integer value indicating mode being requested
422 *
423 * This function will attempt to request a higher mode for the port
424 * so that it can enable either multicast, multicast promiscuous, or
425 * promiscuous mode of operation.
426 **/
427static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw,
428 u16 __always_unused glort, u8 mode)
429{
430 struct fm10k_mbx_info *mbx = &hw->mbx;
431 u32 msg[3];
432
433 if (mode > FM10K_XCAST_MODE_NONE)
434 return FM10K_ERR_PARAM;
435
436 /* generate message requesting to change xcast mode */
437 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
438 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
439
440 /* load onto outgoing mailbox */
441 return mbx->ops.enqueue_tx(hw, mbx, msg);
442}
443
444/**
445 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
446 * @hw: pointer to hardware structure
447 * @stats: pointer to statistics structure
448 *
449 * This function collects and aggregates per queue hardware statistics.
450 **/
451static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
452 struct fm10k_hw_stats *stats)
453{
454 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
455}
456
457/**
458 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
459 * @hw: pointer to hardware structure
460 * @stats: pointer to the stats structure to update
461 *
462 * This function resets the base for queue hardware statistics.
463 **/
464static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
465 struct fm10k_hw_stats *stats)
466{
467 /* Unbind Queue Statistics */
468 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
469
470 /* Reinitialize bases for all stats */
471 fm10k_update_hw_stats_vf(hw, stats);
472}
473
474/**
475 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
476 * @hw: pointer to hardware structure
477 * @dglort: pointer to dglort configuration structure
478 *
479 * Reads the configuration structure contained in dglort_cfg and uses
480 * that information to then populate a DGLORTMAP/DEC entry and the queues
481 * to which it has been assigned.
482 **/
483static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw __always_unused *hw,
484 struct fm10k_dglort_cfg *dglort)
485{
486 /* verify the dglort pointer */
487 if (!dglort)
488 return FM10K_ERR_PARAM;
489
490 /* stub for now until we determine correct message for this */
491
492 return 0;
493}
494
495static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
496 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
497 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
498 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
499 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
500};
501
502static const struct fm10k_mac_ops mac_ops_vf = {
503 .get_bus_info = fm10k_get_bus_info_generic,
504 .reset_hw = fm10k_reset_hw_vf,
505 .init_hw = fm10k_init_hw_vf,
506 .start_hw = fm10k_start_hw_generic,
507 .stop_hw = fm10k_stop_hw_vf,
508 .update_vlan = fm10k_update_vlan_vf,
509 .read_mac_addr = fm10k_read_mac_addr_vf,
510 .update_uc_addr = fm10k_update_uc_addr_vf,
511 .update_mc_addr = fm10k_update_mc_addr_vf,
512 .update_xcast_mode = fm10k_update_xcast_mode_vf,
513 .update_int_moderator = fm10k_update_int_moderator_vf,
514 .update_lport_state = fm10k_update_lport_state_vf,
515 .update_hw_stats = fm10k_update_hw_stats_vf,
516 .rebind_hw_stats = fm10k_rebind_hw_stats_vf,
517 .configure_dglort_map = fm10k_configure_dglort_map_vf,
518 .get_host_state = fm10k_get_host_state_generic,
519};
520
521static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
522{
523 fm10k_get_invariants_generic(hw);
524
525 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
526}
527
528const struct fm10k_info fm10k_vf_info = {
529 .mac = fm10k_mac_vf,
530 .get_invariants = fm10k_get_invariants_vf,
531 .mac_ops = &mac_ops_vf,
532};
1/* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
3 *
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.
7 *
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.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
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
19 */
20
21#include "fm10k_vf.h"
22
23/**
24 * fm10k_stop_hw_vf - Stop Tx/Rx units
25 * @hw: pointer to hardware structure
26 *
27 **/
28static s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
29{
30 u8 *perm_addr = hw->mac.perm_addr;
31 u32 bal = 0, bah = 0, tdlen;
32 s32 err;
33 u16 i;
34
35 /* we need to disable the queues before taking further steps */
36 err = fm10k_stop_hw_generic(hw);
37 if (err)
38 return err;
39
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]);
49 }
50
51 /* restore default itr_scale for next VF initialization */
52 tdlen = hw->mac.itr_scale << FM10K_TDLEN_ITR_SCALE_SHIFT;
53
54 /* The queues have already been disabled so we just need to
55 * update their base address registers
56 */
57 for (i = 0; i < hw->mac.max_queues; i++) {
58 fm10k_write_reg(hw, FM10K_TDBAL(i), bal);
59 fm10k_write_reg(hw, FM10K_TDBAH(i), bah);
60 fm10k_write_reg(hw, FM10K_RDBAL(i), bal);
61 fm10k_write_reg(hw, FM10K_RDBAH(i), bah);
62 /* Restore ITR scale in software-defined mechanism in TDLEN
63 * for next VF initialization. See definition of
64 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details on the use of
65 * TDLEN here.
66 */
67 fm10k_write_reg(hw, FM10K_TDLEN(i), tdlen);
68 }
69
70 return 0;
71}
72
73/**
74 * fm10k_reset_hw_vf - VF hardware reset
75 * @hw: pointer to hardware structure
76 *
77 * This function should return the hardware to a state similar to the
78 * one it is in after just being initialized.
79 **/
80static s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
81{
82 s32 err;
83
84 /* shut down queues we own and reset DMA configuration */
85 err = fm10k_stop_hw_vf(hw);
86 if (err)
87 return err;
88
89 /* Inititate VF reset */
90 fm10k_write_reg(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
91
92 /* Flush write and allow 100us for reset to complete */
93 fm10k_write_flush(hw);
94 udelay(FM10K_RESET_TIMEOUT);
95
96 /* Clear reset bit and verify it was cleared */
97 fm10k_write_reg(hw, FM10K_VFCTRL, 0);
98 if (fm10k_read_reg(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
99 err = FM10K_ERR_RESET_FAILED;
100
101 return err;
102}
103
104/**
105 * fm10k_init_hw_vf - VF hardware initialization
106 * @hw: pointer to hardware structure
107 *
108 **/
109static s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
110{
111 u32 tqdloc, tqdloc0 = ~fm10k_read_reg(hw, FM10K_TQDLOC(0));
112 s32 err;
113 u16 i;
114
115 /* verify we have at least 1 queue */
116 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(0)) ||
117 !~fm10k_read_reg(hw, FM10K_RXQCTL(0))) {
118 err = FM10K_ERR_NO_RESOURCES;
119 goto reset_max_queues;
120 }
121
122 /* determine how many queues we have */
123 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
124 /* verify the Descriptor cache offsets are increasing */
125 tqdloc = ~fm10k_read_reg(hw, FM10K_TQDLOC(i));
126 if (!tqdloc || (tqdloc == tqdloc0))
127 break;
128
129 /* check to verify the PF doesn't own any of our queues */
130 if (!~fm10k_read_reg(hw, FM10K_TXQCTL(i)) ||
131 !~fm10k_read_reg(hw, FM10K_RXQCTL(i)))
132 break;
133 }
134
135 /* shut down queues we own and reset DMA configuration */
136 err = fm10k_disable_queues_generic(hw, i);
137 if (err)
138 goto reset_max_queues;
139
140 /* record maximum queue count */
141 hw->mac.max_queues = i;
142
143 /* fetch default VLAN and ITR scale */
144 hw->mac.default_vid = (fm10k_read_reg(hw, FM10K_TXQCTL(0)) &
145 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
146 /* Read the ITR scale from TDLEN. See the definition of
147 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
148 * used here.
149 */
150 hw->mac.itr_scale = (fm10k_read_reg(hw, FM10K_TDLEN(0)) &
151 FM10K_TDLEN_ITR_SCALE_MASK) >>
152 FM10K_TDLEN_ITR_SCALE_SHIFT;
153
154 return 0;
155
156reset_max_queues:
157 hw->mac.max_queues = 0;
158
159 return err;
160}
161
162/* This structure defines the attibutes to be parsed below */
163const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
164 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
165 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
166 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
167 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
168 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
169 FM10K_TLV_ATTR_LAST
170};
171
172/**
173 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
174 * @hw: pointer to hardware structure
175 * @vid: VLAN ID to add to table
176 * @vsi: Reserved, should always be 0
177 * @set: Indicates if this is a set or clear operation
178 *
179 * This function adds or removes the corresponding VLAN ID from the VLAN
180 * filter table for this VF.
181 **/
182static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
183{
184 struct fm10k_mbx_info *mbx = &hw->mbx;
185 u32 msg[4];
186
187 /* verify the index is not set */
188 if (vsi)
189 return FM10K_ERR_PARAM;
190
191 /* verify upper 4 bits of vid and length are 0 */
192 if ((vid << 16 | vid) >> 28)
193 return FM10K_ERR_PARAM;
194
195 /* encode set bit into the VLAN ID */
196 if (!set)
197 vid |= FM10K_VLAN_CLEAR;
198
199 /* generate VLAN request */
200 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
201 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
202
203 /* load onto outgoing mailbox */
204 return mbx->ops.enqueue_tx(hw, mbx, msg);
205}
206
207/**
208 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
209 * @hw: pointer to the HW structure
210 * @results: Attributes for message
211 * @mbx: unused mailbox data
212 *
213 * This function should determine the MAC address for the VF
214 **/
215s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
216 struct fm10k_mbx_info *mbx)
217{
218 u8 perm_addr[ETH_ALEN];
219 u16 vid;
220 s32 err;
221
222 /* record MAC address requested */
223 err = fm10k_tlv_attr_get_mac_vlan(
224 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
225 perm_addr, &vid);
226 if (err)
227 return err;
228
229 ether_addr_copy(hw->mac.perm_addr, perm_addr);
230 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
231 hw->mac.vlan_override = !!(vid & FM10K_VLAN_CLEAR);
232
233 return 0;
234}
235
236/**
237 * fm10k_read_mac_addr_vf - Read device MAC address
238 * @hw: pointer to the HW structure
239 *
240 * This function should determine the MAC address for the VF
241 **/
242static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
243{
244 u8 perm_addr[ETH_ALEN];
245 u32 base_addr;
246
247 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
248
249 /* last byte should be 0 */
250 if (base_addr << 24)
251 return FM10K_ERR_INVALID_MAC_ADDR;
252
253 perm_addr[3] = (u8)(base_addr >> 24);
254 perm_addr[4] = (u8)(base_addr >> 16);
255 perm_addr[5] = (u8)(base_addr >> 8);
256
257 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
258
259 /* first byte should be all 1's */
260 if ((~base_addr) >> 24)
261 return FM10K_ERR_INVALID_MAC_ADDR;
262
263 perm_addr[0] = (u8)(base_addr >> 16);
264 perm_addr[1] = (u8)(base_addr >> 8);
265 perm_addr[2] = (u8)(base_addr);
266
267 ether_addr_copy(hw->mac.perm_addr, perm_addr);
268 ether_addr_copy(hw->mac.addr, perm_addr);
269
270 return 0;
271}
272
273/**
274 * fm10k_update_uc_addr_vf - Update device unicast addresses
275 * @hw: pointer to the HW structure
276 * @glort: unused
277 * @mac: MAC address to add/remove from table
278 * @vid: VLAN ID to add/remove from table
279 * @add: Indicates if this is an add or remove operation
280 * @flags: flags field to indicate add and secure - unused
281 *
282 * This function is used to add or remove unicast MAC addresses for
283 * the VF.
284 **/
285static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
286 const u8 *mac, u16 vid, bool add, u8 flags)
287{
288 struct fm10k_mbx_info *mbx = &hw->mbx;
289 u32 msg[7];
290
291 /* verify VLAN ID is valid */
292 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
293 return FM10K_ERR_PARAM;
294
295 /* verify MAC address is valid */
296 if (!is_valid_ether_addr(mac))
297 return FM10K_ERR_PARAM;
298
299 /* verify we are not locked down on the MAC address */
300 if (is_valid_ether_addr(hw->mac.perm_addr) &&
301 !ether_addr_equal(hw->mac.perm_addr, mac))
302 return FM10K_ERR_PARAM;
303
304 /* add bit to notify us if this is a set or clear operation */
305 if (!add)
306 vid |= FM10K_VLAN_CLEAR;
307
308 /* generate VLAN request */
309 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
310 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
311
312 /* load onto outgoing mailbox */
313 return mbx->ops.enqueue_tx(hw, mbx, msg);
314}
315
316/**
317 * fm10k_update_mc_addr_vf - Update device multicast addresses
318 * @hw: pointer to the HW structure
319 * @glort: unused
320 * @mac: MAC address to add/remove from table
321 * @vid: VLAN ID to add/remove from table
322 * @add: Indicates if this is an add or remove operation
323 *
324 * This function is used to add or remove multicast MAC addresses for
325 * the VF.
326 **/
327static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
328 const u8 *mac, u16 vid, bool add)
329{
330 struct fm10k_mbx_info *mbx = &hw->mbx;
331 u32 msg[7];
332
333 /* verify VLAN ID is valid */
334 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
335 return FM10K_ERR_PARAM;
336
337 /* verify multicast address is valid */
338 if (!is_multicast_ether_addr(mac))
339 return FM10K_ERR_PARAM;
340
341 /* add bit to notify us if this is a set or clear operation */
342 if (!add)
343 vid |= FM10K_VLAN_CLEAR;
344
345 /* generate VLAN request */
346 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
347 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
348 mac, vid);
349
350 /* load onto outgoing mailbox */
351 return mbx->ops.enqueue_tx(hw, mbx, msg);
352}
353
354/**
355 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
356 * @hw: pointer to hardware structure
357 *
358 * This function will issue a request to the PF to rescan our MSI-X table
359 * and to update the interrupt moderator linked list.
360 **/
361static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
362{
363 struct fm10k_mbx_info *mbx = &hw->mbx;
364 u32 msg[1];
365
366 /* generate MSI-X request */
367 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
368
369 /* load onto outgoing mailbox */
370 mbx->ops.enqueue_tx(hw, mbx, msg);
371}
372
373/* This structure defines the attibutes to be parsed below */
374const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
375 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
376 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
377 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
378 FM10K_TLV_ATTR_LAST
379};
380
381/**
382 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
383 * @hw: Pointer to hardware structure
384 * @results: pointer array containing parsed data
385 * @mbx: Pointer to mailbox information structure
386 *
387 * This handler is meant to capture the indication from the PF that we
388 * are ready to bring up the interface.
389 **/
390s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
391 struct fm10k_mbx_info *mbx)
392{
393 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
394 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
395
396 return 0;
397}
398
399/**
400 * fm10k_update_lport_state_vf - Update device state in lower device
401 * @hw: pointer to the HW structure
402 * @glort: unused
403 * @count: number of logical ports to enable - unused (always 1)
404 * @enable: boolean value indicating if this is an enable or disable request
405 *
406 * Notify the lower device of a state change. If the lower device is
407 * enabled we can add filters, if it is disabled all filters for this
408 * logical port are flushed.
409 **/
410static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
411 u16 count, bool enable)
412{
413 struct fm10k_mbx_info *mbx = &hw->mbx;
414 u32 msg[2];
415
416 /* reset glort mask 0 as we have to wait to be enabled */
417 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
418
419 /* generate port state request */
420 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
421 if (!enable)
422 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
423
424 /* load onto outgoing mailbox */
425 return mbx->ops.enqueue_tx(hw, mbx, msg);
426}
427
428/**
429 * fm10k_update_xcast_mode_vf - Request update of multicast mode
430 * @hw: pointer to hardware structure
431 * @glort: unused
432 * @mode: integer value indicating mode being requested
433 *
434 * This function will attempt to request a higher mode for the port
435 * so that it can enable either multicast, multicast promiscuous, or
436 * promiscuous mode of operation.
437 **/
438static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
439{
440 struct fm10k_mbx_info *mbx = &hw->mbx;
441 u32 msg[3];
442
443 if (mode > FM10K_XCAST_MODE_NONE)
444 return FM10K_ERR_PARAM;
445
446 /* generate message requesting to change xcast mode */
447 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
448 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
449
450 /* load onto outgoing mailbox */
451 return mbx->ops.enqueue_tx(hw, mbx, msg);
452}
453
454const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
455 FM10K_TLV_ATTR_U64(FM10K_1588_MSG_TIMESTAMP),
456 FM10K_TLV_ATTR_LAST
457};
458
459/* currently there is no shared 1588 timestamp handler */
460
461/**
462 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
463 * @hw: pointer to hardware structure
464 * @stats: pointer to statistics structure
465 *
466 * This function collects and aggregates per queue hardware statistics.
467 **/
468static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
469 struct fm10k_hw_stats *stats)
470{
471 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
472}
473
474/**
475 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
476 * @hw: pointer to hardware structure
477 * @stats: pointer to the stats structure to update
478 *
479 * This function resets the base for queue hardware statistics.
480 **/
481static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
482 struct fm10k_hw_stats *stats)
483{
484 /* Unbind Queue Statistics */
485 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
486
487 /* Reinitialize bases for all stats */
488 fm10k_update_hw_stats_vf(hw, stats);
489}
490
491/**
492 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
493 * @hw: pointer to hardware structure
494 * @dglort: pointer to dglort configuration structure
495 *
496 * Reads the configuration structure contained in dglort_cfg and uses
497 * that information to then populate a DGLORTMAP/DEC entry and the queues
498 * to which it has been assigned.
499 **/
500static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
501 struct fm10k_dglort_cfg *dglort)
502{
503 /* verify the dglort pointer */
504 if (!dglort)
505 return FM10K_ERR_PARAM;
506
507 /* stub for now until we determine correct message for this */
508
509 return 0;
510}
511
512/**
513 * fm10k_adjust_systime_vf - Adjust systime frequency
514 * @hw: pointer to hardware structure
515 * @ppb: adjustment rate in parts per billion
516 *
517 * This function takes an adjustment rate in parts per billion and will
518 * verify that this value is 0 as the VF cannot support adjusting the
519 * systime clock.
520 *
521 * If the ppb value is non-zero the return is ERR_PARAM else success
522 **/
523static s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
524{
525 /* The VF cannot adjust the clock frequency, however it should
526 * already have a syntonic clock with whichever host interface is
527 * running as the master for the host interface clock domain so
528 * there should be not frequency adjustment necessary.
529 */
530 return ppb ? FM10K_ERR_PARAM : 0;
531}
532
533/**
534 * fm10k_read_systime_vf - Reads value of systime registers
535 * @hw: pointer to the hardware structure
536 *
537 * Function reads the content of 2 registers, combined to represent a 64 bit
538 * value measured in nanoseconds. In order to guarantee the value is accurate
539 * we check the 32 most significant bits both before and after reading the
540 * 32 least significant bits to verify they didn't change as we were reading
541 * the registers.
542 **/
543static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
544{
545 u32 systime_l, systime_h, systime_tmp;
546
547 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
548
549 do {
550 systime_tmp = systime_h;
551 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
552 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
553 } while (systime_tmp != systime_h);
554
555 return ((u64)systime_h << 32) | systime_l;
556}
557
558static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
559 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
560 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
561 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
562 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
563};
564
565static const struct fm10k_mac_ops mac_ops_vf = {
566 .get_bus_info = fm10k_get_bus_info_generic,
567 .reset_hw = fm10k_reset_hw_vf,
568 .init_hw = fm10k_init_hw_vf,
569 .start_hw = fm10k_start_hw_generic,
570 .stop_hw = fm10k_stop_hw_vf,
571 .update_vlan = fm10k_update_vlan_vf,
572 .read_mac_addr = fm10k_read_mac_addr_vf,
573 .update_uc_addr = fm10k_update_uc_addr_vf,
574 .update_mc_addr = fm10k_update_mc_addr_vf,
575 .update_xcast_mode = fm10k_update_xcast_mode_vf,
576 .update_int_moderator = fm10k_update_int_moderator_vf,
577 .update_lport_state = fm10k_update_lport_state_vf,
578 .update_hw_stats = fm10k_update_hw_stats_vf,
579 .rebind_hw_stats = fm10k_rebind_hw_stats_vf,
580 .configure_dglort_map = fm10k_configure_dglort_map_vf,
581 .get_host_state = fm10k_get_host_state_generic,
582 .adjust_systime = fm10k_adjust_systime_vf,
583 .read_systime = fm10k_read_systime_vf,
584};
585
586static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
587{
588 fm10k_get_invariants_generic(hw);
589
590 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
591}
592
593const struct fm10k_info fm10k_vf_info = {
594 .mac = fm10k_mac_vf,
595 .get_invariants = fm10k_get_invariants_vf,
596 .mac_ops = &mac_ops_vf,
597};