Lines Matching +full:no +full:- +full:pbl +full:- +full:x8

1 // SPDX-License-Identifier: GPL-2.0-or-later
12 * 1) RX Free Fifo - RXF - holds descriptors of empty buffers to accept incoming
16 * 2) RX Data Fifo - RXD - holds descriptors of full buffers. This Fifo is
23 * One holds 1.5K packets and another - 26K packets. Depending on incoming
30 * skb db - used to keep track of all skbs owned by SW and their dma addresses.
34 * fifo - keeps info about fifo's size and location, relevant HW registers,
42 * NIC sees that there is no RXF buffers and raises
45 * NAPI - interrupt-driven mixed with polling
46 * interrupt-driven only
48 * Interrupt-driven only flow is following. When buffer is ready, HW raises
107 nic->port_num == 1 ? "" : ", 2-Port"); in print_hw_id()
109 readl(nic->regs + SROM_VER), readl(nic->regs + FPGA_VER) & 0xFFF, in print_hw_id()
110 readl(nic->regs + FPGA_SEED), in print_hw_id()
117 pr_info("fw 0x%x\n", readl(nic->regs + FW_VER)); in print_fw_id()
123 BDX_NIC_NAME, (ndev->if_port == 0) ? 'A' : 'B'); in print_eth_id()
137 * bdx_fifo_init - create TX/RX descriptor fifo for host-NIC communication.
140 * @fsz_type: fifo size type: 0-4KB, 1-8KB, 2-16KB, 3-32KB
159 /* dma_alloc_coherent gives us 4k-aligned memory */ in bdx_fifo_init()
160 f->va = dma_alloc_coherent(&priv->pdev->dev, memsz + FIFO_EXTRA_SPACE, in bdx_fifo_init()
161 &f->da, GFP_ATOMIC); in bdx_fifo_init()
162 if (!f->va) { in bdx_fifo_init()
164 RET(-ENOMEM); in bdx_fifo_init()
166 f->reg_CFG0 = reg_CFG0; in bdx_fifo_init()
167 f->reg_CFG1 = reg_CFG1; in bdx_fifo_init()
168 f->reg_RPTR = reg_RPTR; in bdx_fifo_init()
169 f->reg_WPTR = reg_WPTR; in bdx_fifo_init()
170 f->rptr = 0; in bdx_fifo_init()
171 f->wptr = 0; in bdx_fifo_init()
172 f->memsz = memsz; in bdx_fifo_init()
173 f->size_mask = memsz - 1; in bdx_fifo_init()
174 WRITE_REG(priv, reg_CFG0, (u32) ((f->da & TX_RX_CFG0_BASE) | fsz_type)); in bdx_fifo_init()
175 WRITE_REG(priv, reg_CFG1, H32_64(f->da)); in bdx_fifo_init()
181 * bdx_fifo_free - free all resources used by fifo
188 if (f->va) { in bdx_fifo_free()
189 dma_free_coherent(&priv->pdev->dev, in bdx_fifo_free()
190 f->memsz + FIFO_EXTRA_SPACE, f->va, f->da); in bdx_fifo_free()
191 f->va = NULL; in bdx_fifo_free()
197 * bdx_link_changed - notifies OS about hw link state.
205 if (netif_carrier_ok(priv->ndev)) { in bdx_link_changed()
206 netif_stop_queue(priv->ndev); in bdx_link_changed()
207 netif_carrier_off(priv->ndev); in bdx_link_changed()
208 netdev_err(priv->ndev, "Link Down\n"); in bdx_link_changed()
211 if (!netif_carrier_ok(priv->ndev)) { in bdx_link_changed()
212 netif_wake_queue(priv->ndev); in bdx_link_changed()
213 netif_carrier_on(priv->ndev); in bdx_link_changed()
214 netdev_err(priv->ndev, "Link Up\n"); in bdx_link_changed()
222 bdx_rx_alloc_skbs(priv, &priv->rxf_fifo0); in bdx_isr_extra()
230 netdev_err(priv->ndev, "PCI-E Link Fault\n"); in bdx_isr_extra()
233 netdev_err(priv->ndev, "PCI-E Time Out\n"); in bdx_isr_extra()
238 * bdx_isr_napi - Interrupt Service Routine for Bordeaux NIC
242 * Return IRQ_NONE if it was not our interrupt, IRQ_HANDLED - otherwise
246 * RX_DESC - new packet has arrived and RXD fifo holds its descriptor
247 * RX_FREE - number of free Rx buffers in RXF fifo gets low
248 * TX_FREE - packet was transmited and RXF fifo holds its descriptor
268 if (likely(napi_schedule_prep(&priv->napi))) { in bdx_isr_napi()
269 __napi_schedule(&priv->napi); in bdx_isr_napi()
296 work_done = bdx_rx_receive(priv, &priv->rxd_fifo0, budget); in bdx_poll()
298 (priv->napi_stop++ >= 30)) { in bdx_poll()
299 DBG("rx poll is done. backing to isr-driven\n"); in bdx_poll()
303 priv->napi_stop = 0; in bdx_poll()
312 * bdx_fw_load - loads firmware to NIC
330 rc = request_firmware(&fw, "tehuti/bdx.bin", &priv->pdev->dev); in bdx_fw_load()
333 bdx_tx_push_desc_safe(priv, (char *)fw->data, fw->size); in bdx_fw_load()
343 rc = -EIO; in bdx_fw_load()
351 netdev_err(priv->ndev, "firmware loading failed\n"); in bdx_fw_load()
352 if (rc == -EIO) in bdx_fw_load()
359 DBG("%s: firmware loading success\n", priv->ndev->name); in bdx_fw_load()
373 val = (ndev->dev_addr[0] << 8) | (ndev->dev_addr[1]); in bdx_restore_mac()
375 val = (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]); in bdx_restore_mac()
377 val = (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]); in bdx_restore_mac()
387 * bdx_hw_start - inits registers and starts HW's Rx and Tx engines
392 int rc = -EIO; in bdx_hw_start()
393 struct net_device *ndev = priv->ndev; in bdx_hw_start()
410 priv->rxf_fifo0.m.pktsz & MAX_FRAME_AB_VAL); in bdx_hw_start()
412 DBG("RDINTCM=%08x\n", priv->rdintcm); /*NOTE: test script uses this */ in bdx_hw_start()
413 WRITE_REG(priv, regRDINTCM0, priv->rdintcm); in bdx_hw_start()
416 DBG("TDINTCM=%08x\n", priv->tdintcm); /*NOTE: test script uses this */ in bdx_hw_start()
417 WRITE_REG(priv, regTDINTCM0, priv->tdintcm); /* old val = 0x300064 */ in bdx_hw_start()
421 bdx_restore_mac(priv->ndev, priv); in bdx_hw_start()
426 #define BDX_IRQ_TYPE ((priv->nic->irq_type == IRQ_MSI) ? 0 : IRQF_SHARED) in bdx_hw_start()
428 rc = request_irq(priv->pdev->irq, bdx_isr_napi, BDX_IRQ_TYPE, in bdx_hw_start()
429 ndev->name, ndev); in bdx_hw_start()
444 free_irq(priv->pdev->irq, priv->ndev); in bdx_hw_stop()
446 netif_carrier_off(priv->ndev); in bdx_hw_stop()
447 netif_stop_queue(priv->ndev); in bdx_hw_stop()
459 writel((val | CLKPLL_SFTRST) + 0x8, regs + regCLKPLL); in bdx_hw_reset_direct()
467 /* do any PCI-E read transaction */ in bdx_hw_reset_direct()
480 if (priv->port == 0) { in bdx_hw_reset()
483 WRITE_REG(priv, regCLKPLL, (val | CLKPLL_SFTRST) + 0x8); in bdx_hw_reset()
491 /* do any PCI-E read transaction */ in bdx_hw_reset()
519 netdev_err(priv->ndev, "SW reset timeout. continuing anyway\n"); in bdx_sw_reset()
553 /* bdx_reset - performs right type of reset depending on hw type */
557 RET((priv->pdev->device == 0x3009) in bdx_reset()
563 * bdx_close - Disables a network interface
568 * The close entry point is called when an interface is de-activated
580 napi_disable(&priv->napi); in bdx_close()
590 * bdx_open - Called when a network interface is made active
610 netif_stop_queue(priv->ndev); in bdx_open()
617 bdx_rx_alloc_skbs(priv, &priv->rxf_fifo0); in bdx_open()
623 napi_enable(&priv->napi); in bdx_open()
625 print_fw_id(priv->nic); in bdx_open()
636 return (offset > (u32) (BDX_REGS_SIZE / priv->nic->port_num)) ? in bdx_range_check()
637 -EINVAL : 0; in bdx_range_check()
654 RET(-EFAULT); in bdx_siocdevprivate()
658 return -EOPNOTSUPP; in bdx_siocdevprivate()
662 return -EPERM; in bdx_siocdevprivate()
675 RET(-EFAULT); in bdx_siocdevprivate()
687 RET(-EOPNOTSUPP); in bdx_siocdevprivate()
693 * __bdx_vlan_rx_vid - private helper for adding/killing VLAN vid
725 * bdx_vlan_rx_add_vid - kernel hook for adding VLAN vid to hw filtering table
737 * bdx_vlan_rx_kill_vid - kernel hook for killing VLAN vid in hw filtering table
749 * bdx_change_mtu - Change the Maximum Transfer Unit
759 WRITE_ONCE(ndev->mtu, new_mtu); in bdx_change_mtu()
776 /* IMF - imperfect (hash) rx multicat filter */ in bdx_setmulti()
777 /* PMF - perfect rx multicat filter */ in bdx_setmulti()
780 if (ndev->flags & IFF_PROMISC) { in bdx_setmulti()
782 } else if (ndev->flags & IFF_ALLMULTI) { in bdx_setmulti()
808 hash ^= ha->addr[i]; in bdx_setmulti()
833 return -EBUSY in bdx_set_mac()
835 eth_hw_addr_set(ndev, addr->sa_data); in bdx_set_mac()
856 eth_hw_addr_set(priv->ndev, addr); in bdx_read_mac()
869 /*Do the statistics-update work*/
872 struct bdx_stats *stats = &priv->hw_stats; in bdx_update_stats()
879 /*First 12 statistics - 0x7200 - 0x72B0 */ in bdx_update_stats()
885 /* 0x72C0-0x72E0 RSRV */ in bdx_update_stats()
892 /* 0x7330-0x7360 RSRV */ in bdx_update_stats()
899 /* 0x73A0-0x73B0 RSRV */ in bdx_update_stats()
931 db->stack = (int *)(db + 1); in bdx_rxdb_create()
932 db->elems = (void *)(db->stack + nelem); in bdx_rxdb_create()
933 db->nelem = nelem; in bdx_rxdb_create()
934 db->top = nelem; in bdx_rxdb_create()
936 db->stack[i] = nelem - i - 1; /* to make first allocs in bdx_rxdb_create()
945 BDX_ASSERT(db->top <= 0); in bdx_rxdb_alloc_elem()
946 return db->stack[--(db->top)]; in bdx_rxdb_alloc_elem()
951 BDX_ASSERT((n < 0) || (n >= db->nelem)); in bdx_rxdb_addr_elem()
952 return db->elems + n; in bdx_rxdb_addr_elem()
957 return db->top; in bdx_rxdb_available()
962 BDX_ASSERT((n >= db->nelem) || (n < 0)); in bdx_rxdb_free_elem()
963 db->stack[(db->top)++] = n; in bdx_rxdb_free_elem()
971 * bdx_rx_init - initialize RX all related HW and SW resources
982 * cousing interrupt. Anyway, in that condition, host has no chance to process
992 if (bdx_fifo_init(priv, &priv->rxd_fifo0.m, priv->rxd_size, in bdx_rx_init()
996 if (bdx_fifo_init(priv, &priv->rxf_fifo0.m, priv->rxf_size, in bdx_rx_init()
1000 priv->rxdb = bdx_rxdb_create(priv->rxf_fifo0.m.memsz / in bdx_rx_init()
1002 if (!priv->rxdb) in bdx_rx_init()
1005 priv->rxf_fifo0.m.pktsz = priv->ndev->mtu + VLAN_ETH_HLEN; in bdx_rx_init()
1009 netdev_err(priv->ndev, "Rx init failed\n"); in bdx_rx_init()
1010 return -ENOMEM; in bdx_rx_init()
1014 * bdx_rx_free_skbs - frees and unmaps all skbs allocated for the fifo
1021 struct rxdb *db = priv->rxdb; in bdx_rx_free_skbs()
1025 DBG("total=%d free=%d busy=%d\n", db->nelem, bdx_rxdb_available(db), in bdx_rx_free_skbs()
1026 db->nelem - bdx_rxdb_available(db)); in bdx_rx_free_skbs()
1030 dm->dma = 0; in bdx_rx_free_skbs()
1032 for (i = 0; i < db->nelem; i++) { in bdx_rx_free_skbs()
1034 if (dm->dma) { in bdx_rx_free_skbs()
1035 dma_unmap_single(&priv->pdev->dev, dm->dma, in bdx_rx_free_skbs()
1036 f->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_free_skbs()
1037 dev_kfree_skb(dm->skb); in bdx_rx_free_skbs()
1043 * bdx_rx_free - release all Rx resources
1051 if (priv->rxdb) { in bdx_rx_free()
1052 bdx_rx_free_skbs(priv, &priv->rxf_fifo0); in bdx_rx_free()
1053 bdx_rxdb_destroy(priv->rxdb); in bdx_rx_free()
1054 priv->rxdb = NULL; in bdx_rx_free()
1056 bdx_fifo_free(priv, &priv->rxf_fifo0.m); in bdx_rx_free()
1057 bdx_fifo_free(priv, &priv->rxd_fifo0.m); in bdx_rx_free()
1067 * bdx_rx_alloc_skbs - fill rxf fifo with new skbs
1077 /* TBD: do not update WPTR if no desc were written */
1085 struct rxdb *db = priv->rxdb; in bdx_rx_alloc_skbs()
1088 dno = bdx_rxdb_available(db) - 1; in bdx_rx_alloc_skbs()
1090 skb = netdev_alloc_skb(priv->ndev, f->m.pktsz + NET_IP_ALIGN); in bdx_rx_alloc_skbs()
1098 dm->dma = dma_map_single(&priv->pdev->dev, skb->data, in bdx_rx_alloc_skbs()
1099 f->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_alloc_skbs()
1100 dm->skb = skb; in bdx_rx_alloc_skbs()
1101 rxfd = (struct rxf_desc *)(f->m.va + f->m.wptr); in bdx_rx_alloc_skbs()
1102 rxfd->info = CPU_CHIP_SWAP32(0x10003); /* INFO=1 BC=3 */ in bdx_rx_alloc_skbs()
1103 rxfd->va_lo = idx; in bdx_rx_alloc_skbs()
1104 rxfd->pa_lo = CPU_CHIP_SWAP32(L32_64(dm->dma)); in bdx_rx_alloc_skbs()
1105 rxfd->pa_hi = CPU_CHIP_SWAP32(H32_64(dm->dma)); in bdx_rx_alloc_skbs()
1106 rxfd->len = CPU_CHIP_SWAP32(f->m.pktsz); in bdx_rx_alloc_skbs()
1109 f->m.wptr += sizeof(struct rxf_desc); in bdx_rx_alloc_skbs()
1110 delta = f->m.wptr - f->m.memsz; in bdx_rx_alloc_skbs()
1112 f->m.wptr = delta; in bdx_rx_alloc_skbs()
1114 memcpy(f->m.va, f->m.va + f->m.memsz, delta); in bdx_rx_alloc_skbs()
1118 dno--; in bdx_rx_alloc_skbs()
1120 /*TBD: to do - delayed rxf wptr like in txd */ in bdx_rx_alloc_skbs()
1121 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_rx_alloc_skbs()
1130 DBG("rxdd->flags.bits.vtag=%d\n", GET_RXD_VTAG(rxd_val1)); in NETIF_RX_MUX()
1133 priv->ndev->name, in NETIF_RX_MUX()
1151 f = &priv->rxf_fifo0; in bdx_recycle_skb()
1152 db = priv->rxdb; in bdx_recycle_skb()
1154 dm = bdx_rxdb_addr_elem(db, rxdd->va_lo); in bdx_recycle_skb()
1156 rxfd = (struct rxf_desc *)(f->m.va + f->m.wptr); in bdx_recycle_skb()
1157 rxfd->info = CPU_CHIP_SWAP32(0x10003); /* INFO=1 BC=3 */ in bdx_recycle_skb()
1158 rxfd->va_lo = rxdd->va_lo; in bdx_recycle_skb()
1159 rxfd->pa_lo = CPU_CHIP_SWAP32(L32_64(dm->dma)); in bdx_recycle_skb()
1160 rxfd->pa_hi = CPU_CHIP_SWAP32(H32_64(dm->dma)); in bdx_recycle_skb()
1161 rxfd->len = CPU_CHIP_SWAP32(f->m.pktsz); in bdx_recycle_skb()
1164 f->m.wptr += sizeof(struct rxf_desc); in bdx_recycle_skb()
1165 delta = f->m.wptr - f->m.memsz; in bdx_recycle_skb()
1167 f->m.wptr = delta; in bdx_recycle_skb()
1169 memcpy(f->m.va, f->m.va + f->m.memsz, delta); in bdx_recycle_skb()
1177 * bdx_rx_receive - receives full packets from RXD fifo and pass them to OS
1178 * NOTE: a special treatment is given to non-continuous descriptors
1191 struct net_device *ndev = priv->ndev; in bdx_rx_receive()
1200 /* Unmarshalled descriptor - copy of descriptor in host order */ in bdx_rx_receive()
1208 f->m.wptr = READ_REG(priv, f->m.reg_WPTR) & TXF_WPTR_WR_PTR; in bdx_rx_receive()
1210 size = f->m.wptr - f->m.rptr; in bdx_rx_receive()
1212 size = f->m.memsz + size; /* size is negative :-) */ in bdx_rx_receive()
1216 rxdd = (struct rxd_desc *)(f->m.va + f->m.rptr); in bdx_rx_receive()
1217 rxd_val1 = CPU_CHIP_SWAP32(rxdd->rxd_val1); in bdx_rx_receive()
1219 len = CPU_CHIP_SWAP16(rxdd->len); in bdx_rx_receive()
1221 rxd_vlan = CPU_CHIP_SWAP16(rxdd->rxd_vlan); in bdx_rx_receive()
1227 size -= tmp_len; in bdx_rx_receive()
1231 f->m.rptr += tmp_len; in bdx_rx_receive()
1233 tmp_len = f->m.rptr - f->m.memsz; in bdx_rx_receive()
1235 f->m.rptr = tmp_len; in bdx_rx_receive()
1238 f->m.rptr, tmp_len); in bdx_rx_receive()
1239 memcpy(f->m.va + f->m.memsz, f->m.va, tmp_len); in bdx_rx_receive()
1245 ndev->stats.rx_errors++; in bdx_rx_receive()
1250 rxf_fifo = &priv->rxf_fifo0; in bdx_rx_receive()
1251 db = priv->rxdb; in bdx_rx_receive()
1252 dm = bdx_rxdb_addr_elem(db, rxdd->va_lo); in bdx_rx_receive()
1253 skb = dm->skb; in bdx_rx_receive()
1256 (skb2 = netdev_alloc_skb(priv->ndev, len + NET_IP_ALIGN))) { in bdx_rx_receive()
1259 dma_sync_single_for_cpu(&priv->pdev->dev, dm->dma, in bdx_rx_receive()
1260 rxf_fifo->m.pktsz, in bdx_rx_receive()
1262 memcpy(skb2->data, skb->data, len); in bdx_rx_receive()
1266 dma_unmap_single(&priv->pdev->dev, dm->dma, in bdx_rx_receive()
1267 rxf_fifo->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_receive()
1268 bdx_rxdb_free_elem(db, rxdd->va_lo); in bdx_rx_receive()
1271 ndev->stats.rx_bytes += len; in bdx_rx_receive()
1274 skb->protocol = eth_type_trans(skb, ndev); in bdx_rx_receive()
1276 /* Non-IP packets aren't checksum-offloaded */ in bdx_rx_receive()
1280 skb->ip_summed = CHECKSUM_UNNECESSARY; in bdx_rx_receive()
1288 ndev->stats.rx_packets += done; in bdx_rx_receive()
1291 WRITE_REG(priv, f->m.reg_RPTR, f->m.rptr & TXF_WPTR_WR_PTR); in bdx_rx_receive()
1293 bdx_rx_alloc_skbs(priv, &priv->rxf_fifo0); in bdx_rx_receive()
1309 GET_RXD_CFI(rxd_vlan), GET_RXD_PRIO(rxd_vlan), rxdd->va_lo, in print_rxdd()
1310 rxdd->va_hi); in print_rxdd()
1317 rxfd->info, rxfd->va_lo, rxfd->pa_lo, rxfd->pa_hi, rxfd->len); in print_rxfd()
1324 * 1) TX Free Fifo - TXF - holds ack descriptors for sent packets
1325 * 2) TX Data Fifo - TXD - holds descriptors of full buffers.
1332 * txdb - used to keep track of all skbs owned by SW and their dma addresses.
1336 * fifo - keeps info about fifo's size and location, relevant HW registers,
1362 * __bdx_tx_db_ptr_next - helper function, increment read/write pointer + wrap
1370 BDX_ASSERT(*pptr != db->rptr && /* expect either read */ in __bdx_tx_db_ptr_next()
1371 *pptr != db->wptr); /* or write pointer */ in __bdx_tx_db_ptr_next()
1373 BDX_ASSERT(*pptr < db->start || /* pointer has to be */ in __bdx_tx_db_ptr_next()
1374 *pptr >= db->end); /* in range */ in __bdx_tx_db_ptr_next()
1377 if (unlikely(*pptr == db->end)) in __bdx_tx_db_ptr_next()
1378 *pptr = db->start; in __bdx_tx_db_ptr_next()
1382 * bdx_tx_db_inc_rptr - increment read pointer
1387 BDX_ASSERT(db->rptr == db->wptr); /* can't read from empty db */ in bdx_tx_db_inc_rptr()
1388 __bdx_tx_db_ptr_next(db, &db->rptr); in bdx_tx_db_inc_rptr()
1392 * bdx_tx_db_inc_wptr - increment write pointer
1397 __bdx_tx_db_ptr_next(db, &db->wptr); in bdx_tx_db_inc_wptr()
1398 BDX_ASSERT(db->rptr == db->wptr); /* we can not get empty db as in bdx_tx_db_inc_wptr()
1403 * bdx_tx_db_init - creates and initializes tx db
1413 d->start = vmalloc(memsz); in bdx_tx_db_init()
1414 if (!d->start) in bdx_tx_db_init()
1415 return -ENOMEM; in bdx_tx_db_init()
1422 d->size = memsz / sizeof(struct tx_map) - 1; in bdx_tx_db_init()
1423 d->end = d->start + d->size + 1; /* just after last element */ in bdx_tx_db_init()
1426 d->rptr = d->start; in bdx_tx_db_init()
1427 d->wptr = d->start; in bdx_tx_db_init()
1433 * bdx_tx_db_close - closes tx db and frees all memory
1440 vfree(d->start); in bdx_tx_db_close()
1441 d->start = NULL; in bdx_tx_db_close()
1456 * bdx_tx_map_skb - creates and stores dma mappings for skb's data blocks
1461 * It makes dma mappings for skb's data blocks and writes them to PBL of
1471 struct txdb *db = &priv->txdb; in bdx_tx_map_skb()
1472 struct pbl *pbl = &txdd->pbl[0]; in bdx_tx_map_skb() local
1473 int nr_frags = skb_shinfo(skb)->nr_frags; in bdx_tx_map_skb()
1476 db->wptr->len = skb_headlen(skb); in bdx_tx_map_skb()
1477 db->wptr->addr.dma = dma_map_single(&priv->pdev->dev, skb->data, in bdx_tx_map_skb()
1478 db->wptr->len, DMA_TO_DEVICE); in bdx_tx_map_skb()
1479 pbl->len = CPU_CHIP_SWAP32(db->wptr->len); in bdx_tx_map_skb()
1480 pbl->pa_lo = CPU_CHIP_SWAP32(L32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1481 pbl->pa_hi = CPU_CHIP_SWAP32(H32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1482 DBG("=== pbl len: 0x%x ================\n", pbl->len); in bdx_tx_map_skb()
1483 DBG("=== pbl pa_lo: 0x%x ================\n", pbl->pa_lo); in bdx_tx_map_skb()
1484 DBG("=== pbl pa_hi: 0x%x ================\n", pbl->pa_hi); in bdx_tx_map_skb()
1490 frag = &skb_shinfo(skb)->frags[i]; in bdx_tx_map_skb()
1491 db->wptr->len = skb_frag_size(frag); in bdx_tx_map_skb()
1492 db->wptr->addr.dma = skb_frag_dma_map(&priv->pdev->dev, frag, in bdx_tx_map_skb()
1496 pbl++; in bdx_tx_map_skb()
1497 pbl->len = CPU_CHIP_SWAP32(db->wptr->len); in bdx_tx_map_skb()
1498 pbl->pa_lo = CPU_CHIP_SWAP32(L32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1499 pbl->pa_hi = CPU_CHIP_SWAP32(H32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1504 db->wptr->len = -txd_sizes[nr_frags].bytes; in bdx_tx_map_skb()
1505 db->wptr->addr.skb = skb; in bdx_tx_map_skb()
1509 /* init_txd_sizes - precalculate sizes of descriptors for skbs up to 16 frags
1516 /* 7 - is number of lwords in txd with one phys buffer in init_txd_sizes()
1517 * 3 - is number of lwords used for every additional phys buffer */ in init_txd_sizes()
1527 /* bdx_tx_init - initialize all Tx related stuff.
1531 if (bdx_fifo_init(priv, &priv->txd_fifo0.m, priv->txd_size, in bdx_tx_init()
1535 if (bdx_fifo_init(priv, &priv->txf_fifo0.m, priv->txf_size, in bdx_tx_init()
1542 if (bdx_tx_db_init(&priv->txdb, max(priv->txd_size, priv->txf_size))) in bdx_tx_init()
1545 priv->tx_level = BDX_MAX_TX_LEVEL; in bdx_tx_init()
1547 priv->tx_update_mark = priv->tx_level - 1024; in bdx_tx_init()
1552 netdev_err(priv->ndev, "Tx init failed\n"); in bdx_tx_init()
1553 return -ENOMEM; in bdx_tx_init()
1557 * bdx_tx_space - calculates available space in TX fifo
1564 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_space()
1567 f->m.rptr = READ_REG(priv, f->m.reg_RPTR) & TXF_WPTR_WR_PTR; in bdx_tx_space()
1568 fsize = f->m.rptr - f->m.wptr; in bdx_tx_space()
1570 fsize = f->m.memsz + fsize; in bdx_tx_space()
1575 * bdx_tx_transmit - send packet to NIC
1588 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_transmit()
1595 int nr_frags = skb_shinfo(skb)->nr_frags; in bdx_tx_transmit()
1602 spin_lock(&priv->tx_lock); in bdx_tx_transmit()
1605 BDX_ASSERT(f->m.wptr >= f->m.memsz); /* started with valid wptr */ in bdx_tx_transmit()
1606 txdd = (struct txd_desc *)(f->m.va + f->m.wptr); in bdx_tx_transmit()
1607 if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) in bdx_tx_transmit()
1610 if (skb_shinfo(skb)->gso_size) { in bdx_tx_transmit()
1611 txd_mss = skb_shinfo(skb)->gso_size; in bdx_tx_transmit()
1613 DBG("skb %p skb len %d gso size = %d\n", skb, skb->len, in bdx_tx_transmit()
1623 txdd->length = CPU_CHIP_SWAP16(skb->len); in bdx_tx_transmit()
1624 txdd->mss = CPU_CHIP_SWAP16(txd_mss); in bdx_tx_transmit()
1625 txdd->txd_val1 = in bdx_tx_transmit()
1630 DBG("=== w1: 0x%x ================\n", txdd->txd_val1); in bdx_tx_transmit()
1631 DBG("=== w2: mss 0x%x len 0x%x\n", txdd->mss, txdd->length); in bdx_tx_transmit()
1638 f->m.wptr += txd_sizes[nr_frags].bytes; in bdx_tx_transmit()
1639 len = f->m.wptr - f->m.memsz; in bdx_tx_transmit()
1641 f->m.wptr = len; in bdx_tx_transmit()
1643 BDX_ASSERT(len > f->m.memsz); in bdx_tx_transmit()
1644 memcpy(f->m.va, f->m.va + f->m.memsz, len); in bdx_tx_transmit()
1647 BDX_ASSERT(f->m.wptr >= f->m.memsz); /* finished with valid wptr */ in bdx_tx_transmit()
1649 priv->tx_level -= txd_sizes[nr_frags].bytes; in bdx_tx_transmit()
1650 BDX_ASSERT(priv->tx_level <= 0 || priv->tx_level > BDX_MAX_TX_LEVEL); in bdx_tx_transmit()
1652 if (priv->tx_level > priv->tx_update_mark) { in bdx_tx_transmit()
1657 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1659 if (priv->tx_noupd++ > BDX_NO_UPD_PACKETS) { in bdx_tx_transmit()
1660 priv->tx_noupd = 0; in bdx_tx_transmit()
1661 WRITE_REG(priv, f->m.reg_WPTR, in bdx_tx_transmit()
1662 f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1670 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1674 netif_trans_update(ndev); /* dev->lltx driver :( */ in bdx_tx_transmit()
1676 ndev->stats.tx_packets++; in bdx_tx_transmit()
1677 ndev->stats.tx_bytes += skb->len; in bdx_tx_transmit()
1679 if (priv->tx_level < BDX_MIN_TX_LEVEL) { in bdx_tx_transmit()
1681 BDX_DRV_NAME, ndev->name, priv->tx_level); in bdx_tx_transmit()
1685 spin_unlock_irqrestore(&priv->tx_lock, flags); in bdx_tx_transmit()
1690 * bdx_tx_cleanup - clean TXF fifo, run in the context of IRQ.
1698 struct txf_fifo *f = &priv->txf_fifo0; in bdx_tx_cleanup()
1699 struct txdb *db = &priv->txdb; in bdx_tx_cleanup()
1703 f->m.wptr = READ_REG(priv, f->m.reg_WPTR) & TXF_WPTR_MASK; in bdx_tx_cleanup()
1704 BDX_ASSERT(f->m.rptr >= f->m.memsz); /* started with valid rptr */ in bdx_tx_cleanup()
1706 while (f->m.wptr != f->m.rptr) { in bdx_tx_cleanup()
1707 f->m.rptr += BDX_TXF_DESC_SZ; in bdx_tx_cleanup()
1708 f->m.rptr &= f->m.size_mask; in bdx_tx_cleanup()
1712 BDX_ASSERT(db->rptr->len == 0); in bdx_tx_cleanup()
1714 BDX_ASSERT(db->rptr->addr.dma == 0); in bdx_tx_cleanup()
1715 dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, in bdx_tx_cleanup()
1716 db->rptr->len, DMA_TO_DEVICE); in bdx_tx_cleanup()
1718 } while (db->rptr->len > 0); in bdx_tx_cleanup()
1719 tx_level -= db->rptr->len; /* '-' koz len is negative */ in bdx_tx_cleanup()
1721 /* now should come skb pointer - free it */ in bdx_tx_cleanup()
1722 dev_consume_skb_irq(db->rptr->addr.skb); in bdx_tx_cleanup()
1727 BDX_ASSERT((f->m.wptr & TXF_WPTR_WR_PTR) >= f->m.memsz); in bdx_tx_cleanup()
1728 WRITE_REG(priv, f->m.reg_RPTR, f->m.rptr & TXF_WPTR_WR_PTR); in bdx_tx_cleanup()
1732 spin_lock(&priv->tx_lock); in bdx_tx_cleanup()
1733 priv->tx_level += tx_level; in bdx_tx_cleanup()
1734 BDX_ASSERT(priv->tx_level <= 0 || priv->tx_level > BDX_MAX_TX_LEVEL); in bdx_tx_cleanup()
1736 if (priv->tx_noupd) { in bdx_tx_cleanup()
1737 priv->tx_noupd = 0; in bdx_tx_cleanup()
1738 WRITE_REG(priv, priv->txd_fifo0.m.reg_WPTR, in bdx_tx_cleanup()
1739 priv->txd_fifo0.m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_cleanup()
1743 if (unlikely(netif_queue_stopped(priv->ndev) && in bdx_tx_cleanup()
1744 netif_carrier_ok(priv->ndev) && in bdx_tx_cleanup()
1745 (priv->tx_level >= BDX_MIN_TX_LEVEL))) { in bdx_tx_cleanup()
1747 BDX_DRV_NAME, priv->ndev->name, priv->tx_level); in bdx_tx_cleanup()
1748 netif_wake_queue(priv->ndev); in bdx_tx_cleanup()
1750 spin_unlock(&priv->tx_lock); in bdx_tx_cleanup()
1754 * bdx_tx_free_skbs - frees all skbs from TXD fifo.
1761 struct txdb *db = &priv->txdb; in bdx_tx_free_skbs()
1764 while (db->rptr != db->wptr) { in bdx_tx_free_skbs()
1765 if (likely(db->rptr->len)) in bdx_tx_free_skbs()
1766 dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, in bdx_tx_free_skbs()
1767 db->rptr->len, DMA_TO_DEVICE); in bdx_tx_free_skbs()
1769 dev_kfree_skb(db->rptr->addr.skb); in bdx_tx_free_skbs()
1775 /* bdx_tx_free - frees all Tx resources */
1780 bdx_fifo_free(priv, &priv->txd_fifo0.m); in bdx_tx_free()
1781 bdx_fifo_free(priv, &priv->txf_fifo0.m); in bdx_tx_free()
1782 bdx_tx_db_close(&priv->txdb); in bdx_tx_free()
1786 * bdx_tx_push_desc - push descriptor to TxD fifo
1798 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_push_desc()
1799 int i = f->m.memsz - f->m.wptr; in bdx_tx_push_desc()
1805 memcpy(f->m.va + f->m.wptr, data, size); in bdx_tx_push_desc()
1806 f->m.wptr += size; in bdx_tx_push_desc()
1808 memcpy(f->m.va + f->m.wptr, data, i); in bdx_tx_push_desc()
1809 f->m.wptr = size - i; in bdx_tx_push_desc()
1810 memcpy(f->m.va, data + i, f->m.wptr); in bdx_tx_push_desc()
1812 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_push_desc()
1816 * bdx_tx_push_desc_safe - push descriptor to TxD fifo in a safe way
1833 int avail = bdx_tx_space(priv) - 8; in bdx_tx_push_desc_safe()
1846 size -= avail; in bdx_tx_push_desc_safe()
1866 * bdx_probe - Device Initialization Routine
1877 * /usr/src/linux/Documentation/DMA-{API,mapping}.txt
1896 RET(-ENOMEM); in bdx_probe()
1903 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in bdx_probe()
1905 pr_err("No usable DMA configuration, aborting\n"); in bdx_probe()
1917 err = -EIO; in bdx_probe()
1918 pr_err("no MMIO resource\n"); in bdx_probe()
1923 err = -EIO; in bdx_probe()
1928 nic->regs = ioremap(pciaddr, regionSize); in bdx_probe()
1929 if (!nic->regs) { in bdx_probe()
1930 err = -EIO; in bdx_probe()
1935 if (pdev->irq < 2) { in bdx_probe()
1936 err = -EIO; in bdx_probe()
1937 pr_err("invalid irq (%d)\n", pdev->irq); in bdx_probe()
1942 if (pdev->device == 0x3014) in bdx_probe()
1943 nic->port_num = 2; in bdx_probe()
1945 nic->port_num = 1; in bdx_probe()
1949 bdx_hw_reset_direct(nic->regs); in bdx_probe()
1951 nic->irq_type = IRQ_INTX; in bdx_probe()
1953 if ((readl(nic->regs + FPGA_VER) & 0xFFF) >= 378) { in bdx_probe()
1958 nic->irq_type = IRQ_MSI; in bdx_probe()
1964 for (port = 0; port < nic->port_num; port++) { in bdx_probe()
1967 err = -ENOMEM; in bdx_probe()
1971 ndev->netdev_ops = &bdx_netdev_ops; in bdx_probe()
1972 ndev->tx_queue_len = BDX_NDEV_TXQ_LEN; in bdx_probe()
1978 ndev->if_port = port; in bdx_probe()
1979 ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO | in bdx_probe()
1984 ndev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | in bdx_probe()
1988 priv = nic->priv[port] = netdev_priv(ndev); in bdx_probe()
1990 priv->pBdxRegs = nic->regs + port * 0x8000; in bdx_probe()
1991 priv->port = port; in bdx_probe()
1992 priv->pdev = pdev; in bdx_probe()
1993 priv->ndev = ndev; in bdx_probe()
1994 priv->nic = nic; in bdx_probe()
1995 priv->msg_enable = BDX_DEF_MSG_ENABLE; in bdx_probe()
1997 netif_napi_add(ndev, &priv->napi, bdx_poll); in bdx_probe()
1999 if ((readl(nic->regs + FPGA_VER) & 0xFFF) == 308) { in bdx_probe()
2001 priv->stats_flag = 0; in bdx_probe()
2003 priv->stats_flag = 1; in bdx_probe()
2007 priv->txd_size = 2; in bdx_probe()
2008 priv->txf_size = 2; in bdx_probe()
2009 priv->rxd_size = 2; in bdx_probe()
2010 priv->rxf_size = 3; in bdx_probe()
2013 priv->rdintcm = INT_REG_VAL(0x20, 1, 4, 12); in bdx_probe()
2014 priv->tdintcm = INT_REG_VAL(0x20, 1, 0, 12); in bdx_probe()
2016 /* ndev->xmit_lock spinlock is not used. in bdx_probe()
2017 * Private priv->tx_lock is used for synchronization in bdx_probe()
2019 * set multicast list callback has to use priv->tx_lock. in bdx_probe()
2022 ndev->lltx = true; in bdx_probe()
2024 /* MTU range: 60 - 16384 */ in bdx_probe()
2025 ndev->min_mtu = ETH_ZLEN; in bdx_probe()
2026 ndev->max_mtu = BDX_MAX_MTU; in bdx_probe()
2028 spin_lock_init(&priv->tx_lock); in bdx_probe()
2033 err = -EFAULT; in bdx_probe()
2036 SET_NETDEV_DEV(ndev, &pdev->dev); in bdx_probe()
2052 iounmap(nic->regs); in bdx_probe()
2080 /* 0x72C0-0x72E0 RSRV */
2087 /* 0x7330-0x7360 RSRV */
2093 /* 0x73A0-0x73B0 RSRV */
2102 * bdx_get_link_ksettings - get device-specific settings
2118 ecmd->base.speed = SPEED_10000; in bdx_get_link_ksettings()
2119 ecmd->base.duplex = DUPLEX_FULL; in bdx_get_link_ksettings()
2120 ecmd->base.port = PORT_FIBRE; in bdx_get_link_ksettings()
2121 ecmd->base.autoneg = AUTONEG_DISABLE; in bdx_get_link_ksettings()
2127 * bdx_get_drvinfo - report driver information
2136 strscpy(drvinfo->driver, BDX_DRV_NAME, sizeof(drvinfo->driver)); in bdx_get_drvinfo()
2137 strscpy(drvinfo->version, BDX_DRV_VERSION, sizeof(drvinfo->version)); in bdx_get_drvinfo()
2138 strscpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); in bdx_get_drvinfo()
2139 strscpy(drvinfo->bus_info, pci_name(priv->pdev), in bdx_get_drvinfo()
2140 sizeof(drvinfo->bus_info)); in bdx_get_drvinfo()
2144 * bdx_get_coalesce - get interrupt coalescing parameters
2157 rdintcm = priv->rdintcm; in bdx_get_coalesce()
2158 tdintcm = priv->tdintcm; in bdx_get_coalesce()
2162 ecoal->rx_coalesce_usecs = GET_INT_COAL(rdintcm) * INT_COAL_MULT; in bdx_get_coalesce()
2163 ecoal->rx_max_coalesced_frames = in bdx_get_coalesce()
2166 ecoal->tx_coalesce_usecs = GET_INT_COAL(tdintcm) * INT_COAL_MULT; in bdx_get_coalesce()
2167 ecoal->tx_max_coalesced_frames = in bdx_get_coalesce()
2175 * bdx_set_coalesce - set interrupt coalescing parameters
2193 rx_coal = ecoal->rx_coalesce_usecs / INT_COAL_MULT; in bdx_set_coalesce()
2194 tx_coal = ecoal->tx_coalesce_usecs / INT_COAL_MULT; in bdx_set_coalesce()
2195 rx_max_coal = ecoal->rx_max_coalesced_frames; in bdx_set_coalesce()
2196 tx_max_coal = ecoal->tx_max_coalesced_frames; in bdx_set_coalesce()
2200 (((rx_max_coal * sizeof(struct rxf_desc)) + PCK_TH_MULT - 1) in bdx_set_coalesce()
2203 (((tx_max_coal * BDX_TXF_DESC_SZ) + PCK_TH_MULT - 1) in bdx_set_coalesce()
2208 return -EINVAL; in bdx_set_coalesce()
2210 rdintcm = INT_REG_VAL(rx_coal, GET_INT_COAL_RC(priv->rdintcm), in bdx_set_coalesce()
2211 GET_RXF_TH(priv->rdintcm), rx_max_coal); in bdx_set_coalesce()
2212 tdintcm = INT_REG_VAL(tx_coal, GET_INT_COAL_RC(priv->tdintcm), 0, in bdx_set_coalesce()
2215 priv->rdintcm = rdintcm; in bdx_set_coalesce()
2216 priv->tdintcm = tdintcm; in bdx_set_coalesce()
2237 * bdx_get_ringparam - report ring sizes
2250 /*max_pending - the maximum-sized FIFO we allow */ in bdx_get_ringparam()
2251 ring->rx_max_pending = bdx_rx_fifo_size_to_packets(3); in bdx_get_ringparam()
2252 ring->tx_max_pending = bdx_tx_fifo_size_to_packets(3); in bdx_get_ringparam()
2253 ring->rx_pending = bdx_rx_fifo_size_to_packets(priv->rxf_size); in bdx_get_ringparam()
2254 ring->tx_pending = bdx_tx_fifo_size_to_packets(priv->txd_size); in bdx_get_ringparam()
2258 * bdx_set_ringparam - set ring sizes
2274 if (bdx_rx_fifo_size_to_packets(rx_size) >= ring->rx_pending) in bdx_set_ringparam()
2281 if (bdx_tx_fifo_size_to_packets(tx_size) >= ring->tx_pending) in bdx_set_ringparam()
2288 if ((rx_size == priv->rxf_size) && in bdx_set_ringparam()
2289 (tx_size == priv->txd_size)) in bdx_set_ringparam()
2292 priv->rxf_size = rx_size; in bdx_set_ringparam()
2294 priv->rxd_size = rx_size - 1; in bdx_set_ringparam()
2296 priv->rxd_size = rx_size; in bdx_set_ringparam()
2298 priv->txf_size = priv->txd_size = tx_size; in bdx_set_ringparam()
2308 * bdx_get_strings - return a set of strings that describe the requested objects
2322 * bdx_get_sset_count - return number of statistics or tests
2333 return (priv->stats_flag) ? ARRAY_SIZE(bdx_stat_names) : 0; in bdx_get_sset_count()
2336 return -EINVAL; in bdx_get_sset_count()
2340 * bdx_get_ethtool_stats - return device's hardware L2 statistics
2350 if (priv->stats_flag) { in bdx_get_ethtool_stats()
2356 memcpy(data, &priv->hw_stats, sizeof(priv->hw_stats)); in bdx_get_ethtool_stats()
2361 * bdx_set_ethtool_ops - ethtool interface implementation
2381 netdev->ethtool_ops = &bdx_ethtool_ops; in bdx_set_ethtool_ops()
2385 * bdx_remove - Device Removal Routine
2390 * Hot-Plug event, or because the driver is going to be removed from
2399 for (port = 0; port < nic->port_num; port++) { in bdx_remove()
2400 ndev = nic->priv[port]->ndev; in bdx_remove()
2405 /*bdx_hw_reset_direct(nic->regs); */ in bdx_remove()
2407 if (nic->irq_type == IRQ_MSI) in bdx_remove()
2411 iounmap(nic->regs); in bdx_remove()
2427 * print_driver_id - print parameters of the driver build