OSDN Git Service

qed: Add support for processing fcoe tlv request.
[uclinux-h8/linux.git] / include / linux / qed / qed_if.h
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015-2017  QLogic Corporation
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and /or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef _QED_IF_H
34 #define _QED_IF_H
35
36 #include <linux/types.h>
37 #include <linux/interrupt.h>
38 #include <linux/netdevice.h>
39 #include <linux/pci.h>
40 #include <linux/skbuff.h>
41 #include <linux/types.h>
42 #include <asm/byteorder.h>
43 #include <linux/io.h>
44 #include <linux/compiler.h>
45 #include <linux/kernel.h>
46 #include <linux/list.h>
47 #include <linux/slab.h>
48 #include <linux/qed/common_hsi.h>
49 #include <linux/qed/qed_chain.h>
50
51 enum dcbx_protocol_type {
52         DCBX_PROTOCOL_ISCSI,
53         DCBX_PROTOCOL_FCOE,
54         DCBX_PROTOCOL_ROCE,
55         DCBX_PROTOCOL_ROCE_V2,
56         DCBX_PROTOCOL_ETH,
57         DCBX_MAX_PROTOCOL_TYPE
58 };
59
60 #define QED_ROCE_PROTOCOL_INDEX (3)
61
62 #define QED_LLDP_CHASSIS_ID_STAT_LEN 4
63 #define QED_LLDP_PORT_ID_STAT_LEN 4
64 #define QED_DCBX_MAX_APP_PROTOCOL 32
65 #define QED_MAX_PFC_PRIORITIES 8
66 #define QED_DCBX_DSCP_SIZE 64
67
68 struct qed_dcbx_lldp_remote {
69         u32 peer_chassis_id[QED_LLDP_CHASSIS_ID_STAT_LEN];
70         u32 peer_port_id[QED_LLDP_PORT_ID_STAT_LEN];
71         bool enable_rx;
72         bool enable_tx;
73         u32 tx_interval;
74         u32 max_credit;
75 };
76
77 struct qed_dcbx_lldp_local {
78         u32 local_chassis_id[QED_LLDP_CHASSIS_ID_STAT_LEN];
79         u32 local_port_id[QED_LLDP_PORT_ID_STAT_LEN];
80 };
81
82 struct qed_dcbx_app_prio {
83         u8 roce;
84         u8 roce_v2;
85         u8 fcoe;
86         u8 iscsi;
87         u8 eth;
88 };
89
90 struct qed_dbcx_pfc_params {
91         bool willing;
92         bool enabled;
93         u8 prio[QED_MAX_PFC_PRIORITIES];
94         u8 max_tc;
95 };
96
97 enum qed_dcbx_sf_ieee_type {
98         QED_DCBX_SF_IEEE_ETHTYPE,
99         QED_DCBX_SF_IEEE_TCP_PORT,
100         QED_DCBX_SF_IEEE_UDP_PORT,
101         QED_DCBX_SF_IEEE_TCP_UDP_PORT
102 };
103
104 struct qed_app_entry {
105         bool ethtype;
106         enum qed_dcbx_sf_ieee_type sf_ieee;
107         bool enabled;
108         u8 prio;
109         u16 proto_id;
110         enum dcbx_protocol_type proto_type;
111 };
112
113 struct qed_dcbx_params {
114         struct qed_app_entry app_entry[QED_DCBX_MAX_APP_PROTOCOL];
115         u16 num_app_entries;
116         bool app_willing;
117         bool app_valid;
118         bool app_error;
119         bool ets_willing;
120         bool ets_enabled;
121         bool ets_cbs;
122         bool valid;
123         u8 ets_pri_tc_tbl[QED_MAX_PFC_PRIORITIES];
124         u8 ets_tc_bw_tbl[QED_MAX_PFC_PRIORITIES];
125         u8 ets_tc_tsa_tbl[QED_MAX_PFC_PRIORITIES];
126         struct qed_dbcx_pfc_params pfc;
127         u8 max_ets_tc;
128 };
129
130 struct qed_dcbx_admin_params {
131         struct qed_dcbx_params params;
132         bool valid;
133 };
134
135 struct qed_dcbx_remote_params {
136         struct qed_dcbx_params params;
137         bool valid;
138 };
139
140 struct qed_dcbx_operational_params {
141         struct qed_dcbx_app_prio app_prio;
142         struct qed_dcbx_params params;
143         bool valid;
144         bool enabled;
145         bool ieee;
146         bool cee;
147         bool local;
148         u32 err;
149 };
150
151 struct qed_dcbx_get {
152         struct qed_dcbx_operational_params operational;
153         struct qed_dcbx_lldp_remote lldp_remote;
154         struct qed_dcbx_lldp_local lldp_local;
155         struct qed_dcbx_remote_params remote;
156         struct qed_dcbx_admin_params local;
157 };
158
159 enum qed_nvm_images {
160         QED_NVM_IMAGE_ISCSI_CFG,
161         QED_NVM_IMAGE_FCOE_CFG,
162         QED_NVM_IMAGE_NVM_CFG1,
163         QED_NVM_IMAGE_DEFAULT_CFG,
164         QED_NVM_IMAGE_NVM_META,
165 };
166
167 struct qed_link_eee_params {
168         u32 tx_lpi_timer;
169 #define QED_EEE_1G_ADV          BIT(0)
170 #define QED_EEE_10G_ADV         BIT(1)
171
172         /* Capabilities are represented using QED_EEE_*_ADV values */
173         u8 adv_caps;
174         u8 lp_adv_caps;
175         bool enable;
176         bool tx_lpi_enable;
177 };
178
179 enum qed_led_mode {
180         QED_LED_MODE_OFF,
181         QED_LED_MODE_ON,
182         QED_LED_MODE_RESTORE
183 };
184
185 struct qed_mfw_tlv_eth {
186         u16 lso_maxoff_size;
187         bool lso_maxoff_size_set;
188         u16 lso_minseg_size;
189         bool lso_minseg_size_set;
190         u8 prom_mode;
191         bool prom_mode_set;
192         u16 tx_descr_size;
193         bool tx_descr_size_set;
194         u16 rx_descr_size;
195         bool rx_descr_size_set;
196         u16 netq_count;
197         bool netq_count_set;
198         u32 tcp4_offloads;
199         bool tcp4_offloads_set;
200         u32 tcp6_offloads;
201         bool tcp6_offloads_set;
202         u16 tx_descr_qdepth;
203         bool tx_descr_qdepth_set;
204         u16 rx_descr_qdepth;
205         bool rx_descr_qdepth_set;
206         u8 iov_offload;
207 #define QED_MFW_TLV_IOV_OFFLOAD_NONE            (0)
208 #define QED_MFW_TLV_IOV_OFFLOAD_MULTIQUEUE      (1)
209 #define QED_MFW_TLV_IOV_OFFLOAD_VEB             (2)
210 #define QED_MFW_TLV_IOV_OFFLOAD_VEPA            (3)
211         bool iov_offload_set;
212         u8 txqs_empty;
213         bool txqs_empty_set;
214         u8 rxqs_empty;
215         bool rxqs_empty_set;
216         u8 num_txqs_full;
217         bool num_txqs_full_set;
218         u8 num_rxqs_full;
219         bool num_rxqs_full_set;
220 };
221
222 #define QED_MFW_TLV_TIME_SIZE   14
223 struct qed_mfw_tlv_time {
224         bool b_set;
225         u8 month;
226         u8 day;
227         u8 hour;
228         u8 min;
229         u16 msec;
230         u16 usec;
231 };
232
233 struct qed_mfw_tlv_fcoe {
234         u8 scsi_timeout;
235         bool scsi_timeout_set;
236         u32 rt_tov;
237         bool rt_tov_set;
238         u32 ra_tov;
239         bool ra_tov_set;
240         u32 ed_tov;
241         bool ed_tov_set;
242         u32 cr_tov;
243         bool cr_tov_set;
244         u8 boot_type;
245         bool boot_type_set;
246         u8 npiv_state;
247         bool npiv_state_set;
248         u32 num_npiv_ids;
249         bool num_npiv_ids_set;
250         u8 switch_name[8];
251         bool switch_name_set;
252         u16 switch_portnum;
253         bool switch_portnum_set;
254         u8 switch_portid[3];
255         bool switch_portid_set;
256         u8 vendor_name[8];
257         bool vendor_name_set;
258         u8 switch_model[8];
259         bool switch_model_set;
260         u8 switch_fw_version[8];
261         bool switch_fw_version_set;
262         u8 qos_pri;
263         bool qos_pri_set;
264         u8 port_alias[3];
265         bool port_alias_set;
266         u8 port_state;
267 #define QED_MFW_TLV_PORT_STATE_OFFLINE  (0)
268 #define QED_MFW_TLV_PORT_STATE_LOOP             (1)
269 #define QED_MFW_TLV_PORT_STATE_P2P              (2)
270 #define QED_MFW_TLV_PORT_STATE_FABRIC           (3)
271         bool port_state_set;
272         u16 fip_tx_descr_size;
273         bool fip_tx_descr_size_set;
274         u16 fip_rx_descr_size;
275         bool fip_rx_descr_size_set;
276         u16 link_failures;
277         bool link_failures_set;
278         u8 fcoe_boot_progress;
279         bool fcoe_boot_progress_set;
280         u64 rx_bcast;
281         bool rx_bcast_set;
282         u64 tx_bcast;
283         bool tx_bcast_set;
284         u16 fcoe_txq_depth;
285         bool fcoe_txq_depth_set;
286         u16 fcoe_rxq_depth;
287         bool fcoe_rxq_depth_set;
288         u64 fcoe_rx_frames;
289         bool fcoe_rx_frames_set;
290         u64 fcoe_rx_bytes;
291         bool fcoe_rx_bytes_set;
292         u64 fcoe_tx_frames;
293         bool fcoe_tx_frames_set;
294         u64 fcoe_tx_bytes;
295         bool fcoe_tx_bytes_set;
296         u16 crc_count;
297         bool crc_count_set;
298         u32 crc_err_src_fcid[5];
299         bool crc_err_src_fcid_set[5];
300         struct qed_mfw_tlv_time crc_err[5];
301         u16 losync_err;
302         bool losync_err_set;
303         u16 losig_err;
304         bool losig_err_set;
305         u16 primtive_err;
306         bool primtive_err_set;
307         u16 disparity_err;
308         bool disparity_err_set;
309         u16 code_violation_err;
310         bool code_violation_err_set;
311         u32 flogi_param[4];
312         bool flogi_param_set[4];
313         struct qed_mfw_tlv_time flogi_tstamp;
314         u32 flogi_acc_param[4];
315         bool flogi_acc_param_set[4];
316         struct qed_mfw_tlv_time flogi_acc_tstamp;
317         u32 flogi_rjt;
318         bool flogi_rjt_set;
319         struct qed_mfw_tlv_time flogi_rjt_tstamp;
320         u32 fdiscs;
321         bool fdiscs_set;
322         u8 fdisc_acc;
323         bool fdisc_acc_set;
324         u8 fdisc_rjt;
325         bool fdisc_rjt_set;
326         u8 plogi;
327         bool plogi_set;
328         u8 plogi_acc;
329         bool plogi_acc_set;
330         u8 plogi_rjt;
331         bool plogi_rjt_set;
332         u32 plogi_dst_fcid[5];
333         bool plogi_dst_fcid_set[5];
334         struct qed_mfw_tlv_time plogi_tstamp[5];
335         u32 plogi_acc_src_fcid[5];
336         bool plogi_acc_src_fcid_set[5];
337         struct qed_mfw_tlv_time plogi_acc_tstamp[5];
338         u8 tx_plogos;
339         bool tx_plogos_set;
340         u8 plogo_acc;
341         bool plogo_acc_set;
342         u8 plogo_rjt;
343         bool plogo_rjt_set;
344         u32 plogo_src_fcid[5];
345         bool plogo_src_fcid_set[5];
346         struct qed_mfw_tlv_time plogo_tstamp[5];
347         u8 rx_logos;
348         bool rx_logos_set;
349         u8 tx_accs;
350         bool tx_accs_set;
351         u8 tx_prlis;
352         bool tx_prlis_set;
353         u8 rx_accs;
354         bool rx_accs_set;
355         u8 tx_abts;
356         bool tx_abts_set;
357         u8 rx_abts_acc;
358         bool rx_abts_acc_set;
359         u8 rx_abts_rjt;
360         bool rx_abts_rjt_set;
361         u32 abts_dst_fcid[5];
362         bool abts_dst_fcid_set[5];
363         struct qed_mfw_tlv_time abts_tstamp[5];
364         u8 rx_rscn;
365         bool rx_rscn_set;
366         u32 rx_rscn_nport[4];
367         bool rx_rscn_nport_set[4];
368         u8 tx_lun_rst;
369         bool tx_lun_rst_set;
370         u8 abort_task_sets;
371         bool abort_task_sets_set;
372         u8 tx_tprlos;
373         bool tx_tprlos_set;
374         u8 tx_nos;
375         bool tx_nos_set;
376         u8 rx_nos;
377         bool rx_nos_set;
378         u8 ols;
379         bool ols_set;
380         u8 lr;
381         bool lr_set;
382         u8 lrr;
383         bool lrr_set;
384         u8 tx_lip;
385         bool tx_lip_set;
386         u8 rx_lip;
387         bool rx_lip_set;
388         u8 eofa;
389         bool eofa_set;
390         u8 eofni;
391         bool eofni_set;
392         u8 scsi_chks;
393         bool scsi_chks_set;
394         u8 scsi_cond_met;
395         bool scsi_cond_met_set;
396         u8 scsi_busy;
397         bool scsi_busy_set;
398         u8 scsi_inter;
399         bool scsi_inter_set;
400         u8 scsi_inter_cond_met;
401         bool scsi_inter_cond_met_set;
402         u8 scsi_rsv_conflicts;
403         bool scsi_rsv_conflicts_set;
404         u8 scsi_tsk_full;
405         bool scsi_tsk_full_set;
406         u8 scsi_aca_active;
407         bool scsi_aca_active_set;
408         u8 scsi_tsk_abort;
409         bool scsi_tsk_abort_set;
410         u32 scsi_rx_chk[5];
411         bool scsi_rx_chk_set[5];
412         struct qed_mfw_tlv_time scsi_chk_tstamp[5];
413 };
414
415 #define DIRECT_REG_WR(reg_addr, val) writel((u32)val, \
416                                             (void __iomem *)(reg_addr))
417
418 #define DIRECT_REG_RD(reg_addr) readl((void __iomem *)(reg_addr))
419
420 #define QED_COALESCE_MAX 0x1FF
421 #define QED_DEFAULT_RX_USECS 12
422 #define QED_DEFAULT_TX_USECS 48
423
424 /* forward */
425 struct qed_dev;
426
427 struct qed_eth_pf_params {
428         /* The following parameters are used during HW-init
429          * and these parameters need to be passed as arguments
430          * to update_pf_params routine invoked before slowpath start
431          */
432         u16 num_cons;
433
434         /* per-VF number of CIDs */
435         u8 num_vf_cons;
436 #define ETH_PF_PARAMS_VF_CONS_DEFAULT   (32)
437
438         /* To enable arfs, previous to HW-init a positive number needs to be
439          * set [as filters require allocated searcher ILT memory].
440          * This will set the maximal number of configured steering-filters.
441          */
442         u32 num_arfs_filters;
443 };
444
445 struct qed_fcoe_pf_params {
446         /* The following parameters are used during protocol-init */
447         u64 glbl_q_params_addr;
448         u64 bdq_pbl_base_addr[2];
449
450         /* The following parameters are used during HW-init
451          * and these parameters need to be passed as arguments
452          * to update_pf_params routine invoked before slowpath start
453          */
454         u16 num_cons;
455         u16 num_tasks;
456
457         /* The following parameters are used during protocol-init */
458         u16 sq_num_pbl_pages;
459
460         u16 cq_num_entries;
461         u16 cmdq_num_entries;
462         u16 rq_buffer_log_size;
463         u16 mtu;
464         u16 dummy_icid;
465         u16 bdq_xoff_threshold[2];
466         u16 bdq_xon_threshold[2];
467         u16 rq_buffer_size;
468         u8 num_cqs;             /* num of global CQs */
469         u8 log_page_size;
470         u8 gl_rq_pi;
471         u8 gl_cmd_pi;
472         u8 debug_mode;
473         u8 is_target;
474         u8 bdq_pbl_num_entries[2];
475 };
476
477 /* Most of the the parameters below are described in the FW iSCSI / TCP HSI */
478 struct qed_iscsi_pf_params {
479         u64 glbl_q_params_addr;
480         u64 bdq_pbl_base_addr[3];
481         u16 cq_num_entries;
482         u16 cmdq_num_entries;
483         u32 two_msl_timer;
484         u16 tx_sws_timer;
485
486         /* The following parameters are used during HW-init
487          * and these parameters need to be passed as arguments
488          * to update_pf_params routine invoked before slowpath start
489          */
490         u16 num_cons;
491         u16 num_tasks;
492
493         /* The following parameters are used during protocol-init */
494         u16 half_way_close_timeout;
495         u16 bdq_xoff_threshold[3];
496         u16 bdq_xon_threshold[3];
497         u16 cmdq_xoff_threshold;
498         u16 cmdq_xon_threshold;
499         u16 rq_buffer_size;
500
501         u8 num_sq_pages_in_ring;
502         u8 num_r2tq_pages_in_ring;
503         u8 num_uhq_pages_in_ring;
504         u8 num_queues;
505         u8 log_page_size;
506         u8 rqe_log_size;
507         u8 max_fin_rt;
508         u8 gl_rq_pi;
509         u8 gl_cmd_pi;
510         u8 debug_mode;
511         u8 ll2_ooo_queue_id;
512
513         u8 is_target;
514         u8 is_soc_en;
515         u8 soc_num_of_blocks_log;
516         u8 bdq_pbl_num_entries[3];
517 };
518
519 struct qed_rdma_pf_params {
520         /* Supplied to QED during resource allocation (may affect the ILT and
521          * the doorbell BAR).
522          */
523         u32 min_dpis;           /* number of requested DPIs */
524         u32 num_qps;            /* number of requested Queue Pairs */
525         u32 num_srqs;           /* number of requested SRQ */
526         u8 roce_edpm_mode;      /* see QED_ROCE_EDPM_MODE_ENABLE */
527         u8 gl_pi;               /* protocol index */
528
529         /* Will allocate rate limiters to be used with QPs */
530         u8 enable_dcqcn;
531 };
532
533 struct qed_pf_params {
534         struct qed_eth_pf_params eth_pf_params;
535         struct qed_fcoe_pf_params fcoe_pf_params;
536         struct qed_iscsi_pf_params iscsi_pf_params;
537         struct qed_rdma_pf_params rdma_pf_params;
538 };
539
540 enum qed_int_mode {
541         QED_INT_MODE_INTA,
542         QED_INT_MODE_MSIX,
543         QED_INT_MODE_MSI,
544         QED_INT_MODE_POLL,
545 };
546
547 struct qed_sb_info {
548         struct status_block_e4 *sb_virt;
549         dma_addr_t sb_phys;
550         u32 sb_ack; /* Last given ack */
551         u16 igu_sb_id;
552         void __iomem *igu_addr;
553         u8 flags;
554 #define QED_SB_INFO_INIT        0x1
555 #define QED_SB_INFO_SETUP       0x2
556
557         struct qed_dev *cdev;
558 };
559
560 enum qed_dev_type {
561         QED_DEV_TYPE_BB,
562         QED_DEV_TYPE_AH,
563 };
564
565 struct qed_dev_info {
566         unsigned long   pci_mem_start;
567         unsigned long   pci_mem_end;
568         unsigned int    pci_irq;
569         u8              num_hwfns;
570
571         u8              hw_mac[ETH_ALEN];
572
573         /* FW version */
574         u16             fw_major;
575         u16             fw_minor;
576         u16             fw_rev;
577         u16             fw_eng;
578
579         /* MFW version */
580         u32             mfw_rev;
581 #define QED_MFW_VERSION_0_MASK          0x000000FF
582 #define QED_MFW_VERSION_0_OFFSET        0
583 #define QED_MFW_VERSION_1_MASK          0x0000FF00
584 #define QED_MFW_VERSION_1_OFFSET        8
585 #define QED_MFW_VERSION_2_MASK          0x00FF0000
586 #define QED_MFW_VERSION_2_OFFSET        16
587 #define QED_MFW_VERSION_3_MASK          0xFF000000
588 #define QED_MFW_VERSION_3_OFFSET        24
589
590         u32             flash_size;
591         bool            b_inter_pf_switch;
592         bool            tx_switching;
593         bool            rdma_supported;
594         u16             mtu;
595
596         bool wol_support;
597
598         /* MBI version */
599         u32 mbi_version;
600 #define QED_MBI_VERSION_0_MASK          0x000000FF
601 #define QED_MBI_VERSION_0_OFFSET        0
602 #define QED_MBI_VERSION_1_MASK          0x0000FF00
603 #define QED_MBI_VERSION_1_OFFSET        8
604 #define QED_MBI_VERSION_2_MASK          0x00FF0000
605 #define QED_MBI_VERSION_2_OFFSET        16
606
607         enum qed_dev_type dev_type;
608
609         /* Output parameters for qede */
610         bool            vxlan_enable;
611         bool            gre_enable;
612         bool            geneve_enable;
613
614         u8              abs_pf_id;
615 };
616
617 enum qed_sb_type {
618         QED_SB_TYPE_L2_QUEUE,
619         QED_SB_TYPE_CNQ,
620         QED_SB_TYPE_STORAGE,
621 };
622
623 enum qed_protocol {
624         QED_PROTOCOL_ETH,
625         QED_PROTOCOL_ISCSI,
626         QED_PROTOCOL_FCOE,
627 };
628
629 enum qed_link_mode_bits {
630         QED_LM_FIBRE_BIT = BIT(0),
631         QED_LM_Autoneg_BIT = BIT(1),
632         QED_LM_Asym_Pause_BIT = BIT(2),
633         QED_LM_Pause_BIT = BIT(3),
634         QED_LM_1000baseT_Half_BIT = BIT(4),
635         QED_LM_1000baseT_Full_BIT = BIT(5),
636         QED_LM_10000baseKR_Full_BIT = BIT(6),
637         QED_LM_25000baseKR_Full_BIT = BIT(7),
638         QED_LM_40000baseLR4_Full_BIT = BIT(8),
639         QED_LM_50000baseKR2_Full_BIT = BIT(9),
640         QED_LM_100000baseKR4_Full_BIT = BIT(10),
641         QED_LM_COUNT = 11
642 };
643
644 struct qed_link_params {
645         bool    link_up;
646
647 #define QED_LINK_OVERRIDE_SPEED_AUTONEG         BIT(0)
648 #define QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS      BIT(1)
649 #define QED_LINK_OVERRIDE_SPEED_FORCED_SPEED    BIT(2)
650 #define QED_LINK_OVERRIDE_PAUSE_CONFIG          BIT(3)
651 #define QED_LINK_OVERRIDE_LOOPBACK_MODE         BIT(4)
652 #define QED_LINK_OVERRIDE_EEE_CONFIG            BIT(5)
653         u32     override_flags;
654         bool    autoneg;
655         u32     adv_speeds;
656         u32     forced_speed;
657 #define QED_LINK_PAUSE_AUTONEG_ENABLE           BIT(0)
658 #define QED_LINK_PAUSE_RX_ENABLE                BIT(1)
659 #define QED_LINK_PAUSE_TX_ENABLE                BIT(2)
660         u32     pause_config;
661 #define QED_LINK_LOOPBACK_NONE                  BIT(0)
662 #define QED_LINK_LOOPBACK_INT_PHY               BIT(1)
663 #define QED_LINK_LOOPBACK_EXT_PHY               BIT(2)
664 #define QED_LINK_LOOPBACK_EXT                   BIT(3)
665 #define QED_LINK_LOOPBACK_MAC                   BIT(4)
666         u32     loopback_mode;
667         struct qed_link_eee_params eee;
668 };
669
670 struct qed_link_output {
671         bool    link_up;
672
673         /* In QED_LM_* defs */
674         u32     supported_caps;
675         u32     advertised_caps;
676         u32     lp_caps;
677
678         u32     speed;                  /* In Mb/s */
679         u8      duplex;                 /* In DUPLEX defs */
680         u8      port;                   /* In PORT defs */
681         bool    autoneg;
682         u32     pause_config;
683
684         /* EEE - capability & param */
685         bool eee_supported;
686         bool eee_active;
687         u8 sup_caps;
688         struct qed_link_eee_params eee;
689 };
690
691 struct qed_probe_params {
692         enum qed_protocol protocol;
693         u32 dp_module;
694         u8 dp_level;
695         bool is_vf;
696 };
697
698 #define QED_DRV_VER_STR_SIZE 12
699 struct qed_slowpath_params {
700         u32     int_mode;
701         u8      drv_major;
702         u8      drv_minor;
703         u8      drv_rev;
704         u8      drv_eng;
705         u8      name[QED_DRV_VER_STR_SIZE];
706 };
707
708 #define ILT_PAGE_SIZE_TCFC 0x8000 /* 32KB */
709
710 struct qed_int_info {
711         struct msix_entry       *msix;
712         u8                      msix_cnt;
713
714         /* This should be updated by the protocol driver */
715         u8                      used_cnt;
716 };
717
718 #define QED_NVM_SIGNATURE 0x12435687
719
720 enum qed_nvm_flash_cmd {
721         QED_NVM_FLASH_CMD_FILE_DATA = 0x2,
722         QED_NVM_FLASH_CMD_FILE_START = 0x3,
723         QED_NVM_FLASH_CMD_NVM_CHANGE = 0x4,
724         QED_NVM_FLASH_CMD_NVM_MAX,
725 };
726
727 struct qed_common_cb_ops {
728         void (*arfs_filter_op)(void *dev, void *fltr, u8 fw_rc);
729         void    (*link_update)(void                     *dev,
730                                struct qed_link_output   *link);
731         void    (*dcbx_aen)(void *dev, struct qed_dcbx_get *get, u32 mib_type);
732 };
733
734 struct qed_selftest_ops {
735 /**
736  * @brief selftest_interrupt - Perform interrupt test
737  *
738  * @param cdev
739  *
740  * @return 0 on success, error otherwise.
741  */
742         int (*selftest_interrupt)(struct qed_dev *cdev);
743
744 /**
745  * @brief selftest_memory - Perform memory test
746  *
747  * @param cdev
748  *
749  * @return 0 on success, error otherwise.
750  */
751         int (*selftest_memory)(struct qed_dev *cdev);
752
753 /**
754  * @brief selftest_register - Perform register test
755  *
756  * @param cdev
757  *
758  * @return 0 on success, error otherwise.
759  */
760         int (*selftest_register)(struct qed_dev *cdev);
761
762 /**
763  * @brief selftest_clock - Perform clock test
764  *
765  * @param cdev
766  *
767  * @return 0 on success, error otherwise.
768  */
769         int (*selftest_clock)(struct qed_dev *cdev);
770
771 /**
772  * @brief selftest_nvram - Perform nvram test
773  *
774  * @param cdev
775  *
776  * @return 0 on success, error otherwise.
777  */
778         int (*selftest_nvram) (struct qed_dev *cdev);
779 };
780
781 struct qed_common_ops {
782         struct qed_selftest_ops *selftest;
783
784         struct qed_dev* (*probe)(struct pci_dev *dev,
785                                  struct qed_probe_params *params);
786
787         void            (*remove)(struct qed_dev *cdev);
788
789         int             (*set_power_state)(struct qed_dev *cdev,
790                                            pci_power_t state);
791
792         void (*set_name) (struct qed_dev *cdev, char name[]);
793
794         /* Client drivers need to make this call before slowpath_start.
795          * PF params required for the call before slowpath_start is
796          * documented within the qed_pf_params structure definition.
797          */
798         void            (*update_pf_params)(struct qed_dev *cdev,
799                                             struct qed_pf_params *params);
800         int             (*slowpath_start)(struct qed_dev *cdev,
801                                           struct qed_slowpath_params *params);
802
803         int             (*slowpath_stop)(struct qed_dev *cdev);
804
805         /* Requests to use `cnt' interrupts for fastpath.
806          * upon success, returns number of interrupts allocated for fastpath.
807          */
808         int             (*set_fp_int)(struct qed_dev *cdev,
809                                       u16 cnt);
810
811         /* Fills `info' with pointers required for utilizing interrupts */
812         int             (*get_fp_int)(struct qed_dev *cdev,
813                                       struct qed_int_info *info);
814
815         u32             (*sb_init)(struct qed_dev *cdev,
816                                    struct qed_sb_info *sb_info,
817                                    void *sb_virt_addr,
818                                    dma_addr_t sb_phy_addr,
819                                    u16 sb_id,
820                                    enum qed_sb_type type);
821
822         u32             (*sb_release)(struct qed_dev *cdev,
823                                       struct qed_sb_info *sb_info,
824                                       u16 sb_id);
825
826         void            (*simd_handler_config)(struct qed_dev *cdev,
827                                                void *token,
828                                                int index,
829                                                void (*handler)(void *));
830
831         void            (*simd_handler_clean)(struct qed_dev *cdev,
832                                               int index);
833         int (*dbg_grc)(struct qed_dev *cdev,
834                        void *buffer, u32 *num_dumped_bytes);
835
836         int (*dbg_grc_size)(struct qed_dev *cdev);
837
838         int (*dbg_all_data) (struct qed_dev *cdev, void *buffer);
839
840         int (*dbg_all_data_size) (struct qed_dev *cdev);
841
842 /**
843  * @brief can_link_change - can the instance change the link or not
844  *
845  * @param cdev
846  *
847  * @return true if link-change is allowed, false otherwise.
848  */
849         bool (*can_link_change)(struct qed_dev *cdev);
850
851 /**
852  * @brief set_link - set links according to params
853  *
854  * @param cdev
855  * @param params - values used to override the default link configuration
856  *
857  * @return 0 on success, error otherwise.
858  */
859         int             (*set_link)(struct qed_dev *cdev,
860                                     struct qed_link_params *params);
861
862 /**
863  * @brief get_link - returns the current link state.
864  *
865  * @param cdev
866  * @param if_link - structure to be filled with current link configuration.
867  */
868         void            (*get_link)(struct qed_dev *cdev,
869                                     struct qed_link_output *if_link);
870
871 /**
872  * @brief - drains chip in case Tx completions fail to arrive due to pause.
873  *
874  * @param cdev
875  */
876         int             (*drain)(struct qed_dev *cdev);
877
878 /**
879  * @brief update_msglvl - update module debug level
880  *
881  * @param cdev
882  * @param dp_module
883  * @param dp_level
884  */
885         void            (*update_msglvl)(struct qed_dev *cdev,
886                                          u32 dp_module,
887                                          u8 dp_level);
888
889         int             (*chain_alloc)(struct qed_dev *cdev,
890                                        enum qed_chain_use_mode intended_use,
891                                        enum qed_chain_mode mode,
892                                        enum qed_chain_cnt_type cnt_type,
893                                        u32 num_elems,
894                                        size_t elem_size,
895                                        struct qed_chain *p_chain,
896                                        struct qed_chain_ext_pbl *ext_pbl);
897
898         void            (*chain_free)(struct qed_dev *cdev,
899                                       struct qed_chain *p_chain);
900
901 /**
902  * @brief nvm_flash - Flash nvm data.
903  *
904  * @param cdev
905  * @param name - file containing the data
906  *
907  * @return 0 on success, error otherwise.
908  */
909         int (*nvm_flash)(struct qed_dev *cdev, const char *name);
910
911 /**
912  * @brief nvm_get_image - reads an entire image from nvram
913  *
914  * @param cdev
915  * @param type - type of the request nvram image
916  * @param buf - preallocated buffer to fill with the image
917  * @param len - length of the allocated buffer
918  *
919  * @return 0 on success, error otherwise
920  */
921         int (*nvm_get_image)(struct qed_dev *cdev,
922                              enum qed_nvm_images type, u8 *buf, u16 len);
923
924 /**
925  * @brief set_coalesce - Configure Rx coalesce value in usec
926  *
927  * @param cdev
928  * @param rx_coal - Rx coalesce value in usec
929  * @param tx_coal - Tx coalesce value in usec
930  * @param qid - Queue index
931  * @param sb_id - Status Block Id
932  *
933  * @return 0 on success, error otherwise.
934  */
935         int (*set_coalesce)(struct qed_dev *cdev,
936                             u16 rx_coal, u16 tx_coal, void *handle);
937
938 /**
939  * @brief set_led - Configure LED mode
940  *
941  * @param cdev
942  * @param mode - LED mode
943  *
944  * @return 0 on success, error otherwise.
945  */
946         int (*set_led)(struct qed_dev *cdev,
947                        enum qed_led_mode mode);
948
949 /**
950  * @brief update_drv_state - API to inform the change in the driver state.
951  *
952  * @param cdev
953  * @param active
954  *
955  */
956         int (*update_drv_state)(struct qed_dev *cdev, bool active);
957
958 /**
959  * @brief update_mac - API to inform the change in the mac address
960  *
961  * @param cdev
962  * @param mac
963  *
964  */
965         int (*update_mac)(struct qed_dev *cdev, u8 *mac);
966
967 /**
968  * @brief update_mtu - API to inform the change in the mtu
969  *
970  * @param cdev
971  * @param mtu
972  *
973  */
974         int (*update_mtu)(struct qed_dev *cdev, u16 mtu);
975
976 /**
977  * @brief update_wol - update of changes in the WoL configuration
978  *
979  * @param cdev
980  * @param enabled - true iff WoL should be enabled.
981  */
982         int (*update_wol) (struct qed_dev *cdev, bool enabled);
983 };
984
985 #define MASK_FIELD(_name, _value) \
986         ((_value) &= (_name ## _MASK))
987
988 #define FIELD_VALUE(_name, _value) \
989         ((_value & _name ## _MASK) << _name ## _SHIFT)
990
991 #define SET_FIELD(value, name, flag)                           \
992         do {                                                   \
993                 (value) &= ~(name ## _MASK << name ## _SHIFT); \
994                 (value) |= (((u64)flag) << (name ## _SHIFT));  \
995         } while (0)
996
997 #define GET_FIELD(value, name) \
998         (((value) >> (name ## _SHIFT)) & name ## _MASK)
999
1000 /* Debug print definitions */
1001 #define DP_ERR(cdev, fmt, ...)                                  \
1002         do {                                                    \
1003                 pr_err("[%s:%d(%s)]" fmt,                       \
1004                        __func__, __LINE__,                      \
1005                        DP_NAME(cdev) ? DP_NAME(cdev) : "",      \
1006                        ## __VA_ARGS__);                         \
1007         } while (0)
1008
1009 #define DP_NOTICE(cdev, fmt, ...)                                     \
1010         do {                                                          \
1011                 if (unlikely((cdev)->dp_level <= QED_LEVEL_NOTICE)) { \
1012                         pr_notice("[%s:%d(%s)]" fmt,                  \
1013                                   __func__, __LINE__,                 \
1014                                   DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1015                                   ## __VA_ARGS__);                    \
1016                                                                       \
1017                 }                                                     \
1018         } while (0)
1019
1020 #define DP_INFO(cdev, fmt, ...)                                       \
1021         do {                                                          \
1022                 if (unlikely((cdev)->dp_level <= QED_LEVEL_INFO)) {   \
1023                         pr_notice("[%s:%d(%s)]" fmt,                  \
1024                                   __func__, __LINE__,                 \
1025                                   DP_NAME(cdev) ? DP_NAME(cdev) : "", \
1026                                   ## __VA_ARGS__);                    \
1027                 }                                                     \
1028         } while (0)
1029
1030 #define DP_VERBOSE(cdev, module, fmt, ...)                              \
1031         do {                                                            \
1032                 if (unlikely(((cdev)->dp_level <= QED_LEVEL_VERBOSE) && \
1033                              ((cdev)->dp_module & module))) {           \
1034                         pr_notice("[%s:%d(%s)]" fmt,                    \
1035                                   __func__, __LINE__,                   \
1036                                   DP_NAME(cdev) ? DP_NAME(cdev) : "",   \
1037                                   ## __VA_ARGS__);                      \
1038                 }                                                       \
1039         } while (0)
1040
1041 enum DP_LEVEL {
1042         QED_LEVEL_VERBOSE       = 0x0,
1043         QED_LEVEL_INFO          = 0x1,
1044         QED_LEVEL_NOTICE        = 0x2,
1045         QED_LEVEL_ERR           = 0x3,
1046 };
1047
1048 #define QED_LOG_LEVEL_SHIFT     (30)
1049 #define QED_LOG_VERBOSE_MASK    (0x3fffffff)
1050 #define QED_LOG_INFO_MASK       (0x40000000)
1051 #define QED_LOG_NOTICE_MASK     (0x80000000)
1052
1053 enum DP_MODULE {
1054         QED_MSG_SPQ     = 0x10000,
1055         QED_MSG_STATS   = 0x20000,
1056         QED_MSG_DCB     = 0x40000,
1057         QED_MSG_IOV     = 0x80000,
1058         QED_MSG_SP      = 0x100000,
1059         QED_MSG_STORAGE = 0x200000,
1060         QED_MSG_CXT     = 0x800000,
1061         QED_MSG_LL2     = 0x1000000,
1062         QED_MSG_ILT     = 0x2000000,
1063         QED_MSG_RDMA    = 0x4000000,
1064         QED_MSG_DEBUG   = 0x8000000,
1065         /* to be added...up to 0x8000000 */
1066 };
1067
1068 enum qed_mf_mode {
1069         QED_MF_DEFAULT,
1070         QED_MF_OVLAN,
1071         QED_MF_NPAR,
1072 };
1073
1074 struct qed_eth_stats_common {
1075         u64     no_buff_discards;
1076         u64     packet_too_big_discard;
1077         u64     ttl0_discard;
1078         u64     rx_ucast_bytes;
1079         u64     rx_mcast_bytes;
1080         u64     rx_bcast_bytes;
1081         u64     rx_ucast_pkts;
1082         u64     rx_mcast_pkts;
1083         u64     rx_bcast_pkts;
1084         u64     mftag_filter_discards;
1085         u64     mac_filter_discards;
1086         u64     tx_ucast_bytes;
1087         u64     tx_mcast_bytes;
1088         u64     tx_bcast_bytes;
1089         u64     tx_ucast_pkts;
1090         u64     tx_mcast_pkts;
1091         u64     tx_bcast_pkts;
1092         u64     tx_err_drop_pkts;
1093         u64     tpa_coalesced_pkts;
1094         u64     tpa_coalesced_events;
1095         u64     tpa_aborts_num;
1096         u64     tpa_not_coalesced_pkts;
1097         u64     tpa_coalesced_bytes;
1098
1099         /* port */
1100         u64     rx_64_byte_packets;
1101         u64     rx_65_to_127_byte_packets;
1102         u64     rx_128_to_255_byte_packets;
1103         u64     rx_256_to_511_byte_packets;
1104         u64     rx_512_to_1023_byte_packets;
1105         u64     rx_1024_to_1518_byte_packets;
1106         u64     rx_crc_errors;
1107         u64     rx_mac_crtl_frames;
1108         u64     rx_pause_frames;
1109         u64     rx_pfc_frames;
1110         u64     rx_align_errors;
1111         u64     rx_carrier_errors;
1112         u64     rx_oversize_packets;
1113         u64     rx_jabbers;
1114         u64     rx_undersize_packets;
1115         u64     rx_fragments;
1116         u64     tx_64_byte_packets;
1117         u64     tx_65_to_127_byte_packets;
1118         u64     tx_128_to_255_byte_packets;
1119         u64     tx_256_to_511_byte_packets;
1120         u64     tx_512_to_1023_byte_packets;
1121         u64     tx_1024_to_1518_byte_packets;
1122         u64     tx_pause_frames;
1123         u64     tx_pfc_frames;
1124         u64     brb_truncates;
1125         u64     brb_discards;
1126         u64     rx_mac_bytes;
1127         u64     rx_mac_uc_packets;
1128         u64     rx_mac_mc_packets;
1129         u64     rx_mac_bc_packets;
1130         u64     rx_mac_frames_ok;
1131         u64     tx_mac_bytes;
1132         u64     tx_mac_uc_packets;
1133         u64     tx_mac_mc_packets;
1134         u64     tx_mac_bc_packets;
1135         u64     tx_mac_ctrl_frames;
1136 };
1137
1138 struct qed_eth_stats_bb {
1139         u64 rx_1519_to_1522_byte_packets;
1140         u64 rx_1519_to_2047_byte_packets;
1141         u64 rx_2048_to_4095_byte_packets;
1142         u64 rx_4096_to_9216_byte_packets;
1143         u64 rx_9217_to_16383_byte_packets;
1144         u64 tx_1519_to_2047_byte_packets;
1145         u64 tx_2048_to_4095_byte_packets;
1146         u64 tx_4096_to_9216_byte_packets;
1147         u64 tx_9217_to_16383_byte_packets;
1148         u64 tx_lpi_entry_count;
1149         u64 tx_total_collisions;
1150 };
1151
1152 struct qed_eth_stats_ah {
1153         u64 rx_1519_to_max_byte_packets;
1154         u64 tx_1519_to_max_byte_packets;
1155 };
1156
1157 struct qed_eth_stats {
1158         struct qed_eth_stats_common common;
1159
1160         union {
1161                 struct qed_eth_stats_bb bb;
1162                 struct qed_eth_stats_ah ah;
1163         };
1164 };
1165
1166 #define QED_SB_IDX              0x0002
1167
1168 #define RX_PI           0
1169 #define TX_PI(tc)       (RX_PI + 1 + tc)
1170
1171 struct qed_sb_cnt_info {
1172         /* Original, current, and free SBs for PF */
1173         int orig;
1174         int cnt;
1175         int free_cnt;
1176
1177         /* Original, current and free SBS for child VFs */
1178         int iov_orig;
1179         int iov_cnt;
1180         int free_cnt_iov;
1181 };
1182
1183 static inline u16 qed_sb_update_sb_idx(struct qed_sb_info *sb_info)
1184 {
1185         u32 prod = 0;
1186         u16 rc = 0;
1187
1188         prod = le32_to_cpu(sb_info->sb_virt->prod_index) &
1189                STATUS_BLOCK_E4_PROD_INDEX_MASK;
1190         if (sb_info->sb_ack != prod) {
1191                 sb_info->sb_ack = prod;
1192                 rc |= QED_SB_IDX;
1193         }
1194
1195         /* Let SB update */
1196         mmiowb();
1197         return rc;
1198 }
1199
1200 /**
1201  *
1202  * @brief This function creates an update command for interrupts that is
1203  *        written to the IGU.
1204  *
1205  * @param sb_info       - This is the structure allocated and
1206  *                 initialized per status block. Assumption is
1207  *                 that it was initialized using qed_sb_init
1208  * @param int_cmd       - Enable/Disable/Nop
1209  * @param upd_flg       - whether igu consumer should be
1210  *                 updated.
1211  *
1212  * @return inline void
1213  */
1214 static inline void qed_sb_ack(struct qed_sb_info *sb_info,
1215                               enum igu_int_cmd int_cmd,
1216                               u8 upd_flg)
1217 {
1218         struct igu_prod_cons_update igu_ack = { 0 };
1219
1220         igu_ack.sb_id_and_flags =
1221                 ((sb_info->sb_ack << IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT) |
1222                  (upd_flg << IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT) |
1223                  (int_cmd << IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT) |
1224                  (IGU_SEG_ACCESS_REG <<
1225                   IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT));
1226
1227         DIRECT_REG_WR(sb_info->igu_addr, igu_ack.sb_id_and_flags);
1228
1229         /* Both segments (interrupts & acks) are written to same place address;
1230          * Need to guarantee all commands will be received (in-order) by HW.
1231          */
1232         mmiowb();
1233         barrier();
1234 }
1235
1236 static inline void __internal_ram_wr(void *p_hwfn,
1237                                      void __iomem *addr,
1238                                      int size,
1239                                      u32 *data)
1240
1241 {
1242         unsigned int i;
1243
1244         for (i = 0; i < size / sizeof(*data); i++)
1245                 DIRECT_REG_WR(&((u32 __iomem *)addr)[i], data[i]);
1246 }
1247
1248 static inline void internal_ram_wr(void __iomem *addr,
1249                                    int size,
1250                                    u32 *data)
1251 {
1252         __internal_ram_wr(NULL, addr, size, data);
1253 }
1254
1255 enum qed_rss_caps {
1256         QED_RSS_IPV4            = 0x1,
1257         QED_RSS_IPV6            = 0x2,
1258         QED_RSS_IPV4_TCP        = 0x4,
1259         QED_RSS_IPV6_TCP        = 0x8,
1260         QED_RSS_IPV4_UDP        = 0x10,
1261         QED_RSS_IPV6_UDP        = 0x20,
1262 };
1263
1264 #define QED_RSS_IND_TABLE_SIZE 128
1265 #define QED_RSS_KEY_SIZE 10 /* size in 32b chunks */
1266 #endif