2 * Copyright (C) 2003 - 2006 NetXen, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * Source file for NIC routines to initialize the Phantom Hardware
34 #include <linux/netdevice.h>
35 #include <linux/delay.h>
36 #include "netxen_nic.h"
37 #include "netxen_nic_hw.h"
38 #include "netxen_nic_ioctl.h"
39 #include "netxen_nic_phan_reg.h"
41 struct crb_addr_pair {
46 #define NETXEN_MAX_CRB_XFORM 60
47 static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM];
48 #define NETXEN_ADDR_ERROR ((unsigned long ) 0xffffffff )
50 #define crb_addr_transform(name) \
51 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
52 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
55 netxen_nic_locked_write_reg(struct netxen_adapter *adapter,
56 unsigned long off, int *data)
58 void __iomem *addr = (adapter->ahw.pci_base + off);
62 static void crb_addr_transform_setup(void)
64 crb_addr_transform(XDMA);
65 crb_addr_transform(TIMR);
66 crb_addr_transform(SRE);
67 crb_addr_transform(SQN3);
68 crb_addr_transform(SQN2);
69 crb_addr_transform(SQN1);
70 crb_addr_transform(SQN0);
71 crb_addr_transform(SQS3);
72 crb_addr_transform(SQS2);
73 crb_addr_transform(SQS1);
74 crb_addr_transform(SQS0);
75 crb_addr_transform(RPMX7);
76 crb_addr_transform(RPMX6);
77 crb_addr_transform(RPMX5);
78 crb_addr_transform(RPMX4);
79 crb_addr_transform(RPMX3);
80 crb_addr_transform(RPMX2);
81 crb_addr_transform(RPMX1);
82 crb_addr_transform(RPMX0);
83 crb_addr_transform(ROMUSB);
84 crb_addr_transform(SN);
85 crb_addr_transform(QMN);
86 crb_addr_transform(QMS);
87 crb_addr_transform(PGNI);
88 crb_addr_transform(PGND);
89 crb_addr_transform(PGN3);
90 crb_addr_transform(PGN2);
91 crb_addr_transform(PGN1);
92 crb_addr_transform(PGN0);
93 crb_addr_transform(PGSI);
94 crb_addr_transform(PGSD);
95 crb_addr_transform(PGS3);
96 crb_addr_transform(PGS2);
97 crb_addr_transform(PGS1);
98 crb_addr_transform(PGS0);
99 crb_addr_transform(PS);
100 crb_addr_transform(PH);
101 crb_addr_transform(NIU);
102 crb_addr_transform(I2Q);
103 crb_addr_transform(EG);
104 crb_addr_transform(MN);
105 crb_addr_transform(MS);
106 crb_addr_transform(CAS2);
107 crb_addr_transform(CAS1);
108 crb_addr_transform(CAS0);
109 crb_addr_transform(CAM);
110 crb_addr_transform(C2C1);
111 crb_addr_transform(C2C0);
114 int netxen_init_firmware(struct netxen_adapter *adapter)
116 u32 state = 0, loops = 0, err = 0;
119 state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
121 if (state == PHAN_INITIALIZE_ACK)
124 while (state != PHAN_INITIALIZE_COMPLETE && loops < 2000) {
127 state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
132 printk(KERN_ERR "Cmd Peg initialization not complete:%x.\n",
138 writel(PHAN_INITIALIZE_ACK,
139 NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
144 void netxen_initialize_adapter_sw(struct netxen_adapter *adapter)
149 struct netxen_rcv_desc_ctx *rcv_desc;
151 DPRINTK(INFO, "initializing some queues: %p\n", adapter);
152 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
153 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
154 struct netxen_rx_buffer *rx_buf;
155 rcv_desc = &adapter->recv_ctx[ctxid].rcv_desc[ring];
156 rcv_desc->rcv_free = rcv_desc->max_rx_desc_count;
157 rcv_desc->begin_alloc = 0;
158 rx_buf = rcv_desc->rx_buf_arr;
159 num_rx_bufs = rcv_desc->max_rx_desc_count;
161 * Now go through all of them, set reference handles
162 * and put them in the queues.
164 for (i = 0; i < num_rx_bufs; i++) {
165 rx_buf->ref_handle = i;
166 rx_buf->state = NETXEN_BUFFER_FREE;
168 DPRINTK(INFO, "Rx buf:ctx%d i(%d) rx_buf:"
169 "%p\n", ctxid, i, rx_buf);
174 DPRINTK(INFO, "initialized buffers for %s and %s\n",
175 "adapter->free_cmd_buf_list", "adapter->free_rxbuf");
178 void netxen_initialize_adapter_hw(struct netxen_adapter *adapter)
180 if (netxen_nic_get_board_info(adapter) != 0)
181 printk("%s: Error getting board config info.\n",
182 netxen_nic_driver_name);
184 switch (adapter->ahw.board_type) {
186 adapter->ahw.max_ports = 4;
189 case NETXEN_NIC_XGBE:
190 adapter->ahw.max_ports = 1;
194 printk(KERN_ERR "%s: Unknown board type\n",
195 netxen_nic_driver_name);
199 void netxen_initialize_adapter_ops(struct netxen_adapter *adapter)
201 struct netxen_drvops *ops = adapter->ops;
202 switch (adapter->ahw.board_type) {
204 ops->enable_phy_interrupts =
205 netxen_niu_gbe_enable_phy_interrupts;
206 ops->disable_phy_interrupts =
207 netxen_niu_gbe_disable_phy_interrupts;
208 ops->handle_phy_intr = netxen_nic_gbe_handle_phy_intr;
209 ops->macaddr_set = netxen_niu_macaddr_set;
210 ops->set_mtu = netxen_nic_set_mtu_gb;
211 ops->set_promisc = netxen_niu_set_promiscuous_mode;
212 ops->unset_promisc = netxen_niu_set_promiscuous_mode;
213 ops->phy_read = netxen_niu_gbe_phy_read;
214 ops->phy_write = netxen_niu_gbe_phy_write;
215 ops->init_port = netxen_niu_gbe_init_port;
216 ops->init_niu = netxen_nic_init_niu_gb;
217 ops->stop_port = netxen_niu_disable_gbe_port;
220 case NETXEN_NIC_XGBE:
221 ops->enable_phy_interrupts =
222 netxen_niu_xgbe_enable_phy_interrupts;
223 ops->disable_phy_interrupts =
224 netxen_niu_xgbe_disable_phy_interrupts;
225 ops->handle_phy_intr = netxen_nic_xgbe_handle_phy_intr;
226 ops->macaddr_set = netxen_niu_xg_macaddr_set;
227 ops->set_mtu = netxen_nic_set_mtu_xgb;
228 ops->set_promisc = netxen_niu_xg_set_promiscuous_mode;
229 ops->unset_promisc = netxen_niu_xg_set_promiscuous_mode;
230 ops->stop_port = netxen_niu_disable_xg_port;
239 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
240 * address to external PCI CRB address.
242 unsigned long netxen_decode_crb_addr(unsigned long addr)
245 unsigned long base_addr, offset, pci_base;
247 crb_addr_transform_setup();
249 pci_base = NETXEN_ADDR_ERROR;
250 base_addr = addr & 0xfff00000;
251 offset = addr & 0x000fffff;
253 for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) {
254 if (crb_addr_xform[i] == base_addr) {
259 if (pci_base == NETXEN_ADDR_ERROR)
262 return (pci_base + offset);
265 static long rom_max_timeout = 10000;
266 static long rom_lock_timeout = 1000000;
268 static inline int rom_lock(struct netxen_adapter *adapter)
275 /* acquire semaphore2 from PCI HW block */
276 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_LOCK),
280 if (timeout >= rom_lock_timeout)
290 for (iter = 0; iter < 20; iter++)
291 cpu_relax(); /*This a nop instr on i386 */
294 netxen_nic_reg_write(adapter, NETXEN_ROM_LOCK_ID, ROM_LOCK_DRIVER);
298 static inline void rom_unlock(struct netxen_adapter *adapter)
302 /* release semaphore2 */
303 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK), &val);
307 int netxen_wait_rom_done(struct netxen_adapter *adapter)
313 done = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_GLB_STATUS);
316 if (timeout >= rom_max_timeout) {
317 printk("Timeout reached waiting for rom done");
325 do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
327 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
328 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
329 udelay(100); /* prevent bursting on CRB */
330 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
331 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb);
332 if (netxen_wait_rom_done(adapter)) {
333 printk("Error waiting for rom done\n");
336 /* reset abyte_cnt and dummy_byte_cnt */
337 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
338 udelay(100); /* prevent bursting on CRB */
339 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
341 *valp = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_ROM_RDATA);
345 int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
349 if (rom_lock(adapter) != 0)
352 ret = do_rom_fast_read(adapter, addr, valp);
357 #define NETXEN_BOARDTYPE 0x4008
358 #define NETXEN_BOARDNUM 0x400c
359 #define NETXEN_CHIPNUM 0x4010
360 #define NETXEN_ROMBUS_RESET 0xFFFFFFFF
361 #define NETXEN_ROM_FIRST_BARRIER 0x800000000ULL
362 #define NETXEN_ROM_FOUND_INIT 0x400
364 int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
366 int addr, val, status;
369 struct crb_addr_pair *buf;
373 status = netxen_nic_get_board_info(adapter);
375 printk("%s: pinit_from_rom: Error getting board info\n",
376 netxen_nic_driver_name);
378 netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET,
379 NETXEN_ROMBUS_RESET);
383 if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0)
384 printk("P2 ROM board type: 0x%08x\n", val);
386 printk("Could not read board type\n");
387 if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0)
388 printk("P2 ROM board num: 0x%08x\n", val);
390 printk("Could not read board number\n");
391 if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0)
392 printk("P2 ROM chip num: 0x%08x\n", val);
394 printk("Could not read chip number\n");
397 if (netxen_rom_fast_read(adapter, 0, &n) == 0
398 && (n & NETXEN_ROM_FIRST_BARRIER)) {
399 n &= ~NETXEN_ROM_ROUNDUP;
400 if (n < NETXEN_ROM_FOUND_INIT) {
402 printk("%s: %d CRB init values found"
403 " in ROM.\n", netxen_nic_driver_name, n);
405 printk("%s:n=0x%x Error! NetXen card flash not"
406 " initialized.\n", __FUNCTION__, n);
409 buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
411 printk("%s: pinit_from_rom: Unable to calloc memory.\n",
412 netxen_nic_driver_name);
415 for (i = 0; i < n; i++) {
416 if (netxen_rom_fast_read(adapter, 8 * i + 4, &val) != 0
417 || netxen_rom_fast_read(adapter, 8 * i + 8,
425 printk("%s: PCI: 0x%08x == 0x%08x\n",
426 netxen_nic_driver_name, (unsigned int)
427 netxen_decode_crb_addr((unsigned long)
430 for (i = 0; i < n; i++) {
433 netxen_decode_crb_addr((unsigned long)buf[i].addr) +
435 /* skipping cold reboot MAGIC */
436 if (off == NETXEN_CAM_RAM(0x1fc))
439 /* After writing this register, HW needs time for CRB */
440 /* to quiet down (else crb_window returns 0xffffffff) */
441 if (off == NETXEN_ROMUSB_GLB_SW_RESET) {
443 /* hold xdma in reset also */
444 buf[i].data = 0x8000ff;
447 if (ADDR_IN_WINDOW1(off)) {
449 NETXEN_CRB_NORMALIZE(adapter, off));
451 netxen_nic_pci_change_crbwindow(adapter, 0);
453 adapter->ahw.pci_base + off);
455 netxen_nic_pci_change_crbwindow(adapter, 1);
457 if (init_delay == 1) {
465 /* disable_peg_cache_all */
467 /* unreset_net_cache */
468 netxen_nic_hw_read_wx(adapter, NETXEN_ROMUSB_GLB_SW_RESET, &val,
470 netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET,
472 /* p2dn replyCount */
473 netxen_crb_writelit_adapter(adapter,
474 NETXEN_CRB_PEG_NET_D + 0xec, 0x1e);
475 /* disable_peg_cache 0 */
476 netxen_crb_writelit_adapter(adapter,
477 NETXEN_CRB_PEG_NET_D + 0x4c, 8);
478 /* disable_peg_cache 1 */
479 netxen_crb_writelit_adapter(adapter,
480 NETXEN_CRB_PEG_NET_I + 0x4c, 8);
485 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x8,
487 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0xc,
490 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x8,
492 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0xc,
495 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x8,
497 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0xc,
500 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x8,
502 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0xc,
508 void netxen_phantom_init(struct netxen_adapter *adapter)
513 netxen_nic_hw_read_wx(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, &val, 4);
515 NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
518 while (val != PHAN_INITIALIZE_COMPLETE && loops < 200000) {
521 readl(NETXEN_CRB_NORMALIZE
522 (adapter, CRB_CMDPEG_STATE));
525 if (val != PHAN_INITIALIZE_COMPLETE)
526 printk("WARNING: Initial boot wait loop failed...\n");
530 int netxen_nic_rx_has_work(struct netxen_adapter *adapter)
534 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
535 struct netxen_recv_context *recv_ctx =
536 &(adapter->recv_ctx[ctx]);
538 struct status_desc *desc_head;
539 struct status_desc *desc; /* used to read status desc here */
541 consumer = recv_ctx->status_rx_consumer;
542 desc_head = recv_ctx->rcv_status_desc_head;
543 desc = &desc_head[consumer];
545 if (((le16_to_cpu(desc->owner)) & STATUS_OWNER_HOST))
552 void netxen_watchdog_task(unsigned long v)
555 struct netxen_port *port;
556 struct net_device *netdev;
557 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
559 for (port_num = 0; port_num < adapter->ahw.max_ports; port_num++) {
560 port = adapter->port[port_num];
561 netdev = port->netdev;
563 if ((netif_running(netdev)) && !netif_carrier_ok(netdev)) {
564 printk(KERN_INFO "%s port %d, %s carrier is now ok\n",
565 netxen_nic_driver_name, port_num, netdev->name);
566 netif_carrier_on(netdev);
569 if (netif_queue_stopped(netdev))
570 netif_wake_queue(netdev);
573 netxen_nic_pci_change_crbwindow(adapter, 1);
575 if (adapter->ops->handle_phy_intr)
576 adapter->ops->handle_phy_intr(adapter);
577 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
581 * netxen_process_rcv() send the received packet to the protocol stack.
582 * and if the number of receives exceeds RX_BUFFERS_REFILL, then we
583 * invoke the routine to send more rx buffers to the Phantom...
586 netxen_process_rcv(struct netxen_adapter *adapter, int ctxid,
587 struct status_desc *desc)
589 struct netxen_port *port = adapter->port[STATUS_DESC_PORT(desc)];
590 struct pci_dev *pdev = port->pdev;
591 struct net_device *netdev = port->netdev;
592 int index = le16_to_cpu(desc->reference_handle);
593 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]);
594 struct netxen_rx_buffer *buffer;
596 u32 length = le16_to_cpu(desc->total_length);
598 struct netxen_rcv_desc_ctx *rcv_desc;
601 desc_ctx = STATUS_DESC_TYPE(desc);
602 if (unlikely(desc_ctx >= NUM_RCV_DESC_RINGS)) {
603 printk("%s: %s Bad Rcv descriptor ring\n",
604 netxen_nic_driver_name, netdev->name);
608 rcv_desc = &recv_ctx->rcv_desc[desc_ctx];
609 buffer = &rcv_desc->rx_buf_arr[index];
611 pci_unmap_single(pdev, buffer->dma, rcv_desc->dma_size,
614 skb = (struct sk_buff *)buffer->skb;
616 if (likely(STATUS_DESC_STATUS(desc) == STATUS_CKSUM_OK)) {
617 port->stats.csummed++;
618 skb->ip_summed = CHECKSUM_UNNECESSARY;
620 skb->ip_summed = CHECKSUM_NONE;
622 skb_put(skb, length);
623 skb->protocol = eth_type_trans(skb, netdev);
625 ret = netif_receive_skb(skb);
628 * RH: Do we need these stats on a regular basis. Can we get it from
633 port->stats.uphappy++;
637 port->stats.uplcong++;
641 port->stats.upmcong++;
645 port->stats.uphcong++;
649 port->stats.updropped++;
653 port->stats.updunno++;
657 netdev->last_rx = jiffies;
659 rcv_desc->rcv_free++;
660 rcv_desc->rcv_pending--;
663 * We just consumed one buffer so post a buffer.
665 adapter->stats.post_called++;
667 buffer->state = NETXEN_BUFFER_FREE;
669 port->stats.no_rcv++;
670 port->stats.rxbytes += length;
673 /* Process Receive status ring */
674 u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max)
676 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]);
677 struct status_desc *desc_head = recv_ctx->rcv_status_desc_head;
678 struct status_desc *desc; /* used to read status desc here */
679 u32 consumer = recv_ctx->status_rx_consumer;
682 DPRINTK(INFO, "procesing receive\n");
684 * we assume in this case that there is only one port and that is
685 * port #1...changes need to be done in firmware to indicate port
686 * number as part of the descriptor. This way we will be able to get
687 * the netdev which is associated with that device.
689 while (count < max) {
690 desc = &desc_head[consumer];
691 if (!((le16_to_cpu(desc->owner)) & STATUS_OWNER_HOST)) {
692 DPRINTK(ERR, "desc %p ownedby %x\n", desc, desc->owner);
695 netxen_process_rcv(adapter, ctxid, desc);
696 desc->owner = STATUS_OWNER_PHANTOM;
697 consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1);
701 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
702 netxen_post_rx_buffers(adapter, ctxid, ring);
706 /* update the consumer index in phantom */
708 adapter->stats.process_rcv++;
709 recv_ctx->status_rx_consumer = consumer;
713 NETXEN_CRB_NORMALIZE(adapter,
714 recv_crb_registers[ctxid].
715 crb_rcv_status_consumer));
721 /* Process Command status ring */
722 void netxen_process_cmd_ring(unsigned long data)
726 struct netxen_adapter *adapter = (struct netxen_adapter *)data;
728 struct netxen_cmd_buffer *buffer;
729 struct netxen_port *port; /* port #1 */
730 struct netxen_port *nport;
731 struct pci_dev *pdev;
732 struct netxen_skb_frag *frag;
734 struct sk_buff *skb = NULL;
737 spin_lock(&adapter->tx_lock);
738 last_consumer = adapter->last_cmd_consumer;
739 DPRINTK(INFO, "procesing xmit complete\n");
740 /* we assume in this case that there is only one port and that is
741 * port #1...changes need to be done in firmware to indicate port
742 * number as part of the descriptor. This way we will be able to get
743 * the netdev which is associated with that device.
747 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_CONSUMER_OFFSET));
749 if (last_consumer == consumer) { /* Ring is empty */
750 DPRINTK(INFO, "last_consumer %d == consumer %d\n",
751 last_consumer, consumer);
752 spin_unlock(&adapter->tx_lock);
756 adapter->proc_cmd_buf_counter++;
757 adapter->stats.process_xmit++;
759 * Not needed - does not seem to be used anywhere.
760 * adapter->cmd_consumer = consumer;
762 spin_unlock(&adapter->tx_lock);
764 while ((last_consumer != consumer) && (count < MAX_STATUS_HANDLE)) {
765 buffer = &adapter->cmd_buf_arr[last_consumer];
766 port = adapter->port[buffer->port];
768 frag = &buffer->frag_array[0];
770 if (skb && (cmpxchg(&buffer->skb, skb, 0) == skb)) {
771 pci_unmap_single(pdev, frag->dma, frag->length,
773 for (i = 1; i < buffer->frag_count; i++) {
774 DPRINTK(INFO, "getting fragment no %d\n", i);
775 frag++; /* Get the next frag */
776 pci_unmap_page(pdev, frag->dma, frag->length,
780 port->stats.skbfreed++;
781 dev_kfree_skb_any(skb);
783 } else if (adapter->proc_cmd_buf_counter == 1) {
784 port->stats.txnullskb++;
786 if (unlikely(netif_queue_stopped(port->netdev)
787 && netif_carrier_ok(port->netdev))
788 && ((jiffies - port->netdev->trans_start) >
789 port->netdev->watchdog_timeo)) {
790 schedule_work(&port->adapter->tx_timeout_task);
793 last_consumer = get_next_index(last_consumer,
794 adapter->max_tx_desc_count);
797 adapter->stats.noxmitdone += count;
800 spin_lock(&adapter->tx_lock);
801 if ((--adapter->proc_cmd_buf_counter) == 0) {
802 adapter->last_cmd_consumer = last_consumer;
803 while ((adapter->last_cmd_consumer != consumer)
804 && (count < MAX_STATUS_HANDLE)) {
806 &adapter->cmd_buf_arr[adapter->last_cmd_consumer];
811 adapter->last_cmd_consumer =
812 get_next_index(adapter->last_cmd_consumer,
813 adapter->max_tx_desc_count);
817 for (p = 0; p < adapter->ahw.max_ports; p++) {
818 nport = adapter->port[p];
819 if (netif_queue_stopped(nport->netdev)
820 && (nport->flags & NETXEN_NETDEV_STATUS)) {
821 netif_wake_queue(nport->netdev);
822 nport->flags &= ~NETXEN_NETDEV_STATUS;
827 spin_unlock(&adapter->tx_lock);
828 DPRINTK(INFO, "last consumer is %d in %s\n", last_consumer,
833 * netxen_post_rx_buffers puts buffer in the Phantom memory
835 void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid)
837 struct pci_dev *pdev = adapter->ahw.pdev;
839 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]);
840 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
841 struct netxen_recv_crb *crbarea = &recv_crb_registers[ctx];
842 struct netxen_rcv_desc_crb *rcv_desc_crb = NULL;
844 struct rcv_desc *pdesc;
845 struct netxen_rx_buffer *buffer;
849 adapter->stats.post_called++;
850 rcv_desc = &recv_ctx->rcv_desc[ringid];
851 rcv_desc_crb = &crbarea->rcv_desc_crb[ringid];
853 producer = rcv_desc->producer;
854 index = rcv_desc->begin_alloc;
855 buffer = &rcv_desc->rx_buf_arr[index];
856 /* We can start writing rx descriptors into the phantom memory. */
857 while (buffer->state == NETXEN_BUFFER_FREE) {
858 skb = dev_alloc_skb(rcv_desc->skb_size);
859 if (unlikely(!skb)) {
861 * We need to schedule the posting of buffers to the pegs.
863 rcv_desc->begin_alloc = index;
864 DPRINTK(ERR, "unm_post_rx_buffers: "
865 " allocated only %d buffers\n", count);
868 count++; /* now there should be no failure */
869 pdesc = &rcv_desc->desc_head[producer];
870 skb_reserve(skb, NET_IP_ALIGN);
872 * This will be setup when we receive the
873 * buffer after it has been filled
877 buffer->state = NETXEN_BUFFER_BUSY;
878 buffer->dma = pci_map_single(pdev, skb->data,
881 /* make a rcv descriptor */
882 pdesc->reference_handle = le16_to_cpu(buffer->ref_handle);
883 pdesc->buffer_length = le16_to_cpu(rcv_desc->dma_size);
884 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
885 DPRINTK(INFO, "done writing descripter\n");
887 get_next_index(producer, rcv_desc->max_rx_desc_count);
888 index = get_next_index(index, rcv_desc->max_rx_desc_count);
889 buffer = &rcv_desc->rx_buf_arr[index];
892 /* if we did allocate buffers, then write the count to Phantom */
894 rcv_desc->begin_alloc = index;
895 rcv_desc->rcv_pending += count;
896 adapter->stats.lastposted = count;
897 adapter->stats.posted += count;
898 rcv_desc->producer = producer;
899 if (rcv_desc->rcv_free >= 32) {
900 rcv_desc->rcv_free = 0;
902 writel((producer - 1) &
903 (rcv_desc->max_rx_desc_count - 1),
904 NETXEN_CRB_NORMALIZE(adapter,
906 crb_rcv_producer_offset));
912 int netxen_nic_tx_has_work(struct netxen_adapter *adapter)
914 if (find_diff_among(adapter->last_cmd_consumer,
915 adapter->cmd_producer,
916 adapter->max_tx_desc_count) > 0)
923 netxen_nic_fill_statistics(struct netxen_adapter *adapter,
924 struct netxen_port *port,
925 struct netxen_statistics *netxen_stats)
929 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
930 netxen_nic_pci_change_crbwindow(adapter, 0);
931 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_BYTE_CNT,
932 &(netxen_stats->tx_bytes));
933 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_FRAME_CNT,
934 &(netxen_stats->tx_packets));
935 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_BYTE_CNT,
936 &(netxen_stats->rx_bytes));
937 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_FRAME_CNT,
938 &(netxen_stats->rx_packets));
939 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_AGGR_ERROR_CNT,
940 &(netxen_stats->rx_errors));
941 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_CRC_ERROR_CNT,
942 &(netxen_stats->rx_crc_errors));
943 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
945 rx_long_length_error));
946 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
948 rx_short_length_error));
950 netxen_nic_pci_change_crbwindow(adapter, 1);
952 spin_lock_bh(&adapter->tx_lock);
953 netxen_stats->tx_bytes = port->stats.txbytes;
954 netxen_stats->tx_packets = port->stats.xmitedframes +
955 port->stats.xmitfinished;
956 netxen_stats->rx_bytes = port->stats.rxbytes;
957 netxen_stats->rx_packets = port->stats.no_rcv;
958 netxen_stats->rx_errors = port->stats.rcvdbadskb;
959 netxen_stats->tx_errors = port->stats.nocmddescriptor;
960 netxen_stats->rx_short_length_error = port->stats.uplcong;
961 netxen_stats->rx_long_length_error = port->stats.uphcong;
962 netxen_stats->rx_crc_errors = 0;
963 netxen_stats->rx_mac_errors = 0;
964 spin_unlock_bh(&adapter->tx_lock);
969 void netxen_nic_clear_stats(struct netxen_adapter *adapter)
971 struct netxen_port *port;
974 memset(&adapter->stats, 0, sizeof(adapter->stats));
975 for (port_num = 0; port_num < adapter->ahw.max_ports; port_num++) {
976 port = adapter->port[port_num];
977 memset(&port->stats, 0, sizeof(port->stats));
982 netxen_nic_clear_statistics(struct netxen_adapter *adapter,
983 struct netxen_port *port)
987 netxen_nic_pci_change_crbwindow(adapter, 0);
989 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_BYTE_CNT, &data);
990 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_FRAME_CNT,
992 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_BYTE_CNT, &data);
993 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_FRAME_CNT,
995 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_AGGR_ERROR_CNT,
997 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_CRC_ERROR_CNT,
999 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
1001 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
1004 netxen_nic_pci_change_crbwindow(adapter, 1);
1005 netxen_nic_clear_stats(adapter);
1010 netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
1011 struct netxen_port *port)
1013 struct netxen_nic_ioctl_data data;
1014 struct netxen_nic_ioctl_data *up_data;
1016 struct netxen_statistics netxen_stats;
1018 up_data = (void *)u_data;
1020 DPRINTK(INFO, "doing ioctl for %p\n", adapter);
1021 if (copy_from_user(&data, (void __user *)up_data, sizeof(data))) {
1022 /* evil user tried to crash the kernel */
1023 DPRINTK(ERR, "bad copy from userland: %d\n", (int)sizeof(data));
1028 /* Shouldn't access beyond legal limits of "char u[64];" member */
1029 if (!data.ptr && (data.size > sizeof(data.u))) {
1030 /* evil user tried to crash the kernel */
1031 DPRINTK(ERR, "bad size: %d\n", data.size);
1037 case netxen_nic_cmd_pci_read:
1038 if ((retval = netxen_nic_hw_read_wx(adapter, data.off,
1039 &(data.u), data.size)))
1042 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1043 DPRINTK(ERR, "bad copy to userland: %d\n",
1051 case netxen_nic_cmd_pci_write:
1052 data.rv = netxen_nic_hw_write_wx(adapter, data.off, &(data.u),
1056 case netxen_nic_cmd_pci_config_read:
1057 switch (data.size) {
1059 data.rv = pci_read_config_byte(adapter->ahw.pdev,
1064 data.rv = pci_read_config_word(adapter->ahw.pdev,
1066 (short *)&(data.u));
1069 data.rv = pci_read_config_dword(adapter->ahw.pdev,
1071 (u32 *) & (data.u));
1075 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1076 DPRINTK(ERR, "bad copy to userland: %d\n",
1083 case netxen_nic_cmd_pci_config_write:
1084 switch (data.size) {
1086 data.rv = pci_write_config_byte(adapter->ahw.pdev,
1088 *(char *)&(data.u));
1091 data.rv = pci_write_config_word(adapter->ahw.pdev,
1093 *(short *)&(data.u));
1096 data.rv = pci_write_config_dword(adapter->ahw.pdev,
1098 *(u32 *) & (data.u));
1103 case netxen_nic_cmd_get_stats:
1105 netxen_nic_fill_statistics(adapter, port, &netxen_stats);
1107 ((void __user *)(up_data->ptr), (void *)&netxen_stats,
1108 sizeof(struct netxen_statistics))) {
1109 DPRINTK(ERR, "bad copy to userland: %d\n",
1110 (int)sizeof(netxen_stats));
1114 up_data->rv = data.rv;
1117 case netxen_nic_cmd_clear_stats:
1118 data.rv = netxen_nic_clear_statistics(adapter, port);
1119 up_data->rv = data.rv;
1122 case netxen_nic_cmd_get_version:
1124 ((void __user *)&(up_data->u), NETXEN_NIC_LINUX_VERSIONID,
1125 sizeof(NETXEN_NIC_LINUX_VERSIONID))) {
1126 DPRINTK(ERR, "bad copy to userland: %d\n",
1134 DPRINTK(INFO, "bad command %d for %p\n", data.cmd, adapter);
1135 retval = -EOPNOTSUPP;
1138 put_user(data.rv, (u16 __user *) (&(up_data->rv)));
1139 DPRINTK(INFO, "done ioctl for %p well.\n", adapter);