29 #include <linux/slab.h>
43 MAL_DBG(mal,
"reg(%08x, %08x)" NL,
49 spin_unlock_irqrestore(&mal->
lock, flags);
55 if (list_empty(&mal->
list))
56 napi_enable(&mal->
napi);
61 spin_unlock_irqrestore(&mal->
lock, flags);
73 MAL_DBG(mal,
"unreg(%08x, %08x)" NL,
78 list_del_init(&commac->
list);
79 if (list_empty(&mal->
list))
80 napi_disable(&mal->
napi);
82 spin_unlock_irqrestore(&mal->
lock, flags);
90 MAL_DBG(mal,
"set_rbcs(%d, %lu)" NL, channel, size);
94 "mal%d: incorrect RX size %lu for the channel %d\n",
95 mal->
index, size, channel);
99 set_mal_dcrn(mal,
MAL_RCBS(channel), size >> 4);
122 MAL_DBG(mal,
"enable_tx(%d)" NL, channel);
127 spin_unlock_irqrestore(&mal->
lock, flags);
134 MAL_DBG(mal,
"disable_tx(%d)" NL, channel);
151 MAL_DBG(mal,
"enable_rx(%d)" NL, channel);
156 spin_unlock_irqrestore(&mal->
lock, flags);
171 MAL_DBG(mal,
"disable_rx(%d)" NL, channel);
180 MAL_DBG(mal,
"poll_add(%p)" NL, commac);
187 spin_unlock_irqrestore(&mal->
lock, flags);
196 MAL_DBG(mal,
"poll_del(%p)" NL, commac);
200 spin_unlock_irqrestore(&mal->
lock, flags);
204 static inline void mal_enable_eob_irq(
struct mal_instance *mal)
213 static inline void mal_disable_eob_irq(
struct mal_instance *mal)
221 static irqreturn_t mal_serr(
int irq,
void *dev_instance)
228 set_mal_dcrn(mal,
MAL_ESR, esr);
230 MAL_DBG(mal,
"SERR %08x" NL, esr);
246 "mal%d: system error, "
247 "PLB (ESR = 0x%08x)\n",
257 "mal%d: system error, OPB (ESR = 0x%08x)\n",
263 static inline void mal_schedule_poll(
struct mal_instance *mal)
267 mal_disable_eob_irq(mal);
270 MAL_DBG2(mal,
"already in poll" NL);
273 static irqreturn_t mal_txeob(
int irq,
void *dev_instance)
281 mal_schedule_poll(mal);
284 #ifdef CONFIG_PPC_DCR_NATIVE
293 static irqreturn_t mal_rxeob(
int irq,
void *dev_instance)
301 mal_schedule_poll(mal);
304 #ifdef CONFIG_PPC_DCR_NATIVE
313 static irqreturn_t mal_txde(
int irq,
void *dev_instance)
320 MAL_DBG(mal,
"txde %08x" NL, deir);
324 "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n",
330 static irqreturn_t mal_rxde(
int irq,
void *dev_instance)
337 MAL_DBG(mal,
"rxde %08x" NL, deir);
347 mal_schedule_poll(mal);
353 static irqreturn_t mal_int(
int irq,
void *dev_instance)
358 if (esr & MAL_ESR_EVB) {
360 if (esr & MAL_ESR_DE) {
362 return mal_rxde(irq, dev_instance);
364 return mal_txde(irq, dev_instance);
366 return mal_serr(irq, dev_instance);
392 napi_schedule(&mal->
napi);
402 MAL_DBG2(mal,
"poll(%d)" NL, budget);
408 mc->
ops->poll_tx(mc->
dev);
422 n = mc->
ops->poll_rx(mc->
dev, budget);
434 mal_enable_eob_irq(mal);
435 spin_unlock_irqrestore(&mal->
lock, flags);
446 if (napi_reschedule(napi))
447 mal_disable_eob_irq(mal);
449 MAL_DBG2(mal,
"already in poll list" NL);
456 mc->
ops->poll_tx(mc->
dev);
460 MAL_DBG2(mal,
"poll() %d <- %d" NL, budget, received);
483 sizeof(struct mal_regs);
523 int err = 0,
i, bd_size;
524 int index = mal_count++;
525 unsigned int dcr_base;
528 unsigned long irqflags;
534 "mal%d: out of memory allocating MAL structure!\n",
547 "mal%d: can't find MAL num-tx-chans property!\n",
557 "mal%d: can't find MAL num-rx-chans property!\n",
567 "mal%d: can't find DCR resource!\n", index);
571 mal->
dcr_host = dcr_map(ofdev->
dev.of_node, dcr_base, 0x100);
574 "mal%d: failed to map DCRs !\n", index);
580 #if defined(CONFIG_IBM_EMAC_MAL_CLR_ICINTSTAT) && \
581 defined(CONFIG_IBM_EMAC_MAL_COMMON_ERR)
586 ofdev->
dev.of_node->full_name);
607 "mal%d: failed to map interrupts !\n", index);
613 INIT_LIST_HEAD(&mal->
list);
619 CONFIG_IBM_EMAC_POLL_WEIGHT);
635 set_mal_dcrn(mal,
MAL_CFG, cfg);
649 "mal%d: out of memory allocating RX/TX descriptors!\n",
668 hdlr_serr = hdlr_txde = hdlr_rxde = mal_int;
671 hdlr_serr = mal_serr;
672 hdlr_txde = mal_txde;
673 hdlr_rxde = mal_rxde;
699 mal_enable_eob_irq(mal);
702 "MAL v%d %s, %d TX channels, %d RX channels\n",
739 napi_disable(&mal->
napi);
741 if (!list_empty(&mal->
list)) {
744 "mal%d: commac list is not empty on remove!\n",
774 .compatible =
"ibm,mcmal",
777 .compatible =
"ibm,mcmal2",
782 .compatible =
"ibm,mcmal",
786 .compatible =
"ibm,mcmal2",
795 .of_match_table = mal_platform_match,
798 .remove = mal_remove,