Skip to content

Commit 36907cd

Browse files
Ariel Eliordavem330
authored andcommitted
qed: Add doorbell overflow recovery mechanism
Add the database used to register doorbelling entities, and APIs for adding and deleting entries, and logic for traversing the database and doorbelling once on behalf of all entities. Signed-off-by: Ariel Elior <Ariel.Elior@cavium.com> Signed-off-by: Michal Kalderon <Michal.Kalderon@cavium.com> Signed-off-by: Tomer Tayar <Tomer.Tayar@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dd35420 commit 36907cd

4 files changed

Lines changed: 379 additions & 0 deletions

File tree

‎drivers/net/ethernet/qlogic/qed/qed.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ enum qed_wol_support {
296296
QED_WOL_SUPPORT_PME,
297297
};
298298

299+
enum qed_db_rec_exec {
300+
DB_REC_DRY_RUN,
301+
DB_REC_REAL_DEAL,
302+
DB_REC_ONCE,
303+
};
304+
299305
struct qed_hw_info {
300306
/* PCI personality */
301307
enum qed_pci_personality personality;
@@ -425,6 +431,14 @@ struct qed_qm_info {
425431
u8 num_pf_rls;
426432
};
427433

434+
struct qed_db_recovery_info {
435+
struct list_head list;
436+
437+
/* Lock to protect the doorbell recovery mechanism list */
438+
spinlock_t lock;
439+
u32 db_recovery_counter;
440+
};
441+
428442
struct storm_stats {
429443
u32 address;
430444
u32 len;
@@ -640,6 +654,9 @@ struct qed_hwfn {
640654
/* L2-related */
641655
struct qed_l2_info *p_l2_info;
642656

657+
/* Mechanism for recovering from doorbell drop */
658+
struct qed_db_recovery_info db_recovery_info;
659+
643660
/* Nvm images number and attributes */
644661
struct qed_nvm_image_info nvm_info;
645662

‎drivers/net/ethernet/qlogic/qed/qed_dev.c‎

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,318 @@
6666

6767
static DEFINE_SPINLOCK(qm_lock);
6868

69+
/******************** Doorbell Recovery *******************/
70+
/* The doorbell recovery mechanism consists of a list of entries which represent
71+
* doorbelling entities (l2 queues, roce sq/rq/cqs, the slowpath spq, etc). Each
72+
* entity needs to register with the mechanism and provide the parameters
73+
* describing it's doorbell, including a location where last used doorbell data
74+
* can be found. The doorbell execute function will traverse the list and
75+
* doorbell all of the registered entries.
76+
*/
77+
struct qed_db_recovery_entry {
78+
struct list_head list_entry;
79+
void __iomem *db_addr;
80+
void *db_data;
81+
enum qed_db_rec_width db_width;
82+
enum qed_db_rec_space db_space;
83+
u8 hwfn_idx;
84+
};
85+
86+
/* Display a single doorbell recovery entry */
87+
static void qed_db_recovery_dp_entry(struct qed_hwfn *p_hwfn,
88+
struct qed_db_recovery_entry *db_entry,
89+
char *action)
90+
{
91+
DP_VERBOSE(p_hwfn,
92+
QED_MSG_SPQ,
93+
"(%s: db_entry %p, addr %p, data %p, width %s, %s space, hwfn %d)\n",
94+
action,
95+
db_entry,
96+
db_entry->db_addr,
97+
db_entry->db_data,
98+
db_entry->db_width == DB_REC_WIDTH_32B ? "32b" : "64b",
99+
db_entry->db_space == DB_REC_USER ? "user" : "kernel",
100+
db_entry->hwfn_idx);
101+
}
102+
103+
/* Doorbell address sanity (address within doorbell bar range) */
104+
static bool qed_db_rec_sanity(struct qed_dev *cdev,
105+
void __iomem *db_addr, void *db_data)
106+
{
107+
/* Make sure doorbell address is within the doorbell bar */
108+
if (db_addr < cdev->doorbells ||
109+
(u8 __iomem *)db_addr >
110+
(u8 __iomem *)cdev->doorbells + cdev->db_size) {
111+
WARN(true,
112+
"Illegal doorbell address: %p. Legal range for doorbell addresses is [%p..%p]\n",
113+
db_addr,
114+
cdev->doorbells,
115+
(u8 __iomem *)cdev->doorbells + cdev->db_size);
116+
return false;
117+
}
118+
119+
/* ake sure doorbell data pointer is not null */
120+
if (!db_data) {
121+
WARN(true, "Illegal doorbell data pointer: %p", db_data);
122+
return false;
123+
}
124+
125+
return true;
126+
}
127+
128+
/* Find hwfn according to the doorbell address */
129+
static struct qed_hwfn *qed_db_rec_find_hwfn(struct qed_dev *cdev,
130+
void __iomem *db_addr)
131+
{
132+
struct qed_hwfn *p_hwfn;
133+
134+
/* In CMT doorbell bar is split down the middle between engine 0 and enigne 1 */
135+
if (cdev->num_hwfns > 1)
136+
p_hwfn = db_addr < cdev->hwfns[1].doorbells ?
137+
&cdev->hwfns[0] : &cdev->hwfns[1];
138+
else
139+
p_hwfn = QED_LEADING_HWFN(cdev);
140+
141+
return p_hwfn;
142+
}
143+
144+
/* Add a new entry to the doorbell recovery mechanism */
145+
int qed_db_recovery_add(struct qed_dev *cdev,
146+
void __iomem *db_addr,
147+
void *db_data,
148+
enum qed_db_rec_width db_width,
149+
enum qed_db_rec_space db_space)
150+
{
151+
struct qed_db_recovery_entry *db_entry;
152+
struct qed_hwfn *p_hwfn;
153+
154+
/* Shortcircuit VFs, for now */
155+
if (IS_VF(cdev)) {
156+
DP_VERBOSE(cdev,
157+
QED_MSG_IOV, "db recovery - skipping VF doorbell\n");
158+
return 0;
159+
}
160+
161+
/* Sanitize doorbell address */
162+
if (!qed_db_rec_sanity(cdev, db_addr, db_data))
163+
return -EINVAL;
164+
165+
/* Obtain hwfn from doorbell address */
166+
p_hwfn = qed_db_rec_find_hwfn(cdev, db_addr);
167+
168+
/* Create entry */
169+
db_entry = kzalloc(sizeof(*db_entry), GFP_KERNEL);
170+
if (!db_entry) {
171+
DP_NOTICE(cdev, "Failed to allocate a db recovery entry\n");
172+
return -ENOMEM;
173+
}
174+
175+
/* Populate entry */
176+
db_entry->db_addr = db_addr;
177+
db_entry->db_data = db_data;
178+
db_entry->db_width = db_width;
179+
db_entry->db_space = db_space;
180+
db_entry->hwfn_idx = p_hwfn->my_id;
181+
182+
/* Display */
183+
qed_db_recovery_dp_entry(p_hwfn, db_entry, "Adding");
184+
185+
/* Protect the list */
186+
spin_lock_bh(&p_hwfn->db_recovery_info.lock);
187+
list_add_tail(&db_entry->list_entry, &p_hwfn->db_recovery_info.list);
188+
spin_unlock_bh(&p_hwfn->db_recovery_info.lock);
189+
190+
return 0;
191+
}
192+
193+
/* Remove an entry from the doorbell recovery mechanism */
194+
int qed_db_recovery_del(struct qed_dev *cdev,
195+
void __iomem *db_addr, void *db_data)
196+
{
197+
struct qed_db_recovery_entry *db_entry = NULL;
198+
struct qed_hwfn *p_hwfn;
199+
int rc = -EINVAL;
200+
201+
/* Shortcircuit VFs, for now */
202+
if (IS_VF(cdev)) {
203+
DP_VERBOSE(cdev,
204+
QED_MSG_IOV, "db recovery - skipping VF doorbell\n");
205+
return 0;
206+
}
207+
208+
/* Sanitize doorbell address */
209+
if (!qed_db_rec_sanity(cdev, db_addr, db_data))
210+
return -EINVAL;
211+
212+
/* Obtain hwfn from doorbell address */
213+
p_hwfn = qed_db_rec_find_hwfn(cdev, db_addr);
214+
215+
/* Protect the list */
216+
spin_lock_bh(&p_hwfn->db_recovery_info.lock);
217+
list_for_each_entry(db_entry,
218+
&p_hwfn->db_recovery_info.list, list_entry) {
219+
/* search according to db_data addr since db_addr is not unique (roce) */
220+
if (db_entry->db_data == db_data) {
221+
qed_db_recovery_dp_entry(p_hwfn, db_entry, "Deleting");
222+
list_del(&db_entry->list_entry);
223+
rc = 0;
224+
break;
225+
}
226+
}
227+
228+
spin_unlock_bh(&p_hwfn->db_recovery_info.lock);
229+
230+
if (rc == -EINVAL)
231+
232+
DP_NOTICE(p_hwfn,
233+
"Failed to find element in list. Key (db_data addr) was %p. db_addr was %p\n",
234+
db_data, db_addr);
235+
else
236+
kfree(db_entry);
237+
238+
return rc;
239+
}
240+
241+
/* Initialize the doorbell recovery mechanism */
242+
static int qed_db_recovery_setup(struct qed_hwfn *p_hwfn)
243+
{
244+
DP_VERBOSE(p_hwfn, QED_MSG_SPQ, "Setting up db recovery\n");
245+
246+
/* Make sure db_size was set in cdev */
247+
if (!p_hwfn->cdev->db_size) {
248+
DP_ERR(p_hwfn->cdev, "db_size not set\n");
249+
return -EINVAL;
250+
}
251+
252+
INIT_LIST_HEAD(&p_hwfn->db_recovery_info.list);
253+
spin_lock_init(&p_hwfn->db_recovery_info.lock);
254+
p_hwfn->db_recovery_info.db_recovery_counter = 0;
255+
256+
return 0;
257+
}
258+
259+
/* Destroy the doorbell recovery mechanism */
260+
static void qed_db_recovery_teardown(struct qed_hwfn *p_hwfn)
261+
{
262+
struct qed_db_recovery_entry *db_entry = NULL;
263+
264+
DP_VERBOSE(p_hwfn, QED_MSG_SPQ, "Tearing down db recovery\n");
265+
if (!list_empty(&p_hwfn->db_recovery_info.list)) {
266+
DP_VERBOSE(p_hwfn,
267+
QED_MSG_SPQ,
268+
"Doorbell Recovery teardown found the doorbell recovery list was not empty (Expected in disorderly driver unload (e.g. recovery) otherwise this probably means some flow forgot to db_recovery_del). Prepare to purge doorbell recovery list...\n");
269+
while (!list_empty(&p_hwfn->db_recovery_info.list)) {
270+
db_entry =
271+
list_first_entry(&p_hwfn->db_recovery_info.list,
272+
struct qed_db_recovery_entry,
273+
list_entry);
274+
qed_db_recovery_dp_entry(p_hwfn, db_entry, "Purging");
275+
list_del(&db_entry->list_entry);
276+
kfree(db_entry);
277+
}
278+
}
279+
p_hwfn->db_recovery_info.db_recovery_counter = 0;
280+
}
281+
282+
/* Print the content of the doorbell recovery mechanism */
283+
void qed_db_recovery_dp(struct qed_hwfn *p_hwfn)
284+
{
285+
struct qed_db_recovery_entry *db_entry = NULL;
286+
287+
DP_NOTICE(p_hwfn,
288+
"Dispalying doorbell recovery database. Counter was %d\n",
289+
p_hwfn->db_recovery_info.db_recovery_counter);
290+
291+
/* Protect the list */
292+
spin_lock_bh(&p_hwfn->db_recovery_info.lock);
293+
list_for_each_entry(db_entry,
294+
&p_hwfn->db_recovery_info.list, list_entry) {
295+
qed_db_recovery_dp_entry(p_hwfn, db_entry, "Printing");
296+
}
297+
298+
spin_unlock_bh(&p_hwfn->db_recovery_info.lock);
299+
}
300+
301+
/* Ring the doorbell of a single doorbell recovery entry */
302+
static void qed_db_recovery_ring(struct qed_hwfn *p_hwfn,
303+
struct qed_db_recovery_entry *db_entry,
304+
enum qed_db_rec_exec db_exec)
305+
{
306+
if (db_exec != DB_REC_ONCE) {
307+
/* Print according to width */
308+
if (db_entry->db_width == DB_REC_WIDTH_32B) {
309+
DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
310+
"%s doorbell address %p data %x\n",
311+
db_exec == DB_REC_DRY_RUN ?
312+
"would have rung" : "ringing",
313+
db_entry->db_addr,
314+
*(u32 *)db_entry->db_data);
315+
} else {
316+
DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
317+
"%s doorbell address %p data %llx\n",
318+
db_exec == DB_REC_DRY_RUN ?
319+
"would have rung" : "ringing",
320+
db_entry->db_addr,
321+
*(u64 *)(db_entry->db_data));
322+
}
323+
}
324+
325+
/* Sanity */
326+
if (!qed_db_rec_sanity(p_hwfn->cdev, db_entry->db_addr,
327+
db_entry->db_data))
328+
return;
329+
330+
/* Flush the write combined buffer. Since there are multiple doorbelling
331+
* entities using the same address, if we don't flush, a transaction
332+
* could be lost.
333+
*/
334+
wmb();
335+
336+
/* Ring the doorbell */
337+
if (db_exec == DB_REC_REAL_DEAL || db_exec == DB_REC_ONCE) {
338+
if (db_entry->db_width == DB_REC_WIDTH_32B)
339+
DIRECT_REG_WR(db_entry->db_addr,
340+
*(u32 *)(db_entry->db_data));
341+
else
342+
DIRECT_REG_WR64(db_entry->db_addr,
343+
*(u64 *)(db_entry->db_data));
344+
}
345+
346+
/* Flush the write combined buffer. Next doorbell may come from a
347+
* different entity to the same address...
348+
*/
349+
wmb();
350+
}
351+
352+
/* Traverse the doorbell recovery entry list and ring all the doorbells */
353+
void qed_db_recovery_execute(struct qed_hwfn *p_hwfn,
354+
enum qed_db_rec_exec db_exec)
355+
{
356+
struct qed_db_recovery_entry *db_entry = NULL;
357+
358+
if (db_exec != DB_REC_ONCE) {
359+
DP_NOTICE(p_hwfn,
360+
"Executing doorbell recovery. Counter was %d\n",
361+
p_hwfn->db_recovery_info.db_recovery_counter);
362+
363+
/* Track amount of times recovery was executed */
364+
p_hwfn->db_recovery_info.db_recovery_counter++;
365+
}
366+
367+
/* Protect the list */
368+
spin_lock_bh(&p_hwfn->db_recovery_info.lock);
369+
list_for_each_entry(db_entry,
370+
&p_hwfn->db_recovery_info.list, list_entry) {
371+
qed_db_recovery_ring(p_hwfn, db_entry, db_exec);
372+
if (db_exec == DB_REC_ONCE)
373+
break;
374+
}
375+
376+
spin_unlock_bh(&p_hwfn->db_recovery_info.lock);
377+
}
378+
379+
/******************** Doorbell Recovery end ****************/
380+
69381
#define QED_MIN_DPIS (4)
70382
#define QED_MIN_PWM_REGION (QED_WID_SIZE * QED_MIN_DPIS)
71383

@@ -194,6 +506,9 @@ void qed_resc_free(struct qed_dev *cdev)
194506
qed_dmae_info_free(p_hwfn);
195507
qed_dcbx_info_free(p_hwfn);
196508
qed_dbg_user_data_free(p_hwfn);
509+
510+
/* Destroy doorbell recovery mechanism */
511+
qed_db_recovery_teardown(p_hwfn);
197512
}
198513
}
199514

@@ -969,6 +1284,11 @@ int qed_resc_alloc(struct qed_dev *cdev)
9691284
struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
9701285
u32 n_eqes, num_cons;
9711286

1287+
/* Initialize the doorbell recovery mechanism */
1288+
rc = qed_db_recovery_setup(p_hwfn);
1289+
if (rc)
1290+
goto alloc_err;
1291+
9721292
/* First allocate the context manager structure */
9731293
rc = qed_cxt_mngr_alloc(p_hwfn);
9741294
if (rc)

0 commit comments

Comments
 (0)