/* * RQ buffer constructor function * * rqbd - pointer to rq buffer descriptor * rq - pointer to RQ structure * size - size of the buffer * flags - KM_SLEEP OR KM_NOSLEEP * * return DDI_SUCCESS => success, DDI_FAILURE otherwise */ static int oce_rqb_ctor(oce_rq_bdesc_t *rqbd, struct oce_rq *rq, size_t size, int flags) { struct oce_dev *dev; oce_dma_buf_t *dbuf; dev = rq->parent; dbuf = oce_alloc_dma_buffer(dev, size, &oce_rx_buf_attr, flags); if (dbuf == NULL) { return (DDI_FAILURE); } /* Set the call back function parameters */ rqbd->fr_rtn.free_func = (void (*)())oce_rx_pool_free; rqbd->fr_rtn.free_arg = (caddr_t)(void *)rqbd; rqbd->mp = desballoc((uchar_t *)(dbuf->base), dbuf->size, 0, &rqbd->fr_rtn); if (rqbd->mp == NULL) { oce_free_dma_buffer(dev, dbuf); return (DDI_FAILURE); } rqbd->rqb = dbuf; rqbd->rq = rq; rqbd->frag_addr.dw.addr_lo = ADDR_LO(dbuf->addr + OCE_RQE_BUF_HEADROOM); rqbd->frag_addr.dw.addr_hi = ADDR_HI(dbuf->addr + OCE_RQE_BUF_HEADROOM); rqbd->mp->b_rptr = (uchar_t *)rqbd->rqb->base + OCE_RQE_BUF_HEADROOM; return (DDI_SUCCESS); } /* oce_rqb_ctor */
/* * function to create a ring buffer * * dev - software handle to the device * num_items - number of items in the ring * item_size - size of an individual item in the ring * flags - DDI_DMA_CONSISTENT/DDI_DMA_STREAMING for ring memory * * return pointer to a ring_buffer structure, NULL on failure */ oce_ring_buffer_t * create_ring_buffer(struct oce_dev *dev, uint32_t num_items, uint32_t item_size, uint32_t flags) { oce_ring_buffer_t *ring; uint32_t size; /* allocate the ring buffer */ ring = kmem_zalloc(sizeof (oce_ring_buffer_t), KM_NOSLEEP); if (ring == NULL) { return (NULL); } /* get the dbuf defining the ring */ size = num_items * item_size; ring->dbuf = oce_alloc_dma_buffer(dev, size, NULL, flags); if (ring->dbuf == NULL) { oce_log(dev, CE_WARN, MOD_CONFIG, "%s", "Ring buffer allocation failed"); goto dbuf_fail; } /* fill the rest of the ring */ ring->num_items = num_items; ring->item_size = item_size; ring->num_used = 0; return (ring); dbuf_fail: kmem_free(ring, sizeof (oce_ring_buffer_t)); return (NULL); } /* create_ring_buffer */
/* * WQ buffer constructor * * wqbd - pointer to WQ buffer descriptor * wq - pointer to WQ structure * size - size of the buffer * flags - KM_SLEEP or KM_NOSLEEP * * return DDI_SUCCESS=>success, DDI_FAILURE=>error */ static int oce_wqb_ctor(oce_wq_bdesc_t *wqbd, struct oce_wq *wq, size_t size, int flags) { struct oce_dev *dev; dev = wq->parent; wqbd->wqb = oce_alloc_dma_buffer(dev, size, &oce_tx_dma_buf_attr, flags); if (wqbd->wqb == NULL) { return (DDI_FAILURE); } wqbd->frag_addr.dw.addr_lo = ADDR_LO(wqbd->wqb->addr); wqbd->frag_addr.dw.addr_hi = ADDR_HI(wqbd->wqb->addr); return (DDI_SUCCESS); }
int oce_hw_init(struct oce_dev *dev) { int ret; struct mac_address_format mac_addr; ret = oce_POST(dev); if (ret != DDI_SUCCESS) { oce_log(dev, CE_WARN, MOD_CONFIG, "%s", "!!!HW POST1 FAILED"); /* ADD FM FAULT */ return (DDI_FAILURE); } /* create bootstrap mailbox */ dev->bmbx = oce_alloc_dma_buffer(dev, sizeof (struct oce_bmbx), NULL, DDI_DMA_CONSISTENT); if (dev->bmbx == NULL) { oce_log(dev, CE_WARN, MOD_CONFIG, "Failed to allocate bmbx: size = %u", (uint32_t)sizeof (struct oce_bmbx)); return (DDI_FAILURE); } ret = oce_reset_fun(dev); if (ret != 0) { oce_log(dev, CE_WARN, MOD_CONFIG, "%s", "!!!FUNCTION RESET FAILED"); goto init_fail; } /* reset the Endianess of BMBX */ ret = oce_mbox_init(dev); if (ret != 0) { oce_log(dev, CE_WARN, MOD_CONFIG, "Mailbox initialization2 Failed with %d", ret); goto init_fail; } /* read the firmware version */ ret = oce_get_fw_version(dev); if (ret != 0) { oce_log(dev, CE_WARN, MOD_CONFIG, "Firmaware version read failed with %d", ret); goto init_fail; } /* read the fw config */ ret = oce_get_fw_config(dev); if (ret != 0) { oce_log(dev, CE_WARN, MOD_CONFIG, "Firmware configuration read failed with %d", ret); goto init_fail; } /* read the Factory MAC address */ ret = oce_read_mac_addr(dev, 0, 1, MAC_ADDRESS_TYPE_NETWORK, &mac_addr); if (ret != 0) { oce_log(dev, CE_WARN, MOD_CONFIG, "MAC address read failed with %d", ret); goto init_fail; } bcopy(&mac_addr.mac_addr[0], &dev->mac_addr[0], ETHERADDRL); return (DDI_SUCCESS); init_fail: oce_hw_fini(dev); return (DDI_FAILURE); }
/* * function to setup the kstat_t structure for the device and install it * * dev - software handle to the device * * return DDI_SUCCESS => success, failure otherwise */ int oce_stat_init(struct oce_dev *dev) { struct oce_stat *stats; uint32_t num_stats = sizeof (struct oce_stat) / sizeof (kstat_named_t); /* allocate the kstat */ dev->oce_kstats = kstat_create(OCE_MOD_NAME, dev->dev_id, "stats", "net", KSTAT_TYPE_NAMED, num_stats, 0); if (dev->oce_kstats == NULL) { oce_log(dev, CE_NOTE, MOD_CONFIG, "kstat creation failed: 0x%p", (void *)dev->oce_kstats); return (DDI_FAILURE); } /* allocate the device copy of the stats */ dev->stats_dbuf = oce_alloc_dma_buffer(dev, sizeof (struct mbx_get_nic_stats), NULL, DDI_DMA_CONSISTENT); if (dev->stats_dbuf == NULL) { oce_log(dev, CE_NOTE, MOD_CONFIG, "Could not allocate stats_dbuf: %p", (void *)dev->stats_dbuf); kstat_delete(dev->oce_kstats); return (DDI_FAILURE); } dev->hw_stats = (struct mbx_get_nic_stats *)DBUF_VA(dev->stats_dbuf); /* initialize the counters */ stats = (struct oce_stat *)dev->oce_kstats->ks_data; kstat_named_init(&stats->rx_bytes_hi, "rx bytes msd", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_bytes_lo, "rx bytes lsd", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_frames, "rx frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_errors, "rx errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops, "rx drops", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_bytes_hi, "tx bytes msd", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_bytes_lo, "tx bytes lsd", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_frames, "tx frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_errors, "tx errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_unicast_frames, "rx unicast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_multicast_frames, "rx multicast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_broadcast_frames, "rx broadcast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_crc_errors, "rx crc errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_alignment_symbol_errors, "rx alignment symbol errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_in_range_errors, "rx in range errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_out_range_errors, "rx out range errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_frame_too_long, "rx frame too long", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_address_match_errors, "rx address match errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_pause_frames, "rx pause frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_control_frames, "rx control frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_ip_checksum_errs, "rx ip checksum errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_tcp_checksum_errs, "rx tcp checksum errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_udp_checksum_errs, "rx udp checksum errors", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_fifo_overflow, "rx fifo overflow", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_input_fifo_overflow, "rx input fifo overflow", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_unicast_frames, "tx unicast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_multicast_frames, "tx multicast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_broadcast_frames, "tx broadcast frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_pause_frames, "tx pause frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->tx_control_frames, "tx control frames", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_no_pbuf, "rx_drops_no_pbuf", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_no_txpb, "rx_drops_no_txpb", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_no_erx_descr, "rx_drops_no_erx_descr", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_no_tpre_descr, "rx_drops_no_tpre_descr", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_too_many_frags, "rx_drops_too_many_frags", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_invalid_ring, "rx_drops_invalid_ring", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_mtu, "rx_drops_mtu", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_dropped_too_small, "rx_dropped_too_small", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_dropped_too_short, "rx_dropped_too_short", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_dropped_header_too_small, "rx_dropped_header_too_small", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_dropped_tcp_length, "rx_dropped_tcp_length", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_dropped_runt, "rx_dropped_runt", KSTAT_DATA_ULONG); kstat_named_init(&stats->rx_drops_no_fragments, "rx_drop_no_frag", KSTAT_DATA_ULONG); dev->oce_kstats->ks_update = oce_update_stats; dev->oce_kstats->ks_private = (void *)dev; kstat_install(dev->oce_kstats); return (DDI_SUCCESS); } /* oce_stat_init */