Imported Upstream version 16.11
[deb_dpdk.git] / drivers / net / qede / base / ecore_iov_api.h
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #ifndef __ECORE_SRIOV_API_H__
10 #define __ECORE_SRIOV_API_H__
11
12 #include "common_hsi.h"
13 #include "ecore_status.h"
14
15 #define ECORE_ETH_VF_NUM_MAC_FILTERS 1
16 #define ECORE_ETH_VF_NUM_VLAN_FILTERS 2
17 #define ECORE_VF_ARRAY_LENGTH (3)
18
19 #define IS_VF(p_dev)            ((p_dev)->b_is_vf)
20 #define IS_PF(p_dev)            (!((p_dev)->b_is_vf))
21 #ifdef CONFIG_ECORE_SRIOV
22 #define IS_PF_SRIOV(p_hwfn)     (!!((p_hwfn)->p_dev->p_iov_info))
23 #else
24 #define IS_PF_SRIOV(p_hwfn)     (0)
25 #endif
26 #define IS_PF_SRIOV_ALLOC(p_hwfn)       (!!((p_hwfn)->pf_iov_info))
27 #define IS_PF_PDA(p_hwfn)       0 /* @@TBD Michalk */
28
29 /* @@@ TBD MichalK - what should this number be*/
30 #define ECORE_MAX_VF_CHAINS_PER_PF 16
31
32 /* vport update extended feature tlvs flags */
33 enum ecore_iov_vport_update_flag {
34         ECORE_IOV_VP_UPDATE_ACTIVATE            = 0,
35         ECORE_IOV_VP_UPDATE_VLAN_STRIP          = 1,
36         ECORE_IOV_VP_UPDATE_TX_SWITCH           = 2,
37         ECORE_IOV_VP_UPDATE_MCAST               = 3,
38         ECORE_IOV_VP_UPDATE_ACCEPT_PARAM        = 4,
39         ECORE_IOV_VP_UPDATE_RSS                 = 5,
40         ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN     = 6,
41         ECORE_IOV_VP_UPDATE_SGE_TPA             = 7,
42         ECORE_IOV_VP_UPDATE_MAX                 = 8,
43 };
44
45 /* PF to VF STATUS is part of vfpf-channel API
46  * and must be forward compatible
47 */
48 enum ecore_iov_pf_to_vf_status {
49         PFVF_STATUS_WAITING = 0,
50         PFVF_STATUS_SUCCESS,
51         PFVF_STATUS_FAILURE,
52         PFVF_STATUS_NOT_SUPPORTED,
53         PFVF_STATUS_NO_RESOURCE,
54         PFVF_STATUS_FORCED,
55 };
56
57 struct ecore_mcp_link_params;
58 struct ecore_mcp_link_state;
59 struct ecore_mcp_link_capabilities;
60
61 /* These defines are used by the hw-channel; should never change order */
62 #define VFPF_ACQUIRE_OS_LINUX (0)
63 #define VFPF_ACQUIRE_OS_WINDOWS (1)
64 #define VFPF_ACQUIRE_OS_ESX (2)
65 #define VFPF_ACQUIRE_OS_SOLARIS (3)
66 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
67
68 struct ecore_vf_acquire_sw_info {
69         u32 driver_version;
70         u8 os_type;
71
72         /* We have several close releases that all use ~same FW with different
73          * versions [making it incompatible as the versioning scheme is still
74          * tied directly to FW version], allow to override the checking. Only
75          * those versions would actually support this feature [so it would not
76          * break forward compatibility with newer HV drivers that are no longer
77          * suited].
78          */
79         bool override_fw_version;
80 };
81
82 struct ecore_public_vf_info {
83         /* These copies will later be reflected in the bulletin board,
84          * but this copy should be newer.
85          */
86         u8 forced_mac[ETH_ALEN];
87         u16 forced_vlan;
88 };
89
90 #ifdef CONFIG_ECORE_SW_CHANNEL
91 /* This is SW channel related only... */
92 enum mbx_state {
93         VF_PF_UNKNOWN_STATE                     = 0,
94         VF_PF_WAIT_FOR_START_REQUEST            = 1,
95         VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST    = 2,
96         VF_PF_REQUEST_IN_PROCESSING             = 3,
97         VF_PF_RESPONSE_READY                    = 4,
98 };
99
100 struct ecore_iov_sw_mbx {
101         enum mbx_state          mbx_state;
102
103         u32                     request_size;
104         u32                     request_offset;
105
106         u32                     response_size;
107         u32                     response_offset;
108 };
109
110 /**
111  * @brief Get the vf sw mailbox params
112  *
113  * @param p_hwfn
114  * @param rel_vf_id
115  *
116  * @return struct ecore_iov_sw_mbx*
117  */
118 struct ecore_iov_sw_mbx*
119 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
120                         u16 rel_vf_id);
121 #endif
122
123 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
124  * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
125  */
126 struct ecore_hw_sriov_info {
127         /* standard SRIOV capability fields, mostly for debugging */
128         int     pos;            /* capability position */
129         int     nres;           /* number of resources */
130         u32     cap;            /* SR-IOV Capabilities */
131         u16     ctrl;           /* SR-IOV Control */
132         u16     total_vfs;      /* total VFs associated with the PF */
133         u16     num_vfs;        /* number of vfs that have been started */
134         u16     initial_vfs;    /* initial VFs associated with the PF */
135         u16     nr_virtfn;      /* number of VFs available */
136         u16     offset;         /* first VF Routing ID offset */
137         u16     stride;         /* following VF stride */
138         u16     vf_device_id;   /* VF device id */
139         u32     pgsz;           /* page size for BAR alignment */
140         u8      link;           /* Function Dependency Link */
141
142         u32     first_vf_in_pf;
143 };
144
145 #ifdef CONFIG_ECORE_SRIOV
146 #ifndef LINUX_REMOVE
147 /**
148  * @brief mark/clear all VFs before/after an incoming PCIe sriov
149  *        disable.
150  *
151  * @param p_dev
152  * @param to_disable
153  */
154 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
155                                   u8 to_disable);
156
157 /**
158  * @brief mark/clear chosen VF before/after an incoming PCIe
159  *        sriov disable.
160  *
161  * @param p_dev
162  * @param rel_vf_id
163  * @param to_disable
164  */
165 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
166                                  u16 rel_vf_id,
167                                  u8 to_disable);
168
169 /**
170  * @brief ecore_iov_init_hw_for_vf - initialize the HW for
171  *        enabling access of a VF. Also includes preparing the
172  *        IGU for VF access. This needs to be called AFTER hw is
173  *        initialized and BEFORE VF is loaded inside the VM.
174  *
175  * @param p_hwfn
176  * @param p_ptt
177  * @param rel_vf_id
178  * @param num_rx_queues
179  *
180  * @return enum _ecore_status_t
181  */
182 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
183                                               struct ecore_ptt *p_ptt,
184                                               u16 rel_vf_id,
185                                               u16 num_rx_queues);
186
187 /**
188  * @brief ecore_iov_process_mbx_req - process a request received
189  *        from the VF
190  *
191  * @param p_hwfn
192  * @param p_ptt
193  * @param vfid
194  */
195 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
196                                struct ecore_ptt *p_ptt,
197                                int vfid);
198
199 /**
200  * @brief ecore_iov_release_hw_for_vf - called once upper layer
201  *        knows VF is done with - can release any resources
202  *        allocated for VF at this point. this must be done once
203  *        we know VF is no longer loaded in VM.
204  *
205  * @param p_hwfn
206  * @param p_ptt
207  * @param rel_vf_id
208  *
209  * @return enum _ecore_status_t
210  */
211 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
212                                                  struct ecore_ptt *p_ptt,
213                                                  u16 rel_vf_id);
214
215 /**
216  * @brief ecore_iov_set_vf_ctx - set a context for a given VF
217  *
218  * @param p_hwfn
219  * @param vf_id
220  * @param ctx
221  *
222  * @return enum _ecore_status_t
223  */
224 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
225                                           u16 vf_id,
226                                           void *ctx);
227
228 /**
229  * @brief FLR cleanup for all VFs
230  *
231  * @param p_hwfn
232  * @param p_ptt
233  *
234  * @return enum _ecore_status_t
235  */
236 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
237                                               struct ecore_ptt *p_ptt);
238
239 /**
240  * @brief FLR cleanup for single VF
241  *
242  * @param p_hwfn
243  * @param p_ptt
244  * @param rel_vf_id
245  *
246  * @return enum _ecore_status_t
247  */
248 enum _ecore_status_t
249 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
250                                 struct ecore_ptt *p_ptt,
251                                 u16 rel_vf_id);
252
253 /**
254  * @brief Update the bulletin with link information. Notice this does NOT
255  *        send a bulletin update, only updates the PF's bulletin.
256  *
257  * @param p_hwfn
258  * @param p_vf
259  * @param params - the link params to use for the VF link configuration
260  * @param link - the link output to use for the VF link configuration
261  * @param p_caps - the link default capabilities.
262  */
263 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
264                         u16 vfid,
265                         struct ecore_mcp_link_params *params,
266                         struct ecore_mcp_link_state *link,
267                         struct ecore_mcp_link_capabilities *p_caps);
268
269 /**
270  * @brief Returns link information as perceived by VF.
271  *
272  * @param p_hwfn
273  * @param p_vf
274  * @param p_params - the link params visible to vf.
275  * @param p_link - the link state visible to vf.
276  * @param p_caps - the link default capabilities visible to vf.
277  */
278 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
279                         u16 vfid,
280                         struct ecore_mcp_link_params *params,
281                         struct ecore_mcp_link_state *link,
282                         struct ecore_mcp_link_capabilities *p_caps);
283
284 /**
285  * @brief return if the VF is pending FLR
286  *
287  * @param p_hwfn
288  * @param rel_vf_id
289  *
290  * @return bool
291  */
292 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
293                                  u16 rel_vf_id);
294
295 /**
296  * @brief Check if given VF ID @vfid is valid
297  *        w.r.t. @b_enabled_only value
298  *        if b_enabled_only = true - only enabled VF id is valid
299  *        else any VF id less than max_vfs is valid
300  *
301  * @param p_hwfn
302  * @param rel_vf_id - Relative VF ID
303  * @param b_enabled_only - consider only enabled VF
304  *
305  * @return bool - true for valid VF ID
306  */
307 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
308                              int rel_vf_id,
309                              bool b_enabled_only);
310
311 /**
312  * @brief Get VF's public info structure
313  *
314  * @param p_hwfn
315  * @param vfid - Relative VF ID
316  * @param b_enabled_only - false if want to access even if vf is disabled
317  *
318  * @return struct ecore_public_vf_info *
319  */
320 struct ecore_public_vf_info*
321 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
322                              u16 vfid, bool b_enabled_only);
323
324 /**
325  * @brief Set pending events bitmap for given @vfid
326  *
327  * @param p_hwfn
328  * @param vfid
329  */
330 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid);
331
332 /**
333  * @brief Copy pending events bitmap in @events and clear
334  *        original copy of events
335  *
336  * @param p_hwfn
337  */
338 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
339                                                u64 *events);
340
341 /**
342  * @brief Copy VF's message to PF's buffer
343  *
344  * @param p_hwfn
345  * @param ptt
346  * @param vfid
347  *
348  * @return enum _ecore_status_t
349  */
350 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
351                                            struct ecore_ptt *ptt,
352                                            int vfid);
353 /**
354  * @brief Set forced MAC address in PFs copy of bulletin board
355  *        and configures FW/HW to support the configuration.
356  *
357  * @param p_hwfn
358  * @param mac
359  * @param vfid
360  */
361 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
362                                        u8 *mac, int vfid);
363
364 /**
365  * @brief Set MAC address in PFs copy of bulletin board without
366  *        configuring FW/HW.
367  *
368  * @param p_hwfn
369  * @param mac
370  * @param vfid
371  */
372 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
373                                                 u8 *mac, int vfid);
374
375 /**
376  * @brief Set default behaviour of VF in case no vlans are configured for it
377  *        whether to accept only untagged traffic or all.
378  *        Must be called prior to the VF vport-start.
379  *
380  * @param p_hwfn
381  * @param b_untagged_only
382  * @param vfid
383  *
384  * @return ECORE_SUCCESS if configuration would stick.
385  */
386 enum _ecore_status_t
387 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
388                                                bool b_untagged_only,
389                                                int vfid);
390
391 /**
392  * @brief Get VFs opaque fid.
393  *
394  * @param p_hwfn
395  * @param vfid
396  * @param opaque_fid
397  */
398 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
399                                   u16 *opaque_fid);
400
401 /**
402  * @brief Get VFs VPORT id.
403  *
404  * @param p_hwfn
405  * @param vfid
406  * @param vport id
407  */
408 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
409                                 u8 *p_vport_id);
410
411 /**
412  * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
413  *        and configures FW/HW to support the configuration.
414  *        Setting of pvid 0 would clear the feature.
415  * @param p_hwfn
416  * @param pvid
417  * @param vfid
418  */
419 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
420                                         u16 pvid, int vfid);
421
422 /**
423  * @brief Check if VF has VPORT instance. This can be used
424  *        to check if VPORT is active.
425  *
426  * @param p_hwfn
427  */
428 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
429
430 /**
431  * @brief PF posts the bulletin to the VF
432  *
433  * @param p_hwfn
434  * @param p_vf
435  * @param p_ptt
436  *
437  * @return enum _ecore_status_t
438  */
439 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
440                                                 int vfid,
441                                                 struct ecore_ptt *p_ptt);
442
443 /**
444  * @brief Check if given VF (@vfid) is marked as stopped
445  *
446  * @param p_hwfn
447  * @param vfid
448  *
449  * @return bool : true if stopped
450  */
451 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
452
453 /**
454  * @brief Configure VF anti spoofing
455  *
456  * @param p_hwfn
457  * @param vfid
458  * @param val - spoofchk value - true/false
459  *
460  * @return enum _ecore_status_t
461  */
462 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
463                                             int vfid, bool val);
464
465 /**
466  * @brief Get VF's configured spoof value.
467  *
468  * @param p_hwfn
469  * @param vfid
470  *
471  * @return bool - spoofchk value - true/false
472  */
473 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
474
475 /**
476  * @brief Check for SRIOV sanity by PF.
477  *
478  * @param p_hwfn
479  * @param vfid
480  *
481  * @return bool - true if sanity checks passes, else false
482  */
483 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
484
485 /**
486  * @brief Get the num of VF chains.
487  *
488  * @param p_hwfn
489  *
490  * @return u8
491  */
492 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
493
494 /**
495  * @brief Get vf request mailbox params
496  *
497  * @param p_hwfn
498  * @param rel_vf_id
499  * @param pp_req_virt_addr
500  * @param p_req_virt_size
501  */
502 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
503                                           u16 rel_vf_id,
504                                           void **pp_req_virt_addr,
505                                           u16 *p_req_virt_size);
506
507 /**
508  * @brief Get vf mailbox params
509  *
510  * @param p_hwfn
511  * @param rel_vf_id
512  * @param pp_reply_virt_addr
513  * @param p_reply_virt_size
514  */
515 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
516                                             u16 rel_vf_id,
517                                             void **pp_reply_virt_addr,
518                                             u16 *p_reply_virt_size);
519
520 /**
521  * @brief Validate if the given length is a valid vfpf message
522  *        length
523  *
524  * @param length
525  *
526  * @return bool
527  */
528 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
529
530 /**
531  * @brief Return the max pfvf message length
532  *
533  * @return u32
534  */
535 u32 ecore_iov_pfvf_msg_length(void);
536
537 /**
538  * @brief Returns forced MAC address if one is configured
539  *
540  * @parm p_hwfn
541  * @parm rel_vf_id
542  *
543  * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
544  */
545 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
546                                       u16 rel_vf_id);
547
548 /**
549  * @brief Returns pvid if one is configured
550  *
551  * @parm p_hwfn
552  * @parm rel_vf_id
553  *
554  * @return 0 if no pvid is configured, otherwise the pvid.
555  */
556 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
557                                        u16 rel_vf_id);
558 /**
559  * @brief Configure VFs tx rate
560  *
561  * @param p_hwfn
562  * @param p_ptt
563  * @param vfid
564  * @param val - tx rate value in Mb/sec.
565  *
566  * @return enum _ecore_status_t
567  */
568 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
569                                                  struct ecore_ptt *p_ptt,
570                                                  int vfid, int val);
571
572 /**
573  * @brief - Retrieves the statistics associated with a VF
574  *
575  * @param p_hwfn
576  * @param p_ptt
577  * @param vfid
578  * @param p_stats - this will be filled with the VF statistics
579  *
580  * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
581  */
582 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
583                                             struct ecore_ptt *p_ptt,
584                                             int vfid,
585                                             struct ecore_eth_stats *p_stats);
586
587 /**
588  * @brief - Retrieves num of rxqs chains
589  *
590  * @param p_hwfn
591  * @param rel_vf_id
592  *
593  * @return num of rxqs chains.
594  */
595 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
596                              u16 rel_vf_id);
597
598 /**
599  * @brief - Retrieves num of active rxqs chains
600  *
601  * @param p_hwfn
602  * @param rel_vf_id
603  *
604  * @return
605  */
606 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
607                                     u16 rel_vf_id);
608
609 /**
610  * @brief - Retrieves ctx pointer
611  *
612  * @param p_hwfn
613  * @param rel_vf_id
614  *
615  * @return
616  */
617 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
618                            u16 rel_vf_id);
619
620 /**
621  * @brief - Retrieves VF`s num sbs
622  *
623  * @param p_hwfn
624  * @param rel_vf_id
625  *
626  * @return
627  */
628 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
629                             u16 rel_vf_id);
630
631 /**
632  * @brief - Returm true if VF is waiting for acquire
633  *
634  * @param p_hwfn
635  * @param rel_vf_id
636  *
637  * @return
638  */
639 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
640                                       u16 rel_vf_id);
641
642 /**
643  * @brief - Returm true if VF is acquired but not initialized
644  *
645  * @param p_hwfn
646  * @param rel_vf_id
647  *
648  * @return
649  */
650 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
651                                               u16 rel_vf_id);
652
653 /**
654  * @brief - Returm true if VF is acquired and initialized
655  *
656  * @param p_hwfn
657  * @param rel_vf_id
658  *
659  * @return
660  */
661 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
662                                  u16 rel_vf_id);
663
664 /**
665  * @brief - Get VF's vport min rate configured.
666  * @param p_hwfn
667  * @param rel_vf_id
668  *
669  * @return - rate in Mbps
670  */
671 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
672
673 /**
674  * @brief - Configure min rate for VF's vport.
675  * @param p_dev
676  * @param vfid
677  * @param - rate in Mbps
678  *
679  * @return
680  */
681 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
682                                                      int vfid, u32 rate);
683 #endif
684
685 /**
686  * @brief - Given a VF index, return index of next [including that] active VF.
687  *
688  * @param p_hwfn
689  * @param rel_vf_id
690  *
691  * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
692  */
693 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
694
695 #endif /* CONFIG_ECORE_SRIOV */
696
697 #define ecore_for_each_vf(_p_hwfn, _i)                                  \
698         for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0);             \
699              _i < MAX_NUM_VFS;                                          \
700              _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))
701
702 #endif