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()
650 error = copy_from_user(data, ifr->ifr_data, sizeof(data)); in bdx_ioctl_priv()
653 RET(-EFAULT); in bdx_ioctl_priv()
657 return -EOPNOTSUPP; in bdx_ioctl_priv()
661 return -EPERM; in bdx_ioctl_priv()
672 error = copy_to_user(ifr->ifr_data, data, sizeof(data)); in bdx_ioctl_priv()
674 RET(-EFAULT); in bdx_ioctl_priv()
686 RET(-EOPNOTSUPP); in bdx_ioctl_priv()
697 RET(-EOPNOTSUPP); in bdx_ioctl()
701 * __bdx_vlan_rx_vid - private helper for adding/killing VLAN vid
733 * bdx_vlan_rx_add_vid - kernel hook for adding VLAN vid to hw filtering table
745 * bdx_vlan_rx_kill_vid - kernel hook for killing VLAN vid in hw filtering table
757 * bdx_change_mtu - Change the Maximum Transfer Unit
767 ndev->mtu = new_mtu; in bdx_change_mtu()
784 /* IMF - imperfect (hash) rx multicat filter */ in bdx_setmulti()
785 /* PMF - perfect rx multicat filter */ in bdx_setmulti()
788 if (ndev->flags & IFF_PROMISC) { in bdx_setmulti()
790 } else if (ndev->flags & IFF_ALLMULTI) { in bdx_setmulti()
816 hash ^= ha->addr[i]; in bdx_setmulti()
841 return -EBUSY in bdx_set_mac()
843 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len); in bdx_set_mac()
860 priv->ndev->dev_addr[i * 2 + 1] = macAddress[i]; in bdx_read_mac()
861 priv->ndev->dev_addr[i * 2] = macAddress[i] >> 8; in bdx_read_mac()
875 /*Do the statistics-update work*/
878 struct bdx_stats *stats = &priv->hw_stats; in bdx_update_stats()
885 /*First 12 statistics - 0x7200 - 0x72B0 */ in bdx_update_stats()
891 /* 0x72C0-0x72E0 RSRV */ in bdx_update_stats()
898 /* 0x7330-0x7360 RSRV */ in bdx_update_stats()
905 /* 0x73A0-0x73B0 RSRV */ in bdx_update_stats()
937 db->stack = (int *)(db + 1); in bdx_rxdb_create()
938 db->elems = (void *)(db->stack + nelem); in bdx_rxdb_create()
939 db->nelem = nelem; in bdx_rxdb_create()
940 db->top = nelem; in bdx_rxdb_create()
942 db->stack[i] = nelem - i - 1; /* to make first allocs in bdx_rxdb_create()
951 BDX_ASSERT(db->top <= 0); in bdx_rxdb_alloc_elem()
952 return db->stack[--(db->top)]; in bdx_rxdb_alloc_elem()
957 BDX_ASSERT((n < 0) || (n >= db->nelem)); in bdx_rxdb_addr_elem()
958 return db->elems + n; in bdx_rxdb_addr_elem()
963 return db->top; in bdx_rxdb_available()
968 BDX_ASSERT((n >= db->nelem) || (n < 0)); in bdx_rxdb_free_elem()
969 db->stack[(db->top)++] = n; in bdx_rxdb_free_elem()
977 * bdx_rx_init - initialize RX all related HW and SW resources
988 * cousing interrupt. Anyway, in that condition, host has no chance to process
998 if (bdx_fifo_init(priv, &priv->rxd_fifo0.m, priv->rxd_size, in bdx_rx_init()
1002 if (bdx_fifo_init(priv, &priv->rxf_fifo0.m, priv->rxf_size, in bdx_rx_init()
1006 priv->rxdb = bdx_rxdb_create(priv->rxf_fifo0.m.memsz / in bdx_rx_init()
1008 if (!priv->rxdb) in bdx_rx_init()
1011 priv->rxf_fifo0.m.pktsz = priv->ndev->mtu + VLAN_ETH_HLEN; in bdx_rx_init()
1015 netdev_err(priv->ndev, "Rx init failed\n"); in bdx_rx_init()
1016 return -ENOMEM; in bdx_rx_init()
1020 * bdx_rx_free_skbs - frees and unmaps all skbs allocated for the fifo
1027 struct rxdb *db = priv->rxdb; in bdx_rx_free_skbs()
1031 DBG("total=%d free=%d busy=%d\n", db->nelem, bdx_rxdb_available(db), in bdx_rx_free_skbs()
1032 db->nelem - bdx_rxdb_available(db)); in bdx_rx_free_skbs()
1036 dm->dma = 0; in bdx_rx_free_skbs()
1038 for (i = 0; i < db->nelem; i++) { in bdx_rx_free_skbs()
1040 if (dm->dma) { in bdx_rx_free_skbs()
1041 dma_unmap_single(&priv->pdev->dev, dm->dma, in bdx_rx_free_skbs()
1042 f->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_free_skbs()
1043 dev_kfree_skb(dm->skb); in bdx_rx_free_skbs()
1049 * bdx_rx_free - release all Rx resources
1057 if (priv->rxdb) { in bdx_rx_free()
1058 bdx_rx_free_skbs(priv, &priv->rxf_fifo0); in bdx_rx_free()
1059 bdx_rxdb_destroy(priv->rxdb); in bdx_rx_free()
1060 priv->rxdb = NULL; in bdx_rx_free()
1062 bdx_fifo_free(priv, &priv->rxf_fifo0.m); in bdx_rx_free()
1063 bdx_fifo_free(priv, &priv->rxd_fifo0.m); in bdx_rx_free()
1073 * bdx_rx_alloc_skbs - fill rxf fifo with new skbs
1083 /* TBD: do not update WPTR if no desc were written */
1091 struct rxdb *db = priv->rxdb; in bdx_rx_alloc_skbs()
1094 dno = bdx_rxdb_available(db) - 1; in bdx_rx_alloc_skbs()
1096 skb = netdev_alloc_skb(priv->ndev, f->m.pktsz + NET_IP_ALIGN); in bdx_rx_alloc_skbs()
1104 dm->dma = dma_map_single(&priv->pdev->dev, skb->data, in bdx_rx_alloc_skbs()
1105 f->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_alloc_skbs()
1106 dm->skb = skb; in bdx_rx_alloc_skbs()
1107 rxfd = (struct rxf_desc *)(f->m.va + f->m.wptr); in bdx_rx_alloc_skbs()
1108 rxfd->info = CPU_CHIP_SWAP32(0x10003); /* INFO=1 BC=3 */ in bdx_rx_alloc_skbs()
1109 rxfd->va_lo = idx; in bdx_rx_alloc_skbs()
1110 rxfd->pa_lo = CPU_CHIP_SWAP32(L32_64(dm->dma)); in bdx_rx_alloc_skbs()
1111 rxfd->pa_hi = CPU_CHIP_SWAP32(H32_64(dm->dma)); in bdx_rx_alloc_skbs()
1112 rxfd->len = CPU_CHIP_SWAP32(f->m.pktsz); in bdx_rx_alloc_skbs()
1115 f->m.wptr += sizeof(struct rxf_desc); in bdx_rx_alloc_skbs()
1116 delta = f->m.wptr - f->m.memsz; in bdx_rx_alloc_skbs()
1118 f->m.wptr = delta; in bdx_rx_alloc_skbs()
1120 memcpy(f->m.va, f->m.va + f->m.memsz, delta); in bdx_rx_alloc_skbs()
1124 dno--; in bdx_rx_alloc_skbs()
1126 /*TBD: to do - delayed rxf wptr like in txd */ in bdx_rx_alloc_skbs()
1127 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_rx_alloc_skbs()
1136 DBG("rxdd->flags.bits.vtag=%d\n", GET_RXD_VTAG(rxd_val1)); in NETIF_RX_MUX()
1139 priv->ndev->name, in NETIF_RX_MUX()
1157 f = &priv->rxf_fifo0; in bdx_recycle_skb()
1158 db = priv->rxdb; in bdx_recycle_skb()
1160 dm = bdx_rxdb_addr_elem(db, rxdd->va_lo); in bdx_recycle_skb()
1162 rxfd = (struct rxf_desc *)(f->m.va + f->m.wptr); in bdx_recycle_skb()
1163 rxfd->info = CPU_CHIP_SWAP32(0x10003); /* INFO=1 BC=3 */ in bdx_recycle_skb()
1164 rxfd->va_lo = rxdd->va_lo; in bdx_recycle_skb()
1165 rxfd->pa_lo = CPU_CHIP_SWAP32(L32_64(dm->dma)); in bdx_recycle_skb()
1166 rxfd->pa_hi = CPU_CHIP_SWAP32(H32_64(dm->dma)); in bdx_recycle_skb()
1167 rxfd->len = CPU_CHIP_SWAP32(f->m.pktsz); in bdx_recycle_skb()
1170 f->m.wptr += sizeof(struct rxf_desc); in bdx_recycle_skb()
1171 delta = f->m.wptr - f->m.memsz; in bdx_recycle_skb()
1173 f->m.wptr = delta; in bdx_recycle_skb()
1175 memcpy(f->m.va, f->m.va + f->m.memsz, delta); in bdx_recycle_skb()
1183 * bdx_rx_receive - receives full packets from RXD fifo and pass them to OS
1184 * NOTE: a special treatment is given to non-continuous descriptors
1197 struct net_device *ndev = priv->ndev; in bdx_rx_receive()
1206 /* Unmarshalled descriptor - copy of descriptor in host order */ in bdx_rx_receive()
1214 f->m.wptr = READ_REG(priv, f->m.reg_WPTR) & TXF_WPTR_WR_PTR; in bdx_rx_receive()
1216 size = f->m.wptr - f->m.rptr; in bdx_rx_receive()
1218 size = f->m.memsz + size; /* size is negative :-) */ in bdx_rx_receive()
1222 rxdd = (struct rxd_desc *)(f->m.va + f->m.rptr); in bdx_rx_receive()
1223 rxd_val1 = CPU_CHIP_SWAP32(rxdd->rxd_val1); in bdx_rx_receive()
1225 len = CPU_CHIP_SWAP16(rxdd->len); in bdx_rx_receive()
1227 rxd_vlan = CPU_CHIP_SWAP16(rxdd->rxd_vlan); in bdx_rx_receive()
1233 size -= tmp_len; in bdx_rx_receive()
1237 f->m.rptr += tmp_len; in bdx_rx_receive()
1239 tmp_len = f->m.rptr - f->m.memsz; in bdx_rx_receive()
1241 f->m.rptr = tmp_len; in bdx_rx_receive()
1244 f->m.rptr, tmp_len); in bdx_rx_receive()
1245 memcpy(f->m.va + f->m.memsz, f->m.va, tmp_len); in bdx_rx_receive()
1251 ndev->stats.rx_errors++; in bdx_rx_receive()
1256 rxf_fifo = &priv->rxf_fifo0; in bdx_rx_receive()
1257 db = priv->rxdb; in bdx_rx_receive()
1258 dm = bdx_rxdb_addr_elem(db, rxdd->va_lo); in bdx_rx_receive()
1259 skb = dm->skb; in bdx_rx_receive()
1262 (skb2 = netdev_alloc_skb(priv->ndev, len + NET_IP_ALIGN))) { in bdx_rx_receive()
1265 dma_sync_single_for_cpu(&priv->pdev->dev, dm->dma, in bdx_rx_receive()
1266 rxf_fifo->m.pktsz, in bdx_rx_receive()
1268 memcpy(skb2->data, skb->data, len); in bdx_rx_receive()
1272 dma_unmap_single(&priv->pdev->dev, dm->dma, in bdx_rx_receive()
1273 rxf_fifo->m.pktsz, DMA_FROM_DEVICE); in bdx_rx_receive()
1274 bdx_rxdb_free_elem(db, rxdd->va_lo); in bdx_rx_receive()
1277 ndev->stats.rx_bytes += len; in bdx_rx_receive()
1280 skb->protocol = eth_type_trans(skb, ndev); in bdx_rx_receive()
1282 /* Non-IP packets aren't checksum-offloaded */ in bdx_rx_receive()
1286 skb->ip_summed = CHECKSUM_UNNECESSARY; in bdx_rx_receive()
1294 ndev->stats.rx_packets += done; in bdx_rx_receive()
1297 WRITE_REG(priv, f->m.reg_RPTR, f->m.rptr & TXF_WPTR_WR_PTR); in bdx_rx_receive()
1299 bdx_rx_alloc_skbs(priv, &priv->rxf_fifo0); in bdx_rx_receive()
1315 GET_RXD_CFI(rxd_vlan), GET_RXD_PRIO(rxd_vlan), rxdd->va_lo, in print_rxdd()
1316 rxdd->va_hi); in print_rxdd()
1323 rxfd->info, rxfd->va_lo, rxfd->pa_lo, rxfd->pa_hi, rxfd->len); in print_rxfd()
1330 * 1) TX Free Fifo - TXF - holds ack descriptors for sent packets
1331 * 2) TX Data Fifo - TXD - holds descriptors of full buffers.
1338 * txdb - used to keep track of all skbs owned by SW and their dma addresses.
1342 * fifo - keeps info about fifo's size and location, relevant HW registers,
1368 * __bdx_tx_db_ptr_next - helper function, increment read/write pointer + wrap
1376 BDX_ASSERT(*pptr != db->rptr && /* expect either read */ in __bdx_tx_db_ptr_next()
1377 *pptr != db->wptr); /* or write pointer */ in __bdx_tx_db_ptr_next()
1379 BDX_ASSERT(*pptr < db->start || /* pointer has to be */ in __bdx_tx_db_ptr_next()
1380 *pptr >= db->end); /* in range */ in __bdx_tx_db_ptr_next()
1383 if (unlikely(*pptr == db->end)) in __bdx_tx_db_ptr_next()
1384 *pptr = db->start; in __bdx_tx_db_ptr_next()
1388 * bdx_tx_db_inc_rptr - increment read pointer
1393 BDX_ASSERT(db->rptr == db->wptr); /* can't read from empty db */ in bdx_tx_db_inc_rptr()
1394 __bdx_tx_db_ptr_next(db, &db->rptr); in bdx_tx_db_inc_rptr()
1398 * bdx_tx_db_inc_wptr - increment write pointer
1403 __bdx_tx_db_ptr_next(db, &db->wptr); in bdx_tx_db_inc_wptr()
1404 BDX_ASSERT(db->rptr == db->wptr); /* we can not get empty db as in bdx_tx_db_inc_wptr()
1409 * bdx_tx_db_init - creates and initializes tx db
1419 d->start = vmalloc(memsz); in bdx_tx_db_init()
1420 if (!d->start) in bdx_tx_db_init()
1421 return -ENOMEM; in bdx_tx_db_init()
1428 d->size = memsz / sizeof(struct tx_map) - 1; in bdx_tx_db_init()
1429 d->end = d->start + d->size + 1; /* just after last element */ in bdx_tx_db_init()
1432 d->rptr = d->start; in bdx_tx_db_init()
1433 d->wptr = d->start; in bdx_tx_db_init()
1439 * bdx_tx_db_close - closes tx db and frees all memory
1446 vfree(d->start); in bdx_tx_db_close()
1447 d->start = NULL; in bdx_tx_db_close()
1462 * bdx_tx_map_skb - creates and stores dma mappings for skb's data blocks
1467 * It makes dma mappings for skb's data blocks and writes them to PBL of
1477 struct txdb *db = &priv->txdb; in bdx_tx_map_skb()
1478 struct pbl *pbl = &txdd->pbl[0]; in bdx_tx_map_skb() local
1479 int nr_frags = skb_shinfo(skb)->nr_frags; in bdx_tx_map_skb()
1482 db->wptr->len = skb_headlen(skb); in bdx_tx_map_skb()
1483 db->wptr->addr.dma = dma_map_single(&priv->pdev->dev, skb->data, in bdx_tx_map_skb()
1484 db->wptr->len, DMA_TO_DEVICE); in bdx_tx_map_skb()
1485 pbl->len = CPU_CHIP_SWAP32(db->wptr->len); in bdx_tx_map_skb()
1486 pbl->pa_lo = CPU_CHIP_SWAP32(L32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1487 pbl->pa_hi = CPU_CHIP_SWAP32(H32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1488 DBG("=== pbl len: 0x%x ================\n", pbl->len); in bdx_tx_map_skb()
1489 DBG("=== pbl pa_lo: 0x%x ================\n", pbl->pa_lo); in bdx_tx_map_skb()
1490 DBG("=== pbl pa_hi: 0x%x ================\n", pbl->pa_hi); in bdx_tx_map_skb()
1496 frag = &skb_shinfo(skb)->frags[i]; in bdx_tx_map_skb()
1497 db->wptr->len = skb_frag_size(frag); in bdx_tx_map_skb()
1498 db->wptr->addr.dma = skb_frag_dma_map(&priv->pdev->dev, frag, in bdx_tx_map_skb()
1502 pbl++; in bdx_tx_map_skb()
1503 pbl->len = CPU_CHIP_SWAP32(db->wptr->len); in bdx_tx_map_skb()
1504 pbl->pa_lo = CPU_CHIP_SWAP32(L32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1505 pbl->pa_hi = CPU_CHIP_SWAP32(H32_64(db->wptr->addr.dma)); in bdx_tx_map_skb()
1510 db->wptr->len = -txd_sizes[nr_frags].bytes; in bdx_tx_map_skb()
1511 db->wptr->addr.skb = skb; in bdx_tx_map_skb()
1515 /* init_txd_sizes - precalculate sizes of descriptors for skbs up to 16 frags
1522 /* 7 - is number of lwords in txd with one phys buffer in init_txd_sizes()
1523 * 3 - is number of lwords used for every additional phys buffer */ in init_txd_sizes()
1533 /* bdx_tx_init - initialize all Tx related stuff.
1537 if (bdx_fifo_init(priv, &priv->txd_fifo0.m, priv->txd_size, in bdx_tx_init()
1541 if (bdx_fifo_init(priv, &priv->txf_fifo0.m, priv->txf_size, in bdx_tx_init()
1548 if (bdx_tx_db_init(&priv->txdb, max(priv->txd_size, priv->txf_size))) in bdx_tx_init()
1551 priv->tx_level = BDX_MAX_TX_LEVEL; in bdx_tx_init()
1553 priv->tx_update_mark = priv->tx_level - 1024; in bdx_tx_init()
1558 netdev_err(priv->ndev, "Tx init failed\n"); in bdx_tx_init()
1559 return -ENOMEM; in bdx_tx_init()
1563 * bdx_tx_space - calculates available space in TX fifo
1570 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_space()
1573 f->m.rptr = READ_REG(priv, f->m.reg_RPTR) & TXF_WPTR_WR_PTR; in bdx_tx_space()
1574 fsize = f->m.rptr - f->m.wptr; in bdx_tx_space()
1576 fsize = f->m.memsz + fsize; in bdx_tx_space()
1581 * bdx_tx_transmit - send packet to NIC
1594 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_transmit()
1601 int nr_frags = skb_shinfo(skb)->nr_frags; in bdx_tx_transmit()
1608 spin_lock(&priv->tx_lock); in bdx_tx_transmit()
1611 BDX_ASSERT(f->m.wptr >= f->m.memsz); /* started with valid wptr */ in bdx_tx_transmit()
1612 txdd = (struct txd_desc *)(f->m.va + f->m.wptr); in bdx_tx_transmit()
1613 if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) in bdx_tx_transmit()
1616 if (skb_shinfo(skb)->gso_size) { in bdx_tx_transmit()
1617 txd_mss = skb_shinfo(skb)->gso_size; in bdx_tx_transmit()
1619 DBG("skb %p skb len %d gso size = %d\n", skb, skb->len, in bdx_tx_transmit()
1629 txdd->length = CPU_CHIP_SWAP16(skb->len); in bdx_tx_transmit()
1630 txdd->mss = CPU_CHIP_SWAP16(txd_mss); in bdx_tx_transmit()
1631 txdd->txd_val1 = in bdx_tx_transmit()
1636 DBG("=== w1: 0x%x ================\n", txdd->txd_val1); in bdx_tx_transmit()
1637 DBG("=== w2: mss 0x%x len 0x%x\n", txdd->mss, txdd->length); in bdx_tx_transmit()
1644 f->m.wptr += txd_sizes[nr_frags].bytes; in bdx_tx_transmit()
1645 len = f->m.wptr - f->m.memsz; in bdx_tx_transmit()
1647 f->m.wptr = len; in bdx_tx_transmit()
1649 BDX_ASSERT(len > f->m.memsz); in bdx_tx_transmit()
1650 memcpy(f->m.va, f->m.va + f->m.memsz, len); in bdx_tx_transmit()
1653 BDX_ASSERT(f->m.wptr >= f->m.memsz); /* finished with valid wptr */ in bdx_tx_transmit()
1655 priv->tx_level -= txd_sizes[nr_frags].bytes; in bdx_tx_transmit()
1656 BDX_ASSERT(priv->tx_level <= 0 || priv->tx_level > BDX_MAX_TX_LEVEL); in bdx_tx_transmit()
1658 if (priv->tx_level > priv->tx_update_mark) { in bdx_tx_transmit()
1663 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1665 if (priv->tx_noupd++ > BDX_NO_UPD_PACKETS) { in bdx_tx_transmit()
1666 priv->tx_noupd = 0; in bdx_tx_transmit()
1667 WRITE_REG(priv, f->m.reg_WPTR, in bdx_tx_transmit()
1668 f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1676 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_transmit()
1682 ndev->stats.tx_packets++; in bdx_tx_transmit()
1683 ndev->stats.tx_bytes += skb->len; in bdx_tx_transmit()
1685 if (priv->tx_level < BDX_MIN_TX_LEVEL) { in bdx_tx_transmit()
1687 BDX_DRV_NAME, ndev->name, priv->tx_level); in bdx_tx_transmit()
1691 spin_unlock_irqrestore(&priv->tx_lock, flags); in bdx_tx_transmit()
1696 * bdx_tx_cleanup - clean TXF fifo, run in the context of IRQ.
1704 struct txf_fifo *f = &priv->txf_fifo0; in bdx_tx_cleanup()
1705 struct txdb *db = &priv->txdb; in bdx_tx_cleanup()
1709 f->m.wptr = READ_REG(priv, f->m.reg_WPTR) & TXF_WPTR_MASK; in bdx_tx_cleanup()
1710 BDX_ASSERT(f->m.rptr >= f->m.memsz); /* started with valid rptr */ in bdx_tx_cleanup()
1712 while (f->m.wptr != f->m.rptr) { in bdx_tx_cleanup()
1713 f->m.rptr += BDX_TXF_DESC_SZ; in bdx_tx_cleanup()
1714 f->m.rptr &= f->m.size_mask; in bdx_tx_cleanup()
1718 BDX_ASSERT(db->rptr->len == 0); in bdx_tx_cleanup()
1720 BDX_ASSERT(db->rptr->addr.dma == 0); in bdx_tx_cleanup()
1721 dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, in bdx_tx_cleanup()
1722 db->rptr->len, DMA_TO_DEVICE); in bdx_tx_cleanup()
1724 } while (db->rptr->len > 0); in bdx_tx_cleanup()
1725 tx_level -= db->rptr->len; /* '-' koz len is negative */ in bdx_tx_cleanup()
1727 /* now should come skb pointer - free it */ in bdx_tx_cleanup()
1728 dev_consume_skb_irq(db->rptr->addr.skb); in bdx_tx_cleanup()
1733 BDX_ASSERT((f->m.wptr & TXF_WPTR_WR_PTR) >= f->m.memsz); in bdx_tx_cleanup()
1734 WRITE_REG(priv, f->m.reg_RPTR, f->m.rptr & TXF_WPTR_WR_PTR); in bdx_tx_cleanup()
1738 spin_lock(&priv->tx_lock); in bdx_tx_cleanup()
1739 priv->tx_level += tx_level; in bdx_tx_cleanup()
1740 BDX_ASSERT(priv->tx_level <= 0 || priv->tx_level > BDX_MAX_TX_LEVEL); in bdx_tx_cleanup()
1742 if (priv->tx_noupd) { in bdx_tx_cleanup()
1743 priv->tx_noupd = 0; in bdx_tx_cleanup()
1744 WRITE_REG(priv, priv->txd_fifo0.m.reg_WPTR, in bdx_tx_cleanup()
1745 priv->txd_fifo0.m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_cleanup()
1749 if (unlikely(netif_queue_stopped(priv->ndev) && in bdx_tx_cleanup()
1750 netif_carrier_ok(priv->ndev) && in bdx_tx_cleanup()
1751 (priv->tx_level >= BDX_MIN_TX_LEVEL))) { in bdx_tx_cleanup()
1753 BDX_DRV_NAME, priv->ndev->name, priv->tx_level); in bdx_tx_cleanup()
1754 netif_wake_queue(priv->ndev); in bdx_tx_cleanup()
1756 spin_unlock(&priv->tx_lock); in bdx_tx_cleanup()
1760 * bdx_tx_free_skbs - frees all skbs from TXD fifo.
1767 struct txdb *db = &priv->txdb; in bdx_tx_free_skbs()
1770 while (db->rptr != db->wptr) { in bdx_tx_free_skbs()
1771 if (likely(db->rptr->len)) in bdx_tx_free_skbs()
1772 dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, in bdx_tx_free_skbs()
1773 db->rptr->len, DMA_TO_DEVICE); in bdx_tx_free_skbs()
1775 dev_kfree_skb(db->rptr->addr.skb); in bdx_tx_free_skbs()
1781 /* bdx_tx_free - frees all Tx resources */
1786 bdx_fifo_free(priv, &priv->txd_fifo0.m); in bdx_tx_free()
1787 bdx_fifo_free(priv, &priv->txf_fifo0.m); in bdx_tx_free()
1788 bdx_tx_db_close(&priv->txdb); in bdx_tx_free()
1792 * bdx_tx_push_desc - push descriptor to TxD fifo
1804 struct txd_fifo *f = &priv->txd_fifo0; in bdx_tx_push_desc()
1805 int i = f->m.memsz - f->m.wptr; in bdx_tx_push_desc()
1811 memcpy(f->m.va + f->m.wptr, data, size); in bdx_tx_push_desc()
1812 f->m.wptr += size; in bdx_tx_push_desc()
1814 memcpy(f->m.va + f->m.wptr, data, i); in bdx_tx_push_desc()
1815 f->m.wptr = size - i; in bdx_tx_push_desc()
1816 memcpy(f->m.va, data + i, f->m.wptr); in bdx_tx_push_desc()
1818 WRITE_REG(priv, f->m.reg_WPTR, f->m.wptr & TXF_WPTR_WR_PTR); in bdx_tx_push_desc()
1822 * bdx_tx_push_desc_safe - push descriptor to TxD fifo in a safe way
1839 int avail = bdx_tx_space(priv) - 8; in bdx_tx_push_desc_safe()
1852 size -= avail; in bdx_tx_push_desc_safe()
1872 * bdx_probe - Device Initialization Routine
1883 * /usr/src/linux/Documentation/DMA-{API,mapping}.txt
1902 RET(-ENOMEM); in bdx_probe()
1909 if (!(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) && in bdx_probe()
1910 !(err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)))) { in bdx_probe()
1913 if ((err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) || in bdx_probe()
1914 (err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)))) { in bdx_probe()
1915 pr_err("No usable DMA configuration, aborting\n"); in bdx_probe()
1929 err = -EIO; in bdx_probe()
1930 pr_err("no MMIO resource\n"); in bdx_probe()
1935 err = -EIO; in bdx_probe()
1940 nic->regs = ioremap(pciaddr, regionSize); in bdx_probe()
1941 if (!nic->regs) { in bdx_probe()
1942 err = -EIO; in bdx_probe()
1947 if (pdev->irq < 2) { in bdx_probe()
1948 err = -EIO; in bdx_probe()
1949 pr_err("invalid irq (%d)\n", pdev->irq); in bdx_probe()
1954 if (pdev->device == 0x3014) in bdx_probe()
1955 nic->port_num = 2; in bdx_probe()
1957 nic->port_num = 1; in bdx_probe()
1961 bdx_hw_reset_direct(nic->regs); in bdx_probe()
1963 nic->irq_type = IRQ_INTX; in bdx_probe()
1965 if ((readl(nic->regs + FPGA_VER) & 0xFFF) >= 378) { in bdx_probe()
1970 nic->irq_type = IRQ_MSI; in bdx_probe()
1976 for (port = 0; port < nic->port_num; port++) { in bdx_probe()
1979 err = -ENOMEM; in bdx_probe()
1983 ndev->netdev_ops = &bdx_netdev_ops; in bdx_probe()
1984 ndev->tx_queue_len = BDX_NDEV_TXQ_LEN; in bdx_probe()
1990 ndev->if_port = port; in bdx_probe()
1991 ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO in bdx_probe()
1995 ndev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | in bdx_probe()
1999 ndev->features |= NETIF_F_HIGHDMA; in bdx_probe()
2002 priv = nic->priv[port] = netdev_priv(ndev); in bdx_probe()
2004 priv->pBdxRegs = nic->regs + port * 0x8000; in bdx_probe()
2005 priv->port = port; in bdx_probe()
2006 priv->pdev = pdev; in bdx_probe()
2007 priv->ndev = ndev; in bdx_probe()
2008 priv->nic = nic; in bdx_probe()
2009 priv->msg_enable = BDX_DEF_MSG_ENABLE; in bdx_probe()
2011 netif_napi_add(ndev, &priv->napi, bdx_poll, 64); in bdx_probe()
2013 if ((readl(nic->regs + FPGA_VER) & 0xFFF) == 308) { in bdx_probe()
2015 priv->stats_flag = 0; in bdx_probe()
2017 priv->stats_flag = 1; in bdx_probe()
2021 priv->txd_size = 2; in bdx_probe()
2022 priv->txf_size = 2; in bdx_probe()
2023 priv->rxd_size = 2; in bdx_probe()
2024 priv->rxf_size = 3; in bdx_probe()
2027 priv->rdintcm = INT_REG_VAL(0x20, 1, 4, 12); in bdx_probe()
2028 priv->tdintcm = INT_REG_VAL(0x20, 1, 0, 12); in bdx_probe()
2030 /* ndev->xmit_lock spinlock is not used. in bdx_probe()
2031 * Private priv->tx_lock is used for synchronization in bdx_probe()
2033 * set multicast list callback has to use priv->tx_lock. in bdx_probe()
2036 ndev->features |= NETIF_F_LLTX; in bdx_probe()
2038 /* MTU range: 60 - 16384 */ in bdx_probe()
2039 ndev->min_mtu = ETH_ZLEN; in bdx_probe()
2040 ndev->max_mtu = BDX_MAX_MTU; in bdx_probe()
2042 spin_lock_init(&priv->tx_lock); in bdx_probe()
2049 SET_NETDEV_DEV(ndev, &pdev->dev); in bdx_probe()
2065 iounmap(nic->regs); in bdx_probe()
2093 /* 0x72C0-0x72E0 RSRV */
2100 /* 0x7330-0x7360 RSRV */
2106 /* 0x73A0-0x73B0 RSRV */
2115 * bdx_get_link_ksettings - get device-specific settings
2131 ecmd->base.speed = SPEED_10000; in bdx_get_link_ksettings()
2132 ecmd->base.duplex = DUPLEX_FULL; in bdx_get_link_ksettings()
2133 ecmd->base.port = PORT_FIBRE; in bdx_get_link_ksettings()
2134 ecmd->base.autoneg = AUTONEG_DISABLE; in bdx_get_link_ksettings()
2140 * bdx_get_drvinfo - report driver information
2149 strlcpy(drvinfo->driver, BDX_DRV_NAME, sizeof(drvinfo->driver)); in bdx_get_drvinfo()
2150 strlcpy(drvinfo->version, BDX_DRV_VERSION, sizeof(drvinfo->version)); in bdx_get_drvinfo()
2151 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); in bdx_get_drvinfo()
2152 strlcpy(drvinfo->bus_info, pci_name(priv->pdev), in bdx_get_drvinfo()
2153 sizeof(drvinfo->bus_info)); in bdx_get_drvinfo()
2157 * bdx_get_coalesce - get interrupt coalescing parameters
2168 rdintcm = priv->rdintcm; in bdx_get_coalesce()
2169 tdintcm = priv->tdintcm; in bdx_get_coalesce()
2173 ecoal->rx_coalesce_usecs = GET_INT_COAL(rdintcm) * INT_COAL_MULT; in bdx_get_coalesce()
2174 ecoal->rx_max_coalesced_frames = in bdx_get_coalesce()
2177 ecoal->tx_coalesce_usecs = GET_INT_COAL(tdintcm) * INT_COAL_MULT; in bdx_get_coalesce()
2178 ecoal->tx_max_coalesced_frames = in bdx_get_coalesce()
2186 * bdx_set_coalesce - set interrupt coalescing parameters
2202 rx_coal = ecoal->rx_coalesce_usecs / INT_COAL_MULT; in bdx_set_coalesce()
2203 tx_coal = ecoal->tx_coalesce_usecs / INT_COAL_MULT; in bdx_set_coalesce()
2204 rx_max_coal = ecoal->rx_max_coalesced_frames; in bdx_set_coalesce()
2205 tx_max_coal = ecoal->tx_max_coalesced_frames; in bdx_set_coalesce()
2209 (((rx_max_coal * sizeof(struct rxf_desc)) + PCK_TH_MULT - 1) in bdx_set_coalesce()
2212 (((tx_max_coal * BDX_TXF_DESC_SZ) + PCK_TH_MULT - 1) in bdx_set_coalesce()
2217 return -EINVAL; in bdx_set_coalesce()
2219 rdintcm = INT_REG_VAL(rx_coal, GET_INT_COAL_RC(priv->rdintcm), in bdx_set_coalesce()
2220 GET_RXF_TH(priv->rdintcm), rx_max_coal); in bdx_set_coalesce()
2221 tdintcm = INT_REG_VAL(tx_coal, GET_INT_COAL_RC(priv->tdintcm), 0, in bdx_set_coalesce()
2224 priv->rdintcm = rdintcm; in bdx_set_coalesce()
2225 priv->tdintcm = tdintcm; in bdx_set_coalesce()
2246 * bdx_get_ringparam - report ring sizes
2255 /*max_pending - the maximum-sized FIFO we allow */ in bdx_get_ringparam()
2256 ring->rx_max_pending = bdx_rx_fifo_size_to_packets(3); in bdx_get_ringparam()
2257 ring->tx_max_pending = bdx_tx_fifo_size_to_packets(3); in bdx_get_ringparam()
2258 ring->rx_pending = bdx_rx_fifo_size_to_packets(priv->rxf_size); in bdx_get_ringparam()
2259 ring->tx_pending = bdx_tx_fifo_size_to_packets(priv->txd_size); in bdx_get_ringparam()
2263 * bdx_set_ringparam - set ring sizes
2275 if (bdx_rx_fifo_size_to_packets(rx_size) >= ring->rx_pending) in bdx_set_ringparam()
2282 if (bdx_tx_fifo_size_to_packets(tx_size) >= ring->tx_pending) in bdx_set_ringparam()
2289 if ((rx_size == priv->rxf_size) && in bdx_set_ringparam()
2290 (tx_size == priv->txd_size)) in bdx_set_ringparam()
2293 priv->rxf_size = rx_size; in bdx_set_ringparam()
2295 priv->rxd_size = rx_size - 1; in bdx_set_ringparam()
2297 priv->rxd_size = rx_size; in bdx_set_ringparam()
2299 priv->txf_size = priv->txd_size = tx_size; in bdx_set_ringparam()
2309 * bdx_get_strings - return a set of strings that describe the requested objects
2323 * bdx_get_sset_count - return number of statistics or tests
2334 return (priv->stats_flag) ? ARRAY_SIZE(bdx_stat_names) : 0; in bdx_get_sset_count()
2337 return -EINVAL; in bdx_get_sset_count()
2341 * bdx_get_ethtool_stats - return device's hardware L2 statistics
2351 if (priv->stats_flag) { in bdx_get_ethtool_stats()
2357 memcpy(data, &priv->hw_stats, sizeof(priv->hw_stats)); in bdx_get_ethtool_stats()
2362 * bdx_set_ethtool_ops - ethtool interface implementation
2382 netdev->ethtool_ops = &bdx_ethtool_ops; in bdx_set_ethtool_ops()
2386 * bdx_remove - Device Removal Routine
2391 * Hot-Plug event, or because the driver is going to be removed from
2400 for (port = 0; port < nic->port_num; port++) { in bdx_remove()
2401 ndev = nic->priv[port]->ndev; in bdx_remove()
2406 /*bdx_hw_reset_direct(nic->regs); */ in bdx_remove()
2408 if (nic->irq_type == IRQ_MSI) in bdx_remove()
2412 iounmap(nic->regs); in bdx_remove()
2428 * print_driver_id - print parameters of the driver build