Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / net / ethernet / intel / fm10k / fm10k_vf.c
blob36c8b0aa08fd2eeadfbc7b87ee5ce9d8d619b589
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;
134 /* This structure defines the attibutes to be parsed below */
135 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
136 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
137 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
138 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
139 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
140 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
141 FM10K_TLV_ATTR_LAST
145 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
146 * @hw: pointer to hardware structure
147 * @vid: VLAN ID to add to table
148 * @vsi: Reserved, should always be 0
149 * @set: Indicates if this is a set or clear operation
151 * This function adds or removes the corresponding VLAN ID from the VLAN
152 * filter table for this VF.
154 static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
156 struct fm10k_mbx_info *mbx = &hw->mbx;
157 u32 msg[4];
159 /* verify the index is not set */
160 if (vsi)
161 return FM10K_ERR_PARAM;
163 /* verify upper 4 bits of vid and length are 0 */
164 if ((vid << 16 | vid) >> 28)
165 return FM10K_ERR_PARAM;
167 /* encode set bit into the VLAN ID */
168 if (!set)
169 vid |= FM10K_VLAN_CLEAR;
171 /* generate VLAN request */
172 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
173 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
175 /* load onto outgoing mailbox */
176 return mbx->ops.enqueue_tx(hw, mbx, msg);
180 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
181 * @hw: pointer to the HW structure
182 * @results: Attributes for message
183 * @mbx: unused mailbox data
185 * This function should determine the MAC address for the VF
187 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
188 struct fm10k_mbx_info *mbx)
190 u8 perm_addr[ETH_ALEN];
191 u16 vid;
192 s32 err;
194 /* record MAC address requested */
195 err = fm10k_tlv_attr_get_mac_vlan(
196 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
197 perm_addr, &vid);
198 if (err)
199 return err;
201 ether_addr_copy(hw->mac.perm_addr, perm_addr);
202 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
203 hw->mac.vlan_override = !!(vid & FM10K_VLAN_CLEAR);
205 return 0;
209 * fm10k_read_mac_addr_vf - Read device MAC address
210 * @hw: pointer to the HW structure
212 * This function should determine the MAC address for the VF
214 static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
216 u8 perm_addr[ETH_ALEN];
217 u32 base_addr;
219 base_addr = fm10k_read_reg(hw, FM10K_TDBAL(0));
221 /* last byte should be 0 */
222 if (base_addr << 24)
223 return FM10K_ERR_INVALID_MAC_ADDR;
225 perm_addr[3] = (u8)(base_addr >> 24);
226 perm_addr[4] = (u8)(base_addr >> 16);
227 perm_addr[5] = (u8)(base_addr >> 8);
229 base_addr = fm10k_read_reg(hw, FM10K_TDBAH(0));
231 /* first byte should be all 1's */
232 if ((~base_addr) >> 24)
233 return FM10K_ERR_INVALID_MAC_ADDR;
235 perm_addr[0] = (u8)(base_addr >> 16);
236 perm_addr[1] = (u8)(base_addr >> 8);
237 perm_addr[2] = (u8)(base_addr);
239 ether_addr_copy(hw->mac.perm_addr, perm_addr);
240 ether_addr_copy(hw->mac.addr, perm_addr);
242 return 0;
246 * fm10k_update_uc_addr_vf - Update device unicast addresses
247 * @hw: pointer to the HW structure
248 * @glort: unused
249 * @mac: MAC address to add/remove from table
250 * @vid: VLAN ID to add/remove from table
251 * @add: Indicates if this is an add or remove operation
252 * @flags: flags field to indicate add and secure - unused
254 * This function is used to add or remove unicast MAC addresses for
255 * the VF.
257 static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
258 const u8 *mac, u16 vid, bool add, u8 flags)
260 struct fm10k_mbx_info *mbx = &hw->mbx;
261 u32 msg[7];
263 /* verify VLAN ID is valid */
264 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
265 return FM10K_ERR_PARAM;
267 /* verify MAC address is valid */
268 if (!is_valid_ether_addr(mac))
269 return FM10K_ERR_PARAM;
271 /* verify we are not locked down on the MAC address */
272 if (is_valid_ether_addr(hw->mac.perm_addr) &&
273 memcmp(hw->mac.perm_addr, mac, ETH_ALEN))
274 return FM10K_ERR_PARAM;
276 /* add bit to notify us if this is a set or clear operation */
277 if (!add)
278 vid |= FM10K_VLAN_CLEAR;
280 /* generate VLAN request */
281 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
282 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
284 /* load onto outgoing mailbox */
285 return mbx->ops.enqueue_tx(hw, mbx, msg);
289 * fm10k_update_mc_addr_vf - Update device multicast addresses
290 * @hw: pointer to the HW structure
291 * @glort: unused
292 * @mac: MAC address to add/remove from table
293 * @vid: VLAN ID to add/remove from table
294 * @add: Indicates if this is an add or remove operation
296 * This function is used to add or remove multicast MAC addresses for
297 * the VF.
299 static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
300 const u8 *mac, u16 vid, bool add)
302 struct fm10k_mbx_info *mbx = &hw->mbx;
303 u32 msg[7];
305 /* verify VLAN ID is valid */
306 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
307 return FM10K_ERR_PARAM;
309 /* verify multicast address is valid */
310 if (!is_multicast_ether_addr(mac))
311 return FM10K_ERR_PARAM;
313 /* add bit to notify us if this is a set or clear operation */
314 if (!add)
315 vid |= FM10K_VLAN_CLEAR;
317 /* generate VLAN request */
318 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
319 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
320 mac, vid);
322 /* load onto outgoing mailbox */
323 return mbx->ops.enqueue_tx(hw, mbx, msg);
327 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
328 * @hw: pointer to hardware structure
330 * This function will issue a request to the PF to rescan our MSI-X table
331 * and to update the interrupt moderator linked list.
333 static void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
335 struct fm10k_mbx_info *mbx = &hw->mbx;
336 u32 msg[1];
338 /* generate MSI-X request */
339 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
341 /* load onto outgoing mailbox */
342 mbx->ops.enqueue_tx(hw, mbx, msg);
345 /* This structure defines the attibutes to be parsed below */
346 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
347 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
348 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
349 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
350 FM10K_TLV_ATTR_LAST
354 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
355 * @hw: Pointer to hardware structure
356 * @results: pointer array containing parsed data
357 * @mbx: Pointer to mailbox information structure
359 * This handler is meant to capture the indication from the PF that we
360 * are ready to bring up the interface.
362 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
363 struct fm10k_mbx_info *mbx)
365 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
366 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
368 return 0;
372 * fm10k_update_lport_state_vf - Update device state in lower device
373 * @hw: pointer to the HW structure
374 * @glort: unused
375 * @count: number of logical ports to enable - unused (always 1)
376 * @enable: boolean value indicating if this is an enable or disable request
378 * Notify the lower device of a state change. If the lower device is
379 * enabled we can add filters, if it is disabled all filters for this
380 * logical port are flushed.
382 static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
383 u16 count, bool enable)
385 struct fm10k_mbx_info *mbx = &hw->mbx;
386 u32 msg[2];
388 /* reset glort mask 0 as we have to wait to be enabled */
389 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
391 /* generate port state request */
392 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
393 if (!enable)
394 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
396 /* load onto outgoing mailbox */
397 return mbx->ops.enqueue_tx(hw, mbx, msg);
401 * fm10k_update_xcast_mode_vf - Request update of multicast mode
402 * @hw: pointer to hardware structure
403 * @glort: unused
404 * @mode: integer value indicating mode being requested
406 * This function will attempt to request a higher mode for the port
407 * so that it can enable either multicast, multicast promiscuous, or
408 * promiscuous mode of operation.
410 static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
412 struct fm10k_mbx_info *mbx = &hw->mbx;
413 u32 msg[3];
415 if (mode > FM10K_XCAST_MODE_NONE)
416 return FM10K_ERR_PARAM;
417 /* generate message requesting to change xcast mode */
418 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
419 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
421 /* load onto outgoing mailbox */
422 return mbx->ops.enqueue_tx(hw, mbx, msg);
425 const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
426 FM10K_TLV_ATTR_U64(FM10K_1588_MSG_TIMESTAMP),
427 FM10K_TLV_ATTR_LAST
430 /* currently there is no shared 1588 timestamp handler */
433 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
434 * @hw: pointer to hardware structure
435 * @stats: pointer to statistics structure
437 * This function collects and aggregates per queue hardware statistics.
439 static void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
440 struct fm10k_hw_stats *stats)
442 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
446 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
447 * @hw: pointer to hardware structure
448 * @stats: pointer to the stats structure to update
450 * This function resets the base for queue hardware statistics.
452 static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
453 struct fm10k_hw_stats *stats)
455 /* Unbind Queue Statistics */
456 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
458 /* Reinitialize bases for all stats */
459 fm10k_update_hw_stats_vf(hw, stats);
463 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
464 * @hw: pointer to hardware structure
465 * @dglort: pointer to dglort configuration structure
467 * Reads the configuration structure contained in dglort_cfg and uses
468 * that information to then populate a DGLORTMAP/DEC entry and the queues
469 * to which it has been assigned.
471 static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
472 struct fm10k_dglort_cfg *dglort)
474 /* verify the dglort pointer */
475 if (!dglort)
476 return FM10K_ERR_PARAM;
478 /* stub for now until we determine correct message for this */
480 return 0;
484 * fm10k_adjust_systime_vf - Adjust systime frequency
485 * @hw: pointer to hardware structure
486 * @ppb: adjustment rate in parts per billion
488 * This function takes an adjustment rate in parts per billion and will
489 * verify that this value is 0 as the VF cannot support adjusting the
490 * systime clock.
492 * If the ppb value is non-zero the return is ERR_PARAM else success
494 static s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
496 /* The VF cannot adjust the clock frequency, however it should
497 * already have a syntonic clock with whichever host interface is
498 * running as the master for the host interface clock domain so
499 * there should be not frequency adjustment necessary.
501 return ppb ? FM10K_ERR_PARAM : 0;
505 * fm10k_read_systime_vf - Reads value of systime registers
506 * @hw: pointer to the hardware structure
508 * Function reads the content of 2 registers, combined to represent a 64 bit
509 * value measured in nanoseconds. In order to guarantee the value is accurate
510 * we check the 32 most significant bits both before and after reading the
511 * 32 least significant bits to verify they didn't change as we were reading
512 * the registers.
514 static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
516 u32 systime_l, systime_h, systime_tmp;
518 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
520 do {
521 systime_tmp = systime_h;
522 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
523 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
524 } while (systime_tmp != systime_h);
526 return ((u64)systime_h << 32) | systime_l;
529 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
530 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
531 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
532 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
533 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
536 static struct fm10k_mac_ops mac_ops_vf = {
537 .get_bus_info = &fm10k_get_bus_info_generic,
538 .reset_hw = &fm10k_reset_hw_vf,
539 .init_hw = &fm10k_init_hw_vf,
540 .start_hw = &fm10k_start_hw_generic,
541 .stop_hw = &fm10k_stop_hw_vf,
542 .update_vlan = &fm10k_update_vlan_vf,
543 .read_mac_addr = &fm10k_read_mac_addr_vf,
544 .update_uc_addr = &fm10k_update_uc_addr_vf,
545 .update_mc_addr = &fm10k_update_mc_addr_vf,
546 .update_xcast_mode = &fm10k_update_xcast_mode_vf,
547 .update_int_moderator = &fm10k_update_int_moderator_vf,
548 .update_lport_state = &fm10k_update_lport_state_vf,
549 .update_hw_stats = &fm10k_update_hw_stats_vf,
550 .rebind_hw_stats = &fm10k_rebind_hw_stats_vf,
551 .configure_dglort_map = &fm10k_configure_dglort_map_vf,
552 .get_host_state = &fm10k_get_host_state_generic,
553 .adjust_systime = &fm10k_adjust_systime_vf,
554 .read_systime = &fm10k_read_systime_vf,
557 static s32 fm10k_get_invariants_vf(struct fm10k_hw *hw)
559 fm10k_get_invariants_generic(hw);
561 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
564 struct fm10k_info fm10k_vf_info = {
565 .mac = fm10k_mac_vf,
566 .get_invariants = &fm10k_get_invariants_vf,
567 .mac_ops = &mac_ops_vf,