1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
11 #include <asm/param.h>
12 #include <linux/delay.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/etherdevice.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
20 #include <linux/stddef.h>
21 #include <linux/string.h>
22 #include <linux/version.h>
23 #include <linux/workqueue.h>
24 #include <linux/bitops.h>
25 #include <linux/bug.h>
27 #include <linux/qed/qed_chain.h>
29 #include "qed_dev_api.h"
30 #include <linux/qed/qed_eth_if.h>
34 #include "qed_reg_addr.h"
40 QED_RSS_IPV4_TCP
= 0x4,
41 QED_RSS_IPV6_TCP
= 0x8,
42 QED_RSS_IPV4_UDP
= 0x10,
43 QED_RSS_IPV6_UDP
= 0x20,
46 /* Should be the same as ETH_RSS_IND_TABLE_ENTRIES_NUM */
47 #define QED_RSS_IND_TABLE_SIZE 128
48 #define QED_RSS_KEY_SIZE 10 /* size in 32b chunks */
50 struct qed_rss_params
{
54 u8 update_rss_capabilities
;
55 u8 update_rss_ind_table
;
58 u8 rss_table_size_log
;
59 u16 rss_ind_table
[QED_RSS_IND_TABLE_SIZE
];
60 u32 rss_key
[QED_RSS_KEY_SIZE
];
63 enum qed_filter_opcode
{
67 QED_FILTER_REPLACE
, /* Delete all MACs and add new one instead */
68 QED_FILTER_FLUSH
, /* Removes all filters */
71 enum qed_filter_ucast_type
{
76 QED_FILTER_INNER_VLAN
,
77 QED_FILTER_INNER_PAIR
,
78 QED_FILTER_INNER_MAC_VNI_PAIR
,
79 QED_FILTER_MAC_VNI_PAIR
,
83 struct qed_filter_ucast
{
84 enum qed_filter_opcode opcode
;
85 enum qed_filter_ucast_type type
;
89 u8 vport_to_remove_from
;
90 unsigned char mac
[ETH_ALEN
];
96 struct qed_filter_mcast
{
97 /* MOVE is not supported for multicast */
98 enum qed_filter_opcode opcode
;
100 u8 vport_to_remove_from
;
102 #define QED_MAX_MC_ADDRS 64
103 unsigned char mac
[QED_MAX_MC_ADDRS
][ETH_ALEN
];
106 struct qed_filter_accept_flags
{
107 u8 update_rx_mode_config
;
108 u8 update_tx_mode_config
;
111 #define QED_ACCEPT_NONE 0x01
112 #define QED_ACCEPT_UCAST_MATCHED 0x02
113 #define QED_ACCEPT_UCAST_UNMATCHED 0x04
114 #define QED_ACCEPT_MCAST_MATCHED 0x08
115 #define QED_ACCEPT_MCAST_UNMATCHED 0x10
116 #define QED_ACCEPT_BCAST 0x20
119 struct qed_sp_vport_update_params
{
122 u8 update_vport_active_rx_flg
;
123 u8 vport_active_rx_flg
;
124 u8 update_vport_active_tx_flg
;
125 u8 vport_active_tx_flg
;
126 u8 update_approx_mcast_flg
;
127 u8 update_accept_any_vlan_flg
;
129 unsigned long bins
[8];
130 struct qed_rss_params
*rss_params
;
131 struct qed_filter_accept_flags accept_flags
;
134 #define QED_MAX_SGES_NUM 16
135 #define CRC32_POLY 0x1edc6f41
137 static int qed_sp_vport_start(struct qed_hwfn
*p_hwfn
,
143 u8 inner_vlan_removal_en_flg
)
145 struct vport_start_ramrod_data
*p_ramrod
= NULL
;
146 struct qed_spq_entry
*p_ent
= NULL
;
147 struct qed_sp_init_data init_data
;
152 rc
= qed_fw_vport(p_hwfn
, vport_id
, &abs_vport_id
);
156 memset(&init_data
, 0, sizeof(init_data
));
157 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
158 init_data
.opaque_fid
= opaque_fid
;
159 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
161 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
162 ETH_RAMROD_VPORT_START
,
163 PROTOCOLID_ETH
, &init_data
);
167 p_ramrod
= &p_ent
->ramrod
.vport_start
;
168 p_ramrod
->vport_id
= abs_vport_id
;
170 p_ramrod
->mtu
= cpu_to_le16(mtu
);
171 p_ramrod
->inner_vlan_removal_en
= inner_vlan_removal_en_flg
;
172 p_ramrod
->drop_ttl0_en
= drop_ttl0_flg
;
174 SET_FIELD(rx_mode
, ETH_VPORT_RX_MODE_UCAST_DROP_ALL
, 1);
175 SET_FIELD(rx_mode
, ETH_VPORT_RX_MODE_MCAST_DROP_ALL
, 1);
177 p_ramrod
->rx_mode
.state
= cpu_to_le16(rx_mode
);
179 /* TPA related fields */
180 memset(&p_ramrod
->tpa_param
, 0,
181 sizeof(struct eth_vport_tpa_param
));
183 /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
184 p_ramrod
->sw_fid
= qed_concrete_to_sw_fid(p_hwfn
->cdev
,
187 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
191 qed_sp_vport_update_rss(struct qed_hwfn
*p_hwfn
,
192 struct vport_update_ramrod_data
*p_ramrod
,
193 struct qed_rss_params
*p_params
)
195 struct eth_vport_rss_config
*rss
= &p_ramrod
->rss_config
;
196 u16 abs_l2_queue
= 0, capabilities
= 0;
200 p_ramrod
->common
.update_rss_flg
= 0;
204 BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE
!=
205 ETH_RSS_IND_TABLE_ENTRIES_NUM
);
207 rc
= qed_fw_rss_eng(p_hwfn
, p_params
->rss_eng_id
, &rss
->rss_id
);
211 p_ramrod
->common
.update_rss_flg
= p_params
->update_rss_config
;
212 rss
->update_rss_capabilities
= p_params
->update_rss_capabilities
;
213 rss
->update_rss_ind_table
= p_params
->update_rss_ind_table
;
214 rss
->update_rss_key
= p_params
->update_rss_key
;
216 rss
->rss_mode
= p_params
->rss_enable
?
217 ETH_VPORT_RSS_MODE_REGULAR
:
218 ETH_VPORT_RSS_MODE_DISABLED
;
220 SET_FIELD(capabilities
,
221 ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY
,
222 !!(p_params
->rss_caps
& QED_RSS_IPV4
));
223 SET_FIELD(capabilities
,
224 ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY
,
225 !!(p_params
->rss_caps
& QED_RSS_IPV6
));
226 SET_FIELD(capabilities
,
227 ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY
,
228 !!(p_params
->rss_caps
& QED_RSS_IPV4_TCP
));
229 SET_FIELD(capabilities
,
230 ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY
,
231 !!(p_params
->rss_caps
& QED_RSS_IPV6_TCP
));
232 SET_FIELD(capabilities
,
233 ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY
,
234 !!(p_params
->rss_caps
& QED_RSS_IPV4_UDP
));
235 SET_FIELD(capabilities
,
236 ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY
,
237 !!(p_params
->rss_caps
& QED_RSS_IPV6_UDP
));
238 rss
->tbl_size
= p_params
->rss_table_size_log
;
240 rss
->capabilities
= cpu_to_le16(capabilities
);
242 DP_VERBOSE(p_hwfn
, NETIF_MSG_IFUP
,
243 "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
244 p_ramrod
->common
.update_rss_flg
,
245 rss
->rss_mode
, rss
->update_rss_capabilities
,
246 capabilities
, rss
->update_rss_ind_table
,
247 rss
->update_rss_key
);
249 for (i
= 0; i
< QED_RSS_IND_TABLE_SIZE
; i
++) {
250 rc
= qed_fw_l2_queue(p_hwfn
,
251 (u8
)p_params
->rss_ind_table
[i
],
256 rss
->indirection_table
[i
] = cpu_to_le16(abs_l2_queue
);
257 DP_VERBOSE(p_hwfn
, NETIF_MSG_IFUP
, "i= %d, queue = %d\n",
258 i
, rss
->indirection_table
[i
]);
261 for (i
= 0; i
< 10; i
++)
262 rss
->rss_key
[i
] = cpu_to_le32(p_params
->rss_key
[i
]);
268 qed_sp_update_accept_mode(struct qed_hwfn
*p_hwfn
,
269 struct vport_update_ramrod_data
*p_ramrod
,
270 struct qed_filter_accept_flags accept_flags
)
272 p_ramrod
->common
.update_rx_mode_flg
=
273 accept_flags
.update_rx_mode_config
;
275 p_ramrod
->common
.update_tx_mode_flg
=
276 accept_flags
.update_tx_mode_config
;
278 /* Set Rx mode accept flags */
279 if (p_ramrod
->common
.update_rx_mode_flg
) {
280 u8 accept_filter
= accept_flags
.rx_accept_filter
;
283 SET_FIELD(state
, ETH_VPORT_RX_MODE_UCAST_DROP_ALL
,
284 !(!!(accept_filter
& QED_ACCEPT_UCAST_MATCHED
) ||
285 !!(accept_filter
& QED_ACCEPT_UCAST_UNMATCHED
)));
287 SET_FIELD(state
, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED
,
288 !!(accept_filter
& QED_ACCEPT_UCAST_UNMATCHED
));
290 SET_FIELD(state
, ETH_VPORT_RX_MODE_MCAST_DROP_ALL
,
291 !(!!(accept_filter
& QED_ACCEPT_MCAST_MATCHED
) ||
292 !!(accept_filter
& QED_ACCEPT_MCAST_UNMATCHED
)));
294 SET_FIELD(state
, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL
,
295 (!!(accept_filter
& QED_ACCEPT_MCAST_MATCHED
) &&
296 !!(accept_filter
& QED_ACCEPT_MCAST_UNMATCHED
)));
298 SET_FIELD(state
, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL
,
299 !!(accept_filter
& QED_ACCEPT_BCAST
));
301 p_ramrod
->rx_mode
.state
= cpu_to_le16(state
);
302 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
303 "p_ramrod->rx_mode.state = 0x%x\n", state
);
306 /* Set Tx mode accept flags */
307 if (p_ramrod
->common
.update_tx_mode_flg
) {
308 u8 accept_filter
= accept_flags
.tx_accept_filter
;
311 SET_FIELD(state
, ETH_VPORT_TX_MODE_UCAST_DROP_ALL
,
312 !!(accept_filter
& QED_ACCEPT_NONE
));
314 SET_FIELD(state
, ETH_VPORT_TX_MODE_UCAST_ACCEPT_ALL
,
315 (!!(accept_filter
& QED_ACCEPT_UCAST_MATCHED
) &&
316 !!(accept_filter
& QED_ACCEPT_UCAST_UNMATCHED
)));
318 SET_FIELD(state
, ETH_VPORT_TX_MODE_MCAST_DROP_ALL
,
319 !!(accept_filter
& QED_ACCEPT_NONE
));
321 SET_FIELD(state
, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL
,
322 (!!(accept_filter
& QED_ACCEPT_MCAST_MATCHED
) &&
323 !!(accept_filter
& QED_ACCEPT_MCAST_UNMATCHED
)));
325 SET_FIELD(state
, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL
,
326 !!(accept_filter
& QED_ACCEPT_BCAST
));
328 p_ramrod
->tx_mode
.state
= cpu_to_le16(state
);
329 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
330 "p_ramrod->tx_mode.state = 0x%x\n", state
);
335 qed_sp_update_mcast_bin(struct qed_hwfn
*p_hwfn
,
336 struct vport_update_ramrod_data
*p_ramrod
,
337 struct qed_sp_vport_update_params
*p_params
)
341 memset(&p_ramrod
->approx_mcast
.bins
, 0,
342 sizeof(p_ramrod
->approx_mcast
.bins
));
344 if (p_params
->update_approx_mcast_flg
) {
345 p_ramrod
->common
.update_approx_mcast_flg
= 1;
346 for (i
= 0; i
< ETH_MULTICAST_MAC_BINS_IN_REGS
; i
++) {
347 u32
*p_bins
= (u32
*)p_params
->bins
;
348 __le32 val
= cpu_to_le32(p_bins
[i
]);
350 p_ramrod
->approx_mcast
.bins
[i
] = val
;
356 qed_sp_vport_update(struct qed_hwfn
*p_hwfn
,
357 struct qed_sp_vport_update_params
*p_params
,
358 enum spq_mode comp_mode
,
359 struct qed_spq_comp_cb
*p_comp_data
)
361 struct qed_rss_params
*p_rss_params
= p_params
->rss_params
;
362 struct vport_update_ramrod_data_cmn
*p_cmn
;
363 struct qed_sp_init_data init_data
;
364 struct vport_update_ramrod_data
*p_ramrod
= NULL
;
365 struct qed_spq_entry
*p_ent
= NULL
;
369 rc
= qed_fw_vport(p_hwfn
, p_params
->vport_id
, &abs_vport_id
);
373 memset(&init_data
, 0, sizeof(init_data
));
374 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
375 init_data
.opaque_fid
= p_params
->opaque_fid
;
376 init_data
.comp_mode
= comp_mode
;
377 init_data
.p_comp_data
= p_comp_data
;
379 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
380 ETH_RAMROD_VPORT_UPDATE
,
381 PROTOCOLID_ETH
, &init_data
);
385 /* Copy input params to ramrod according to FW struct */
386 p_ramrod
= &p_ent
->ramrod
.vport_update
;
387 p_cmn
= &p_ramrod
->common
;
389 p_cmn
->vport_id
= abs_vport_id
;
390 p_cmn
->rx_active_flg
= p_params
->vport_active_rx_flg
;
391 p_cmn
->update_rx_active_flg
= p_params
->update_vport_active_rx_flg
;
392 p_cmn
->tx_active_flg
= p_params
->vport_active_tx_flg
;
393 p_cmn
->update_tx_active_flg
= p_params
->update_vport_active_tx_flg
;
394 p_cmn
->accept_any_vlan
= p_params
->accept_any_vlan
;
395 p_cmn
->update_accept_any_vlan_flg
=
396 p_params
->update_accept_any_vlan_flg
;
397 rc
= qed_sp_vport_update_rss(p_hwfn
, p_ramrod
, p_rss_params
);
399 /* Return spq entry which is taken in qed_sp_init_request()*/
400 qed_spq_return_entry(p_hwfn
, p_ent
);
404 /* Update mcast bins for VFs, PF doesn't use this functionality */
405 qed_sp_update_mcast_bin(p_hwfn
, p_ramrod
, p_params
);
407 qed_sp_update_accept_mode(p_hwfn
, p_ramrod
, p_params
->accept_flags
);
408 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
411 static int qed_sp_vport_stop(struct qed_hwfn
*p_hwfn
,
415 struct vport_stop_ramrod_data
*p_ramrod
;
416 struct qed_sp_init_data init_data
;
417 struct qed_spq_entry
*p_ent
;
421 rc
= qed_fw_vport(p_hwfn
, vport_id
, &abs_vport_id
);
425 memset(&init_data
, 0, sizeof(init_data
));
426 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
427 init_data
.opaque_fid
= opaque_fid
;
428 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
430 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
431 ETH_RAMROD_VPORT_STOP
,
432 PROTOCOLID_ETH
, &init_data
);
436 p_ramrod
= &p_ent
->ramrod
.vport_stop
;
437 p_ramrod
->vport_id
= abs_vport_id
;
439 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
442 static int qed_filter_accept_cmd(struct qed_dev
*cdev
,
444 struct qed_filter_accept_flags accept_flags
,
445 u8 update_accept_any_vlan
,
447 enum spq_mode comp_mode
,
448 struct qed_spq_comp_cb
*p_comp_data
)
450 struct qed_sp_vport_update_params vport_update_params
;
453 /* Prepare and send the vport rx_mode change */
454 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
455 vport_update_params
.vport_id
= vport
;
456 vport_update_params
.accept_flags
= accept_flags
;
457 vport_update_params
.update_accept_any_vlan_flg
= update_accept_any_vlan
;
458 vport_update_params
.accept_any_vlan
= accept_any_vlan
;
460 for_each_hwfn(cdev
, i
) {
461 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
463 vport_update_params
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
465 rc
= qed_sp_vport_update(p_hwfn
, &vport_update_params
,
466 comp_mode
, p_comp_data
);
468 DP_ERR(cdev
, "Update rx_mode failed %d\n", rc
);
472 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
473 "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
474 accept_flags
.rx_accept_filter
,
475 accept_flags
.tx_accept_filter
);
476 if (update_accept_any_vlan
)
477 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
478 "accept_any_vlan=%d configured\n",
485 static int qed_sp_release_queue_cid(
486 struct qed_hwfn
*p_hwfn
,
487 struct qed_hw_cid_data
*p_cid_data
)
489 if (!p_cid_data
->b_cid_allocated
)
492 qed_cxt_release_cid(p_hwfn
, p_cid_data
->cid
);
494 p_cid_data
->b_cid_allocated
= false;
500 qed_sp_eth_rxq_start_ramrod(struct qed_hwfn
*p_hwfn
,
503 struct qed_queue_start_common_params
*params
,
506 dma_addr_t bd_chain_phys_addr
,
507 dma_addr_t cqe_pbl_addr
,
510 struct rx_queue_start_ramrod_data
*p_ramrod
= NULL
;
511 struct qed_spq_entry
*p_ent
= NULL
;
512 struct qed_sp_init_data init_data
;
513 struct qed_hw_cid_data
*p_rx_cid
;
518 /* Store information for the stop */
519 p_rx_cid
= &p_hwfn
->p_rx_cids
[params
->queue_id
];
521 p_rx_cid
->opaque_fid
= opaque_fid
;
522 p_rx_cid
->vport_id
= params
->vport_id
;
524 rc
= qed_fw_vport(p_hwfn
, params
->vport_id
, &abs_vport_id
);
528 rc
= qed_fw_l2_queue(p_hwfn
, params
->queue_id
, &abs_rx_q_id
);
532 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
533 "opaque_fid=0x%x, cid=0x%x, rx_qid=0x%x, vport_id=0x%x, sb_id=0x%x\n",
534 opaque_fid
, cid
, params
->queue_id
, params
->vport_id
,
538 memset(&init_data
, 0, sizeof(init_data
));
540 init_data
.opaque_fid
= opaque_fid
;
541 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
543 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
544 ETH_RAMROD_RX_QUEUE_START
,
545 PROTOCOLID_ETH
, &init_data
);
549 p_ramrod
= &p_ent
->ramrod
.rx_queue_start
;
551 p_ramrod
->sb_id
= cpu_to_le16(params
->sb
);
552 p_ramrod
->sb_index
= params
->sb_idx
;
553 p_ramrod
->vport_id
= abs_vport_id
;
554 p_ramrod
->stats_counter_id
= stats_id
;
555 p_ramrod
->rx_queue_id
= cpu_to_le16(abs_rx_q_id
);
556 p_ramrod
->complete_cqe_flg
= 0;
557 p_ramrod
->complete_event_flg
= 1;
559 p_ramrod
->bd_max_bytes
= cpu_to_le16(bd_max_bytes
);
560 p_ramrod
->bd_base
.hi
= DMA_HI_LE(bd_chain_phys_addr
);
561 p_ramrod
->bd_base
.lo
= DMA_LO_LE(bd_chain_phys_addr
);
563 p_ramrod
->num_of_pbl_pages
= cpu_to_le16(cqe_pbl_size
);
564 p_ramrod
->cqe_pbl_addr
.hi
= DMA_HI_LE(cqe_pbl_addr
);
565 p_ramrod
->cqe_pbl_addr
.lo
= DMA_LO_LE(cqe_pbl_addr
);
567 rc
= qed_spq_post(p_hwfn
, p_ent
, NULL
);
573 qed_sp_eth_rx_queue_start(struct qed_hwfn
*p_hwfn
,
575 struct qed_queue_start_common_params
*params
,
577 dma_addr_t bd_chain_phys_addr
,
578 dma_addr_t cqe_pbl_addr
,
580 void __iomem
**pp_prod
)
582 struct qed_hw_cid_data
*p_rx_cid
;
583 u64 init_prod_val
= 0;
584 u16 abs_l2_queue
= 0;
588 rc
= qed_fw_l2_queue(p_hwfn
, params
->queue_id
, &abs_l2_queue
);
592 rc
= qed_fw_vport(p_hwfn
, params
->vport_id
, &abs_stats_id
);
596 *pp_prod
= (u8 __iomem
*)p_hwfn
->regview
+
597 GTT_BAR0_MAP_REG_MSDM_RAM
+
598 MSTORM_PRODS_OFFSET(abs_l2_queue
);
600 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
601 __internal_ram_wr(p_hwfn
, *pp_prod
, sizeof(u64
),
602 (u32
*)(&init_prod_val
));
604 /* Allocate a CID for the queue */
605 p_rx_cid
= &p_hwfn
->p_rx_cids
[params
->queue_id
];
606 rc
= qed_cxt_acquire_cid(p_hwfn
, PROTOCOLID_ETH
,
609 DP_NOTICE(p_hwfn
, "Failed to acquire cid\n");
612 p_rx_cid
->b_cid_allocated
= true;
614 rc
= qed_sp_eth_rxq_start_ramrod(p_hwfn
,
625 qed_sp_release_queue_cid(p_hwfn
, p_rx_cid
);
630 static int qed_sp_eth_rx_queue_stop(struct qed_hwfn
*p_hwfn
,
632 bool eq_completion_only
,
635 struct qed_hw_cid_data
*p_rx_cid
= &p_hwfn
->p_rx_cids
[rx_queue_id
];
636 struct rx_queue_stop_ramrod_data
*p_ramrod
= NULL
;
637 struct qed_spq_entry
*p_ent
= NULL
;
638 struct qed_sp_init_data init_data
;
643 memset(&init_data
, 0, sizeof(init_data
));
644 init_data
.cid
= p_rx_cid
->cid
;
645 init_data
.opaque_fid
= p_rx_cid
->opaque_fid
;
646 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
648 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
649 ETH_RAMROD_RX_QUEUE_STOP
,
650 PROTOCOLID_ETH
, &init_data
);
654 p_ramrod
= &p_ent
->ramrod
.rx_queue_stop
;
656 qed_fw_vport(p_hwfn
, p_rx_cid
->vport_id
, &p_ramrod
->vport_id
);
657 qed_fw_l2_queue(p_hwfn
, rx_queue_id
, &abs_rx_q_id
);
658 p_ramrod
->rx_queue_id
= cpu_to_le16(abs_rx_q_id
);
660 /* Cleaning the queue requires the completion to arrive there.
661 * In addition, VFs require the answer to come as eqe to PF.
663 p_ramrod
->complete_cqe_flg
=
664 (!!(p_rx_cid
->opaque_fid
== p_hwfn
->hw_info
.opaque_fid
) &&
665 !eq_completion_only
) || cqe_completion
;
666 p_ramrod
->complete_event_flg
=
667 !(p_rx_cid
->opaque_fid
== p_hwfn
->hw_info
.opaque_fid
) ||
670 rc
= qed_spq_post(p_hwfn
, p_ent
, NULL
);
674 return qed_sp_release_queue_cid(p_hwfn
, p_rx_cid
);
678 qed_sp_eth_txq_start_ramrod(struct qed_hwfn
*p_hwfn
,
681 struct qed_queue_start_common_params
*p_params
,
685 union qed_qm_pq_params
*p_pq_params
)
687 struct tx_queue_start_ramrod_data
*p_ramrod
= NULL
;
688 struct qed_spq_entry
*p_ent
= NULL
;
689 struct qed_sp_init_data init_data
;
690 struct qed_hw_cid_data
*p_tx_cid
;
695 /* Store information for the stop */
696 p_tx_cid
= &p_hwfn
->p_tx_cids
[p_params
->queue_id
];
698 p_tx_cid
->opaque_fid
= opaque_fid
;
700 rc
= qed_fw_vport(p_hwfn
, p_params
->vport_id
, &abs_vport_id
);
705 memset(&init_data
, 0, sizeof(init_data
));
707 init_data
.opaque_fid
= opaque_fid
;
708 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
710 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
711 ETH_RAMROD_TX_QUEUE_START
,
712 PROTOCOLID_ETH
, &init_data
);
716 p_ramrod
= &p_ent
->ramrod
.tx_queue_start
;
717 p_ramrod
->vport_id
= abs_vport_id
;
719 p_ramrod
->sb_id
= cpu_to_le16(p_params
->sb
);
720 p_ramrod
->sb_index
= p_params
->sb_idx
;
721 p_ramrod
->stats_counter_id
= stats_id
;
723 p_ramrod
->pbl_size
= cpu_to_le16(pbl_size
);
724 p_ramrod
->pbl_base_addr
.hi
= DMA_HI_LE(pbl_addr
);
725 p_ramrod
->pbl_base_addr
.lo
= DMA_LO_LE(pbl_addr
);
727 pq_id
= qed_get_qm_pq(p_hwfn
,
730 p_ramrod
->qm_pq_id
= cpu_to_le16(pq_id
);
732 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
736 qed_sp_eth_tx_queue_start(struct qed_hwfn
*p_hwfn
,
738 struct qed_queue_start_common_params
*p_params
,
741 void __iomem
**pp_doorbell
)
743 struct qed_hw_cid_data
*p_tx_cid
;
744 union qed_qm_pq_params pq_params
;
748 rc
= qed_fw_vport(p_hwfn
, p_params
->vport_id
, &abs_stats_id
);
752 p_tx_cid
= &p_hwfn
->p_tx_cids
[p_params
->queue_id
];
753 memset(p_tx_cid
, 0, sizeof(*p_tx_cid
));
754 memset(&pq_params
, 0, sizeof(pq_params
));
756 /* Allocate a CID for the queue */
757 rc
= qed_cxt_acquire_cid(p_hwfn
, PROTOCOLID_ETH
,
760 DP_NOTICE(p_hwfn
, "Failed to acquire cid\n");
763 p_tx_cid
->b_cid_allocated
= true;
765 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
766 "opaque_fid=0x%x, cid=0x%x, tx_qid=0x%x, vport_id=0x%x, sb_id=0x%x\n",
767 opaque_fid
, p_tx_cid
->cid
,
768 p_params
->queue_id
, p_params
->vport_id
, p_params
->sb
);
770 rc
= qed_sp_eth_txq_start_ramrod(p_hwfn
,
779 *pp_doorbell
= (u8 __iomem
*)p_hwfn
->doorbells
+
780 qed_db_addr(p_tx_cid
->cid
, DQ_DEMS_LEGACY
);
783 qed_sp_release_queue_cid(p_hwfn
, p_tx_cid
);
788 static int qed_sp_eth_tx_queue_stop(struct qed_hwfn
*p_hwfn
,
791 struct qed_hw_cid_data
*p_tx_cid
= &p_hwfn
->p_tx_cids
[tx_queue_id
];
792 struct qed_spq_entry
*p_ent
= NULL
;
793 struct qed_sp_init_data init_data
;
797 memset(&init_data
, 0, sizeof(init_data
));
798 init_data
.cid
= p_tx_cid
->cid
;
799 init_data
.opaque_fid
= p_tx_cid
->opaque_fid
;
800 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
802 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
803 ETH_RAMROD_TX_QUEUE_STOP
,
804 PROTOCOLID_ETH
, &init_data
);
808 rc
= qed_spq_post(p_hwfn
, p_ent
, NULL
);
812 return qed_sp_release_queue_cid(p_hwfn
, p_tx_cid
);
815 static enum eth_filter_action
816 qed_filter_action(enum qed_filter_opcode opcode
)
818 enum eth_filter_action action
= MAX_ETH_FILTER_ACTION
;
822 action
= ETH_FILTER_ACTION_ADD
;
824 case QED_FILTER_REMOVE
:
825 action
= ETH_FILTER_ACTION_REMOVE
;
827 case QED_FILTER_FLUSH
:
828 action
= ETH_FILTER_ACTION_REMOVE_ALL
;
831 action
= MAX_ETH_FILTER_ACTION
;
837 static void qed_set_fw_mac_addr(__le16
*fw_msb
,
842 ((u8
*)fw_msb
)[0] = mac
[1];
843 ((u8
*)fw_msb
)[1] = mac
[0];
844 ((u8
*)fw_mid
)[0] = mac
[3];
845 ((u8
*)fw_mid
)[1] = mac
[2];
846 ((u8
*)fw_lsb
)[0] = mac
[5];
847 ((u8
*)fw_lsb
)[1] = mac
[4];
851 qed_filter_ucast_common(struct qed_hwfn
*p_hwfn
,
853 struct qed_filter_ucast
*p_filter_cmd
,
854 struct vport_filter_update_ramrod_data
**pp_ramrod
,
855 struct qed_spq_entry
**pp_ent
,
856 enum spq_mode comp_mode
,
857 struct qed_spq_comp_cb
*p_comp_data
)
859 u8 vport_to_add_to
= 0, vport_to_remove_from
= 0;
860 struct vport_filter_update_ramrod_data
*p_ramrod
;
861 struct eth_filter_cmd
*p_first_filter
;
862 struct eth_filter_cmd
*p_second_filter
;
863 struct qed_sp_init_data init_data
;
864 enum eth_filter_action action
;
867 rc
= qed_fw_vport(p_hwfn
, p_filter_cmd
->vport_to_remove_from
,
868 &vport_to_remove_from
);
872 rc
= qed_fw_vport(p_hwfn
, p_filter_cmd
->vport_to_add_to
,
878 memset(&init_data
, 0, sizeof(init_data
));
879 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
880 init_data
.opaque_fid
= opaque_fid
;
881 init_data
.comp_mode
= comp_mode
;
882 init_data
.p_comp_data
= p_comp_data
;
884 rc
= qed_sp_init_request(p_hwfn
, pp_ent
,
885 ETH_RAMROD_FILTERS_UPDATE
,
886 PROTOCOLID_ETH
, &init_data
);
890 *pp_ramrod
= &(*pp_ent
)->ramrod
.vport_filter_update
;
891 p_ramrod
= *pp_ramrod
;
892 p_ramrod
->filter_cmd_hdr
.rx
= p_filter_cmd
->is_rx_filter
? 1 : 0;
893 p_ramrod
->filter_cmd_hdr
.tx
= p_filter_cmd
->is_tx_filter
? 1 : 0;
895 switch (p_filter_cmd
->opcode
) {
896 case QED_FILTER_REPLACE
:
897 case QED_FILTER_MOVE
:
898 p_ramrod
->filter_cmd_hdr
.cmd_cnt
= 2; break;
900 p_ramrod
->filter_cmd_hdr
.cmd_cnt
= 1; break;
903 p_first_filter
= &p_ramrod
->filter_cmds
[0];
904 p_second_filter
= &p_ramrod
->filter_cmds
[1];
906 switch (p_filter_cmd
->type
) {
908 p_first_filter
->type
= ETH_FILTER_TYPE_MAC
; break;
909 case QED_FILTER_VLAN
:
910 p_first_filter
->type
= ETH_FILTER_TYPE_VLAN
; break;
911 case QED_FILTER_MAC_VLAN
:
912 p_first_filter
->type
= ETH_FILTER_TYPE_PAIR
; break;
913 case QED_FILTER_INNER_MAC
:
914 p_first_filter
->type
= ETH_FILTER_TYPE_INNER_MAC
; break;
915 case QED_FILTER_INNER_VLAN
:
916 p_first_filter
->type
= ETH_FILTER_TYPE_INNER_VLAN
; break;
917 case QED_FILTER_INNER_PAIR
:
918 p_first_filter
->type
= ETH_FILTER_TYPE_INNER_PAIR
; break;
919 case QED_FILTER_INNER_MAC_VNI_PAIR
:
920 p_first_filter
->type
= ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR
;
922 case QED_FILTER_MAC_VNI_PAIR
:
923 p_first_filter
->type
= ETH_FILTER_TYPE_MAC_VNI_PAIR
; break;
925 p_first_filter
->type
= ETH_FILTER_TYPE_VNI
; break;
928 if ((p_first_filter
->type
== ETH_FILTER_TYPE_MAC
) ||
929 (p_first_filter
->type
== ETH_FILTER_TYPE_PAIR
) ||
930 (p_first_filter
->type
== ETH_FILTER_TYPE_INNER_MAC
) ||
931 (p_first_filter
->type
== ETH_FILTER_TYPE_INNER_PAIR
) ||
932 (p_first_filter
->type
== ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR
) ||
933 (p_first_filter
->type
== ETH_FILTER_TYPE_MAC_VNI_PAIR
)) {
934 qed_set_fw_mac_addr(&p_first_filter
->mac_msb
,
935 &p_first_filter
->mac_mid
,
936 &p_first_filter
->mac_lsb
,
937 (u8
*)p_filter_cmd
->mac
);
940 if ((p_first_filter
->type
== ETH_FILTER_TYPE_VLAN
) ||
941 (p_first_filter
->type
== ETH_FILTER_TYPE_PAIR
) ||
942 (p_first_filter
->type
== ETH_FILTER_TYPE_INNER_VLAN
) ||
943 (p_first_filter
->type
== ETH_FILTER_TYPE_INNER_PAIR
))
944 p_first_filter
->vlan_id
= cpu_to_le16(p_filter_cmd
->vlan
);
946 if ((p_first_filter
->type
== ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR
) ||
947 (p_first_filter
->type
== ETH_FILTER_TYPE_MAC_VNI_PAIR
) ||
948 (p_first_filter
->type
== ETH_FILTER_TYPE_VNI
))
949 p_first_filter
->vni
= cpu_to_le32(p_filter_cmd
->vni
);
951 if (p_filter_cmd
->opcode
== QED_FILTER_MOVE
) {
952 p_second_filter
->type
= p_first_filter
->type
;
953 p_second_filter
->mac_msb
= p_first_filter
->mac_msb
;
954 p_second_filter
->mac_mid
= p_first_filter
->mac_mid
;
955 p_second_filter
->mac_lsb
= p_first_filter
->mac_lsb
;
956 p_second_filter
->vlan_id
= p_first_filter
->vlan_id
;
957 p_second_filter
->vni
= p_first_filter
->vni
;
959 p_first_filter
->action
= ETH_FILTER_ACTION_REMOVE
;
961 p_first_filter
->vport_id
= vport_to_remove_from
;
963 p_second_filter
->action
= ETH_FILTER_ACTION_ADD
;
964 p_second_filter
->vport_id
= vport_to_add_to
;
965 } else if (p_filter_cmd
->opcode
== QED_FILTER_REPLACE
) {
966 p_first_filter
->vport_id
= vport_to_add_to
;
967 memcpy(p_second_filter
, p_first_filter
,
968 sizeof(*p_second_filter
));
969 p_first_filter
->action
= ETH_FILTER_ACTION_REMOVE_ALL
;
970 p_second_filter
->action
= ETH_FILTER_ACTION_ADD
;
972 action
= qed_filter_action(p_filter_cmd
->opcode
);
974 if (action
== MAX_ETH_FILTER_ACTION
) {
976 "%d is not supported yet\n",
977 p_filter_cmd
->opcode
);
981 p_first_filter
->action
= action
;
982 p_first_filter
->vport_id
= (p_filter_cmd
->opcode
==
984 vport_to_remove_from
:
991 static int qed_sp_eth_filter_ucast(struct qed_hwfn
*p_hwfn
,
993 struct qed_filter_ucast
*p_filter_cmd
,
994 enum spq_mode comp_mode
,
995 struct qed_spq_comp_cb
*p_comp_data
)
997 struct vport_filter_update_ramrod_data
*p_ramrod
= NULL
;
998 struct qed_spq_entry
*p_ent
= NULL
;
999 struct eth_filter_cmd_header
*p_header
;
1002 rc
= qed_filter_ucast_common(p_hwfn
, opaque_fid
, p_filter_cmd
,
1004 comp_mode
, p_comp_data
);
1006 DP_ERR(p_hwfn
, "Uni. filter command failed %d\n", rc
);
1009 p_header
= &p_ramrod
->filter_cmd_hdr
;
1010 p_header
->assert_on_error
= p_filter_cmd
->assert_on_error
;
1012 rc
= qed_spq_post(p_hwfn
, p_ent
, NULL
);
1015 "Unicast filter ADD command failed %d\n",
1020 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
1021 "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
1022 (p_filter_cmd
->opcode
== QED_FILTER_ADD
) ? "ADD" :
1023 ((p_filter_cmd
->opcode
== QED_FILTER_REMOVE
) ?
1025 ((p_filter_cmd
->opcode
== QED_FILTER_MOVE
) ?
1026 "MOVE" : "REPLACE")),
1027 (p_filter_cmd
->type
== QED_FILTER_MAC
) ? "MAC" :
1028 ((p_filter_cmd
->type
== QED_FILTER_VLAN
) ?
1029 "VLAN" : "MAC & VLAN"),
1030 p_ramrod
->filter_cmd_hdr
.cmd_cnt
,
1031 p_filter_cmd
->is_rx_filter
,
1032 p_filter_cmd
->is_tx_filter
);
1033 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
1034 "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
1035 p_filter_cmd
->vport_to_add_to
,
1036 p_filter_cmd
->vport_to_remove_from
,
1037 p_filter_cmd
->mac
[0],
1038 p_filter_cmd
->mac
[1],
1039 p_filter_cmd
->mac
[2],
1040 p_filter_cmd
->mac
[3],
1041 p_filter_cmd
->mac
[4],
1042 p_filter_cmd
->mac
[5],
1043 p_filter_cmd
->vlan
);
1048 /*******************************************************************************
1050 * Calculates crc 32 on a buffer
1051 * Note: crc32_length MUST be aligned to 8
1053 ******************************************************************************/
1054 static u32
qed_calc_crc32c(u8
*crc32_packet
,
1062 u8 current_byte
= 0;
1063 u32 crc32_result
= crc32_seed
;
1065 if ((!crc32_packet
) ||
1066 (crc32_length
== 0) ||
1067 ((crc32_length
% 8) != 0))
1068 return crc32_result
;
1069 for (byte
= 0; byte
< crc32_length
; byte
++) {
1070 current_byte
= crc32_packet
[byte
];
1071 for (bit
= 0; bit
< 8; bit
++) {
1072 msb
= (u8
)(crc32_result
>> 31);
1073 crc32_result
= crc32_result
<< 1;
1074 if (msb
!= (0x1 & (current_byte
>> bit
))) {
1075 crc32_result
= crc32_result
^ CRC32_POLY
;
1076 crc32_result
|= 1; /*crc32_result[0] = 1;*/
1080 return crc32_result
;
1083 static inline u32
qed_crc32c_le(u32 seed
,
1087 u32 packet_buf
[2] = { 0 };
1089 memcpy((u8
*)(&packet_buf
[0]), &mac
[0], 6);
1090 return qed_calc_crc32c((u8
*)packet_buf
, 8, seed
, 0);
1093 static u8
qed_mcast_bin_from_mac(u8
*mac
)
1095 u32 crc
= qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED
,
1102 qed_sp_eth_filter_mcast(struct qed_hwfn
*p_hwfn
,
1104 struct qed_filter_mcast
*p_filter_cmd
,
1105 enum spq_mode comp_mode
,
1106 struct qed_spq_comp_cb
*p_comp_data
)
1108 unsigned long bins
[ETH_MULTICAST_MAC_BINS_IN_REGS
];
1109 struct vport_update_ramrod_data
*p_ramrod
= NULL
;
1110 struct qed_spq_entry
*p_ent
= NULL
;
1111 struct qed_sp_init_data init_data
;
1112 u8 abs_vport_id
= 0;
1115 if (p_filter_cmd
->opcode
== QED_FILTER_ADD
) {
1116 rc
= qed_fw_vport(p_hwfn
, p_filter_cmd
->vport_to_add_to
,
1121 rc
= qed_fw_vport(p_hwfn
, p_filter_cmd
->vport_to_remove_from
,
1128 memset(&init_data
, 0, sizeof(init_data
));
1129 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
1130 init_data
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
1131 init_data
.comp_mode
= comp_mode
;
1132 init_data
.p_comp_data
= p_comp_data
;
1134 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
1135 ETH_RAMROD_VPORT_UPDATE
,
1136 PROTOCOLID_ETH
, &init_data
);
1138 DP_ERR(p_hwfn
, "Multi-cast command failed %d\n", rc
);
1142 p_ramrod
= &p_ent
->ramrod
.vport_update
;
1143 p_ramrod
->common
.update_approx_mcast_flg
= 1;
1145 /* explicitly clear out the entire vector */
1146 memset(&p_ramrod
->approx_mcast
.bins
, 0,
1147 sizeof(p_ramrod
->approx_mcast
.bins
));
1148 memset(bins
, 0, sizeof(unsigned long) *
1149 ETH_MULTICAST_MAC_BINS_IN_REGS
);
1150 /* filter ADD op is explicit set op and it removes
1151 * any existing filters for the vport
1153 if (p_filter_cmd
->opcode
== QED_FILTER_ADD
) {
1154 for (i
= 0; i
< p_filter_cmd
->num_mc_addrs
; i
++) {
1157 bit
= qed_mcast_bin_from_mac(p_filter_cmd
->mac
[i
]);
1158 __set_bit(bit
, bins
);
1161 /* Convert to correct endianity */
1162 for (i
= 0; i
< ETH_MULTICAST_MAC_BINS_IN_REGS
; i
++) {
1163 u32
*p_bins
= (u32
*)bins
;
1164 struct vport_update_ramrod_mcast
*approx_mcast
;
1166 approx_mcast
= &p_ramrod
->approx_mcast
;
1167 approx_mcast
->bins
[i
] = cpu_to_le32(p_bins
[i
]);
1171 p_ramrod
->common
.vport_id
= abs_vport_id
;
1173 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
1177 qed_filter_mcast_cmd(struct qed_dev
*cdev
,
1178 struct qed_filter_mcast
*p_filter_cmd
,
1179 enum spq_mode comp_mode
,
1180 struct qed_spq_comp_cb
*p_comp_data
)
1185 /* only ADD and REMOVE operations are supported for multi-cast */
1186 if ((p_filter_cmd
->opcode
!= QED_FILTER_ADD
&&
1187 (p_filter_cmd
->opcode
!= QED_FILTER_REMOVE
)) ||
1188 (p_filter_cmd
->num_mc_addrs
> QED_MAX_MC_ADDRS
))
1191 for_each_hwfn(cdev
, i
) {
1192 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1199 opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
1201 rc
= qed_sp_eth_filter_mcast(p_hwfn
,
1210 static int qed_filter_ucast_cmd(struct qed_dev
*cdev
,
1211 struct qed_filter_ucast
*p_filter_cmd
,
1212 enum spq_mode comp_mode
,
1213 struct qed_spq_comp_cb
*p_comp_data
)
1218 for_each_hwfn(cdev
, i
) {
1219 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1225 opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
1227 rc
= qed_sp_eth_filter_ucast(p_hwfn
,
1237 static int qed_fill_eth_dev_info(struct qed_dev
*cdev
,
1238 struct qed_dev_eth_info
*info
)
1242 memset(info
, 0, sizeof(*info
));
1246 if (cdev
->int_params
.out
.int_mode
== QED_INT_MODE_MSIX
) {
1247 for_each_hwfn(cdev
, i
)
1248 info
->num_queues
+= FEAT_NUM(&cdev
->hwfns
[i
],
1250 if (cdev
->int_params
.fp_msix_cnt
)
1251 info
->num_queues
= min_t(u8
, info
->num_queues
,
1252 cdev
->int_params
.fp_msix_cnt
);
1254 info
->num_queues
= cdev
->num_hwfns
;
1257 info
->num_vlan_filters
= RESC_NUM(&cdev
->hwfns
[0], QED_VLAN
);
1258 ether_addr_copy(info
->port_mac
,
1259 cdev
->hwfns
[0].hw_info
.hw_mac_addr
);
1261 qed_fill_dev_info(cdev
, &info
->common
);
1266 static void qed_register_eth_ops(struct qed_dev
*cdev
,
1267 struct qed_eth_cb_ops
*ops
,
1270 cdev
->protocol_ops
.eth
= ops
;
1271 cdev
->ops_cookie
= cookie
;
1274 static int qed_start_vport(struct qed_dev
*cdev
,
1278 u8 inner_vlan_removal_en_flg
)
1282 for_each_hwfn(cdev
, i
) {
1283 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1285 rc
= qed_sp_vport_start(p_hwfn
,
1286 p_hwfn
->hw_info
.concrete_fid
,
1287 p_hwfn
->hw_info
.opaque_fid
,
1291 inner_vlan_removal_en_flg
);
1294 DP_ERR(cdev
, "Failed to start VPORT\n");
1298 qed_hw_start_fastpath(p_hwfn
);
1300 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1301 "Started V-PORT %d with MTU %d\n",
1305 qed_reset_vport_stats(cdev
);
1310 static int qed_stop_vport(struct qed_dev
*cdev
,
1315 for_each_hwfn(cdev
, i
) {
1316 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1318 rc
= qed_sp_vport_stop(p_hwfn
,
1319 p_hwfn
->hw_info
.opaque_fid
,
1323 DP_ERR(cdev
, "Failed to stop VPORT\n");
1330 static int qed_update_vport(struct qed_dev
*cdev
,
1331 struct qed_update_vport_params
*params
)
1333 struct qed_sp_vport_update_params sp_params
;
1334 struct qed_rss_params sp_rss_params
;
1340 memset(&sp_params
, 0, sizeof(sp_params
));
1341 memset(&sp_rss_params
, 0, sizeof(sp_rss_params
));
1343 /* Translate protocol params into sp params */
1344 sp_params
.vport_id
= params
->vport_id
;
1345 sp_params
.update_vport_active_rx_flg
=
1346 params
->update_vport_active_flg
;
1347 sp_params
.update_vport_active_tx_flg
=
1348 params
->update_vport_active_flg
;
1349 sp_params
.vport_active_rx_flg
= params
->vport_active_flg
;
1350 sp_params
.vport_active_tx_flg
= params
->vport_active_flg
;
1351 sp_params
.accept_any_vlan
= params
->accept_any_vlan
;
1352 sp_params
.update_accept_any_vlan_flg
=
1353 params
->update_accept_any_vlan_flg
;
1355 /* RSS - is a bit tricky, since upper-layer isn't familiar with hwfns.
1356 * We need to re-fix the rss values per engine for CMT.
1358 if (cdev
->num_hwfns
> 1 && params
->update_rss_flg
) {
1359 struct qed_update_vport_rss_params
*rss
=
1360 ¶ms
->rss_params
;
1363 /* Find largest entry, since it's possible RSS needs to
1364 * be disabled [in case only 1 queue per-hwfn]
1366 for (k
= 0; k
< QED_RSS_IND_TABLE_SIZE
; k
++)
1367 max
= (max
> rss
->rss_ind_table
[k
]) ?
1368 max
: rss
->rss_ind_table
[k
];
1370 /* Either fix RSS values or disable RSS */
1371 if (cdev
->num_hwfns
< max
+ 1) {
1372 int divisor
= (max
+ cdev
->num_hwfns
- 1) /
1375 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1376 "CMT - fixing RSS values (modulo %02x)\n",
1379 for (k
= 0; k
< QED_RSS_IND_TABLE_SIZE
; k
++)
1380 rss
->rss_ind_table
[k
] =
1381 rss
->rss_ind_table
[k
] % divisor
;
1383 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1384 "CMT - 1 queue per-hwfn; Disabling RSS\n");
1385 params
->update_rss_flg
= 0;
1389 /* Now, update the RSS configuration for actual configuration */
1390 if (params
->update_rss_flg
) {
1391 sp_rss_params
.update_rss_config
= 1;
1392 sp_rss_params
.rss_enable
= 1;
1393 sp_rss_params
.update_rss_capabilities
= 1;
1394 sp_rss_params
.update_rss_ind_table
= 1;
1395 sp_rss_params
.update_rss_key
= 1;
1396 sp_rss_params
.rss_caps
= QED_RSS_IPV4
|
1398 QED_RSS_IPV4_TCP
| QED_RSS_IPV6_TCP
;
1399 sp_rss_params
.rss_table_size_log
= 7; /* 2^7 = 128 */
1400 memcpy(sp_rss_params
.rss_ind_table
,
1401 params
->rss_params
.rss_ind_table
,
1402 QED_RSS_IND_TABLE_SIZE
* sizeof(u16
));
1403 memcpy(sp_rss_params
.rss_key
, params
->rss_params
.rss_key
,
1404 QED_RSS_KEY_SIZE
* sizeof(u32
));
1406 sp_params
.rss_params
= &sp_rss_params
;
1408 for_each_hwfn(cdev
, i
) {
1409 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1411 sp_params
.opaque_fid
= p_hwfn
->hw_info
.opaque_fid
;
1412 rc
= qed_sp_vport_update(p_hwfn
, &sp_params
,
1413 QED_SPQ_MODE_EBLOCK
,
1416 DP_ERR(cdev
, "Failed to update VPORT\n");
1420 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1421 "Updated V-PORT %d: active_flag %d [update %d]\n",
1422 params
->vport_id
, params
->vport_active_flg
,
1423 params
->update_vport_active_flg
);
1429 static int qed_start_rxq(struct qed_dev
*cdev
,
1430 struct qed_queue_start_common_params
*params
,
1432 dma_addr_t bd_chain_phys_addr
,
1433 dma_addr_t cqe_pbl_addr
,
1435 void __iomem
**pp_prod
)
1438 struct qed_hwfn
*p_hwfn
;
1440 hwfn_index
= params
->rss_id
% cdev
->num_hwfns
;
1441 p_hwfn
= &cdev
->hwfns
[hwfn_index
];
1443 /* Fix queue ID in 100g mode */
1444 params
->queue_id
/= cdev
->num_hwfns
;
1446 rc
= qed_sp_eth_rx_queue_start(p_hwfn
,
1447 p_hwfn
->hw_info
.opaque_fid
,
1456 DP_ERR(cdev
, "Failed to start RXQ#%d\n", params
->queue_id
);
1460 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1461 "Started RX-Q %d [rss %d] on V-PORT %d and SB %d\n",
1462 params
->queue_id
, params
->rss_id
, params
->vport_id
,
1468 static int qed_stop_rxq(struct qed_dev
*cdev
,
1469 struct qed_stop_rxq_params
*params
)
1472 struct qed_hwfn
*p_hwfn
;
1474 hwfn_index
= params
->rss_id
% cdev
->num_hwfns
;
1475 p_hwfn
= &cdev
->hwfns
[hwfn_index
];
1477 rc
= qed_sp_eth_rx_queue_stop(p_hwfn
,
1478 params
->rx_queue_id
/ cdev
->num_hwfns
,
1479 params
->eq_completion_only
,
1482 DP_ERR(cdev
, "Failed to stop RXQ#%d\n", params
->rx_queue_id
);
1489 static int qed_start_txq(struct qed_dev
*cdev
,
1490 struct qed_queue_start_common_params
*p_params
,
1491 dma_addr_t pbl_addr
,
1493 void __iomem
**pp_doorbell
)
1495 struct qed_hwfn
*p_hwfn
;
1498 hwfn_index
= p_params
->rss_id
% cdev
->num_hwfns
;
1499 p_hwfn
= &cdev
->hwfns
[hwfn_index
];
1501 /* Fix queue ID in 100g mode */
1502 p_params
->queue_id
/= cdev
->num_hwfns
;
1504 rc
= qed_sp_eth_tx_queue_start(p_hwfn
,
1505 p_hwfn
->hw_info
.opaque_fid
,
1512 DP_ERR(cdev
, "Failed to start TXQ#%d\n", p_params
->queue_id
);
1516 DP_VERBOSE(cdev
, (QED_MSG_SPQ
| NETIF_MSG_IFUP
),
1517 "Started TX-Q %d [rss %d] on V-PORT %d and SB %d\n",
1518 p_params
->queue_id
, p_params
->rss_id
, p_params
->vport_id
,
1524 #define QED_HW_STOP_RETRY_LIMIT (10)
1525 static int qed_fastpath_stop(struct qed_dev
*cdev
)
1527 qed_hw_stop_fastpath(cdev
);
1532 static int qed_stop_txq(struct qed_dev
*cdev
,
1533 struct qed_stop_txq_params
*params
)
1535 struct qed_hwfn
*p_hwfn
;
1538 hwfn_index
= params
->rss_id
% cdev
->num_hwfns
;
1539 p_hwfn
= &cdev
->hwfns
[hwfn_index
];
1541 rc
= qed_sp_eth_tx_queue_stop(p_hwfn
,
1542 params
->tx_queue_id
/ cdev
->num_hwfns
);
1544 DP_ERR(cdev
, "Failed to stop TXQ#%d\n", params
->tx_queue_id
);
1551 static int qed_configure_filter_rx_mode(struct qed_dev
*cdev
,
1552 enum qed_filter_rx_mode_type type
)
1554 struct qed_filter_accept_flags accept_flags
;
1556 memset(&accept_flags
, 0, sizeof(accept_flags
));
1558 accept_flags
.update_rx_mode_config
= 1;
1559 accept_flags
.update_tx_mode_config
= 1;
1560 accept_flags
.rx_accept_filter
= QED_ACCEPT_UCAST_MATCHED
|
1561 QED_ACCEPT_MCAST_MATCHED
|
1563 accept_flags
.tx_accept_filter
= QED_ACCEPT_UCAST_MATCHED
|
1564 QED_ACCEPT_MCAST_MATCHED
|
1567 if (type
== QED_FILTER_RX_MODE_TYPE_PROMISC
)
1568 accept_flags
.rx_accept_filter
|= QED_ACCEPT_UCAST_UNMATCHED
|
1569 QED_ACCEPT_MCAST_UNMATCHED
;
1570 else if (type
== QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC
)
1571 accept_flags
.rx_accept_filter
|= QED_ACCEPT_MCAST_UNMATCHED
;
1573 return qed_filter_accept_cmd(cdev
, 0, accept_flags
, false, false,
1574 QED_SPQ_MODE_CB
, NULL
);
1577 static int qed_configure_filter_ucast(struct qed_dev
*cdev
,
1578 struct qed_filter_ucast_params
*params
)
1580 struct qed_filter_ucast ucast
;
1582 if (!params
->vlan_valid
&& !params
->mac_valid
) {
1585 "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
1589 memset(&ucast
, 0, sizeof(ucast
));
1590 switch (params
->type
) {
1591 case QED_FILTER_XCAST_TYPE_ADD
:
1592 ucast
.opcode
= QED_FILTER_ADD
;
1594 case QED_FILTER_XCAST_TYPE_DEL
:
1595 ucast
.opcode
= QED_FILTER_REMOVE
;
1597 case QED_FILTER_XCAST_TYPE_REPLACE
:
1598 ucast
.opcode
= QED_FILTER_REPLACE
;
1601 DP_NOTICE(cdev
, "Unknown unicast filter type %d\n",
1605 if (params
->vlan_valid
&& params
->mac_valid
) {
1606 ucast
.type
= QED_FILTER_MAC_VLAN
;
1607 ether_addr_copy(ucast
.mac
, params
->mac
);
1608 ucast
.vlan
= params
->vlan
;
1609 } else if (params
->mac_valid
) {
1610 ucast
.type
= QED_FILTER_MAC
;
1611 ether_addr_copy(ucast
.mac
, params
->mac
);
1613 ucast
.type
= QED_FILTER_VLAN
;
1614 ucast
.vlan
= params
->vlan
;
1617 ucast
.is_rx_filter
= true;
1618 ucast
.is_tx_filter
= true;
1620 return qed_filter_ucast_cmd(cdev
, &ucast
, QED_SPQ_MODE_CB
, NULL
);
1623 static int qed_configure_filter_mcast(struct qed_dev
*cdev
,
1624 struct qed_filter_mcast_params
*params
)
1626 struct qed_filter_mcast mcast
;
1629 memset(&mcast
, 0, sizeof(mcast
));
1630 switch (params
->type
) {
1631 case QED_FILTER_XCAST_TYPE_ADD
:
1632 mcast
.opcode
= QED_FILTER_ADD
;
1634 case QED_FILTER_XCAST_TYPE_DEL
:
1635 mcast
.opcode
= QED_FILTER_REMOVE
;
1638 DP_NOTICE(cdev
, "Unknown multicast filter type %d\n",
1642 mcast
.num_mc_addrs
= params
->num
;
1643 for (i
= 0; i
< mcast
.num_mc_addrs
; i
++)
1644 ether_addr_copy(mcast
.mac
[i
], params
->mac
[i
]);
1646 return qed_filter_mcast_cmd(cdev
, &mcast
,
1647 QED_SPQ_MODE_CB
, NULL
);
1650 static int qed_configure_filter(struct qed_dev
*cdev
,
1651 struct qed_filter_params
*params
)
1653 enum qed_filter_rx_mode_type accept_flags
;
1655 switch (params
->type
) {
1656 case QED_FILTER_TYPE_UCAST
:
1657 return qed_configure_filter_ucast(cdev
, ¶ms
->filter
.ucast
);
1658 case QED_FILTER_TYPE_MCAST
:
1659 return qed_configure_filter_mcast(cdev
, ¶ms
->filter
.mcast
);
1660 case QED_FILTER_TYPE_RX_MODE
:
1661 accept_flags
= params
->filter
.accept_flags
;
1662 return qed_configure_filter_rx_mode(cdev
, accept_flags
);
1664 DP_NOTICE(cdev
, "Unknown filter type %d\n",
1670 static int qed_fp_cqe_completion(struct qed_dev
*dev
,
1672 struct eth_slow_path_rx_cqe
*cqe
)
1674 return qed_eth_cqe_completion(&dev
->hwfns
[rss_id
% dev
->num_hwfns
],
1678 static const struct qed_eth_ops qed_eth_ops_pass
= {
1679 .common
= &qed_common_ops_pass
,
1680 .fill_dev_info
= &qed_fill_eth_dev_info
,
1681 .register_ops
= &qed_register_eth_ops
,
1682 .vport_start
= &qed_start_vport
,
1683 .vport_stop
= &qed_stop_vport
,
1684 .vport_update
= &qed_update_vport
,
1685 .q_rx_start
= &qed_start_rxq
,
1686 .q_rx_stop
= &qed_stop_rxq
,
1687 .q_tx_start
= &qed_start_txq
,
1688 .q_tx_stop
= &qed_stop_txq
,
1689 .filter_config
= &qed_configure_filter
,
1690 .fastpath_stop
= &qed_fastpath_stop
,
1691 .eth_cqe_completion
= &qed_fp_cqe_completion
,
1692 .get_vport_stats
= &qed_get_vport_stats
,
1695 const struct qed_eth_ops
*qed_get_eth_ops(u32 version
)
1697 if (version
!= QED_ETH_INTERFACE_VERSION
) {
1698 pr_notice("Cannot supply ethtool operations [%08x != %08x]\n",
1699 version
, QED_ETH_INTERFACE_VERSION
);
1703 return &qed_eth_ops_pass
;
1705 EXPORT_SYMBOL(qed_get_eth_ops
);
1707 void qed_put_eth_ops(void)
1709 /* TODO - reference count for module? */
1711 EXPORT_SYMBOL(qed_put_eth_ops
);