#include <strings.h>#include <errno.h>#include <gpxe/malloc.h>#include <gpxe/umalloc.h>#include <byteswap.h>#include <unistd.h>#include <gpxe/io.h>#include <gpxe/pci.h>#include <gpxe/ethernet.h>#include <gpxe/netdevice.h>#include <gpxe/iobuf.h>#include "mtnic.h"Go to the source code of this file.
Defines | |
| #define | DO_QUERY_CAP(cap, mod, var) |
Functions | |
| FILE_LICENCE (GPL2_ONLY) | |
| static int | mtnic_alloc_aligned (unsigned int size, void **va, unsigned long *pa, unsigned int alignment) |
| mtnic_alloc_aligned | |
| static int | mtnic_alloc_cmdif (struct mtnic *mtnic) |
| mtnic alloc command interface | |
| static void | mtnic_free_io_buffers (struct mtnic_ring *ring) |
| Free RX io buffers. | |
| static int | mtnic_alloc_iobuf (struct mtnic_port *priv, struct mtnic_ring *ring, unsigned int size) |
| mtnic alloc and attach io buffers | |
| static int | mtnic_alloc_ring (struct mtnic_port *priv, struct mtnic_ring *ring, u32 size, u16 stride, u16 cq, u8 is_rx) |
| mtnic alloc ring | |
| static int | mtnic_alloc_cq (struct net_device *dev, int num, struct mtnic_cq *cq, u8 is_rx, u32 size, u32 offset_ind) |
| mtnic alloc CQ | |
| unsigned int | mtnic_alloc_resources (struct net_device *dev) |
| mtnic_alloc_resources | |
| static int | mtnic_alloc_eq (struct mtnic *mtnic) |
| mtnic alloc_eq | |
| static int | cmdif_go_bit (struct mtnic *mtnic) |
| static int | mtnic_cmd (struct mtnic *mtnic, void *in_imm, void *out_imm, u32 in_modifier, u16 op) |
| static int | mtnic_map_cmd (struct mtnic *mtnic, u16 op, struct mtnic_pages pages) |
| static int | mtnic_QUERY_FW (struct mtnic *mtnic) |
| static int | mtnic_OPEN_NIC (struct mtnic *mtnic) |
| static int | mtnic_CONFIG_RX (struct mtnic *mtnic) |
| static int | mtnic_CONFIG_TX (struct mtnic *mtnic) |
| static int | mtnic_HEART_BEAT (struct mtnic_port *priv, u32 *link_state) |
| static int | mtnic_SET_PORT_DEFAULT_RING (struct mtnic_port *priv, u8 port, u16 ring) |
| static int | mtnic_CONFIG_PORT_RSS_STEER (struct mtnic_port *priv, int port) |
| static int | mtnic_SET_PORT_RSS_INDIRECTION (struct mtnic_port *priv, int port) |
| static int | mtnic_CONFIG_CQ (struct mtnic_port *priv, int port, u16 cq_ind, struct mtnic_cq *cq) |
| static int | mtnic_CONFIG_TX_RING (struct mtnic_port *priv, u8 port, u16 ring_ind, struct mtnic_ring *ring) |
| static int | mtnic_CONFIG_RX_RING (struct mtnic_port *priv, u8 port, u16 ring_ind, struct mtnic_ring *ring) |
| static int | mtnic_CONFIG_EQ (struct mtnic *mtnic) |
| static int | mtnic_SET_RX_RING_ADDR (struct mtnic_port *priv, u8 port, u64 *mac) |
| static int | mtnic_SET_PORT_STATE (struct mtnic_port *priv, u8 port, u8 state) |
| static int | mtnic_SET_PORT_MTU (struct mtnic_port *priv, u8 port, u16 mtu) |
| static int | mtnic_RELEASE_RESOURCE (struct mtnic_port *priv, u8 port, u8 type, u8 index) |
| static int | mtnic_QUERY_CAP (struct mtnic *mtnic, u8 index, u8 mod, u64 *result) |
| static int | mtnic_query_num_ports (struct mtnic *mtnic) |
| static int | mtnic_query_mac (struct mtnic *mtnic) |
| static int | mtnic_query_offsets (struct mtnic *mtnic) |
| void | mtnic_reset (void) |
| Reset device. | |
| static int | restore_config (void) |
| Restore PCI config. | |
| static int | mtnic_init_pci (struct pci_device *dev) |
| Init PCI configuration. | |
| static int | mtnic_init_card (struct mtnic *mtnic) |
| Initial hardware. | |
| void | mtnic_process_tx_cq (struct mtnic_port *priv, struct net_device *dev, struct mtnic_cq *cq) |
| int | mtnic_process_rx_cq (struct mtnic_port *priv, struct net_device *dev, struct mtnic_cq *cq) |
| static int | mtnic_open (struct net_device *dev) |
| static void | mtnic_poll (struct net_device *dev) |
| Check if we got completion for receive and transmit and check the line with heart_bit command. | |
| static int | mtnic_transmit (struct net_device *dev, struct io_buffer *iobuf) |
| static void | mtnic_close (struct net_device *dev) |
| static void | mtnic_disable (struct pci_device *pci) |
| static void | mtnic_irq (struct net_device *netdev __unused, int enable __unused) |
| static int | mtnic_probe (struct pci_device *pci, const struct pci_device_id *id __unused) |
Variables | |
| static struct net_device_operations | mtnic_operations |
| mtnic net device operations | |
| static struct pci_device_id | mtnic_nics [] |
| struct pci_driver mtnic_driver | __pci_driver |
| #define DO_QUERY_CAP | ( | cap, | |||
| mod, | |||||
| var | ) |
Value:
err = mtnic_QUERY_CAP(mtnic, cap, mod, &result);\ if (err) \ return err; \ (var) = result
Definition at line 895 of file mtnic.c.
Referenced by mtnic_query_mac(), mtnic_query_num_ports(), and mtnic_query_offsets().
| FILE_LICENCE | ( | GPL2_ONLY | ) |
| static int mtnic_alloc_aligned | ( | unsigned int | size, | |
| void ** | va, | |||
| unsigned long * | pa, | |||
| unsigned int | alignment | |||
| ) | [static] |
mtnic_alloc_aligned
| unsigned | int size size | |
| void | **va virtual address | |
| u32 | *pa physical address | |
| u32 | aligment aligment |
Definition at line 77 of file mtnic.c.
References alloc_memblock(), EADDRINUSE, u32, and virt_to_bus().
Referenced by mtnic_alloc_cmdif(), mtnic_alloc_cq(), mtnic_alloc_eq(), and mtnic_alloc_ring().
00078 { 00079 *va = alloc_memblock(size, alignment); 00080 if (!*va) { 00081 return -EADDRINUSE; 00082 } 00083 *pa = (u32)virt_to_bus(*va); 00084 return 0; 00085 }
| static int mtnic_alloc_cmdif | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 95 of file mtnic.c.
References pcidev::bar, mtnic_cmd::buf, mtnic::cmd, DBG, dev_pci_struct::dev, EADDRINUSE, mtnic::hcr, ioremap(), mtnic_cmd::mapping, mtnic_alloc_aligned(), MTNIC_HCR_BASE, MTNIC_HCR_SIZE, mtnic_pci_dev, PAGE_SIZE, and u32.
Referenced by mtnic_init_card().
00096 { 00097 u32 bar = mtnic_pci_dev.dev.bar[0]; 00098 00099 mtnic->hcr = ioremap(bar + MTNIC_HCR_BASE, MTNIC_HCR_SIZE); 00100 if ( !mtnic->hcr ) { 00101 DBG("Couldn't map command register\n"); 00102 return -EADDRINUSE; 00103 } 00104 mtnic_alloc_aligned(PAGE_SIZE, (void *)&mtnic->cmd.buf, &mtnic->cmd.mapping, PAGE_SIZE); 00105 if ( !mtnic->cmd.buf ) { 00106 DBG("Error in allocating buffer for command interface\n"); 00107 return -EADDRINUSE; 00108 } 00109 return 0; 00110 }
| static void mtnic_free_io_buffers | ( | struct mtnic_ring * | ring | ) | [static] |
Free RX io buffers.
Definition at line 116 of file mtnic.c.
References mtnic_ring::cons, free_iob(), index, mtnic_ring::iobuf, mtnic_ring::prod, and mtnic_ring::size_mask.
Referenced by mtnic_alloc_resources(), mtnic_close(), and mtnic_open().
00117 { 00118 int index; 00119 00120 for (; ring->cons <= ring->prod; ++ring->cons) { 00121 index = ring->cons & ring->size_mask; 00122 if ( ring->iobuf[index] ) { 00123 free_iob(ring->iobuf[index]); 00124 } 00125 } 00126 }
| static int mtnic_alloc_iobuf | ( | struct mtnic_port * | priv, | |
| struct mtnic_ring * | ring, | |||
| unsigned int | size | |||
| ) | [static] |
mtnic alloc and attach io buffers
Definition at line 136 of file mtnic.c.
References mtnic_data_seg::addr_l, alloc_iob(), mtnic_ring::buf, mtnic_ring::cons, mtnic_rx_db_record::count, mtnic_data_seg::count, cpu_to_be32, io_buffer::data, mtnic_rx_desc::data, mtnic_ring::db, DBG, mtnic::fw, index, mtnic_ring::iobuf, mtnic_data_seg::mem_type, mtnic::mem_type_snoop_be, mtnic_port::mtnic, mtnic_ring::prod, mtnic_ring::size_mask, u32, UNITS_BUFFER_SIZE, and virt_to_bus().
Referenced by mtnic_alloc_ring(), and mtnic_process_rx_cq().
00138 { 00139 struct mtnic_rx_desc *rx_desc_ptr = ring->buf; 00140 u32 index; 00141 00142 while ((u32)(ring->prod - ring->cons) < UNITS_BUFFER_SIZE) { 00143 index = ring->prod & ring->size_mask; 00144 ring->iobuf[index] = alloc_iob(size); 00145 if (!ring->iobuf[index]) { 00146 if (ring->prod <= (ring->cons + 1)) { 00147 DBG ( "Dropping packet, buffer is full\n" ); 00148 } 00149 break; 00150 } 00151 00152 /* Attach io_buffer to descriptor */ 00153 rx_desc_ptr = ring->buf + 00154 (sizeof(struct mtnic_rx_desc) * index); 00155 rx_desc_ptr->data.count = cpu_to_be32(size); 00156 rx_desc_ptr->data.mem_type = priv->mtnic->fw.mem_type_snoop_be; 00157 rx_desc_ptr->data.addr_l = cpu_to_be32( 00158 virt_to_bus(ring->iobuf[index]->data)); 00159 00160 ++ ring->prod; 00161 } 00162 00163 /* Update RX producer index (PI) */ 00164 ring->db->count = cpu_to_be32(ring->prod & 0xffff); 00165 return 0; 00166 }
| static int mtnic_alloc_ring | ( | struct mtnic_port * | priv, | |
| struct mtnic_ring * | ring, | |||
| u32 | size, | |||
| u16 | stride, | |||
| u16 | cq, | |||
| u8 | is_rx | |||
| ) | [static] |
mtnic alloc ring
Alloc and configure TX or RX ring
Definition at line 176 of file mtnic.c.
References pcidev::bar, mtnic_ring::buf, mtnic_ring::buf_size, mtnic_ring::cons, cpu_to_be16, cpu_to_be32, mtnic_ring::cq, mtnic_tx_desc::ctrl, mtnic_ring::db, mtnic_ring::db_dma, mtnic_ring::db_offset, DBG, DEF_IOBUF_SIZE, dev_pci_struct::dev, mtnic_ring::dma, EADDRINUSE, free_memblock(), mtnic::fw, ioremap(), memset(), mtnic_port::mtnic, mtnic_alloc_aligned(), mtnic_alloc_iobuf(), MTNIC_BIT_DESC_OWN, mtnic_pci_dev, mtnic_rx_desc::next, mtnic_ctrl_seg::op_own, PAGE_SIZE, mtnic_port::port, mtnic_ring::prod, mtnic_ring::size, mtnic_ring::size_mask, mtnic_ring::stride, mtnic::tx_offset, mtnic_ring::txcq_db, mtnic::txcq_db_offset, u32, and UNITS_BUFFER_SIZE.
Referenced by mtnic_alloc_resources().
00178 { 00179 unsigned int i; 00180 int err; 00181 struct mtnic_rx_desc *rx_desc; 00182 struct mtnic_tx_desc *tx_desc; 00183 00184 ring->size = size; /* Number of descriptors */ 00185 ring->size_mask = size - 1; 00186 ring->stride = stride; /* Size of each entry */ 00187 ring->cq = cq; /* CQ number associated with this ring */ 00188 ring->cons = 0; 00189 ring->prod = 0; 00190 00191 /* Alloc descriptors buffer */ 00192 ring->buf_size = ring->size * ((is_rx) ? sizeof(struct mtnic_rx_desc) : 00193 sizeof(struct mtnic_tx_desc)); 00194 err = mtnic_alloc_aligned(ring->buf_size, (void *)&ring->buf, 00195 &ring->dma, PAGE_SIZE); 00196 if (err) { 00197 DBG("Failed allocating descriptor ring sizeof %x\n", 00198 ring->buf_size); 00199 return -EADDRINUSE; 00200 } 00201 memset(ring->buf, 0, ring->buf_size); 00202 00203 DBG("Allocated %s ring (addr:%p) - buf:%p size:%x" 00204 "buf_size:%x dma:%lx\n", 00205 is_rx ? "Rx" : "Tx", ring, ring->buf, ring->size, 00206 ring->buf_size, ring->dma); 00207 00208 00209 if (is_rx) { /* RX ring */ 00210 /* Alloc doorbell */ 00211 err = mtnic_alloc_aligned(sizeof(struct mtnic_cq_db_record), 00212 (void *)&ring->db, &ring->db_dma, 32); 00213 if (err) { 00214 DBG("Failed allocating Rx ring doorbell record\n"); 00215 free_memblock(ring->buf, ring->buf_size); 00216 return -EADDRINUSE; 00217 } 00218 00219 /* ==- Configure Descriptor -== */ 00220 /* Init ctrl seg of rx desc */ 00221 for (i = 0; i < UNITS_BUFFER_SIZE; ++i) { 00222 rx_desc = ring->buf + 00223 (sizeof(struct mtnic_rx_desc) * i); 00224 /* Pre-link descriptor */ 00225 rx_desc->next = cpu_to_be16(i + 1); 00226 } 00227 /*The last ctrl descriptor is '0' and points to the first one*/ 00228 00229 /* Alloc IO_BUFFERS */ 00230 err = mtnic_alloc_iobuf ( priv, ring, DEF_IOBUF_SIZE ); 00231 if (err) { 00232 DBG("ERROR Allocating io buffer\n"); 00233 free_memblock(ring->buf, ring->buf_size); 00234 return -EADDRINUSE; 00235 } 00236 00237 } else { /* TX ring */ 00238 /* Set initial ownership of all Tx Desc' to SW (1) */ 00239 for (i = 0; i < ring->size; i++) { 00240 tx_desc = ring->buf + ring->stride * i; 00241 tx_desc->ctrl.op_own = cpu_to_be32(MTNIC_BIT_DESC_OWN); 00242 } 00243 /* DB */ 00244 ring->db_offset = cpu_to_be32( 00245 ((u32) priv->mtnic->fw.tx_offset[priv->port]) << 8); 00246 00247 /* Map Tx+CQ doorbells */ 00248 DBG("Mapping TxCQ doorbell at offset:0x%x\n", 00249 priv->mtnic->fw.txcq_db_offset); 00250 ring->txcq_db = ioremap(mtnic_pci_dev.dev.bar[2] + 00251 priv->mtnic->fw.txcq_db_offset, PAGE_SIZE); 00252 if (!ring->txcq_db) { 00253 DBG("Couldn't map txcq doorbell, aborting...\n"); 00254 free_memblock(ring->buf, ring->buf_size); 00255 return -EADDRINUSE; 00256 } 00257 } 00258 00259 return 0; 00260 }
| static int mtnic_alloc_cq | ( | struct net_device * | dev, | |
| int | num, | |||
| struct mtnic_cq * | cq, | |||
| u8 | is_rx, | |||
| u32 | size, | |||
| u32 | offset_ind | |||
| ) | [static] |
mtnic alloc CQ
Alloc and configure CQ.
Definition at line 271 of file mtnic.c.
References mtnic_cq::buf, mtnic_cq::buf_size, mtnic_cq::db, mtnic_cq::db_dma, DBG, mtnic_cq::dev, mtnic_cq::dma, EADDRINUSE, free_memblock(), mtnic_cq::is_rx, mtnic_cq::last, memset(), mtnic_alloc_aligned(), MTNIC_BIT_CQ_OWN, mtnic_cq::num, mtnic_cq::offset_ind, mtnic_cqe::op_tr_own, PAGE_SIZE, and mtnic_cq::size.
Referenced by mtnic_alloc_resources().
00273 { 00274 int err ; 00275 unsigned int i; 00276 00277 cq->num = num; 00278 cq->dev = dev; 00279 cq->size = size; 00280 cq->last = 0; 00281 cq->is_rx = is_rx; 00282 cq->offset_ind = offset_ind; 00283 00284 /* Alloc doorbell */ 00285 err = mtnic_alloc_aligned(sizeof(struct mtnic_cq_db_record), 00286 (void *)&cq->db, &cq->db_dma, 32); 00287 if (err) { 00288 DBG("Failed allocating CQ doorbell record\n"); 00289 return -EADDRINUSE; 00290 } 00291 memset(cq->db, 0, sizeof(struct mtnic_cq_db_record)); 00292 00293 /* Alloc CQEs buffer */ 00294 cq->buf_size = size * sizeof(struct mtnic_cqe); 00295 err = mtnic_alloc_aligned(cq->buf_size, 00296 (void *)&cq->buf, &cq->dma, PAGE_SIZE); 00297 if (err) { 00298 DBG("Failed allocating CQ buffer\n"); 00299 free_memblock(cq->db, sizeof(struct mtnic_cq_db_record)); 00300 return -EADDRINUSE; 00301 } 00302 memset(cq->buf, 0, cq->buf_size); 00303 DBG("Allocated CQ (addr:%p) - size:%x buf:%p buf_size:%x " 00304 "dma:%lx db:%p db_dma:%lx\n" 00305 "cqn offset:%x \n", cq, cq->size, cq->buf, 00306 cq->buf_size, cq->dma, cq->db, 00307 cq->db_dma, offset_ind); 00308 00309 00310 /* Set ownership of all CQEs to HW */ 00311 DBG("Setting HW ownership for CQ:%d\n", num); 00312 for (i = 0; i < cq->size; i++) { 00313 /* Initial HW ownership is 1 */ 00314 cq->buf[i].op_tr_own = MTNIC_BIT_CQ_OWN; 00315 } 00316 return 0; 00317 }
| unsigned int mtnic_alloc_resources | ( | struct net_device * | dev | ) |
mtnic_alloc_resources
Alloc and configure CQs, Tx, Rx
Definition at line 327 of file mtnic.c.
References mtnic_ring::buf, mtnic_cq::buf, mtnic_ring::buf_size, mtnic_cq::buf_size, mtnic_port::cq, mtnic::cq_offset, mtnic_ring::db, mtnic_cq::db, DBG, EADDRINUSE, free_memblock(), mtnic::fw, mtnic_port::mtnic, mtnic_alloc_cq(), mtnic_alloc_ring(), mtnic_free_io_buffers(), netdev_priv(), priv, mtnic_port::rx_ring, mtnic_port::tx_ring, and UNITS_BUFFER_SIZE.
Referenced by mtnic_open().
00328 { 00329 struct mtnic_port *priv = netdev_priv(dev); 00330 int err; 00331 int cq_ind = 0; 00332 int cq_offset = priv->mtnic->fw.cq_offset; 00333 00334 /* Alloc 1st CQ */ 00335 err = mtnic_alloc_cq(dev, cq_ind, &priv->cq[cq_ind], 1 /* RX */, 00336 UNITS_BUFFER_SIZE, cq_offset + cq_ind); 00337 if (err) { 00338 DBG("Failed allocating Rx CQ\n"); 00339 return -EADDRINUSE; 00340 } 00341 00342 00343 /* Alloc RX */ 00344 err = mtnic_alloc_ring(priv, &priv->rx_ring, UNITS_BUFFER_SIZE, 00345 sizeof(struct mtnic_rx_desc), cq_ind, /* RX */1); 00346 if (err) { 00347 DBG("Failed allocating Rx Ring\n"); 00348 goto cq0_error; 00349 } 00350 00351 00352 ++cq_ind; 00353 00354 /* alloc 2nd CQ */ 00355 err = mtnic_alloc_cq(dev, cq_ind, &priv->cq[cq_ind], 0 /* TX */, 00356 UNITS_BUFFER_SIZE, cq_offset + cq_ind); 00357 if (err) { 00358 DBG("Failed allocating Tx CQ\n"); 00359 goto rx_error; 00360 } 00361 00362 /* Alloc TX */ 00363 err = mtnic_alloc_ring(priv, &priv->tx_ring, UNITS_BUFFER_SIZE, 00364 sizeof(struct mtnic_tx_desc), cq_ind, /* TX */ 0); 00365 if (err) { 00366 DBG("Failed allocating Tx ring\n"); 00367 goto cq1_error; 00368 } 00369 00370 return 0; 00371 00372 cq1_error: 00373 free_memblock(priv->cq[1].buf, priv->cq[1].buf_size); 00374 free_memblock(priv->cq[1].db, sizeof(struct mtnic_cq_db_record)); 00375 00376 rx_error: 00377 free_memblock(priv->rx_ring.buf, priv->rx_ring.buf_size); 00378 free_memblock(priv->rx_ring.db, sizeof(struct mtnic_cq_db_record)); 00379 mtnic_free_io_buffers(&priv->rx_ring); 00380 cq0_error: 00381 free_memblock(priv->cq[0].buf, priv->cq[0].buf_size); 00382 free_memblock(priv->cq[0].db, sizeof(struct mtnic_cq_db_record)); 00383 00384 return -EADDRINUSE; 00385 }
| static int mtnic_alloc_eq | ( | struct mtnic * | mtnic | ) | [static] |
mtnic alloc_eq
Note: EQ is not used by the driver but must be allocated
Definition at line 394 of file mtnic.c.
References pcidev::bar, mtnic_eq::buf, mtnic_eq::buf_size, DBG, dev_pci_struct::dev, mtnic_eq::dma, EADDRINUSE, mtnic::eq, mtnic::eq_db, mtnic::eq_db_offset, mtnic::fw, ioremap(), iounmap(), mdelay(), memset(), mtnic_alloc_aligned(), MTNIC_BIT_EQE_OWN, mtnic_pci_dev, NULL, NUM_EQES, mtnic_eqe::own, PAGE_SIZE, mtnic_eq::size, and u32.
Referenced by mtnic_init_card().
00395 { 00396 int err; 00397 unsigned int i; 00398 struct mtnic_eqe *eqe_desc = NULL; 00399 00400 /* Allocating doorbell */ 00401 mtnic->eq_db = ioremap(mtnic_pci_dev.dev.bar[2] + 00402 mtnic->fw.eq_db_offset, sizeof(u32)); 00403 if (!mtnic->eq_db) { 00404 DBG("Couldn't map EQ doorbell, aborting...\n"); 00405 return -EADDRINUSE; 00406 } 00407 00408 /* Allocating buffer */ 00409 mtnic->eq.size = NUM_EQES; 00410 mtnic->eq.buf_size = mtnic->eq.size * sizeof(struct mtnic_eqe); 00411 err = mtnic_alloc_aligned(mtnic->eq.buf_size, (void *)&mtnic->eq.buf, 00412 &mtnic->eq.dma, PAGE_SIZE); 00413 if (err) { 00414 DBG("Failed allocating EQ buffer\n"); 00415 iounmap(mtnic->eq_db); 00416 return -EADDRINUSE; 00417 } 00418 memset(mtnic->eq.buf, 0, mtnic->eq.buf_size); 00419 00420 for (i = 0; i < mtnic->eq.size; i++) 00421 eqe_desc = mtnic->eq.buf + (sizeof(struct mtnic_eqe) * i); 00422 eqe_desc->own |= MTNIC_BIT_EQE_OWN; 00423 00424 mdelay(20); 00425 return 0; 00426 }
| static int cmdif_go_bit | ( | struct mtnic * | mtnic | ) | [inline, static] |
Definition at line 447 of file mtnic.c.
References be32_to_cpu, mtnic::cmd, DBG, EBUSY, mtnic::hcr, MTNIC_BC_MASK, MTNIC_BC_OFF, MTNIC_MASK_CMD_REG_GO_BIT, MTNIC_MASK_CMD_REG_T_BIT, readl, mtnic_if_cmd_reg::status_go_opcode, mtnic_cmd::tbit, TBIT_RETRIES, and u32.
Referenced by mtnic_cmd().
00448 { 00449 struct mtnic_if_cmd_reg *hcr = mtnic->hcr; 00450 u32 status; 00451 int i; 00452 00453 for (i = 0; i < TBIT_RETRIES; i++) { 00454 status = be32_to_cpu(readl(&hcr->status_go_opcode)); 00455 if ((status & MTNIC_BC_MASK(MTNIC_MASK_CMD_REG_T_BIT)) == 00456 (mtnic->cmd.tbit << MTNIC_BC_OFF(MTNIC_MASK_CMD_REG_T_BIT))) { 00457 /* Read expected t-bit - now return go-bit value */ 00458 return status & MTNIC_BC_MASK(MTNIC_MASK_CMD_REG_GO_BIT); 00459 } 00460 } 00461 00462 DBG("Invalid tbit after %d retries!\n", TBIT_RETRIES); 00463 return -EBUSY; /* Return busy... */ 00464 }
| static int mtnic_cmd | ( | struct mtnic * | mtnic, | |
| void * | in_imm, | |||
| void * | out_imm, | |||
| u32 | in_modifier, | |||
| u16 | op | |||
| ) | [static] |
Definition at line 468 of file mtnic.c.
References be32_to_cpu, mtnic::cmd, cmdif_go_bit(), cpu_to_be32, DBG, EBUSY, GO_BIT_TIMEOUT, mtnic::hcr, mtnic_if_cmd_reg::in_param_h, mtnic_if_cmd_reg::in_param_l, mtnic_if_cmd_reg::input_modifier, mtnic_cmd::mapping, mdelay(), MTNIC_BC_MASK, MTNIC_BC_OFF, MTNIC_MASK_CMD_REG_GO_BIT, MTNIC_MASK_CMD_REG_T_BIT, mtnic_if_cmd_reg::out_param_h, mtnic_if_cmd_reg::out_param_l, readl, mtnic_if_cmd_reg::status_go_opcode, mtnic_cmd::tbit, timeout(), mtnic_if_cmd_reg::token, u16, u32, wmb, and writel.
Referenced by mtnic_CONFIG_CQ(), mtnic_CONFIG_EQ(), mtnic_CONFIG_PORT_RSS_STEER(), mtnic_CONFIG_RX(), mtnic_CONFIG_RX_RING(), mtnic_CONFIG_TX(), mtnic_CONFIG_TX_RING(), mtnic_disable(), mtnic_HEART_BEAT(), mtnic_init_card(), mtnic_map_cmd(), mtnic_OPEN_NIC(), mtnic_QUERY_CAP(), mtnic_QUERY_FW(), mtnic_RELEASE_RESOURCE(), mtnic_SET_PORT_DEFAULT_RING(), mtnic_SET_PORT_MTU(), mtnic_SET_PORT_RSS_INDIRECTION(), mtnic_SET_PORT_STATE(), and mtnic_SET_RX_RING_ADDR().
00470 { 00471 00472 struct mtnic_if_cmd_reg *hcr = mtnic->hcr; 00473 int err = 0; 00474 u32 out_param_h = 0; 00475 u32 out_param_l = 0; 00476 u32 in_param_h = 0; 00477 u32 in_param_l = 0; 00478 00479 00480 static u16 token = 0x8000; 00481 u32 status; 00482 unsigned int timeout = 0; 00483 00484 token++; 00485 00486 if ( cmdif_go_bit ( mtnic ) ) { 00487 DBG("GO BIT BUSY:%p.\n", hcr + 6); 00488 err = -EBUSY; 00489 goto out; 00490 } 00491 if (in_imm) { 00492 in_param_h = *((u32*)in_imm); 00493 in_param_l = *((u32*)in_imm + 1); 00494 } else { 00495 in_param_l = cpu_to_be32(mtnic->cmd.mapping); 00496 } 00497 out_param_l = cpu_to_be32(mtnic->cmd.mapping); 00498 00499 /* writing to MCR */ 00500 writel(in_param_h, &hcr->in_param_h); 00501 writel(in_param_l, &hcr->in_param_l); 00502 writel((u32) cpu_to_be32(in_modifier), &hcr->input_modifier); 00503 writel(out_param_h, &hcr->out_param_h); 00504 writel(out_param_l, &hcr->out_param_l); 00505 writel((u32)cpu_to_be32(token << 16), &hcr->token); 00506 wmb(); 00507 00508 /* flip toggle bit before each write to the HCR */ 00509 mtnic->cmd.tbit = !mtnic->cmd.tbit; 00510 writel( ( u32 ) 00511 cpu_to_be32(MTNIC_BC_MASK(MTNIC_MASK_CMD_REG_GO_BIT) | 00512 ( mtnic->cmd.tbit << MTNIC_BC_OFF ( MTNIC_MASK_CMD_REG_T_BIT ) ) | op ), 00513 &hcr->status_go_opcode); 00514 00515 while ( cmdif_go_bit ( mtnic ) && ( timeout <= GO_BIT_TIMEOUT ) ) { 00516 mdelay ( 1 ); 00517 ++timeout; 00518 } 00519 00520 if ( cmdif_go_bit ( mtnic ) ) { 00521 DBG("Command opcode:0x%x token:0x%x TIMEOUT.\n", op, token); 00522 err = -EBUSY; 00523 goto out; 00524 } 00525 00526 if (out_imm) { 00527 *((u32 *)out_imm) = readl(&hcr->out_param_h); 00528 *((u32 *)out_imm + 1) = readl(&hcr->out_param_l); 00529 } 00530 00531 status = be32_to_cpu((u32)readl(&hcr->status_go_opcode)) >> 24; 00532 00533 if (status) { 00534 DBG("Command opcode:0x%x token:0x%x returned:0x%x\n", 00535 op, token, status); 00536 return status; 00537 } 00538 00539 out: 00540 return err; 00541 }
| static int mtnic_map_cmd | ( | struct mtnic * | mtnic, | |
| u16 | op, | |||
| struct mtnic_pages | pages | |||
| ) | [static] |
Definition at line 545 of file mtnic.c.
References mtnic_pages::buf, mtnic_cmd::buf, mtnic::cmd, cpu_to_be32, DBG, EADDRINUSE, EIO, memset(), mtnic_cmd(), MTNIC_MAILBOX_SIZE, NULL, mtnic_pages::num, PAGE_MASK, PAGE_SIZE, u32, umalloc(), and virt_to_bus().
Referenced by mtnic_init_card().
00546 { 00547 unsigned int j; 00548 u32 addr; 00549 unsigned int len; 00550 u32 *page_arr = mtnic->cmd.buf; 00551 int nent = 0; 00552 int err = 0; 00553 00554 memset(page_arr, 0, PAGE_SIZE); 00555 00556 len = PAGE_SIZE * pages.num; 00557 pages.buf = (u32 *)umalloc(PAGE_SIZE * (pages.num + 1)); 00558 addr = PAGE_SIZE + ((virt_to_bus(pages.buf) & 0xfffff000) + PAGE_SIZE); 00559 DBG("Mapping pages: size: %x address: %p\n", pages.num, pages.buf); 00560 00561 if (addr & (PAGE_MASK)) { 00562 DBG("Got FW area not aligned to %d (%llx/%x)\n", 00563 PAGE_SIZE, (u64) addr, len); 00564 return -EADDRINUSE; 00565 } 00566 00567 /* Function maps each PAGE seperately */ 00568 for (j = 0; j < len; j+= PAGE_SIZE) { 00569 page_arr[nent * 4 + 3] = cpu_to_be32(addr + j); 00570 if (++nent == MTNIC_MAILBOX_SIZE / 16) { 00571 err = mtnic_cmd(mtnic, NULL, NULL, nent, op); 00572 if (err) 00573 return -EIO; 00574 nent = 0; 00575 } 00576 } 00577 00578 if (nent) { 00579 err = mtnic_cmd(mtnic, NULL, NULL, nent, op); 00580 } 00581 return err; 00582 }
| static int mtnic_QUERY_FW | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 590 of file mtnic.c.
References be16_to_cpu, be32_to_cpu, be64_to_cpu, mtnic_cmd::buf, mtnic::cmd, DBG, EIO, mtnic::err_buf, mtnic_if_query_fw_out_mbox::err_buf_size, mtnic_if_query_fw_out_mbox::err_buf_start, mtnic::fw, mtnic_if_query_fw_out_mbox::fw_pages, mtnic::fw_pages, mtnic::fw_ver, mtnic_if_query_fw_out_mbox::ifc_rev, mtnic::ifc_rev, mtnic_cmd(), MTNIC_IF_CMD_QUERY_FW, NULL, mtnic_pages::num, mtnic_err_buf::offset, mtnic_if_query_fw_out_mbox::rev_maj, mtnic_if_query_fw_out_mbox::rev_min, mtnic_if_query_fw_out_mbox::rev_smin, and mtnic_err_buf::size.
Referenced by mtnic_init_card().
00591 { 00592 int err; 00593 struct mtnic_if_query_fw_out_mbox *cmd = mtnic->cmd.buf; 00594 00595 err = mtnic_cmd(mtnic, NULL, NULL, 0, MTNIC_IF_CMD_QUERY_FW); 00596 if (err) 00597 return -EIO; 00598 00599 /* Get FW and interface versions */ 00600 mtnic->fw_ver = ((u64) be16_to_cpu(cmd->rev_maj) << 32) | 00601 ((u64) be16_to_cpu(cmd->rev_min) << 16) | 00602 (u64) be16_to_cpu(cmd->rev_smin); 00603 mtnic->fw.ifc_rev = be16_to_cpu(cmd->ifc_rev); 00604 00605 /* Get offset for internal error reports (debug) */ 00606 mtnic->fw.err_buf.offset = be64_to_cpu(cmd->err_buf_start); 00607 mtnic->fw.err_buf.size = be32_to_cpu(cmd->err_buf_size); 00608 00609 DBG("Error buf offset is %llx\n", mtnic->fw.err_buf.offset); 00610 00611 /* Get number of required FW (4k) pages */ 00612 mtnic->fw.fw_pages.num = be16_to_cpu(cmd->fw_pages); 00613 00614 return 0; 00615 }
| static int mtnic_OPEN_NIC | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 619 of file mtnic.c.
References be32_to_cpu, mtnic_cmd::buf, mtnic::cmd, DBG, mtnic::extra_pages, mtnic::fw, mtnic_if_open_nic_in_mbox::log_cq_p1, mtnic_if_open_nic_in_mbox::log_cq_p2, mtnic_if_open_nic_in_mbox::log_rx_p1, mtnic_if_open_nic_in_mbox::log_rx_p2, mtnic_if_open_nic_in_mbox::log_tx_p1, mtnic_if_open_nic_in_mbox::log_tx_p2, memset(), mtnic_cmd(), MTNIC_IF_CMD_OPEN_NIC, MTNIC_IF_STEER_RSS, NULL, mtnic_pages::num, mtnic_if_open_nic_in_mbox::steer_p1, mtnic_if_open_nic_in_mbox::steer_p2, and u32.
Referenced by mtnic_init_card().
00620 { 00621 struct mtnic_if_open_nic_in_mbox *open_nic = mtnic->cmd.buf; 00622 u32 extra_pages[2] = {0}; 00623 int err; 00624 00625 memset(open_nic, 0, sizeof *open_nic); 00626 00627 /* port 1 */ 00628 open_nic->log_rx_p1 = 0; 00629 open_nic->log_cq_p1 = 1; 00630 00631 open_nic->log_tx_p1 = 0; 00632 open_nic->steer_p1 = MTNIC_IF_STEER_RSS; 00633 /* MAC + VLAN - leave reserved */ 00634 00635 /* port 2 */ 00636 open_nic->log_rx_p2 = 0; 00637 open_nic->log_cq_p2 = 1; 00638 00639 open_nic->log_tx_p2 = 0; 00640 open_nic->steer_p2 = MTNIC_IF_STEER_RSS; 00641 /* MAC + VLAN - leave reserved */ 00642 00643 err = mtnic_cmd(mtnic, NULL, extra_pages, 0, MTNIC_IF_CMD_OPEN_NIC); 00644 00645 mtnic->fw.extra_pages.num = be32_to_cpu(*(extra_pages+1)); 00646 DBG("Extra pages num is %x\n", mtnic->fw.extra_pages.num); 00647 return err; 00648 }
| static int mtnic_CONFIG_RX | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 651 of file mtnic.c.
References memset(), mtnic_cmd(), MTNIC_IF_CMD_CONFIG_RX, and NULL.
Referenced by mtnic_init_card().
00652 { 00653 struct mtnic_if_config_rx_in_imm config_rx; 00654 00655 memset(&config_rx, 0, sizeof config_rx); 00656 return mtnic_cmd(mtnic, &config_rx, NULL, 0, MTNIC_IF_CMD_CONFIG_RX); 00657 }
| static int mtnic_CONFIG_TX | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 660 of file mtnic.c.
References mtnic_if_config_send_in_imm::enph_gpf, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_TX, and NULL.
Referenced by mtnic_init_card().
00661 { 00662 struct mtnic_if_config_send_in_imm config_tx; 00663 00664 config_tx.enph_gpf = 0; 00665 return mtnic_cmd(mtnic, &config_tx, NULL, 0, MTNIC_IF_CMD_CONFIG_TX); 00666 }
| static int mtnic_HEART_BEAT | ( | struct mtnic_port * | priv, | |
| u32 * | link_state | |||
| ) | [static] |
Definition at line 669 of file mtnic.c.
References be32_to_cpu, DBG, EIO, mtnic_if_heart_beat_out_imm::flags, mtnic_port::mtnic, MTNIC_BC_MASK, mtnic_cmd(), MTNIC_IF_CMD_HEART_BEAT, MTNIC_MASK_HEAR_BEAT_INT_ERROR, NULL, and u32.
Referenced by mtnic_open(), and mtnic_poll().
00670 { 00671 struct mtnic_if_heart_beat_out_imm heart_beat; 00672 00673 int err; 00674 u32 flags; 00675 err = mtnic_cmd(priv->mtnic, NULL, &heart_beat, 0, MTNIC_IF_CMD_HEART_BEAT); 00676 if (!err) { 00677 flags = be32_to_cpu(heart_beat.flags); 00678 if (flags & MTNIC_BC_MASK(MTNIC_MASK_HEAR_BEAT_INT_ERROR)) { 00679 DBG("Internal error detected\n"); 00680 return -EIO; 00681 } 00682 *link_state = flags & 00683 ~((u32) MTNIC_BC_MASK(MTNIC_MASK_HEAR_BEAT_INT_ERROR)); 00684 } 00685 return err; 00686 }
| static int mtnic_SET_PORT_DEFAULT_RING | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u16 | ring | |||
| ) | [static] |
Definition at line 694 of file mtnic.c.
References memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_SET_PORT_DEFAULT_RING, NULL, and mtnic_if_set_port_default_ring_in_imm::ring.
Referenced by mtnic_open().
00695 { 00696 struct mtnic_if_set_port_default_ring_in_imm def_ring; 00697 00698 memset(&def_ring, 0, sizeof(def_ring)); 00699 def_ring.ring = ring; 00700 return mtnic_cmd(priv->mtnic, &def_ring, NULL, port + 1, 00701 MTNIC_IF_CMD_SET_PORT_DEFAULT_RING); 00702 }
| static int mtnic_CONFIG_PORT_RSS_STEER | ( | struct mtnic_port * | priv, | |
| int | port | |||
| ) | [static] |
Definition at line 705 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_PORT_RSS_STEER, NULL, and PAGE_SIZE.
Referenced by mtnic_open().
00706 { 00707 memset(priv->mtnic->cmd.buf, 0, PAGE_SIZE); 00708 return mtnic_cmd(priv->mtnic, NULL, NULL, port + 1, 00709 MTNIC_IF_CMD_CONFIG_PORT_RSS_STEER); 00710 }
| static int mtnic_SET_PORT_RSS_INDIRECTION | ( | struct mtnic_port * | priv, | |
| int | port | |||
| ) | [static] |
Definition at line 713 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_SET_PORT_RSS_INDIRECTION, NULL, and PAGE_SIZE.
Referenced by mtnic_open().
00715 { 00716 memset(priv->mtnic->cmd.buf, 0, PAGE_SIZE); 00717 return mtnic_cmd(priv->mtnic, NULL, NULL, port + 1, 00718 MTNIC_IF_CMD_SET_PORT_RSS_INDIRECTION); 00719 }
| static int mtnic_CONFIG_CQ | ( | struct mtnic_port * | priv, | |
| int | port, | |||
| u16 | cq_ind, | |||
| struct mtnic_cq * | cq | |||
| ) | [static] |
Definition at line 726 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, cpu_to_be32, mtnic_if_config_cq_in_mbox::cq, mtnic_cq::db_dma, mtnic_if_config_cq_in_mbox::db_record_addr_l, DBG, mtnic_cq::dma, fls, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_CQ, NULL, mtnic_if_config_cq_in_mbox::offset, mtnic_if_config_cq_in_mbox::page_address, PAGE_MASK, mtnic_if_config_cq_in_mbox::size, and UNITS_BUFFER_SIZE.
Referenced by mtnic_open().
00728 { 00729 struct mtnic_if_config_cq_in_mbox *config_cq = priv->mtnic->cmd.buf; 00730 00731 memset(config_cq, 0, sizeof *config_cq); 00732 config_cq->cq = cq_ind; 00733 config_cq->size = fls(UNITS_BUFFER_SIZE - 1); 00734 config_cq->offset = ((cq->dma) & (PAGE_MASK)) >> 6; 00735 config_cq->db_record_addr_l = cpu_to_be32(cq->db_dma); 00736 config_cq->page_address[1] = cpu_to_be32(cq->dma); 00737 DBG("config cq address: %x dma_address: %lx" 00738 "offset: %d size %d index: %d\n" 00739 , config_cq->page_address[1],cq->dma, 00740 config_cq->offset, config_cq->size, config_cq->cq ); 00741 00742 return mtnic_cmd(priv->mtnic, NULL, NULL, port + 1, 00743 MTNIC_IF_CMD_CONFIG_CQ); 00744 }
| static int mtnic_CONFIG_TX_RING | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u16 | ring_ind, | |||
| struct mtnic_ring * | ring | |||
| ) | [static] |
Definition at line 748 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, cpu_to_be16, cpu_to_be32, mtnic_ring::cq, mtnic_if_config_send_ring_in_mbox::cq, mtnic_ring::dma, fls, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_TX_RING, NULL, mtnic_if_config_send_ring_in_mbox::page_address, mtnic_if_config_send_ring_in_mbox::ring, mtnic_if_config_send_ring_in_mbox::size, and UNITS_BUFFER_SIZE.
Referenced by mtnic_open().
00750 { 00751 struct mtnic_if_config_send_ring_in_mbox *config_tx_ring = priv->mtnic->cmd.buf; 00752 memset(config_tx_ring, 0, sizeof *config_tx_ring); 00753 config_tx_ring->ring = cpu_to_be16(ring_ind); 00754 config_tx_ring->size = fls(UNITS_BUFFER_SIZE - 1); 00755 config_tx_ring->cq = cpu_to_be16(ring->cq); 00756 config_tx_ring->page_address[1] = cpu_to_be32(ring->dma); 00757 00758 return mtnic_cmd(priv->mtnic, NULL, NULL, port + 1, 00759 MTNIC_IF_CMD_CONFIG_TX_RING); 00760 }
| static int mtnic_CONFIG_RX_RING | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u16 | ring_ind, | |||
| struct mtnic_ring * | ring | |||
| ) | [static] |
Definition at line 763 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, cpu_to_be16, cpu_to_be32, mtnic_ring::cq, mtnic_if_config_rx_ring_in_mbox::cq, mtnic_ring::db_dma, mtnic_if_config_rx_ring_in_mbox::db_record_addr_l, DBG, mtnic_ring::dma, fls, memset(), mtnic_port::mtnic, MTNIC_BC_PUT, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_RX_RING, MTNIC_MASK_CONFIG_RX_RING_SIZE, MTNIC_MASK_CONFIG_RX_RING_STRIDE, NULL, mtnic_if_config_rx_ring_in_mbox::page_address, mtnic_if_config_rx_ring_in_mbox::ring, mtnic_if_config_rx_ring_in_mbox::stride_size, and UNITS_BUFFER_SIZE.
Referenced by mtnic_open().
00765 { 00766 struct mtnic_if_config_rx_ring_in_mbox *config_rx_ring = priv->mtnic->cmd.buf; 00767 memset(config_rx_ring, 0, sizeof *config_rx_ring); 00768 config_rx_ring->ring = ring_ind; 00769 MTNIC_BC_PUT(config_rx_ring->stride_size, fls(UNITS_BUFFER_SIZE - 1), 00770 MTNIC_MASK_CONFIG_RX_RING_SIZE); 00771 MTNIC_BC_PUT(config_rx_ring->stride_size, 1, 00772 MTNIC_MASK_CONFIG_RX_RING_STRIDE); 00773 config_rx_ring->cq = cpu_to_be16(ring->cq); 00774 config_rx_ring->db_record_addr_l = cpu_to_be32(ring->db_dma); 00775 00776 DBG("Config RX ring starting at address:%lx\n", ring->dma); 00777 00778 config_rx_ring->page_address[1] = cpu_to_be32(ring->dma); 00779 00780 return mtnic_cmd(priv->mtnic, NULL, NULL, port + 1, 00781 MTNIC_IF_CMD_CONFIG_RX_RING); 00782 }
| static int mtnic_CONFIG_EQ | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 785 of file mtnic.c.
References mtnic_cmd::buf, mtnic::cmd, cpu_to_be32, DBG, mtnic_eq::dma, EADDRINUSE, mtnic::eq, fls, mtnic_if_config_eq_in_mbox::int_vector, memset(), MTNIC_BC_PUT, mtnic_cmd(), MTNIC_IF_CMD_CONFIG_EQ, MTNIC_MASK_CONFIG_EQ_INT_VEC, MTNIC_MASK_CONFIG_EQ_OFFSET, MTNIC_MASK_CONFIG_EQ_SIZE, NULL, mtnic_if_config_eq_in_mbox::offset, mtnic_if_config_eq_in_mbox::page_address, PAGE_MASK, mtnic_eq::size, and mtnic_if_config_eq_in_mbox::size.
Referenced by mtnic_init_card().
00786 { 00787 struct mtnic_if_config_eq_in_mbox *eq = mtnic->cmd.buf; 00788 00789 if (mtnic->eq.dma & (PAGE_MASK)) { 00790 DBG("misalligned eq buffer:%lx\n", 00791 mtnic->eq.dma); 00792 return -EADDRINUSE; 00793 } 00794 00795 memset(eq, 0, sizeof *eq); 00796 MTNIC_BC_PUT(eq->offset, mtnic->eq.dma >> 6, MTNIC_MASK_CONFIG_EQ_OFFSET); 00797 MTNIC_BC_PUT(eq->size, fls(mtnic->eq.size - 1) - 1, MTNIC_MASK_CONFIG_EQ_SIZE); 00798 MTNIC_BC_PUT(eq->int_vector, 0, MTNIC_MASK_CONFIG_EQ_INT_VEC); 00799 eq->page_address[1] = cpu_to_be32(mtnic->eq.dma); 00800 00801 return mtnic_cmd(mtnic, NULL, NULL, 0, MTNIC_IF_CMD_CONFIG_EQ); 00802 }
| static int mtnic_SET_RX_RING_ADDR | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u64 * | mac | |||
| ) | [static] |
Definition at line 808 of file mtnic.c.
References cpu_to_be16, cpu_to_be32, mtnic_if_set_rx_ring_addr_in_imm::flags_vlan_id, mtnic_if_set_rx_ring_addr_in_imm::mac_31_0, mtnic_if_set_rx_ring_addr_in_imm::mac_47_32, memset(), mtnic_port::mtnic, MTNIC_BC_MASK, mtnic_cmd(), MTNIC_IF_CMD_SET_RX_RING_ADDR, MTNIC_MASK_SET_RX_RING_ADDR_BY_MAC, NULL, and u32.
Referenced by mtnic_open().
00809 { 00810 struct mtnic_if_set_rx_ring_addr_in_imm ring_addr; 00811 u32 modifier = ((u32) port + 1) << 16; 00812 00813 memset(&ring_addr, 0, sizeof(ring_addr)); 00814 00815 ring_addr.mac_31_0 = cpu_to_be32(*mac & 0xffffffff); 00816 ring_addr.mac_47_32 = cpu_to_be16((*mac >> 32) & 0xffff); 00817 ring_addr.flags_vlan_id |= cpu_to_be16( 00818 MTNIC_BC_MASK(MTNIC_MASK_SET_RX_RING_ADDR_BY_MAC)); 00819 00820 return mtnic_cmd(priv->mtnic, &ring_addr, NULL, modifier, MTNIC_IF_CMD_SET_RX_RING_ADDR); 00821 }
| static int mtnic_SET_PORT_STATE | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u8 | state | |||
| ) | [static] |
Definition at line 824 of file mtnic.c.
References cpu_to_be32, mtnic_port::mtnic, MTNIC_BC_MASK, mtnic_cmd(), MTNIC_IF_CMD_SET_PORT_STATE, MTNIC_MASK_CONFIG_PORT_STATE, NULL, mtnic_if_set_port_state_in_imm::reserved, and mtnic_if_set_port_state_in_imm::state.
Referenced by mtnic_close(), and mtnic_open().
00825 { 00826 struct mtnic_if_set_port_state_in_imm port_state; 00827 00828 port_state.state = state ? cpu_to_be32( 00829 MTNIC_BC_MASK(MTNIC_MASK_CONFIG_PORT_STATE)) : 0; 00830 port_state.reserved = 0; 00831 return mtnic_cmd(priv->mtnic, &port_state, NULL, port + 1, 00832 MTNIC_IF_CMD_SET_PORT_STATE); 00833 }
| static int mtnic_SET_PORT_MTU | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u16 | mtu | |||
| ) | [static] |
Definition at line 836 of file mtnic.c.
References cpu_to_be16, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_SET_PORT_MTU, mtnic_if_set_port_mtu_in_imm::mtu, and NULL.
Referenced by mtnic_open().
00837 { 00838 struct mtnic_if_set_port_mtu_in_imm set_mtu; 00839 00840 memset(&set_mtu, 0, sizeof(set_mtu)); 00841 set_mtu.mtu = cpu_to_be16(mtu); 00842 return mtnic_cmd(priv->mtnic, &set_mtu, NULL, port + 1, 00843 MTNIC_IF_CMD_SET_PORT_MTU); 00844 }
| static int mtnic_RELEASE_RESOURCE | ( | struct mtnic_port * | priv, | |
| u8 | port, | |||
| u8 | type, | |||
| u8 | index | |||
| ) | [static] |
Definition at line 862 of file mtnic.c.
References mtnic_if_release_resource_in_imm::index, memset(), mtnic_port::mtnic, mtnic_cmd(), MTNIC_IF_CMD_RELEASE_RESOURCE, MTNIC_IF_RESOURCE_TYPE_EQ, NULL, and mtnic_if_release_resource_in_imm::type.
Referenced by mtnic_close(), mtnic_disable(), and mtnic_open().
00863 { 00864 struct mtnic_if_release_resource_in_imm rel; 00865 memset(&rel, 0, sizeof rel); 00866 rel.index = index; 00867 rel.type = type; 00868 return mtnic_cmd ( priv->mtnic, 00869 &rel, NULL, ( type == MTNIC_IF_RESOURCE_TYPE_EQ ) ? 00870 0 : port + 1, MTNIC_IF_CMD_RELEASE_RESOURCE ); 00871 }
Definition at line 875 of file mtnic.c.
References be32_to_cpu, mtnic_if_query_cap_in_imm::cap_index, mtnic_if_query_cap_in_imm::cap_modifier, DBG, memset(), mtnic_cmd(), MTNIC_IF_CMD_QUERY_CAP, and u32.
00876 { 00877 struct mtnic_if_query_cap_in_imm cap; 00878 u32 out_imm[2]; 00879 int err; 00880 00881 memset(&cap, 0, sizeof cap); 00882 cap.cap_index = index; 00883 cap.cap_modifier = mod; 00884 err = mtnic_cmd(mtnic, &cap, &out_imm, 0, MTNIC_IF_CMD_QUERY_CAP); 00885 00886 *((u32*)result) = be32_to_cpu(*(out_imm+1)); 00887 *((u32*)result + 1) = be32_to_cpu(*out_imm); 00888 00889 DBG("Called Query cap with index:0x%x mod:%d result:0x%llx" 00890 " error:%d\n", index, mod, *result, err); 00891 return err; 00892 }
| static int mtnic_query_num_ports | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 902 of file mtnic.c.
References DO_QUERY_CAP, mtnic::fw, MTNIC_IF_CAP_NUM_PORTS, and mtnic::num_ports.
Referenced by mtnic_init_card().
00903 { 00904 int err = 0; 00905 u64 result; 00906 00907 DO_QUERY_CAP(MTNIC_IF_CAP_NUM_PORTS, 0, mtnic->fw.num_ports); 00908 00909 return 0; 00910 }
| static int mtnic_query_mac | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 913 of file mtnic.c.
References DO_QUERY_CAP, mtnic::fw, mtnic::mac, MTNIC_IF_CAP_DEFAULT_MAC, and mtnic::num_ports.
Referenced by mtnic_init_card().
00914 { 00915 int err = 0; 00916 int i; 00917 u64 result; 00918 00919 for (i = 0; i < mtnic->fw.num_ports; i++) { 00920 DO_QUERY_CAP(MTNIC_IF_CAP_DEFAULT_MAC, i + 1, mtnic->fw.mac[i]); 00921 } 00922 00923 return 0; 00924 }
| static int mtnic_query_offsets | ( | struct mtnic * | mtnic | ) | [static] |
Definition at line 927 of file mtnic.c.
References cpu_to_be32, mtnic::cq_offset, DBG, DO_QUERY_CAP, mtnic::eq_db_offset, mtnic::fw, mdelay(), mtnic::mem_type_snoop_be, MTNIC_IF_CAP_CQ_OFFSET, MTNIC_IF_CAP_EQ_DB_OFFSET, MTNIC_IF_CAP_MEM_KEY, MTNIC_IF_CAP_RX_OFFSET, MTNIC_IF_CAP_TX_CQ_DB_OFFSET, MTNIC_IF_CAP_TX_OFFSET, MTNIC_IF_MEM_TYPE_SNOOP, mtnic::num_ports, mtnic::rx_offset, mtnic::tx_offset, and mtnic::txcq_db_offset.
Referenced by mtnic_init_card().
00928 { 00929 int err; 00930 int i; 00931 u64 result; 00932 00933 DO_QUERY_CAP(MTNIC_IF_CAP_MEM_KEY, 00934 MTNIC_IF_MEM_TYPE_SNOOP, 00935 mtnic->fw.mem_type_snoop_be); 00936 mtnic->fw.mem_type_snoop_be = cpu_to_be32(mtnic->fw.mem_type_snoop_be); 00937 DO_QUERY_CAP(MTNIC_IF_CAP_TX_CQ_DB_OFFSET, 0, mtnic->fw.txcq_db_offset); 00938 DO_QUERY_CAP(MTNIC_IF_CAP_EQ_DB_OFFSET, 0, mtnic->fw.eq_db_offset); 00939 00940 for (i = 0; i < mtnic->fw.num_ports; i++) { 00941 DO_QUERY_CAP(MTNIC_IF_CAP_CQ_OFFSET, i + 1, mtnic->fw.cq_offset); 00942 DO_QUERY_CAP(MTNIC_IF_CAP_TX_OFFSET, i + 1, mtnic->fw.tx_offset[i]); 00943 DO_QUERY_CAP(MTNIC_IF_CAP_RX_OFFSET, i + 1, mtnic->fw.rx_offset[i]); 00944 DBG("--> Port %d CQ offset:0x%x\n", i, mtnic->fw.cq_offset); 00945 DBG("--> Port %d Tx offset:0x%x\n", i, mtnic->fw.tx_offset[i]); 00946 DBG("--> Port %d Rx offset:0x%x\n", i, mtnic->fw.rx_offset[i]); 00947 } 00948 00949 mdelay(20); 00950 return 0; 00951 }
| void mtnic_reset | ( | void | ) |
Reset device.
Definition at line 976 of file mtnic.c.
References pcidev::bar, cpu_to_be32, dev_pci_struct::dev, ioremap(), iounmap(), mtnic_pci_dev, MTNIC_RESET_OFFSET, and writel.
Referenced by mtnic_disable(), and mtnic_probe().
00977 { 00978 void *reset = ioremap ( mtnic_pci_dev.dev.bar[0] + MTNIC_RESET_OFFSET, 00979 4 ); 00980 writel ( cpu_to_be32 ( 1 ), reset ); 00981 iounmap ( reset ); 00982 }
| static int restore_config | ( | void | ) | [static] |
Restore PCI config.
Definition at line 989 of file mtnic.c.
References pcidev::dev, dev_pci_struct::dev, mtnic_pci_dev, and pci_write_config_dword().
Referenced by mtnic_disable(), and mtnic_probe().
00990 { 00991 int i; 00992 int rc; 00993 00994 for (i = 0; i < 64; ++i) { 00995 if (i != 22 && i != 23) { 00996 rc = pci_write_config_dword(mtnic_pci_dev.dev.dev, 00997 i << 2, 00998 mtnic_pci_dev.dev. 00999 dev_config_space[i]); 01000 if (rc) 01001 return rc; 01002 } 01003 } 01004 return 0; 01005 }
| static int mtnic_init_pci | ( | struct pci_device * | dev | ) | [static] |
Init PCI configuration.
Definition at line 1013 of file mtnic.c.
References pcidev::bar, pci_device::bus, DBG, pcidev::dev, dev_pci_struct::dev, pci_device::devfn, mtnic_pci_dev, pci_bar_start(), PCI_BASE_ADDRESS_0, and pci_read_config_dword().
Referenced by mtnic_probe().
01014 { 01015 int i; 01016 int err; 01017 01018 /* save bars */ 01019 DBG("bus=%d devfn=0x%x\n", dev->bus, dev->devfn); 01020 for (i = 0; i < 6; ++i) { 01021 mtnic_pci_dev.dev.bar[i] = 01022 pci_bar_start(dev, PCI_BASE_ADDRESS_0 + (i << 2)); 01023 DBG("bar[%d]= 0x%08lx \n", i, mtnic_pci_dev.dev.bar[i]); 01024 } 01025 01026 /* save config space */ 01027 for (i = 0; i < 64; ++i) { 01028 err = pci_read_config_dword(dev, i << 2, 01029 &mtnic_pci_dev.dev. 01030 dev_config_space[i]); 01031 if (err) { 01032 DBG("Can not save configuration space"); 01033 return err; 01034 } 01035 } 01036 01037 mtnic_pci_dev.dev.dev = dev; 01038 01039 return 0; 01040 }
| static int mtnic_init_card | ( | struct mtnic * | mtnic | ) | [inline, static] |
Initial hardware.
Bring up HW
Definition at line 1046 of file mtnic.c.
References mtnic_cmd::buf, mtnic_eq::buf, mtnic_pages::buf, mtnic_eq::buf_size, mtnic::cmd, DBG, EADDRINUSE, mtnic::eq, mtnic::eq_db, mtnic::extra_pages, free_memblock(), mtnic::fw, mtnic::fw_pages, mtnic::fw_ver, mtnic::hcr, mtnic::ifc_rev, iounmap(), mtnic_alloc_cmdif(), mtnic_alloc_eq(), mtnic_cmd(), mtnic_CONFIG_EQ(), mtnic_CONFIG_RX(), mtnic_CONFIG_TX(), MTNIC_IF_CMD_MAP_FW, MTNIC_IF_CMD_MAP_PAGES, MTNIC_IF_CMD_RUN_FW, mtnic_map_cmd(), mtnic_OPEN_NIC(), mtnic_QUERY_FW(), mtnic_query_mac(), mtnic_query_num_ports(), mtnic_query_offsets(), NULL, mtnic_pages::num, PAGE_SIZE, u16, and ufree().
Referenced by mtnic_probe().
01047 { 01048 int err = 0; 01049 01050 01051 /* Alloc command interface */ 01052 err = mtnic_alloc_cmdif ( mtnic ); 01053 if (err) { 01054 DBG("Failed to init command interface, aborting\n"); 01055 return -EADDRINUSE; 01056 } 01057 01058 01059 /** 01060 * Bring up HW 01061 */ 01062 err = mtnic_QUERY_FW ( mtnic ); 01063 if (err) { 01064 DBG("QUERY_FW command failed, aborting\n"); 01065 goto cmd_error; 01066 } 01067 DBG("Command interface revision:%d\n", mtnic->fw.ifc_rev); 01068 01069 /* Allocate memory for FW and start it */ 01070 err = mtnic_map_cmd(mtnic, MTNIC_IF_CMD_MAP_FW, mtnic->fw.fw_pages); 01071 if (err) { 01072 DBG("Eror In MAP_FW\n"); 01073 if (mtnic->fw.fw_pages.buf) 01074 ufree((intptr_t)mtnic->fw.fw_pages.buf); 01075 goto cmd_error; 01076 } 01077 01078 /* Run firmware */ 01079 err = mtnic_cmd(mtnic, NULL, NULL, 0, MTNIC_IF_CMD_RUN_FW); 01080 if (err) { 01081 DBG("Eror In RUN FW\n"); 01082 goto map_fw_error; 01083 } 01084 01085 DBG("FW version:%d.%d.%d\n", 01086 (u16) (mtnic->fw_ver >> 32), 01087 (u16) ((mtnic->fw_ver >> 16) & 0xffff), 01088 (u16) (mtnic->fw_ver & 0xffff)); 01089 01090 01091 /* Query num ports */ 01092 err = mtnic_query_num_ports(mtnic); 01093 if (err) { 01094 DBG("Insufficient resources, aborting\n"); 01095 goto map_fw_error; 01096 } 01097 01098 /* Open NIC */ 01099 err = mtnic_OPEN_NIC(mtnic); 01100 if (err) { 01101 DBG("Failed opening NIC, aborting\n"); 01102 goto map_fw_error; 01103 } 01104 01105 /* Allocate and map pages worksace */ 01106 err = mtnic_map_cmd(mtnic, MTNIC_IF_CMD_MAP_PAGES, mtnic->fw.extra_pages); 01107 if (err) { 01108 DBG("Couldn't allocate %x FW extra pages, aborting\n", 01109 mtnic->fw.extra_pages.num); 01110 if (mtnic->fw.extra_pages.buf) 01111 ufree((intptr_t)mtnic->fw.extra_pages.buf); 01112 goto map_fw_error; 01113 } 01114 01115 01116 /* Get device information */ 01117 err = mtnic_query_mac(mtnic); 01118 if (err) { 01119 DBG("Insufficient resources in quesry mac, aborting\n"); 01120 goto map_fw_error; 01121 } 01122 01123 /* Get device offsets */ 01124 err = mtnic_query_offsets(mtnic); 01125 if (err) { 01126 DBG("Failed retrieving resource offests, aborting\n"); 01127 ufree((intptr_t)mtnic->fw.extra_pages.buf); 01128 goto map_extra_error; 01129 } 01130 01131 01132 /* Alloc EQ */ 01133 err = mtnic_alloc_eq(mtnic); 01134 if (err) { 01135 DBG("Failed init shared resources. error: %d\n", err); 01136 goto map_extra_error; 01137 } 01138 01139 /* Configure HW */ 01140 err = mtnic_CONFIG_EQ(mtnic); 01141 if (err) { 01142 DBG("Failed configuring EQ\n"); 01143 goto eq_error; 01144 } 01145 err = mtnic_CONFIG_RX(mtnic); 01146 if (err) { 01147 DBG("Failed Rx configuration\n"); 01148 goto eq_error; 01149 } 01150 err = mtnic_CONFIG_TX(mtnic); 01151 if (err) { 01152 DBG("Failed Tx configuration\n"); 01153 goto eq_error; 01154 } 01155 01156 01157 return 0; 01158 01159 01160 eq_error: 01161 iounmap(mtnic->eq_db); 01162 free_memblock(mtnic->eq.buf, mtnic->eq.buf_size); 01163 map_extra_error: 01164 ufree((intptr_t)mtnic->fw.extra_pages.buf); 01165 map_fw_error: 01166 ufree((intptr_t)mtnic->fw.fw_pages.buf); 01167 01168 cmd_error: 01169 iounmap(mtnic->hcr); 01170 free_memblock(mtnic->cmd.buf, PAGE_SIZE); 01171 01172 return -EADDRINUSE; 01173 }
| void mtnic_process_tx_cq | ( | struct mtnic_port * | priv, | |
| struct net_device * | dev, | |||
| struct mtnic_cq * | cq | |||
| ) |
Definition at line 1192 of file mtnic.c.
References mtnic_cq::buf, mtnic_ring::cons, cpu_to_be32, mtnic_cq::db, index, mtnic_ring::iobuf, mtnic_cq::last, MTNIC_BIT_CQ_OWN, netdev_tx_complete(), mtnic_cqe::op_tr_own, mtnic_cq::size, mtnic_port::tx_ring, u16, mtnic_cq_db_record::update_ci, wmb, and XNOR.
Referenced by mtnic_poll().
01194 { 01195 struct mtnic_cqe *cqe = cq->buf; 01196 struct mtnic_ring *ring = &priv->tx_ring; 01197 u16 index; 01198 01199 01200 index = cq->last & (cq->size-1); 01201 cqe = &cq->buf[index]; 01202 01203 /* Owner bit changes every round */ 01204 while (XNOR(cqe->op_tr_own & MTNIC_BIT_CQ_OWN, cq->last & cq->size)) { 01205 netdev_tx_complete (dev, ring->iobuf[index]); 01206 ++cq->last; 01207 index = cq->last & (cq->size-1); 01208 cqe = &cq->buf[index]; 01209 } 01210 01211 /* Update consumer index */ 01212 cq->db->update_ci = cpu_to_be32(cq->last & 0xffffff); 01213 wmb(); /* ensure HW sees CQ consumer before we post new buffers */ 01214 ring->cons = cq->last; 01215 }
| int mtnic_process_rx_cq | ( | struct mtnic_port * | priv, | |
| struct net_device * | dev, | |||
| struct mtnic_cq * | cq | |||
| ) |
Definition at line 1218 of file mtnic.c.
References be32_to_cpu, mtnic_cq::buf, mtnic_cqe::byte_cnt, mtnic_ring::cons, cpu_to_be32, mtnic_cq::db, DBG, DEF_IOBUF_SIZE, EADDRINUSE, mtnic_cqe::enc_bf, free_iob(), index, iob_put, mtnic_ring::iobuf, mtnic_cq::last, MAX_GAP_PROD_CONS, mtnic_alloc_iobuf(), MTNIC_BIT_BAD_FCS, MTNIC_BIT_CQ_OWN, MTNIC_OPCODE_ERROR, netdev_rx(), NULL, mtnic_cqe::op_tr_own, mtnic_ring::prod, mtnic_port::rx_ring, mtnic_cq::size, mtnic_cq_db_record::update_ci, wmb, and XNOR.
Referenced by mtnic_poll().
01221 { 01222 struct mtnic_cqe *cqe; 01223 struct mtnic_ring *ring = &priv->rx_ring; 01224 int index; 01225 int err; 01226 struct io_buffer *rx_iob; 01227 unsigned int length; 01228 01229 01230 /* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx 01231 * descriptor offset can be deduced from the CQE index instead of 01232 * reading 'cqe->index' */ 01233 index = cq->last & (cq->size-1); 01234 cqe = &cq->buf[index]; 01235 01236 /* Process all completed CQEs */ 01237 while (XNOR(cqe->op_tr_own & MTNIC_BIT_CQ_OWN, cq->last & cq->size)) { 01238 /* Drop packet on bad receive or bad checksum */ 01239 if ((cqe->op_tr_own & 0x1f) == MTNIC_OPCODE_ERROR) { 01240 DBG("CQE completed with error - vendor \n"); 01241 free_iob(ring->iobuf[index]); 01242 goto next; 01243 } 01244 if (cqe->enc_bf & MTNIC_BIT_BAD_FCS) { 01245 DBG("Accepted packet with bad FCS\n"); 01246 free_iob(ring->iobuf[index]); 01247 goto next; 01248 } 01249 01250 /* 01251 * Packet is OK - process it. 01252 */ 01253 length = be32_to_cpu(cqe->byte_cnt); 01254 rx_iob = ring->iobuf[index]; 01255 iob_put(rx_iob, length); 01256 01257 /* Add this packet to the receive queue. */ 01258 netdev_rx(dev, rx_iob); 01259 ring->iobuf[index] = NULL; 01260 01261 next: 01262 ++cq->last; 01263 index = cq->last & (cq->size-1); 01264 cqe = &cq->buf[index]; 01265 01266 01267 01268 } 01269 01270 /* Update consumer index */ 01271 cq->db->update_ci = cpu_to_be32(cq->last & 0xffffff); 01272 wmb(); /* ensure HW sees CQ consumer before we post new buffers */ 01273 ring->cons = cq->last; 01274 01275 if (ring->prod - ring->cons < (MAX_GAP_PROD_CONS)) { 01276 err = mtnic_alloc_iobuf(priv, &priv->rx_ring, DEF_IOBUF_SIZE); 01277 if (err) { 01278 DBG("ERROR Allocating io buffer"); 01279 return -EADDRINUSE; 01280 } 01281 } 01282 01283 return 0; 01284 }
| static int mtnic_open | ( | struct net_device * | dev | ) | [static] |
Definition at line 1310 of file mtnic.c.
References mtnic_cq::buf, mtnic_ring::buf, mtnic_cq::buf_size, mtnic_ring::buf_size, CARD_UP, CHECK_LINK_TIMES, cpu_to_be32, mtnic_port::cq, mtnic_ring::db, mtnic_cq::db, DBG, DEF_MTU, DELAY_LINK_CHECK, EADDRINUSE, ENETDOWN, free_memblock(), mtnic::fw, iounmap(), mtnic_cq::last, mtnic::mac, mdelay(), mtnic_port::mtnic, mtnic_alloc_resources(), mtnic_CONFIG_CQ(), mtnic_CONFIG_PORT_RSS_STEER(), mtnic_CONFIG_RX_RING(), mtnic_CONFIG_TX_RING(), mtnic_free_io_buffers(), mtnic_HEART_BEAT(), MTNIC_IF_RESOURCE_TYPE_CQ, MTNIC_IF_RESOURCE_TYPE_RX_RING, MTNIC_IF_RESOURCE_TYPE_TX_RING, mtnic_RELEASE_RESOURCE(), mtnic_SET_PORT_DEFAULT_RING(), mtnic_SET_PORT_MTU(), mtnic_SET_PORT_RSS_INDIRECTION(), mtnic_SET_PORT_STATE(), mtnic_SET_RX_RING_ADDR(), netdev_link_down(), netdev_link_up(), netdev_priv(), NUM_CQS, mtnic_port::port, priv, mtnic_port::rx_ring, mtnic_port::state, mtnic_port::tx_ring, mtnic_ring::txcq_db, u32, and mtnic_cq_db_record::update_ci.
01311 { 01312 struct mtnic_port *priv = netdev_priv(dev); 01313 01314 int err = 0; 01315 struct mtnic_ring *ring; 01316 struct mtnic_cq *cq; 01317 int cq_ind = 0; 01318 u32 dev_link_state; 01319 int link_check; 01320 01321 DBG("starting port:%d, MAC Address: 0x%12llx\n", 01322 priv->port, priv->mtnic->fw.mac[priv->port]); 01323 01324 /* Alloc and configure CQs, TX, RX */ 01325 err = mtnic_alloc_resources ( dev ); 01326 if (err) { 01327 DBG("Error allocating resources\n"); 01328 return -EADDRINUSE; 01329 } 01330 01331 /* Pass CQs configuration to HW */ 01332 for (cq_ind = 0; cq_ind < NUM_CQS; ++cq_ind) { 01333 cq = &priv->cq[cq_ind]; 01334 err = mtnic_CONFIG_CQ(priv, priv->port, cq_ind, cq); 01335 if (err) { 01336 DBG("Failed configuring CQ:%d error %d\n", 01337 cq_ind, err); 01338 if (cq_ind) 01339 goto cq_error; 01340 else 01341 goto allocation_error; 01342 } 01343 /* Update consumer index */ 01344 cq->db->update_ci = cpu_to_be32(cq->last & 0xffffff); 01345 } 01346 01347 01348 01349 /* Pass Tx configuration to HW */ 01350 ring = &priv->tx_ring; 01351 err = mtnic_CONFIG_TX_RING(priv, priv->port, 0, ring); 01352 if (err) { 01353 DBG("Failed configuring Tx ring:0\n"); 01354 goto cq_error; 01355 } 01356 01357 /* Pass RX configuration to HW */ 01358 ring = &priv->rx_ring; 01359 err = mtnic_CONFIG_RX_RING(priv, priv->port, 0, ring); 01360 if (err) { 01361 DBG("Failed configuring Rx ring:0\n"); 01362 goto tx_error; 01363 } 01364 01365 /* Configure Rx steering */ 01366 err = mtnic_CONFIG_PORT_RSS_STEER(priv, priv->port); 01367 if (!err) 01368 err = mtnic_SET_PORT_RSS_INDIRECTION(priv, priv->port); 01369 if (err) { 01370 DBG("Failed configuring RSS steering\n"); 01371 goto rx_error; 01372 } 01373 01374 01375 /* Set the port default ring to ring 0 */ 01376 err = mtnic_SET_PORT_DEFAULT_RING(priv, priv->port, 0); 01377 if (err) { 01378 DBG("Failed setting default ring\n"); 01379 goto rx_error; 01380 } 01381 01382 /* Set Mac address */ 01383 err = mtnic_SET_RX_RING_ADDR(priv, priv->port, &priv->mtnic->fw.mac[priv->port]); 01384 if (err) { 01385 DBG("Failed setting default MAC address\n"); 01386 goto rx_error; 01387 } 01388 01389 /* Set MTU */ 01390 err = mtnic_SET_PORT_MTU(priv, priv->port, DEF_MTU); 01391 if (err) { 01392 DBG("Failed setting MTU\n"); 01393 goto rx_error; 01394 } 01395 01396 /* Configure VLAN filter */ 01397 /* By adding this function, The second port won't accept packets 01398 err = mtnic_CONFIG_PORT_VLAN_FILTER(priv, priv->port); 01399 if (err) { 01400 DBG("Failed configuring VLAN filter\n"); 01401 goto rx_error; 01402 } 01403 */ 01404 01405 01406 /* Bring up physical link */ 01407 err = mtnic_SET_PORT_STATE(priv, priv->port, 1); 01408 if (err) { 01409 DBG("Failed bringing up port\n"); 01410 goto rx_error; 01411 } 01412 01413 /* PORT IS UP */ 01414 priv->state = CARD_UP; 01415 01416 01417 /* Checking Link is up */ 01418 DBG ( "Checking if link is up\n" ); 01419 01420 01421 for ( link_check = 0; link_check < CHECK_LINK_TIMES; link_check ++ ) { 01422 /* Let link state stabilize if cable was connected */ 01423 mdelay ( DELAY_LINK_CHECK ); 01424 01425 err = mtnic_HEART_BEAT(priv, &dev_link_state); 01426 if (err) { 01427 DBG("Failed getting device link state\n"); 01428 return -ENETDOWN; 01429 } 01430 01431 if ( dev_link_state & priv->port ) { 01432 /* Link is up */ 01433 break; 01434 } 01435 } 01436 01437 01438 if ( ! ( dev_link_state & 0x3 ) ) { 01439 DBG("Link down, check cables and restart\n"); 01440 netdev_link_down ( dev ); 01441 return -ENETDOWN; 01442 } 01443 01444 DBG ( "Link is up!\n" ); 01445 01446 /* Mark as link up */ 01447 netdev_link_up ( dev ); 01448 01449 return 0; 01450 01451 rx_error: 01452 err = mtnic_RELEASE_RESOURCE(priv, priv->port, 01453 MTNIC_IF_RESOURCE_TYPE_RX_RING, 0); 01454 tx_error: 01455 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01456 MTNIC_IF_RESOURCE_TYPE_TX_RING, 0); 01457 01458 cq_error: 01459 while (cq_ind) { 01460 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01461 MTNIC_IF_RESOURCE_TYPE_CQ, --cq_ind); 01462 } 01463 if (err) 01464 DBG("Eror Releasing resources\n"); 01465 01466 allocation_error: 01467 01468 free_memblock(priv->tx_ring.buf, priv->tx_ring.buf_size); 01469 iounmap(priv->tx_ring.txcq_db); 01470 free_memblock(priv->cq[1].buf, priv->cq[1].buf_size); 01471 free_memblock(priv->cq[1].db, sizeof(struct mtnic_cq_db_record)); 01472 free_memblock(priv->rx_ring.buf, priv->rx_ring.buf_size); 01473 free_memblock(priv->rx_ring.db, sizeof(struct mtnic_cq_db_record)); 01474 free_memblock(priv->cq[0].buf, priv->cq[0].buf_size); 01475 free_memblock(priv->cq[0].db, sizeof(struct mtnic_cq_db_record)); 01476 01477 mtnic_free_io_buffers(&priv->rx_ring); 01478 01479 return -ENETDOWN; 01480 }
| static void mtnic_poll | ( | struct net_device * | dev | ) | [static] |
Check if we got completion for receive and transmit and check the line with heart_bit command.
Definition at line 1488 of file mtnic.c.
References CARD_LINK_DOWN, CARD_UP, mtnic_port::cq, DBG, mtnic_cq::dev, mtnic_cq::is_rx, mtnic_HEART_BEAT(), mtnic_process_rx_cq(), mtnic_process_tx_cq(), netdev_priv(), NUM_CQS, mtnic_port::poll_counter, priv, ROUND_TO_CHECK, mtnic_port::state, and u32.
01489 { 01490 struct mtnic_port *priv = netdev_priv(dev); 01491 struct mtnic_cq *cq; 01492 u32 dev_link_state; 01493 int err; 01494 unsigned int i; 01495 01496 /* In case of an old error then return */ 01497 if (priv->state != CARD_UP) 01498 return; 01499 01500 /* We do not check the device every call _poll call, 01501 since it will slow it down */ 01502 if ((priv->poll_counter % ROUND_TO_CHECK) == 0) { 01503 /* Check device */ 01504 err = mtnic_HEART_BEAT(priv, &dev_link_state); 01505 if (err) { 01506 DBG("Device has internal error\n"); 01507 priv->state = CARD_LINK_DOWN; 01508 return; 01509 } 01510 if (!(dev_link_state & 0x3)) { 01511 DBG("Link down, check cables and restart\n"); 01512 priv->state = CARD_LINK_DOWN; 01513 return; 01514 } 01515 } 01516 /* Polling CQ */ 01517 for (i = 0; i < NUM_CQS; i++) { 01518 cq = &priv->cq[i]; //Passing on the 2 cqs. 01519 01520 if (cq->is_rx) { 01521 err = mtnic_process_rx_cq(priv, cq->dev, cq); 01522 if (err) { 01523 priv->state = CARD_LINK_DOWN; 01524 DBG(" Error allocating RX buffers\n"); 01525 return; 01526 } 01527 } else { 01528 mtnic_process_tx_cq(priv, cq->dev, cq); 01529 } 01530 } 01531 ++ priv->poll_counter; 01532 }
| static int mtnic_transmit | ( | struct net_device * | dev, | |
| struct io_buffer * | iobuf | |||
| ) | [static] |
Definition at line 1537 of file mtnic.c.
References mtnic_data_seg::addr_l, mtnic_ring::buf, CARD_UP, mtnic_ring::cons, mtnic_data_seg::count, cpu_to_be32, mtnic_tx_desc::ctrl, io_buffer::data, mtnic_tx_desc::data, mtnic_ring::db_offset, DBG, EAGAIN, ENETDOWN, mtnic_ctrl_seg::flags, mtnic::fw, index, iob_len(), mtnic_ring::iobuf, mdelay(), mtnic_data_seg::mem_type, mtnic::mem_type_snoop_be, mtnic_port::mtnic, MTNIC_BIT_DESC_OWN, MTNIC_BIT_NO_ICRC, MTNIC_BIT_TX_COMP, MTNIC_OPCODE_SEND, netdev_priv(), mtnic_ctrl_seg::op_own, priv, mtnic_ring::prod, mtnic_txcq_db::send_db, mtnic_ring::size, mtnic_ring::size_mask, mtnic_ctrl_seg::size_vlan, mtnic_port::state, mtnic_port::tx_ring, mtnic_ring::txcq_db, u32, virt_to_bus(), wmb, and writel.
01538 { 01539 01540 struct mtnic_port *priv = netdev_priv(dev); 01541 struct mtnic_ring *ring; 01542 struct mtnic_tx_desc *tx_desc; 01543 struct mtnic_data_seg *data; 01544 u32 index; 01545 01546 /* In case of an error then return */ 01547 if (priv->state != CARD_UP) 01548 return -ENETDOWN; 01549 01550 ring = &priv->tx_ring; 01551 01552 index = ring->prod & ring->size_mask; 01553 if ((ring->prod - ring->cons) >= ring->size) { 01554 DBG("No space left for descriptors!!! cons: %x prod: %x\n", 01555 ring->cons, ring->prod); 01556 mdelay(5); 01557 return -EAGAIN;/* no space left */ 01558 } 01559 01560 /* get current descriptor */ 01561 tx_desc = ring->buf + (index * sizeof(struct mtnic_tx_desc)); 01562 01563 /* Prepare Data Seg */ 01564 data = &tx_desc->data; 01565 data->addr_l = cpu_to_be32((u32)virt_to_bus(iobuf->data)); 01566 data->count = cpu_to_be32(iob_len(iobuf)); 01567 data->mem_type = priv->mtnic->fw.mem_type_snoop_be; 01568 01569 /* Prepare ctrl segement */ 01570 tx_desc->ctrl.size_vlan = cpu_to_be32(2); 01571 tx_desc->ctrl.flags = cpu_to_be32(MTNIC_BIT_TX_COMP | 01572 MTNIC_BIT_NO_ICRC); 01573 tx_desc->ctrl.op_own = cpu_to_be32(MTNIC_OPCODE_SEND) | 01574 ((ring->prod & ring->size) ? 01575 cpu_to_be32(MTNIC_BIT_DESC_OWN) : 0); 01576 01577 /* Attach io_buffer */ 01578 ring->iobuf[index] = iobuf; 01579 01580 /* Update producer index */ 01581 ++ring->prod; 01582 01583 /* Ring doorbell! */ 01584 wmb(); 01585 writel((u32) ring->db_offset, &ring->txcq_db->send_db); 01586 01587 return 0; 01588 }
| static void mtnic_close | ( | struct net_device * | dev | ) | [static] |
Definition at line 1592 of file mtnic.c.
References mtnic_cq::buf, mtnic_ring::buf, mtnic_cq::buf_size, mtnic_ring::buf_size, CARD_INITIALIZED, CARD_LINK_DOWN, CARD_UP, mtnic_port::cq, mtnic_ring::db, mtnic_cq::db, DBG, free_memblock(), iounmap(), mdelay(), mtnic_free_io_buffers(), MTNIC_IF_RESOURCE_TYPE_CQ, MTNIC_IF_RESOURCE_TYPE_RX_RING, MTNIC_IF_RESOURCE_TYPE_TX_RING, mtnic_RELEASE_RESOURCE(), mtnic_SET_PORT_STATE(), netdev_priv(), mtnic_port::port, priv, mtnic_port::rx_ring, mtnic_port::state, mtnic_port::tx_ring, and mtnic_ring::txcq_db.
Referenced by mtnic_disable().
01593 { 01594 struct mtnic_port *priv = netdev_priv(dev); 01595 int err = 0; 01596 DBG("Close called for port:%d\n", priv->port); 01597 01598 if ( ( priv->state == CARD_UP ) || 01599 ( priv->state == CARD_LINK_DOWN ) ) { 01600 01601 /* Disable port */ 01602 err |= mtnic_SET_PORT_STATE(priv, priv->port, 0); 01603 /* 01604 * Stop HW associated with this port 01605 */ 01606 mdelay(5); 01607 01608 /* Stop RX */ 01609 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01610 MTNIC_IF_RESOURCE_TYPE_RX_RING, 0); 01611 01612 /* Stop TX */ 01613 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01614 MTNIC_IF_RESOURCE_TYPE_TX_RING, 0); 01615 01616 /* Stop CQs */ 01617 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01618 MTNIC_IF_RESOURCE_TYPE_CQ, 0); 01619 err |= mtnic_RELEASE_RESOURCE(priv, priv->port, 01620 MTNIC_IF_RESOURCE_TYPE_CQ, 1); 01621 if (err) { 01622 DBG("Close reported error %d\n", err); 01623 } 01624 01625 mdelay ( 10 ); 01626 01627 /* free memory */ 01628 free_memblock(priv->tx_ring.buf, priv->tx_ring.buf_size); 01629 iounmap(priv->tx_ring.txcq_db); 01630 free_memblock(priv->cq[1].buf, priv->cq[1].buf_size); 01631 free_memblock(priv->cq[1].db, sizeof(struct mtnic_cq_db_record)); 01632 free_memblock(priv->rx_ring.buf, priv->rx_ring.buf_size); 01633 free_memblock(priv->rx_ring.db, sizeof(struct mtnic_cq_db_record)); 01634 free_memblock(priv->cq[0].buf, priv->cq[0].buf_size); 01635 free_memblock(priv->cq[0].db, sizeof(struct mtnic_cq_db_record)); 01636 01637 /* Free RX buffers */ 01638 mtnic_free_io_buffers(&priv->rx_ring); 01639 01640 01641 01642 } 01643 01644 priv->state = CARD_INITIALIZED; 01645 01646 }
| static void mtnic_disable | ( | struct pci_device * | pci | ) | [static] |
Definition at line 1650 of file mtnic.c.
References mtnic_eq::buf, mtnic_pages::buf, mtnic_cmd::buf, mtnic_eq::buf_size, CARD_LINK_DOWN, CARD_UP, mtnic::cmd, DBG, net_device::dev, mtnic::eq, mtnic::eq_db, mtnic::extra_pages, free(), free_memblock(), mtnic::fw, mtnic::fw_pages, mtnic::hcr, iounmap(), mdelay(), mtnic_close(), mtnic_cmd(), MTNIC_IF_CMD_CLOSE_NIC, MTNIC_IF_RESOURCE_TYPE_EQ, mtnic_RELEASE_RESOURCE(), mtnic_reset(), mtnic::netdev, netdev_nullify(), netdev_priv(), netdev_put(), NULL, mtnic::num_ports, PAGE_SIZE, pci_get_drvdata(), priv, restore_config(), mtnic_port::state, ufree(), and unregister_netdev().
01651 { 01652 01653 int err; 01654 int i; 01655 struct mtnic *mtnic = pci_get_drvdata(pci); 01656 01657 01658 struct net_device *dev; 01659 struct mtnic_port *priv; 01660 01661 for ( i = ( mtnic->fw.num_ports - 1 ); i >= 0; i-- ) { 01662 01663 dev = mtnic->netdev[i]; 01664 01665 priv = netdev_priv(dev); 01666 01667 /* Just in case */ 01668 if ( ( priv->state == CARD_UP ) || 01669 ( priv->state == CARD_LINK_DOWN ) ) 01670 mtnic_close ( dev ); 01671 } 01672 01673 /* Releasing EQ */ 01674 priv = netdev_priv ( mtnic->netdev[0] ); 01675 err = mtnic_RELEASE_RESOURCE(priv, 1, 01676 MTNIC_IF_RESOURCE_TYPE_EQ, 0); 01677 01678 DBG("Calling MTNIC_CLOSE command\n"); 01679 err |= mtnic_cmd(mtnic, NULL, NULL, 0, 01680 MTNIC_IF_CMD_CLOSE_NIC); 01681 if (err) { 01682 DBG("Error Releasing resources %d\n", err); 01683 } 01684 01685 free_memblock(mtnic->cmd.buf, PAGE_SIZE); 01686 iounmap(mtnic->hcr); 01687 ufree((intptr_t)mtnic->fw.fw_pages.buf); 01688 ufree((intptr_t)mtnic->fw.extra_pages.buf); 01689 free_memblock(mtnic->eq.buf, mtnic->eq.buf_size); 01690 iounmap(mtnic->eq_db); 01691 01692 01693 for ( i = ( mtnic->fw.num_ports - 1 ); i >= 0; i-- ) { 01694 dev = mtnic->netdev[i]; 01695 unregister_netdev ( dev ); 01696 netdev_nullify ( dev ); 01697 netdev_put ( dev ); 01698 } 01699 01700 free ( mtnic ); 01701 01702 01703 mtnic_reset (); 01704 mdelay ( 1000 ); 01705 /* Restore config, if we would like to retry booting */ 01706 restore_config (); 01707 01708 01709 }
| static void mtnic_irq | ( | struct net_device *netdev | __unused, | |
| int enable | __unused | |||
| ) | [static] |
| static int mtnic_probe | ( | struct pci_device * | pci, | |
| const struct pci_device_id *id | __unused | |||
| ) | [static] |
Definition at line 1737 of file mtnic.c.
References adjust_pci_device(), alloc_etherdev(), CARD_DOWN, CARD_INITIALIZED, DBG, pci_device::dev, net_device::dev, EADDRINUSE, EIO, free(), mtnic::fw, net_device::hw_addr, mtnic::mac, MAC_ADDRESS_SIZE, mdelay(), memset(), mtnic_port::mtnic, mtnic_init_card(), mtnic_init_pci(), mtnic_reset(), mtnic_port::netdev, mtnic::netdev, netdev_init(), netdev_priv(), NULL, mtnic::num_ports, pci_set_drvdata(), mtnic::pdev, mtnic_port::port, priv, register_netdev(), restore_config(), mtnic_port::state, and zalloc().
01739 { 01740 struct mtnic_port *priv; 01741 struct mtnic *mtnic; 01742 int err; 01743 u64 mac; 01744 int port_index; 01745 01746 01747 adjust_pci_device(pci); 01748 01749 err = mtnic_init_pci(pci); 01750 if (err) { 01751 DBG("Error in pci_init\n"); 01752 return -EIO; 01753 } 01754 01755 mtnic_reset(); 01756 mdelay(1000); 01757 01758 err = restore_config(); 01759 if (err) { 01760 DBG("Error in restoring config\n"); 01761 return err; 01762 } 01763 01764 mtnic = zalloc ( sizeof ( *mtnic ) ); 01765 if ( ! mtnic ) { 01766 DBG ( "Error Allocating mtnic buffer\n" ); 01767 return -EADDRINUSE; 01768 } 01769 01770 pci_set_drvdata(pci, mtnic); 01771 01772 mtnic->pdev = pci; 01773 01774 01775 /* Initialize hardware */ 01776 err = mtnic_init_card ( mtnic ); 01777 if (err) { 01778 DBG("Error in init_card\n"); 01779 goto err_init_card; 01780 } 01781 01782 for ( port_index = 0; port_index < mtnic->fw.num_ports; port_index ++ ) { 01783 /* Initializing net device */ 01784 mtnic->netdev[port_index] = alloc_etherdev( sizeof ( struct mtnic_port ) ); 01785 if ( mtnic->netdev[port_index] == NULL ) { 01786 DBG("Net device allocation failed\n"); 01787 goto err_alloc_mtnic; 01788 } 01789 01790 /* 01791 * Initialize driver private data 01792 */ 01793 01794 mtnic->netdev[port_index]->dev = &pci->dev; 01795 priv = netdev_priv ( mtnic->netdev[port_index] ); 01796 memset ( priv, 0, sizeof ( struct mtnic_port ) ); 01797 priv->mtnic = mtnic; 01798 priv->netdev = mtnic->netdev[port_index]; 01799 01800 /* Attach pci device */ 01801 netdev_init(mtnic->netdev[port_index], &mtnic_operations); 01802 01803 /* Set port number */ 01804 priv->port = port_index; 01805 01806 /* Set state */ 01807 priv->state = CARD_DOWN; 01808 } 01809 01810 01811 int mac_idx; 01812 for ( port_index = 0; port_index < mtnic->fw.num_ports; port_index ++ ) { 01813 priv = netdev_priv ( mtnic->netdev[port_index] ); 01814 /* Program the MAC address */ 01815 mac = priv->mtnic->fw.mac[port_index]; 01816 for (mac_idx = 0; mac_idx < MAC_ADDRESS_SIZE; ++mac_idx) { 01817 mtnic->netdev[port_index]->hw_addr[MAC_ADDRESS_SIZE - mac_idx - 1] = mac & 0xFF; 01818 mac = mac >> 8; 01819 } 01820 01821 if ( register_netdev ( mtnic->netdev[port_index] ) ) { 01822 DBG("Netdev registration failed\n"); 01823 priv->state = CARD_INITIALIZED; 01824 goto err_alloc_mtnic; 01825 } 01826 } 01827 01828 01829 return 0; 01830 01831 err_alloc_mtnic: 01832 free ( mtnic ); 01833 err_init_card: 01834 return -EIO; 01835 }
struct net_device_operations mtnic_operations [static] |
Initial value:
{
.open = mtnic_open,
.close = mtnic_close,
.transmit = mtnic_transmit,
.poll = mtnic_poll,
.irq = mtnic_irq,
}
struct pci_device_id mtnic_nics[] [static] |
Initial value:
{
PCI_ROM ( 0x15b3, 0x6368, "mt25448", "Mellanox ConnectX EN driver", 0 ),
PCI_ROM ( 0x15b3, 0x6372, "mt25458", "Mellanox ConnectX ENt driver", 0 ),
PCI_ROM ( 0x15b3, 0x6750, "mt26448", "Mellanox ConnectX EN GEN2 driver", 0 ),
PCI_ROM ( 0x15b3, 0x675a, "mt26458", "Mellanox ConnectX ENt GEN2 driver", 0 ),
}
| struct pci_driver mtnic_driver __pci_driver |
Initial value:
{
.ids = mtnic_nics,
.id_count = sizeof(mtnic_nics) / sizeof(mtnic_nics[0]),
.probe = mtnic_probe,
.remove = mtnic_disable,
}
1.5.7.1