1 /* QLogic qed NIC Driver
3 * Copyright (c) 2015 QLogic Corporation
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
13 #include <linux/types.h>
14 #include <linux/interrupt.h>
15 #include <linux/netdevice.h>
16 #include <linux/pci.h>
17 #include <linux/skbuff.h>
18 #include <linux/types.h>
19 #include <asm/byteorder.h>
21 #include <linux/compiler.h>
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/slab.h>
25 #include <linux/qed/common_hsi.h>
26 #include <linux/qed/qed_chain.h>
34 #define DIRECT_REG_WR(reg_addr, val) writel((u32)val, \
35 (void __iomem *)(reg_addr))
37 #define DIRECT_REG_RD(reg_addr) readl((void __iomem *)(reg_addr))
39 #define QED_COALESCE_MAX 0xFF
44 struct qed_eth_pf_params
{
45 /* The following parameters are used during HW-init
46 * and these parameters need to be passed as arguments
47 * to update_pf_params routine invoked before slowpath start
52 struct qed_pf_params
{
53 struct qed_eth_pf_params eth_pf_params
;
64 struct status_block
*sb_virt
;
66 u32 sb_ack
; /* Last given ack */
68 void __iomem
*igu_addr
;
70 #define QED_SB_INFO_INIT 0x1
71 #define QED_SB_INFO_SETUP 0x2
77 unsigned long pci_mem_start
;
78 unsigned long pci_mem_end
;
106 struct qed_link_params
{
109 #define QED_LINK_OVERRIDE_SPEED_AUTONEG BIT(0)
110 #define QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS BIT(1)
111 #define QED_LINK_OVERRIDE_SPEED_FORCED_SPEED BIT(2)
112 #define QED_LINK_OVERRIDE_PAUSE_CONFIG BIT(3)
117 #define QED_LINK_PAUSE_AUTONEG_ENABLE BIT(0)
118 #define QED_LINK_PAUSE_RX_ENABLE BIT(1)
119 #define QED_LINK_PAUSE_TX_ENABLE BIT(2)
123 struct qed_link_output
{
126 u32 supported_caps
; /* In SUPPORTED defs */
127 u32 advertised_caps
; /* In ADVERTISED defs */
128 u32 lp_caps
; /* In ADVERTISED defs */
129 u32 speed
; /* In Mb/s */
130 u8 duplex
; /* In DUPLEX defs */
131 u8 port
; /* In PORT defs */
136 #define QED_DRV_VER_STR_SIZE 12
137 struct qed_slowpath_params
{
143 u8 name
[QED_DRV_VER_STR_SIZE
];
146 #define ILT_PAGE_SIZE_TCFC 0x8000 /* 32KB */
148 struct qed_int_info
{
149 struct msix_entry
*msix
;
152 /* This should be updated by the protocol driver */
156 struct qed_common_cb_ops
{
157 void (*link_update
)(void *dev
,
158 struct qed_link_output
*link
);
161 struct qed_common_ops
{
162 struct qed_dev
* (*probe
)(struct pci_dev
*dev
,
163 enum qed_protocol protocol
,
164 u32 dp_module
, u8 dp_level
);
166 void (*remove
)(struct qed_dev
*cdev
);
168 int (*set_power_state
)(struct qed_dev
*cdev
,
171 void (*set_id
)(struct qed_dev
*cdev
,
175 /* Client drivers need to make this call before slowpath_start.
176 * PF params required for the call before slowpath_start is
177 * documented within the qed_pf_params structure definition.
179 void (*update_pf_params
)(struct qed_dev
*cdev
,
180 struct qed_pf_params
*params
);
181 int (*slowpath_start
)(struct qed_dev
*cdev
,
182 struct qed_slowpath_params
*params
);
184 int (*slowpath_stop
)(struct qed_dev
*cdev
);
186 /* Requests to use `cnt' interrupts for fastpath.
187 * upon success, returns number of interrupts allocated for fastpath.
189 int (*set_fp_int
)(struct qed_dev
*cdev
,
192 /* Fills `info' with pointers required for utilizing interrupts */
193 int (*get_fp_int
)(struct qed_dev
*cdev
,
194 struct qed_int_info
*info
);
196 u32 (*sb_init
)(struct qed_dev
*cdev
,
197 struct qed_sb_info
*sb_info
,
199 dma_addr_t sb_phy_addr
,
201 enum qed_sb_type type
);
203 u32 (*sb_release
)(struct qed_dev
*cdev
,
204 struct qed_sb_info
*sb_info
,
207 void (*simd_handler_config
)(struct qed_dev
*cdev
,
210 void (*handler
)(void *));
212 void (*simd_handler_clean
)(struct qed_dev
*cdev
,
215 * @brief set_link - set links according to params
218 * @param params - values used to override the default link configuration
220 * @return 0 on success, error otherwise.
222 int (*set_link
)(struct qed_dev
*cdev
,
223 struct qed_link_params
*params
);
226 * @brief get_link - returns the current link state.
229 * @param if_link - structure to be filled with current link configuration.
231 void (*get_link
)(struct qed_dev
*cdev
,
232 struct qed_link_output
*if_link
);
235 * @brief - drains chip in case Tx completions fail to arrive due to pause.
239 int (*drain
)(struct qed_dev
*cdev
);
242 * @brief update_msglvl - update module debug level
248 void (*update_msglvl
)(struct qed_dev
*cdev
,
252 int (*chain_alloc
)(struct qed_dev
*cdev
,
253 enum qed_chain_use_mode intended_use
,
254 enum qed_chain_mode mode
,
257 struct qed_chain
*p_chain
);
259 void (*chain_free
)(struct qed_dev
*cdev
,
260 struct qed_chain
*p_chain
);
263 * @brief set_led - Configure LED mode
266 * @param mode - LED mode
268 * @return 0 on success, error otherwise.
270 int (*set_led
)(struct qed_dev
*cdev
,
271 enum qed_led_mode mode
);
275 * @brief qed_get_protocol_version
279 * @return version supported by qed for given protocol driver
281 u32
qed_get_protocol_version(enum qed_protocol protocol
);
283 #define MASK_FIELD(_name, _value) \
284 ((_value) &= (_name ## _MASK))
286 #define FIELD_VALUE(_name, _value) \
287 ((_value & _name ## _MASK) << _name ## _SHIFT)
289 #define SET_FIELD(value, name, flag) \
291 (value) &= ~(name ## _MASK << name ## _SHIFT); \
292 (value) |= (((u64)flag) << (name ## _SHIFT)); \
295 #define GET_FIELD(value, name) \
296 (((value) >> (name ## _SHIFT)) & name ## _MASK)
298 /* Debug print definitions */
299 #define DP_ERR(cdev, fmt, ...) \
300 pr_err("[%s:%d(%s)]" fmt, \
301 __func__, __LINE__, \
302 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
305 #define DP_NOTICE(cdev, fmt, ...) \
307 if (unlikely((cdev)->dp_level <= QED_LEVEL_NOTICE)) { \
308 pr_notice("[%s:%d(%s)]" fmt, \
309 __func__, __LINE__, \
310 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
316 #define DP_INFO(cdev, fmt, ...) \
318 if (unlikely((cdev)->dp_level <= QED_LEVEL_INFO)) { \
319 pr_notice("[%s:%d(%s)]" fmt, \
320 __func__, __LINE__, \
321 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
326 #define DP_VERBOSE(cdev, module, fmt, ...) \
328 if (unlikely(((cdev)->dp_level <= QED_LEVEL_VERBOSE) && \
329 ((cdev)->dp_module & module))) { \
330 pr_notice("[%s:%d(%s)]" fmt, \
331 __func__, __LINE__, \
332 DP_NAME(cdev) ? DP_NAME(cdev) : "", \
338 QED_LEVEL_VERBOSE
= 0x0,
339 QED_LEVEL_INFO
= 0x1,
340 QED_LEVEL_NOTICE
= 0x2,
344 #define QED_LOG_LEVEL_SHIFT (30)
345 #define QED_LOG_VERBOSE_MASK (0x3fffffff)
346 #define QED_LOG_INFO_MASK (0x40000000)
347 #define QED_LOG_NOTICE_MASK (0x80000000)
350 QED_MSG_SPQ
= 0x10000,
351 QED_MSG_STATS
= 0x20000,
352 QED_MSG_DCB
= 0x40000,
353 QED_MSG_IOV
= 0x80000,
354 QED_MSG_SP
= 0x100000,
355 QED_MSG_STORAGE
= 0x200000,
356 QED_MSG_CXT
= 0x800000,
357 QED_MSG_ILT
= 0x2000000,
358 QED_MSG_ROCE
= 0x4000000,
359 QED_MSG_DEBUG
= 0x8000000,
360 /* to be added...up to 0x8000000 */
369 struct qed_eth_stats
{
370 u64 no_buff_discards
;
371 u64 packet_too_big_discard
;
379 u64 mftag_filter_discards
;
380 u64 mac_filter_discards
;
387 u64 tx_err_drop_pkts
;
388 u64 tpa_coalesced_pkts
;
389 u64 tpa_coalesced_events
;
391 u64 tpa_not_coalesced_pkts
;
392 u64 tpa_coalesced_bytes
;
395 u64 rx_64_byte_packets
;
396 u64 rx_127_byte_packets
;
397 u64 rx_255_byte_packets
;
398 u64 rx_511_byte_packets
;
399 u64 rx_1023_byte_packets
;
400 u64 rx_1518_byte_packets
;
401 u64 rx_1522_byte_packets
;
402 u64 rx_2047_byte_packets
;
403 u64 rx_4095_byte_packets
;
404 u64 rx_9216_byte_packets
;
405 u64 rx_16383_byte_packets
;
407 u64 rx_mac_crtl_frames
;
411 u64 rx_carrier_errors
;
412 u64 rx_oversize_packets
;
414 u64 rx_undersize_packets
;
416 u64 tx_64_byte_packets
;
417 u64 tx_65_to_127_byte_packets
;
418 u64 tx_128_to_255_byte_packets
;
419 u64 tx_256_to_511_byte_packets
;
420 u64 tx_512_to_1023_byte_packets
;
421 u64 tx_1024_to_1518_byte_packets
;
422 u64 tx_1519_to_2047_byte_packets
;
423 u64 tx_2048_to_4095_byte_packets
;
424 u64 tx_4096_to_9216_byte_packets
;
425 u64 tx_9217_to_16383_byte_packets
;
428 u64 tx_lpi_entry_count
;
429 u64 tx_total_collisions
;
433 u64 rx_mac_uc_packets
;
434 u64 rx_mac_mc_packets
;
435 u64 rx_mac_bc_packets
;
436 u64 rx_mac_frames_ok
;
438 u64 tx_mac_uc_packets
;
439 u64 tx_mac_mc_packets
;
440 u64 tx_mac_bc_packets
;
441 u64 tx_mac_ctrl_frames
;
444 #define QED_SB_IDX 0x0002
447 #define TX_PI(tc) (RX_PI + 1 + tc)
449 struct qed_sb_cnt_info
{
455 static inline u16
qed_sb_update_sb_idx(struct qed_sb_info
*sb_info
)
460 prod
= le32_to_cpu(sb_info
->sb_virt
->prod_index
) &
461 STATUS_BLOCK_PROD_INDEX_MASK
;
462 if (sb_info
->sb_ack
!= prod
) {
463 sb_info
->sb_ack
= prod
;
474 * @brief This function creates an update command for interrupts that is
475 * written to the IGU.
477 * @param sb_info - This is the structure allocated and
478 * initialized per status block. Assumption is
479 * that it was initialized using qed_sb_init
480 * @param int_cmd - Enable/Disable/Nop
481 * @param upd_flg - whether igu consumer should be
484 * @return inline void
486 static inline void qed_sb_ack(struct qed_sb_info
*sb_info
,
487 enum igu_int_cmd int_cmd
,
490 struct igu_prod_cons_update igu_ack
= { 0 };
492 igu_ack
.sb_id_and_flags
=
493 ((sb_info
->sb_ack
<< IGU_PROD_CONS_UPDATE_SB_INDEX_SHIFT
) |
494 (upd_flg
<< IGU_PROD_CONS_UPDATE_UPDATE_FLAG_SHIFT
) |
495 (int_cmd
<< IGU_PROD_CONS_UPDATE_ENABLE_INT_SHIFT
) |
496 (IGU_SEG_ACCESS_REG
<<
497 IGU_PROD_CONS_UPDATE_SEGMENT_ACCESS_SHIFT
));
499 DIRECT_REG_WR(sb_info
->igu_addr
, igu_ack
.sb_id_and_flags
);
501 /* Both segments (interrupts & acks) are written to same place address;
502 * Need to guarantee all commands will be received (in-order) by HW.
508 static inline void __internal_ram_wr(void *p_hwfn
,
516 for (i
= 0; i
< size
/ sizeof(*data
); i
++)
517 DIRECT_REG_WR(&((u32 __iomem
*)addr
)[i
], data
[i
]);
520 static inline void internal_ram_wr(void __iomem
*addr
,
524 __internal_ram_wr(NULL
, addr
, size
, data
);