1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/errno.h>
41#include <linux/types.h>
42#include <linux/debugfs.h>
43#include <linux/export.h>
44#include <linux/list.h>
45#include <linux/skbuff.h>
46#include <linux/pci.h>
47
48#include "cxgb4.h"
49#include "cxgb4_uld.h"
50#include "t4_regs.h"
51#include "t4fw_api.h"
52#include "t4_msg.h"
53
54#define for_each_uldrxq(m, i) for (i = 0; i < ((m)->nrxq + (m)->nciq); i++)
55
56static int get_msix_idx_from_bmap(struct adapter *adap)
57{
58 struct uld_msix_bmap *bmap = &adap->msix_bmap_ulds;
59 unsigned long flags;
60 unsigned int msix_idx;
61
62 spin_lock_irqsave(&bmap->lock, flags);
63 msix_idx = find_first_zero_bit(bmap->msix_bmap, bmap->mapsize);
64 if (msix_idx < bmap->mapsize) {
65 __set_bit(msix_idx, bmap->msix_bmap);
66 } else {
67 spin_unlock_irqrestore(&bmap->lock, flags);
68 return -ENOSPC;
69 }
70
71 spin_unlock_irqrestore(&bmap->lock, flags);
72 return msix_idx;
73}
74
75static void free_msix_idx_in_bmap(struct adapter *adap, unsigned int msix_idx)
76{
77 struct uld_msix_bmap *bmap = &adap->msix_bmap_ulds;
78 unsigned long flags;
79
80 spin_lock_irqsave(&bmap->lock, flags);
81 __clear_bit(msix_idx, bmap->msix_bmap);
82 spin_unlock_irqrestore(&bmap->lock, flags);
83}
84
85
86static void uldrx_flush_handler(struct sge_rspq *q)
87{
88 struct adapter *adap = q->adap;
89
90 if (adap->uld[q->uld].lro_flush)
91 adap->uld[q->uld].lro_flush(&q->lro_mgr);
92}
93
94
95
96
97
98
99
100
101
102
103static int uldrx_handler(struct sge_rspq *q, const __be64 *rsp,
104 const struct pkt_gl *gl)
105{
106 struct adapter *adap = q->adap;
107 struct sge_ofld_rxq *rxq = container_of(q, struct sge_ofld_rxq, rspq);
108 int ret;
109
110
111 if (((const struct rss_header *)rsp)->opcode == CPL_FW4_MSG &&
112 ((const struct cpl_fw4_msg *)(rsp + 1))->type == FW_TYPE_RSSCPL)
113 rsp += 2;
114
115 if (q->flush_handler)
116 ret = adap->uld[q->uld].lro_rx_handler(adap->uld[q->uld].handle,
117 rsp, gl, &q->lro_mgr,
118 &q->napi);
119 else
120 ret = adap->uld[q->uld].rx_handler(adap->uld[q->uld].handle,
121 rsp, gl);
122
123 if (ret) {
124 rxq->stats.nomem++;
125 return -1;
126 }
127
128 if (!gl)
129 rxq->stats.imm++;
130 else if (gl == CXGB4_MSG_AN)
131 rxq->stats.an++;
132 else
133 rxq->stats.pkts++;
134 return 0;
135}
136
137static int alloc_uld_rxqs(struct adapter *adap,
138 struct sge_uld_rxq_info *rxq_info, bool lro)
139{
140 struct sge *s = &adap->sge;
141 unsigned int nq = rxq_info->nrxq + rxq_info->nciq;
142 struct sge_ofld_rxq *q = rxq_info->uldrxq;
143 unsigned short *ids = rxq_info->rspq_id;
144 unsigned int bmap_idx = 0;
145 unsigned int per_chan;
146 int i, err, msi_idx, que_idx = 0;
147
148 per_chan = rxq_info->nrxq / adap->params.nports;
149
150 if (adap->flags & USING_MSIX)
151 msi_idx = 1;
152 else
153 msi_idx = -((int)s->intrq.abs_id + 1);
154
155 for (i = 0; i < nq; i++, q++) {
156 if (i == rxq_info->nrxq) {
157
158 per_chan = rxq_info->nciq / adap->params.nports;
159 que_idx = 0;
160 }
161
162 if (msi_idx >= 0) {
163 bmap_idx = get_msix_idx_from_bmap(adap);
164 msi_idx = adap->msix_info_ulds[bmap_idx].idx;
165 }
166 err = t4_sge_alloc_rxq(adap, &q->rspq, false,
167 adap->port[que_idx++ / per_chan],
168 msi_idx,
169 q->fl.size ? &q->fl : NULL,
170 uldrx_handler,
171 lro ? uldrx_flush_handler : NULL,
172 0);
173 if (err)
174 goto freeout;
175 if (msi_idx >= 0)
176 rxq_info->msix_tbl[i] = bmap_idx;
177 memset(&q->stats, 0, sizeof(q->stats));
178 if (ids)
179 ids[i] = q->rspq.abs_id;
180 }
181 return 0;
182freeout:
183 q = rxq_info->uldrxq;
184 for ( ; i; i--, q++) {
185 if (q->rspq.desc)
186 free_rspq_fl(adap, &q->rspq,
187 q->fl.size ? &q->fl : NULL);
188 }
189 return err;
190}
191
192static int
193setup_sge_queues_uld(struct adapter *adap, unsigned int uld_type, bool lro)
194{
195 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
196 int i, ret = 0;
197
198 if (adap->flags & USING_MSIX) {
199 rxq_info->msix_tbl = kcalloc((rxq_info->nrxq + rxq_info->nciq),
200 sizeof(unsigned short),
201 GFP_KERNEL);
202 if (!rxq_info->msix_tbl)
203 return -ENOMEM;
204 }
205
206 ret = !(!alloc_uld_rxqs(adap, rxq_info, lro));
207
208
209 if (adap->flags & FULL_INIT_DONE &&
210 !ret && uld_type == CXGB4_ULD_RDMA) {
211 struct sge *s = &adap->sge;
212 unsigned int cmplqid;
213 u32 param, cmdop;
214
215 cmdop = FW_PARAMS_PARAM_DMAQ_EQ_CMPLIQID_CTRL;
216 for_each_port(adap, i) {
217 cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
218 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
219 FW_PARAMS_PARAM_X_V(cmdop) |
220 FW_PARAMS_PARAM_YZ_V(s->ctrlq[i].q.cntxt_id));
221 ret = t4_set_params(adap, adap->mbox, adap->pf,
222 0, 1, ¶m, &cmplqid);
223 }
224 }
225 return ret;
226}
227
228static void t4_free_uld_rxqs(struct adapter *adap, int n,
229 struct sge_ofld_rxq *q)
230{
231 for ( ; n; n--, q++) {
232 if (q->rspq.desc)
233 free_rspq_fl(adap, &q->rspq,
234 q->fl.size ? &q->fl : NULL);
235 }
236}
237
238static void free_sge_queues_uld(struct adapter *adap, unsigned int uld_type)
239{
240 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
241
242 if (adap->flags & FULL_INIT_DONE && uld_type == CXGB4_ULD_RDMA) {
243 struct sge *s = &adap->sge;
244 u32 param, cmdop, cmplqid = 0;
245 int i;
246
247 cmdop = FW_PARAMS_PARAM_DMAQ_EQ_CMPLIQID_CTRL;
248 for_each_port(adap, i) {
249 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
250 FW_PARAMS_PARAM_X_V(cmdop) |
251 FW_PARAMS_PARAM_YZ_V(s->ctrlq[i].q.cntxt_id));
252 t4_set_params(adap, adap->mbox, adap->pf,
253 0, 1, ¶m, &cmplqid);
254 }
255 }
256
257 if (rxq_info->nciq)
258 t4_free_uld_rxqs(adap, rxq_info->nciq,
259 rxq_info->uldrxq + rxq_info->nrxq);
260 t4_free_uld_rxqs(adap, rxq_info->nrxq, rxq_info->uldrxq);
261 if (adap->flags & USING_MSIX)
262 kfree(rxq_info->msix_tbl);
263}
264
265static int cfg_queues_uld(struct adapter *adap, unsigned int uld_type,
266 const struct cxgb4_uld_info *uld_info)
267{
268 struct sge *s = &adap->sge;
269 struct sge_uld_rxq_info *rxq_info;
270 int i, nrxq, ciq_size;
271
272 rxq_info = kzalloc(sizeof(*rxq_info), GFP_KERNEL);
273 if (!rxq_info)
274 return -ENOMEM;
275
276 if (adap->flags & USING_MSIX && uld_info->nrxq > s->nqs_per_uld) {
277 i = s->nqs_per_uld;
278 rxq_info->nrxq = roundup(i, adap->params.nports);
279 } else {
280 i = min_t(int, uld_info->nrxq,
281 num_online_cpus());
282 rxq_info->nrxq = roundup(i, adap->params.nports);
283 }
284 if (!uld_info->ciq) {
285 rxq_info->nciq = 0;
286 } else {
287 if (adap->flags & USING_MSIX)
288 rxq_info->nciq = min_t(int, s->nqs_per_uld,
289 num_online_cpus());
290 else
291 rxq_info->nciq = min_t(int, MAX_OFLD_QSETS,
292 num_online_cpus());
293 rxq_info->nciq = ((rxq_info->nciq / adap->params.nports) *
294 adap->params.nports);
295 rxq_info->nciq = max_t(int, rxq_info->nciq,
296 adap->params.nports);
297 }
298
299 nrxq = rxq_info->nrxq + rxq_info->nciq;
300 rxq_info->uldrxq = kcalloc(nrxq, sizeof(struct sge_ofld_rxq),
301 GFP_KERNEL);
302 if (!rxq_info->uldrxq) {
303 kfree(rxq_info);
304 return -ENOMEM;
305 }
306
307 rxq_info->rspq_id = kcalloc(nrxq, sizeof(unsigned short), GFP_KERNEL);
308 if (!rxq_info->rspq_id) {
309 kfree(rxq_info->uldrxq);
310 kfree(rxq_info);
311 return -ENOMEM;
312 }
313
314 for (i = 0; i < rxq_info->nrxq; i++) {
315 struct sge_ofld_rxq *r = &rxq_info->uldrxq[i];
316
317 init_rspq(adap, &r->rspq, 5, 1, uld_info->rxq_size, 64);
318 r->rspq.uld = uld_type;
319 r->fl.size = 72;
320 }
321
322 ciq_size = 64 + adap->vres.cq.size + adap->tids.nftids;
323 if (ciq_size > SGE_MAX_IQ_SIZE) {
324 dev_warn(adap->pdev_dev, "CIQ size too small for available IQs\n");
325 ciq_size = SGE_MAX_IQ_SIZE;
326 }
327
328 for (i = rxq_info->nrxq; i < nrxq; i++) {
329 struct sge_ofld_rxq *r = &rxq_info->uldrxq[i];
330
331 init_rspq(adap, &r->rspq, 5, 1, ciq_size, 64);
332 r->rspq.uld = uld_type;
333 }
334
335 memcpy(rxq_info->name, uld_info->name, IFNAMSIZ);
336 adap->sge.uld_rxq_info[uld_type] = rxq_info;
337
338 return 0;
339}
340
341static void free_queues_uld(struct adapter *adap, unsigned int uld_type)
342{
343 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
344
345 kfree(rxq_info->rspq_id);
346 kfree(rxq_info->uldrxq);
347 kfree(rxq_info);
348}
349
350static int
351request_msix_queue_irqs_uld(struct adapter *adap, unsigned int uld_type)
352{
353 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
354 int err = 0;
355 unsigned int idx, bmap_idx;
356
357 for_each_uldrxq(rxq_info, idx) {
358 bmap_idx = rxq_info->msix_tbl[idx];
359 err = request_irq(adap->msix_info_ulds[bmap_idx].vec,
360 t4_sge_intr_msix, 0,
361 adap->msix_info_ulds[bmap_idx].desc,
362 &rxq_info->uldrxq[idx].rspq);
363 if (err)
364 goto unwind;
365 }
366 return 0;
367unwind:
368 while (idx-- > 0) {
369 bmap_idx = rxq_info->msix_tbl[idx];
370 free_msix_idx_in_bmap(adap, bmap_idx);
371 free_irq(adap->msix_info_ulds[bmap_idx].vec,
372 &rxq_info->uldrxq[idx].rspq);
373 }
374 return err;
375}
376
377static void
378free_msix_queue_irqs_uld(struct adapter *adap, unsigned int uld_type)
379{
380 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
381 unsigned int idx, bmap_idx;
382
383 for_each_uldrxq(rxq_info, idx) {
384 bmap_idx = rxq_info->msix_tbl[idx];
385
386 free_msix_idx_in_bmap(adap, bmap_idx);
387 free_irq(adap->msix_info_ulds[bmap_idx].vec,
388 &rxq_info->uldrxq[idx].rspq);
389 }
390}
391
392static void name_msix_vecs_uld(struct adapter *adap, unsigned int uld_type)
393{
394 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
395 int n = sizeof(adap->msix_info_ulds[0].desc);
396 unsigned int idx, bmap_idx;
397
398 for_each_uldrxq(rxq_info, idx) {
399 bmap_idx = rxq_info->msix_tbl[idx];
400
401 snprintf(adap->msix_info_ulds[bmap_idx].desc, n, "%s-%s%d",
402 adap->port[0]->name, rxq_info->name, idx);
403 }
404}
405
406static void enable_rx(struct adapter *adap, struct sge_rspq *q)
407{
408 if (!q)
409 return;
410
411 if (q->handler)
412 napi_enable(&q->napi);
413
414
415 t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
416 SEINTARM_V(q->intr_params) |
417 INGRESSQID_V(q->cntxt_id));
418}
419
420static void quiesce_rx(struct adapter *adap, struct sge_rspq *q)
421{
422 if (q && q->handler)
423 napi_disable(&q->napi);
424}
425
426static void enable_rx_uld(struct adapter *adap, unsigned int uld_type)
427{
428 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
429 int idx;
430
431 for_each_uldrxq(rxq_info, idx)
432 enable_rx(adap, &rxq_info->uldrxq[idx].rspq);
433}
434
435static void quiesce_rx_uld(struct adapter *adap, unsigned int uld_type)
436{
437 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
438 int idx;
439
440 for_each_uldrxq(rxq_info, idx)
441 quiesce_rx(adap, &rxq_info->uldrxq[idx].rspq);
442}
443
444static void
445free_sge_txq_uld(struct adapter *adap, struct sge_uld_txq_info *txq_info)
446{
447 int nq = txq_info->ntxq;
448 int i;
449
450 for (i = 0; i < nq; i++) {
451 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
452
453 if (txq && txq->q.desc) {
454 tasklet_kill(&txq->qresume_tsk);
455 t4_ofld_eq_free(adap, adap->mbox, adap->pf, 0,
456 txq->q.cntxt_id);
457 free_tx_desc(adap, &txq->q, txq->q.in_use, false);
458 kfree(txq->q.sdesc);
459 __skb_queue_purge(&txq->sendq);
460 free_txq(adap, &txq->q);
461 }
462 }
463}
464
465static int
466alloc_sge_txq_uld(struct adapter *adap, struct sge_uld_txq_info *txq_info,
467 unsigned int uld_type)
468{
469 struct sge *s = &adap->sge;
470 int nq = txq_info->ntxq;
471 int i, j, err;
472
473 j = nq / adap->params.nports;
474 for (i = 0; i < nq; i++) {
475 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
476
477 txq->q.size = 1024;
478 err = t4_sge_alloc_uld_txq(adap, txq, adap->port[i / j],
479 s->fw_evtq.cntxt_id, uld_type);
480 if (err)
481 goto freeout;
482 }
483 return 0;
484freeout:
485 free_sge_txq_uld(adap, txq_info);
486 return err;
487}
488
489static void
490release_sge_txq_uld(struct adapter *adap, unsigned int uld_type)
491{
492 struct sge_uld_txq_info *txq_info = NULL;
493 int tx_uld_type = TX_ULD(uld_type);
494
495 txq_info = adap->sge.uld_txq_info[tx_uld_type];
496
497 if (txq_info && atomic_dec_and_test(&txq_info->users)) {
498 free_sge_txq_uld(adap, txq_info);
499 kfree(txq_info->uldtxq);
500 kfree(txq_info);
501 adap->sge.uld_txq_info[tx_uld_type] = NULL;
502 }
503}
504
505static int
506setup_sge_txq_uld(struct adapter *adap, unsigned int uld_type,
507 const struct cxgb4_uld_info *uld_info)
508{
509 struct sge_uld_txq_info *txq_info = NULL;
510 int tx_uld_type, i;
511
512 tx_uld_type = TX_ULD(uld_type);
513 txq_info = adap->sge.uld_txq_info[tx_uld_type];
514
515 if ((tx_uld_type == CXGB4_TX_OFLD) && txq_info &&
516 (atomic_inc_return(&txq_info->users) > 1))
517 return 0;
518
519 txq_info = kzalloc(sizeof(*txq_info), GFP_KERNEL);
520 if (!txq_info)
521 return -ENOMEM;
522
523 i = min_t(int, uld_info->ntxq, num_online_cpus());
524 txq_info->ntxq = roundup(i, adap->params.nports);
525
526 txq_info->uldtxq = kcalloc(txq_info->ntxq, sizeof(struct sge_uld_txq),
527 GFP_KERNEL);
528 if (!txq_info->uldtxq) {
529 kfree(txq_info);
530 return -ENOMEM;
531 }
532
533 if (alloc_sge_txq_uld(adap, txq_info, tx_uld_type)) {
534 kfree(txq_info->uldtxq);
535 kfree(txq_info);
536 return -ENOMEM;
537 }
538
539 atomic_inc(&txq_info->users);
540 adap->sge.uld_txq_info[tx_uld_type] = txq_info;
541 return 0;
542}
543
544static void uld_queue_init(struct adapter *adap, unsigned int uld_type,
545 struct cxgb4_lld_info *lli)
546{
547 struct sge_uld_rxq_info *rxq_info = adap->sge.uld_rxq_info[uld_type];
548
549 lli->rxq_ids = rxq_info->rspq_id;
550 lli->nrxq = rxq_info->nrxq;
551 lli->ciq_ids = rxq_info->rspq_id + rxq_info->nrxq;
552 lli->nciq = rxq_info->nciq;
553}
554
555int t4_uld_mem_alloc(struct adapter *adap)
556{
557 struct sge *s = &adap->sge;
558
559 adap->uld = kcalloc(CXGB4_ULD_MAX, sizeof(*adap->uld), GFP_KERNEL);
560 if (!adap->uld)
561 return -ENOMEM;
562
563 s->uld_rxq_info = kzalloc(CXGB4_ULD_MAX *
564 sizeof(struct sge_uld_rxq_info *),
565 GFP_KERNEL);
566 if (!s->uld_rxq_info)
567 goto err_uld;
568
569 s->uld_txq_info = kzalloc(CXGB4_TX_MAX *
570 sizeof(struct sge_uld_txq_info *),
571 GFP_KERNEL);
572 if (!s->uld_txq_info)
573 goto err_uld_rx;
574 return 0;
575
576err_uld_rx:
577 kfree(s->uld_rxq_info);
578err_uld:
579 kfree(adap->uld);
580 return -ENOMEM;
581}
582
583void t4_uld_mem_free(struct adapter *adap)
584{
585 struct sge *s = &adap->sge;
586
587 kfree(s->uld_txq_info);
588 kfree(s->uld_rxq_info);
589 kfree(adap->uld);
590}
591
592
593static void cxgb4_shutdown_uld_adapter(struct adapter *adap, enum cxgb4_uld type)
594{
595 if (adap->uld[type].handle) {
596 adap->uld[type].handle = NULL;
597 adap->uld[type].add = NULL;
598 release_sge_txq_uld(adap, type);
599
600 if (adap->flags & FULL_INIT_DONE)
601 quiesce_rx_uld(adap, type);
602
603 if (adap->flags & USING_MSIX)
604 free_msix_queue_irqs_uld(adap, type);
605
606 free_sge_queues_uld(adap, type);
607 free_queues_uld(adap, type);
608 }
609}
610
611void t4_uld_clean_up(struct adapter *adap)
612{
613 unsigned int i;
614
615 mutex_lock(&uld_mutex);
616 for (i = 0; i < CXGB4_ULD_MAX; i++) {
617 if (!adap->uld[i].handle)
618 continue;
619
620 cxgb4_shutdown_uld_adapter(adap, i);
621 }
622 mutex_unlock(&uld_mutex);
623}
624
625static void uld_init(struct adapter *adap, struct cxgb4_lld_info *lld)
626{
627 int i;
628
629 lld->pdev = adap->pdev;
630 lld->pf = adap->pf;
631 lld->l2t = adap->l2t;
632 lld->tids = &adap->tids;
633 lld->ports = adap->port;
634 lld->vr = &adap->vres;
635 lld->mtus = adap->params.mtus;
636 lld->ntxq = adap->sge.ofldqsets;
637 lld->nchan = adap->params.nports;
638 lld->nports = adap->params.nports;
639 lld->wr_cred = adap->params.ofldq_wr_cred;
640 lld->iscsi_iolen = MAXRXDATA_G(t4_read_reg(adap, TP_PARA_REG2_A));
641 lld->iscsi_tagmask = t4_read_reg(adap, ULP_RX_ISCSI_TAGMASK_A);
642 lld->iscsi_pgsz_order = t4_read_reg(adap, ULP_RX_ISCSI_PSZ_A);
643 lld->iscsi_llimit = t4_read_reg(adap, ULP_RX_ISCSI_LLIMIT_A);
644 lld->iscsi_ppm = &adap->iscsi_ppm;
645 lld->adapter_type = adap->params.chip;
646 lld->cclk_ps = 1000000000 / adap->params.vpd.cclk;
647 lld->udb_density = 1 << adap->params.sge.eq_qpp;
648 lld->ucq_density = 1 << adap->params.sge.iq_qpp;
649 lld->filt_mode = adap->params.tp.vlan_pri_map;
650
651 for (i = 0; i < NCHAN; i++)
652 lld->tx_modq[i] = i;
653 lld->gts_reg = adap->regs + MYPF_REG(SGE_PF_GTS_A);
654 lld->db_reg = adap->regs + MYPF_REG(SGE_PF_KDOORBELL_A);
655 lld->fw_vers = adap->params.fw_vers;
656 lld->dbfifo_int_thresh = dbfifo_int_thresh;
657 lld->sge_ingpadboundary = adap->sge.fl_align;
658 lld->sge_egrstatuspagesize = adap->sge.stat_len;
659 lld->sge_pktshift = adap->sge.pktshift;
660 lld->ulp_crypto = adap->params.crypto;
661 lld->enable_fw_ofld_conn = adap->flags & FW_OFLD_CONN;
662 lld->max_ordird_qp = adap->params.max_ordird_qp;
663 lld->max_ird_adapter = adap->params.max_ird_adapter;
664 lld->ulptx_memwrite_dsgl = adap->params.ulptx_memwrite_dsgl;
665 lld->nodeid = dev_to_node(adap->pdev_dev);
666 lld->fr_nsmr_tpte_wr_support = adap->params.fr_nsmr_tpte_wr_support;
667}
668
669static void uld_attach(struct adapter *adap, unsigned int uld)
670{
671 void *handle;
672 struct cxgb4_lld_info lli;
673
674 uld_init(adap, &lli);
675 uld_queue_init(adap, uld, &lli);
676
677 handle = adap->uld[uld].add(&lli);
678 if (IS_ERR(handle)) {
679 dev_warn(adap->pdev_dev,
680 "could not attach to the %s driver, error %ld\n",
681 adap->uld[uld].name, PTR_ERR(handle));
682 return;
683 }
684
685 adap->uld[uld].handle = handle;
686 t4_register_netevent_notifier();
687
688 if (adap->flags & FULL_INIT_DONE)
689 adap->uld[uld].state_change(handle, CXGB4_STATE_UP);
690}
691
692
693
694
695
696
697
698
699
700
701int cxgb4_register_uld(enum cxgb4_uld type,
702 const struct cxgb4_uld_info *p)
703{
704 int ret = 0;
705 unsigned int adap_idx = 0;
706 struct adapter *adap;
707
708 if (type >= CXGB4_ULD_MAX)
709 return -EINVAL;
710
711 mutex_lock(&uld_mutex);
712 list_for_each_entry(adap, &adapter_list, list_node) {
713 if ((type == CXGB4_ULD_CRYPTO && !is_pci_uld(adap)) ||
714 (type != CXGB4_ULD_CRYPTO && !is_offload(adap)))
715 continue;
716 if (type == CXGB4_ULD_ISCSIT && is_t4(adap->params.chip))
717 continue;
718 ret = cfg_queues_uld(adap, type, p);
719 if (ret)
720 goto out;
721 ret = setup_sge_queues_uld(adap, type, p->lro);
722 if (ret)
723 goto free_queues;
724 if (adap->flags & USING_MSIX) {
725 name_msix_vecs_uld(adap, type);
726 ret = request_msix_queue_irqs_uld(adap, type);
727 if (ret)
728 goto free_rxq;
729 }
730 if (adap->flags & FULL_INIT_DONE)
731 enable_rx_uld(adap, type);
732 if (adap->uld[type].add) {
733 ret = -EBUSY;
734 goto free_irq;
735 }
736 ret = setup_sge_txq_uld(adap, type, p);
737 if (ret)
738 goto free_irq;
739 adap->uld[type] = *p;
740 uld_attach(adap, type);
741 adap_idx++;
742 }
743 mutex_unlock(&uld_mutex);
744 return 0;
745
746free_irq:
747 if (adap->flags & FULL_INIT_DONE)
748 quiesce_rx_uld(adap, type);
749 if (adap->flags & USING_MSIX)
750 free_msix_queue_irqs_uld(adap, type);
751free_rxq:
752 free_sge_queues_uld(adap, type);
753free_queues:
754 free_queues_uld(adap, type);
755out:
756
757 list_for_each_entry(adap, &adapter_list, list_node) {
758 if ((type == CXGB4_ULD_CRYPTO && !is_pci_uld(adap)) ||
759 (type != CXGB4_ULD_CRYPTO && !is_offload(adap)))
760 continue;
761 if (type == CXGB4_ULD_ISCSIT && is_t4(adap->params.chip))
762 continue;
763 if (!adap_idx)
764 break;
765 adap->uld[type].handle = NULL;
766 adap->uld[type].add = NULL;
767 release_sge_txq_uld(adap, type);
768 if (adap->flags & FULL_INIT_DONE)
769 quiesce_rx_uld(adap, type);
770 if (adap->flags & USING_MSIX)
771 free_msix_queue_irqs_uld(adap, type);
772 free_sge_queues_uld(adap, type);
773 free_queues_uld(adap, type);
774 adap_idx--;
775 }
776 mutex_unlock(&uld_mutex);
777 return ret;
778}
779EXPORT_SYMBOL(cxgb4_register_uld);
780
781
782
783
784
785
786
787int cxgb4_unregister_uld(enum cxgb4_uld type)
788{
789 struct adapter *adap;
790
791 if (type >= CXGB4_ULD_MAX)
792 return -EINVAL;
793
794 mutex_lock(&uld_mutex);
795 list_for_each_entry(adap, &adapter_list, list_node) {
796 if ((type == CXGB4_ULD_CRYPTO && !is_pci_uld(adap)) ||
797 (type != CXGB4_ULD_CRYPTO && !is_offload(adap)))
798 continue;
799 if (type == CXGB4_ULD_ISCSIT && is_t4(adap->params.chip))
800 continue;
801
802 cxgb4_shutdown_uld_adapter(adap, type);
803 }
804 mutex_unlock(&uld_mutex);
805
806 return 0;
807}
808EXPORT_SYMBOL(cxgb4_unregister_uld);
809