Complete the renaming to TuxOnIce with function names, vars etc.
[linux-2.6/suspend2-head.git] / drivers / net / netxen / netxen_nic_init.c
blob1811bcb8c380ad53019033c7e43df01e0ff0912b
1 /*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
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,
18 * MA 02111-1307, USA.
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
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_phan_reg.h"
40 struct crb_addr_pair {
41 u32 addr;
42 u32 data;
45 unsigned long last_schedule_time;
47 #define NETXEN_MAX_CRB_XFORM 60
48 static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM];
49 #define NETXEN_ADDR_ERROR (0xffffffff)
51 #define crb_addr_transform(name) \
52 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
53 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
55 #define NETXEN_NIC_XDMA_RESET 0x8000ff
57 static inline void
58 netxen_nic_locked_write_reg(struct netxen_adapter *adapter,
59 unsigned long off, int *data)
61 void __iomem *addr = pci_base_offset(adapter, off);
62 writel(*data, addr);
65 static void crb_addr_transform_setup(void)
67 crb_addr_transform(XDMA);
68 crb_addr_transform(TIMR);
69 crb_addr_transform(SRE);
70 crb_addr_transform(SQN3);
71 crb_addr_transform(SQN2);
72 crb_addr_transform(SQN1);
73 crb_addr_transform(SQN0);
74 crb_addr_transform(SQS3);
75 crb_addr_transform(SQS2);
76 crb_addr_transform(SQS1);
77 crb_addr_transform(SQS0);
78 crb_addr_transform(RPMX7);
79 crb_addr_transform(RPMX6);
80 crb_addr_transform(RPMX5);
81 crb_addr_transform(RPMX4);
82 crb_addr_transform(RPMX3);
83 crb_addr_transform(RPMX2);
84 crb_addr_transform(RPMX1);
85 crb_addr_transform(RPMX0);
86 crb_addr_transform(ROMUSB);
87 crb_addr_transform(SN);
88 crb_addr_transform(QMN);
89 crb_addr_transform(QMS);
90 crb_addr_transform(PGNI);
91 crb_addr_transform(PGND);
92 crb_addr_transform(PGN3);
93 crb_addr_transform(PGN2);
94 crb_addr_transform(PGN1);
95 crb_addr_transform(PGN0);
96 crb_addr_transform(PGSI);
97 crb_addr_transform(PGSD);
98 crb_addr_transform(PGS3);
99 crb_addr_transform(PGS2);
100 crb_addr_transform(PGS1);
101 crb_addr_transform(PGS0);
102 crb_addr_transform(PS);
103 crb_addr_transform(PH);
104 crb_addr_transform(NIU);
105 crb_addr_transform(I2Q);
106 crb_addr_transform(EG);
107 crb_addr_transform(MN);
108 crb_addr_transform(MS);
109 crb_addr_transform(CAS2);
110 crb_addr_transform(CAS1);
111 crb_addr_transform(CAS0);
112 crb_addr_transform(CAM);
113 crb_addr_transform(C2C1);
114 crb_addr_transform(C2C0);
115 crb_addr_transform(SMB);
118 int netxen_init_firmware(struct netxen_adapter *adapter)
120 u32 state = 0, loops = 0, err = 0;
122 /* Window 1 call */
123 state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
125 if (state == PHAN_INITIALIZE_ACK)
126 return 0;
128 while (state != PHAN_INITIALIZE_COMPLETE && loops < 2000) {
129 udelay(100);
130 /* Window 1 call */
131 state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
133 loops++;
135 if (loops >= 2000) {
136 printk(KERN_ERR "Cmd Peg initialization not complete:%x.\n",
137 state);
138 err = -EIO;
139 return err;
141 /* Window 1 call */
142 writel(INTR_SCHEME_PERPORT,
143 NETXEN_CRB_NORMALIZE(adapter, CRB_NIC_CAPABILITIES_HOST));
144 writel(MPORT_MULTI_FUNCTION_MODE,
145 NETXEN_CRB_NORMALIZE(adapter, CRB_MPORT_MODE));
146 writel(PHAN_INITIALIZE_ACK,
147 NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
149 return err;
152 #define NETXEN_ADDR_LIMIT 0xffffffffULL
154 void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr,
155 struct pci_dev **used_dev)
157 void *addr;
159 addr = pci_alloc_consistent(pdev, sz, ptr);
160 if ((unsigned long long)(*ptr) < NETXEN_ADDR_LIMIT) {
161 *used_dev = pdev;
162 return addr;
164 pci_free_consistent(pdev, sz, addr, *ptr);
165 addr = pci_alloc_consistent(NULL, sz, ptr);
166 *used_dev = NULL;
167 return addr;
170 void netxen_initialize_adapter_sw(struct netxen_adapter *adapter)
172 int ctxid, ring;
173 u32 i;
174 u32 num_rx_bufs = 0;
175 struct netxen_rcv_desc_ctx *rcv_desc;
177 DPRINTK(INFO, "initializing some queues: %p\n", adapter);
178 for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) {
179 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
180 struct netxen_rx_buffer *rx_buf;
181 rcv_desc = &adapter->recv_ctx[ctxid].rcv_desc[ring];
182 rcv_desc->rcv_free = rcv_desc->max_rx_desc_count;
183 rcv_desc->begin_alloc = 0;
184 rx_buf = rcv_desc->rx_buf_arr;
185 num_rx_bufs = rcv_desc->max_rx_desc_count;
187 * Now go through all of them, set reference handles
188 * and put them in the queues.
190 for (i = 0; i < num_rx_bufs; i++) {
191 rx_buf->ref_handle = i;
192 rx_buf->state = NETXEN_BUFFER_FREE;
193 DPRINTK(INFO, "Rx buf:ctx%d i(%d) rx_buf:"
194 "%p\n", ctxid, i, rx_buf);
195 rx_buf++;
201 void netxen_initialize_adapter_hw(struct netxen_adapter *adapter)
203 int ports = 0;
204 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
206 if (netxen_nic_get_board_info(adapter) != 0)
207 printk("%s: Error getting board config info.\n",
208 netxen_nic_driver_name);
209 get_brd_port_by_type(board_info->board_type, &ports);
210 if (ports == 0)
211 printk(KERN_ERR "%s: Unknown board type\n",
212 netxen_nic_driver_name);
213 adapter->ahw.max_ports = ports;
216 void netxen_initialize_adapter_ops(struct netxen_adapter *adapter)
218 switch (adapter->ahw.board_type) {
219 case NETXEN_NIC_GBE:
220 adapter->enable_phy_interrupts =
221 netxen_niu_gbe_enable_phy_interrupts;
222 adapter->disable_phy_interrupts =
223 netxen_niu_gbe_disable_phy_interrupts;
224 adapter->handle_phy_intr = netxen_nic_gbe_handle_phy_intr;
225 adapter->macaddr_set = netxen_niu_macaddr_set;
226 adapter->set_mtu = netxen_nic_set_mtu_gb;
227 adapter->set_promisc = netxen_niu_set_promiscuous_mode;
228 adapter->unset_promisc = netxen_niu_set_promiscuous_mode;
229 adapter->phy_read = netxen_niu_gbe_phy_read;
230 adapter->phy_write = netxen_niu_gbe_phy_write;
231 adapter->init_niu = netxen_nic_init_niu_gb;
232 adapter->stop_port = netxen_niu_disable_gbe_port;
233 break;
235 case NETXEN_NIC_XGBE:
236 adapter->enable_phy_interrupts =
237 netxen_niu_xgbe_enable_phy_interrupts;
238 adapter->disable_phy_interrupts =
239 netxen_niu_xgbe_disable_phy_interrupts;
240 adapter->handle_phy_intr = netxen_nic_xgbe_handle_phy_intr;
241 adapter->macaddr_set = netxen_niu_xg_macaddr_set;
242 adapter->set_mtu = netxen_nic_set_mtu_xgb;
243 adapter->init_port = netxen_niu_xg_init_port;
244 adapter->set_promisc = netxen_niu_xg_set_promiscuous_mode;
245 adapter->unset_promisc = netxen_niu_xg_set_promiscuous_mode;
246 adapter->stop_port = netxen_niu_disable_xg_port;
247 break;
249 default:
250 break;
255 * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB
256 * address to external PCI CRB address.
258 u32 netxen_decode_crb_addr(u32 addr)
260 int i;
261 u32 base_addr, offset, pci_base;
263 crb_addr_transform_setup();
265 pci_base = NETXEN_ADDR_ERROR;
266 base_addr = addr & 0xfff00000;
267 offset = addr & 0x000fffff;
269 for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) {
270 if (crb_addr_xform[i] == base_addr) {
271 pci_base = i << 20;
272 break;
275 if (pci_base == NETXEN_ADDR_ERROR)
276 return pci_base;
277 else
278 return (pci_base + offset);
281 static long rom_max_timeout = 100;
282 static long rom_lock_timeout = 10000;
283 static long rom_write_timeout = 700;
285 static inline int rom_lock(struct netxen_adapter *adapter)
287 int iter;
288 u32 done = 0;
289 int timeout = 0;
291 while (!done) {
292 /* acquire semaphore2 from PCI HW block */
293 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_LOCK),
294 &done);
295 if (done == 1)
296 break;
297 if (timeout >= rom_lock_timeout)
298 return -EIO;
300 timeout++;
302 * Yield CPU
304 if (!in_atomic())
305 schedule();
306 else {
307 for (iter = 0; iter < 20; iter++)
308 cpu_relax(); /*This a nop instr on i386 */
311 netxen_nic_reg_write(adapter, NETXEN_ROM_LOCK_ID, ROM_LOCK_DRIVER);
312 return 0;
315 int netxen_wait_rom_done(struct netxen_adapter *adapter)
317 long timeout = 0;
318 long done = 0;
320 while (done == 0) {
321 done = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_GLB_STATUS);
322 done &= 2;
323 timeout++;
324 if (timeout >= rom_max_timeout) {
325 printk("Timeout reached waiting for rom done");
326 return -EIO;
329 return 0;
332 static inline int netxen_rom_wren(struct netxen_adapter *adapter)
334 /* Set write enable latch in ROM status register */
335 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
336 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE,
337 M25P_INSTR_WREN);
338 if (netxen_wait_rom_done(adapter)) {
339 return -1;
341 return 0;
344 static inline unsigned int netxen_rdcrbreg(struct netxen_adapter *adapter,
345 unsigned int addr)
347 unsigned int data = 0xdeaddead;
348 data = netxen_nic_reg_read(adapter, addr);
349 return data;
352 static inline int netxen_do_rom_rdsr(struct netxen_adapter *adapter)
354 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE,
355 M25P_INSTR_RDSR);
356 if (netxen_wait_rom_done(adapter)) {
357 return -1;
359 return netxen_rdcrbreg(adapter, NETXEN_ROMUSB_ROM_RDATA);
362 static inline void netxen_rom_unlock(struct netxen_adapter *adapter)
364 u32 val;
366 /* release semaphore2 */
367 netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK), &val);
371 int netxen_rom_wip_poll(struct netxen_adapter *adapter)
373 long timeout = 0;
374 long wip = 1;
375 int val;
376 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
377 while (wip != 0) {
378 val = netxen_do_rom_rdsr(adapter);
379 wip = val & 1;
380 timeout++;
381 if (timeout > rom_max_timeout) {
382 return -1;
385 return 0;
388 static inline int do_rom_fast_write(struct netxen_adapter *adapter, int addr,
389 int data)
391 if (netxen_rom_wren(adapter)) {
392 return -1;
394 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_WDATA, data);
395 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
396 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
397 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE,
398 M25P_INSTR_PP);
399 if (netxen_wait_rom_done(adapter)) {
400 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
401 return -1;
404 return netxen_rom_wip_poll(adapter);
407 static inline int
408 do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
410 cond_resched();
412 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
413 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
414 udelay(100); /* prevent bursting on CRB */
415 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
416 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb);
417 if (netxen_wait_rom_done(adapter)) {
418 printk("Error waiting for rom done\n");
419 return -EIO;
421 /* reset abyte_cnt and dummy_byte_cnt */
422 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
423 udelay(100); /* prevent bursting on CRB */
424 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
426 *valp = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_ROM_RDATA);
427 return 0;
430 static inline int
431 do_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
432 u8 *bytes, size_t size)
434 int addridx;
435 int ret = 0;
437 for (addridx = addr; addridx < (addr + size); addridx += 4) {
438 ret = do_rom_fast_read(adapter, addridx, (int *)bytes);
439 if (ret != 0)
440 break;
441 *(int *)bytes = cpu_to_le32(*(int *)bytes);
442 bytes += 4;
445 return ret;
449 netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
450 u8 *bytes, size_t size)
452 int ret;
454 ret = rom_lock(adapter);
455 if (ret < 0)
456 return ret;
458 ret = do_rom_fast_read_words(adapter, addr, bytes, size);
460 netxen_rom_unlock(adapter);
461 return ret;
464 int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
466 int ret;
468 if (rom_lock(adapter) != 0)
469 return -EIO;
471 ret = do_rom_fast_read(adapter, addr, valp);
472 netxen_rom_unlock(adapter);
473 return ret;
476 int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data)
478 int ret = 0;
480 if (rom_lock(adapter) != 0) {
481 return -1;
483 ret = do_rom_fast_write(adapter, addr, data);
484 netxen_rom_unlock(adapter);
485 return ret;
488 static inline int do_rom_fast_write_words(struct netxen_adapter *adapter,
489 int addr, u8 *bytes, size_t size)
491 int addridx = addr;
492 int ret = 0;
494 while (addridx < (addr + size)) {
495 int last_attempt = 0;
496 int timeout = 0;
497 int data;
499 data = le32_to_cpu((*(u32*)bytes));
500 ret = do_rom_fast_write(adapter, addridx, data);
501 if (ret < 0)
502 return ret;
504 while(1) {
505 int data1;
507 ret = do_rom_fast_read(adapter, addridx, &data1);
508 if (ret < 0)
509 return ret;
511 if (data1 == data)
512 break;
514 if (timeout++ >= rom_write_timeout) {
515 if (last_attempt++ < 4) {
516 ret = do_rom_fast_write(adapter,
517 addridx, data);
518 if (ret < 0)
519 return ret;
521 else {
522 printk(KERN_INFO "Data write did not "
523 "succeed at address 0x%x\n", addridx);
524 break;
529 bytes += 4;
530 addridx += 4;
533 return ret;
536 int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr,
537 u8 *bytes, size_t size)
539 int ret = 0;
541 ret = rom_lock(adapter);
542 if (ret < 0)
543 return ret;
545 ret = do_rom_fast_write_words(adapter, addr, bytes, size);
546 netxen_rom_unlock(adapter);
548 return ret;
551 int netxen_rom_wrsr(struct netxen_adapter *adapter, int data)
553 int ret;
555 ret = netxen_rom_wren(adapter);
556 if (ret < 0)
557 return ret;
559 netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_ROM_WDATA, data);
560 netxen_crb_writelit_adapter(adapter,
561 NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0x1);
563 ret = netxen_wait_rom_done(adapter);
564 if (ret < 0)
565 return ret;
567 return netxen_rom_wip_poll(adapter);
570 int netxen_rom_rdsr(struct netxen_adapter *adapter)
572 int ret;
574 ret = rom_lock(adapter);
575 if (ret < 0)
576 return ret;
578 ret = netxen_do_rom_rdsr(adapter);
579 netxen_rom_unlock(adapter);
580 return ret;
583 int netxen_backup_crbinit(struct netxen_adapter *adapter)
585 int ret = FLASH_SUCCESS;
586 int val;
587 char *buffer = kmalloc(NETXEN_FLASH_SECTOR_SIZE, GFP_KERNEL);
589 if (!buffer)
590 return -ENOMEM;
591 /* unlock sector 63 */
592 val = netxen_rom_rdsr(adapter);
593 val = val & 0xe3;
594 ret = netxen_rom_wrsr(adapter, val);
595 if (ret != FLASH_SUCCESS)
596 goto out_kfree;
598 ret = netxen_rom_wip_poll(adapter);
599 if (ret != FLASH_SUCCESS)
600 goto out_kfree;
602 /* copy sector 0 to sector 63 */
603 ret = netxen_rom_fast_read_words(adapter, NETXEN_CRBINIT_START,
604 buffer, NETXEN_FLASH_SECTOR_SIZE);
605 if (ret != FLASH_SUCCESS)
606 goto out_kfree;
608 ret = netxen_rom_fast_write_words(adapter, NETXEN_FIXED_START,
609 buffer, NETXEN_FLASH_SECTOR_SIZE);
610 if (ret != FLASH_SUCCESS)
611 goto out_kfree;
613 /* lock sector 63 */
614 val = netxen_rom_rdsr(adapter);
615 if (!(val & 0x8)) {
616 val |= (0x1 << 2);
617 /* lock sector 63 */
618 if (netxen_rom_wrsr(adapter, val) == 0) {
619 ret = netxen_rom_wip_poll(adapter);
620 if (ret != FLASH_SUCCESS)
621 goto out_kfree;
623 /* lock SR writes */
624 ret = netxen_rom_wip_poll(adapter);
625 if (ret != FLASH_SUCCESS)
626 goto out_kfree;
630 out_kfree:
631 kfree(buffer);
632 return ret;
635 int netxen_do_rom_se(struct netxen_adapter *adapter, int addr)
637 netxen_rom_wren(adapter);
638 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
639 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
640 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE,
641 M25P_INSTR_SE);
642 if (netxen_wait_rom_done(adapter)) {
643 netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
644 return -1;
646 return netxen_rom_wip_poll(adapter);
649 void check_erased_flash(struct netxen_adapter *adapter, int addr)
651 int i;
652 int val;
653 int count = 0, erased_errors = 0;
654 int range;
656 range = (addr == NETXEN_USER_START) ?
657 NETXEN_FIXED_START : addr + NETXEN_FLASH_SECTOR_SIZE;
659 for (i = addr; i < range; i += 4) {
660 netxen_rom_fast_read(adapter, i, &val);
661 if (val != 0xffffffff)
662 erased_errors++;
663 count++;
666 if (erased_errors)
667 printk(KERN_INFO "0x%x out of 0x%x words fail to be erased "
668 "for sector address: %x\n", erased_errors, count, addr);
671 int netxen_rom_se(struct netxen_adapter *adapter, int addr)
673 int ret = 0;
674 if (rom_lock(adapter) != 0) {
675 return -1;
677 ret = netxen_do_rom_se(adapter, addr);
678 netxen_rom_unlock(adapter);
679 msleep(30);
680 check_erased_flash(adapter, addr);
682 return ret;
686 netxen_flash_erase_sections(struct netxen_adapter *adapter, int start, int end)
688 int ret = FLASH_SUCCESS;
689 int i;
691 for (i = start; i < end; i++) {
692 ret = netxen_rom_se(adapter, i * NETXEN_FLASH_SECTOR_SIZE);
693 if (ret)
694 break;
695 ret = netxen_rom_wip_poll(adapter);
696 if (ret < 0)
697 return ret;
700 return ret;
704 netxen_flash_erase_secondary(struct netxen_adapter *adapter)
706 int ret = FLASH_SUCCESS;
707 int start, end;
709 start = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
710 end = NETXEN_USER_START / NETXEN_FLASH_SECTOR_SIZE;
711 ret = netxen_flash_erase_sections(adapter, start, end);
713 return ret;
717 netxen_flash_erase_primary(struct netxen_adapter *adapter)
719 int ret = FLASH_SUCCESS;
720 int start, end;
722 start = NETXEN_PRIMARY_START / NETXEN_FLASH_SECTOR_SIZE;
723 end = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE;
724 ret = netxen_flash_erase_sections(adapter, start, end);
726 return ret;
729 void netxen_halt_pegs(struct netxen_adapter *adapter)
731 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x3c, 1);
732 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x3c, 1);
733 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x3c, 1);
734 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x3c, 1);
737 int netxen_flash_unlock(struct netxen_adapter *adapter)
739 int ret = 0;
741 ret = netxen_rom_wrsr(adapter, 0);
742 if (ret < 0)
743 return ret;
745 ret = netxen_rom_wren(adapter);
746 if (ret < 0)
747 return ret;
749 return ret;
752 #define NETXEN_BOARDTYPE 0x4008
753 #define NETXEN_BOARDNUM 0x400c
754 #define NETXEN_CHIPNUM 0x4010
755 #define NETXEN_ROMBUS_RESET 0xFFFFFFFF
756 #define NETXEN_ROM_FIRST_BARRIER 0x800000000ULL
757 #define NETXEN_ROM_FOUND_INIT 0x400
759 int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
761 int addr, val, status;
762 int n, i;
763 int init_delay = 0;
764 struct crb_addr_pair *buf;
765 u32 off;
767 /* resetall */
768 status = netxen_nic_get_board_info(adapter);
769 if (status)
770 printk("%s: netxen_pinit_from_rom: Error getting board info\n",
771 netxen_nic_driver_name);
773 netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET,
774 NETXEN_ROMBUS_RESET);
776 if (verbose) {
777 int val;
778 if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0)
779 printk("P2 ROM board type: 0x%08x\n", val);
780 else
781 printk("Could not read board type\n");
782 if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0)
783 printk("P2 ROM board num: 0x%08x\n", val);
784 else
785 printk("Could not read board number\n");
786 if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0)
787 printk("P2 ROM chip num: 0x%08x\n", val);
788 else
789 printk("Could not read chip number\n");
792 if (netxen_rom_fast_read(adapter, 0, &n) == 0
793 && (n & NETXEN_ROM_FIRST_BARRIER)) {
794 n &= ~NETXEN_ROM_ROUNDUP;
795 if (n < NETXEN_ROM_FOUND_INIT) {
796 if (verbose)
797 printk("%s: %d CRB init values found"
798 " in ROM.\n", netxen_nic_driver_name, n);
799 } else {
800 printk("%s:n=0x%x Error! NetXen card flash not"
801 " initialized.\n", __FUNCTION__, n);
802 return -EIO;
804 buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
805 if (buf == NULL) {
806 printk("%s: netxen_pinit_from_rom: Unable to calloc "
807 "memory.\n", netxen_nic_driver_name);
808 return -ENOMEM;
810 for (i = 0; i < n; i++) {
811 if (netxen_rom_fast_read(adapter, 8 * i + 4, &val) != 0
812 || netxen_rom_fast_read(adapter, 8 * i + 8,
813 &addr) != 0)
814 return -EIO;
816 buf[i].addr = addr;
817 buf[i].data = val;
819 if (verbose)
820 printk("%s: PCI: 0x%08x == 0x%08x\n",
821 netxen_nic_driver_name, (unsigned int)
822 netxen_decode_crb_addr(addr), val);
824 for (i = 0; i < n; i++) {
826 off = netxen_decode_crb_addr(buf[i].addr);
827 if (off == NETXEN_ADDR_ERROR) {
828 printk(KERN_ERR"CRB init value out of range %x\n",
829 buf[i].addr);
830 continue;
832 off += NETXEN_PCI_CRBSPACE;
833 /* skipping cold reboot MAGIC */
834 if (off == NETXEN_CAM_RAM(0x1fc))
835 continue;
837 /* After writing this register, HW needs time for CRB */
838 /* to quiet down (else crb_window returns 0xffffffff) */
839 if (off == NETXEN_ROMUSB_GLB_SW_RESET) {
840 init_delay = 1;
841 /* hold xdma in reset also */
842 buf[i].data = NETXEN_NIC_XDMA_RESET;
845 if (ADDR_IN_WINDOW1(off)) {
846 writel(buf[i].data,
847 NETXEN_CRB_NORMALIZE(adapter, off));
848 } else {
849 netxen_nic_pci_change_crbwindow(adapter, 0);
850 writel(buf[i].data,
851 pci_base_offset(adapter, off));
853 netxen_nic_pci_change_crbwindow(adapter, 1);
855 if (init_delay == 1) {
856 msleep(2000);
857 init_delay = 0;
859 msleep(20);
861 kfree(buf);
863 /* disable_peg_cache_all */
865 /* unreset_net_cache */
866 netxen_nic_hw_read_wx(adapter, NETXEN_ROMUSB_GLB_SW_RESET, &val,
868 netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET,
869 (val & 0xffffff0f));
870 /* p2dn replyCount */
871 netxen_crb_writelit_adapter(adapter,
872 NETXEN_CRB_PEG_NET_D + 0xec, 0x1e);
873 /* disable_peg_cache 0 */
874 netxen_crb_writelit_adapter(adapter,
875 NETXEN_CRB_PEG_NET_D + 0x4c, 8);
876 /* disable_peg_cache 1 */
877 netxen_crb_writelit_adapter(adapter,
878 NETXEN_CRB_PEG_NET_I + 0x4c, 8);
880 /* peg_clr_all */
882 /* peg_clr 0 */
883 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x8,
885 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0xc,
887 /* peg_clr 1 */
888 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x8,
890 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0xc,
892 /* peg_clr 2 */
893 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x8,
895 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0xc,
897 /* peg_clr 3 */
898 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x8,
900 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0xc,
903 return 0;
906 int netxen_initialize_adapter_offload(struct netxen_adapter *adapter)
908 uint64_t addr;
909 uint32_t hi;
910 uint32_t lo;
912 adapter->dummy_dma.addr =
913 pci_alloc_consistent(adapter->ahw.pdev,
914 NETXEN_HOST_DUMMY_DMA_SIZE,
915 &adapter->dummy_dma.phys_addr);
916 if (adapter->dummy_dma.addr == NULL) {
917 printk("%s: ERROR: Could not allocate dummy DMA memory\n",
918 __FUNCTION__);
919 return -ENOMEM;
922 addr = (uint64_t) adapter->dummy_dma.phys_addr;
923 hi = (addr >> 32) & 0xffffffff;
924 lo = addr & 0xffffffff;
926 writel(hi, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI));
927 writel(lo, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO));
929 return 0;
932 void netxen_free_adapter_offload(struct netxen_adapter *adapter)
934 if (adapter->dummy_dma.addr) {
935 pci_free_consistent(adapter->ahw.pdev,
936 NETXEN_HOST_DUMMY_DMA_SIZE,
937 adapter->dummy_dma.addr,
938 adapter->dummy_dma.phys_addr);
939 adapter->dummy_dma.addr = NULL;
943 int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val)
945 u32 val = 0;
946 int retries = 30;
948 if (!pegtune_val) {
949 do {
950 val = readl(NETXEN_CRB_NORMALIZE
951 (adapter, CRB_CMDPEG_STATE));
952 pegtune_val = readl(NETXEN_CRB_NORMALIZE
953 (adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
955 if (val == PHAN_INITIALIZE_COMPLETE ||
956 val == PHAN_INITIALIZE_ACK)
957 return 0;
959 msleep(1000);
960 } while (--retries);
961 if (!retries) {
962 printk(KERN_WARNING "netxen_phantom_init: init failed, "
963 "pegtune_val=%x\n", pegtune_val);
964 return -1;
968 return 0;
971 int netxen_nic_rx_has_work(struct netxen_adapter *adapter)
973 int ctx;
975 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
976 struct netxen_recv_context *recv_ctx =
977 &(adapter->recv_ctx[ctx]);
978 u32 consumer;
979 struct status_desc *desc_head;
980 struct status_desc *desc;
982 consumer = recv_ctx->status_rx_consumer;
983 desc_head = recv_ctx->rcv_status_desc_head;
984 desc = &desc_head[consumer];
986 if (netxen_get_sts_owner(desc) & STATUS_OWNER_HOST)
987 return 1;
990 return 0;
993 static inline int netxen_nic_check_temp(struct netxen_adapter *adapter)
995 struct net_device *netdev = adapter->netdev;
996 uint32_t temp, temp_state, temp_val;
997 int rv = 0;
999 temp = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_TEMP_STATE));
1001 temp_state = nx_get_temp_state(temp);
1002 temp_val = nx_get_temp_val(temp);
1004 if (temp_state == NX_TEMP_PANIC) {
1005 printk(KERN_ALERT
1006 "%s: Device temperature %d degrees C exceeds"
1007 " maximum allowed. Hardware has been shut down.\n",
1008 netxen_nic_driver_name, temp_val);
1010 netif_carrier_off(netdev);
1011 netif_stop_queue(netdev);
1012 rv = 1;
1013 } else if (temp_state == NX_TEMP_WARN) {
1014 if (adapter->temp == NX_TEMP_NORMAL) {
1015 printk(KERN_ALERT
1016 "%s: Device temperature %d degrees C "
1017 "exceeds operating range."
1018 " Immediate action needed.\n",
1019 netxen_nic_driver_name, temp_val);
1021 } else {
1022 if (adapter->temp == NX_TEMP_WARN) {
1023 printk(KERN_INFO
1024 "%s: Device temperature is now %d degrees C"
1025 " in normal range.\n", netxen_nic_driver_name,
1026 temp_val);
1029 adapter->temp = temp_state;
1030 return rv;
1033 void netxen_watchdog_task(struct work_struct *work)
1035 struct net_device *netdev;
1036 struct netxen_adapter *adapter =
1037 container_of(work, struct netxen_adapter, watchdog_task);
1039 if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter))
1040 return;
1042 if (adapter->handle_phy_intr)
1043 adapter->handle_phy_intr(adapter);
1045 netdev = adapter->netdev;
1046 if ((netif_running(netdev)) && !netif_carrier_ok(netdev) &&
1047 netxen_nic_link_ok(adapter) ) {
1048 printk(KERN_INFO "%s %s (port %d), Link is up\n",
1049 netxen_nic_driver_name, netdev->name, adapter->portnum);
1050 netif_carrier_on(netdev);
1051 netif_wake_queue(netdev);
1052 } else if(!(netif_running(netdev)) && netif_carrier_ok(netdev)) {
1053 printk(KERN_ERR "%s %s Link is Down\n",
1054 netxen_nic_driver_name, netdev->name);
1055 netif_carrier_off(netdev);
1056 netif_stop_queue(netdev);
1059 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1063 * netxen_process_rcv() send the received packet to the protocol stack.
1064 * and if the number of receives exceeds RX_BUFFERS_REFILL, then we
1065 * invoke the routine to send more rx buffers to the Phantom...
1067 void
1068 netxen_process_rcv(struct netxen_adapter *adapter, int ctxid,
1069 struct status_desc *desc)
1071 struct pci_dev *pdev = adapter->pdev;
1072 struct net_device *netdev = adapter->netdev;
1073 int index = netxen_get_sts_refhandle(desc);
1074 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]);
1075 struct netxen_rx_buffer *buffer;
1076 struct sk_buff *skb;
1077 u32 length = netxen_get_sts_totallength(desc);
1078 u32 desc_ctx;
1079 struct netxen_rcv_desc_ctx *rcv_desc;
1080 int ret;
1082 desc_ctx = netxen_get_sts_type(desc);
1083 if (unlikely(desc_ctx >= NUM_RCV_DESC_RINGS)) {
1084 printk("%s: %s Bad Rcv descriptor ring\n",
1085 netxen_nic_driver_name, netdev->name);
1086 return;
1089 rcv_desc = &recv_ctx->rcv_desc[desc_ctx];
1090 if (unlikely(index > rcv_desc->max_rx_desc_count)) {
1091 DPRINTK(ERR, "Got a buffer index:%x Max is %x\n",
1092 index, rcv_desc->max_rx_desc_count);
1093 return;
1095 buffer = &rcv_desc->rx_buf_arr[index];
1096 if (desc_ctx == RCV_DESC_LRO_CTXID) {
1097 buffer->lro_current_frags++;
1098 if (netxen_get_sts_desc_lro_last_frag(desc)) {
1099 buffer->lro_expected_frags =
1100 netxen_get_sts_desc_lro_cnt(desc);
1101 buffer->lro_length = length;
1103 if (buffer->lro_current_frags != buffer->lro_expected_frags) {
1104 if (buffer->lro_expected_frags != 0) {
1105 printk("LRO: (refhandle:%x) recv frag."
1106 "wait for last. flags: %x expected:%d"
1107 "have:%d\n", index,
1108 netxen_get_sts_desc_lro_last_frag(desc),
1109 buffer->lro_expected_frags,
1110 buffer->lro_current_frags);
1112 return;
1116 pci_unmap_single(pdev, buffer->dma, rcv_desc->dma_size,
1117 PCI_DMA_FROMDEVICE);
1119 skb = (struct sk_buff *)buffer->skb;
1121 if (likely(netxen_get_sts_status(desc) == STATUS_CKSUM_OK)) {
1122 adapter->stats.csummed++;
1123 skb->ip_summed = CHECKSUM_UNNECESSARY;
1125 skb->dev = netdev;
1126 if (desc_ctx == RCV_DESC_LRO_CTXID) {
1127 /* True length was only available on the last pkt */
1128 skb_put(skb, buffer->lro_length);
1129 } else {
1130 skb_put(skb, length);
1133 skb->protocol = eth_type_trans(skb, netdev);
1135 ret = netif_receive_skb(skb);
1138 * RH: Do we need these stats on a regular basis. Can we get it from
1139 * Linux stats.
1141 switch (ret) {
1142 case NET_RX_SUCCESS:
1143 adapter->stats.uphappy++;
1144 break;
1146 case NET_RX_CN_LOW:
1147 adapter->stats.uplcong++;
1148 break;
1150 case NET_RX_CN_MOD:
1151 adapter->stats.upmcong++;
1152 break;
1154 case NET_RX_CN_HIGH:
1155 adapter->stats.uphcong++;
1156 break;
1158 case NET_RX_DROP:
1159 adapter->stats.updropped++;
1160 break;
1162 default:
1163 adapter->stats.updunno++;
1164 break;
1167 netdev->last_rx = jiffies;
1169 rcv_desc->rcv_free++;
1170 rcv_desc->rcv_pending--;
1173 * We just consumed one buffer so post a buffer.
1175 buffer->skb = NULL;
1176 buffer->state = NETXEN_BUFFER_FREE;
1177 buffer->lro_current_frags = 0;
1178 buffer->lro_expected_frags = 0;
1180 adapter->stats.no_rcv++;
1181 adapter->stats.rxbytes += length;
1184 /* Process Receive status ring */
1185 u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max)
1187 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]);
1188 struct status_desc *desc_head = recv_ctx->rcv_status_desc_head;
1189 struct status_desc *desc; /* used to read status desc here */
1190 u32 consumer = recv_ctx->status_rx_consumer;
1191 u32 producer = 0;
1192 int count = 0, ring;
1194 DPRINTK(INFO, "procesing receive\n");
1196 * we assume in this case that there is only one port and that is
1197 * port #1...changes need to be done in firmware to indicate port
1198 * number as part of the descriptor. This way we will be able to get
1199 * the netdev which is associated with that device.
1201 while (count < max) {
1202 desc = &desc_head[consumer];
1203 if (!(netxen_get_sts_owner(desc) & STATUS_OWNER_HOST)) {
1204 DPRINTK(ERR, "desc %p ownedby %x\n", desc,
1205 netxen_get_sts_owner(desc));
1206 break;
1208 netxen_process_rcv(adapter, ctxid, desc);
1209 netxen_clear_sts_owner(desc);
1210 netxen_set_sts_owner(desc, STATUS_OWNER_PHANTOM);
1211 consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1);
1212 count++;
1214 if (count) {
1215 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
1216 netxen_post_rx_buffers_nodb(adapter, ctxid, ring);
1220 /* update the consumer index in phantom */
1221 if (count) {
1222 recv_ctx->status_rx_consumer = consumer;
1223 recv_ctx->status_rx_producer = producer;
1225 /* Window = 1 */
1226 writel(consumer,
1227 NETXEN_CRB_NORMALIZE(adapter,
1228 recv_crb_registers[adapter->portnum].
1229 crb_rcv_status_consumer));
1230 wmb();
1233 return count;
1236 /* Process Command status ring */
1237 int netxen_process_cmd_ring(unsigned long data)
1239 u32 last_consumer;
1240 u32 consumer;
1241 struct netxen_adapter *adapter = (struct netxen_adapter *)data;
1242 int count1 = 0;
1243 int count2 = 0;
1244 struct netxen_cmd_buffer *buffer;
1245 struct pci_dev *pdev;
1246 struct netxen_skb_frag *frag;
1247 u32 i;
1248 struct sk_buff *skb = NULL;
1249 int done;
1251 spin_lock(&adapter->tx_lock);
1252 last_consumer = adapter->last_cmd_consumer;
1253 DPRINTK(INFO, "procesing xmit complete\n");
1254 /* we assume in this case that there is only one port and that is
1255 * port #1...changes need to be done in firmware to indicate port
1256 * number as part of the descriptor. This way we will be able to get
1257 * the netdev which is associated with that device.
1260 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1261 if (last_consumer == consumer) { /* Ring is empty */
1262 DPRINTK(INFO, "last_consumer %d == consumer %d\n",
1263 last_consumer, consumer);
1264 spin_unlock(&adapter->tx_lock);
1265 return 1;
1268 adapter->proc_cmd_buf_counter++;
1270 * Not needed - does not seem to be used anywhere.
1271 * adapter->cmd_consumer = consumer;
1273 spin_unlock(&adapter->tx_lock);
1275 while ((last_consumer != consumer) && (count1 < MAX_STATUS_HANDLE)) {
1276 buffer = &adapter->cmd_buf_arr[last_consumer];
1277 pdev = adapter->pdev;
1278 frag = &buffer->frag_array[0];
1279 skb = buffer->skb;
1280 if (skb && (cmpxchg(&buffer->skb, skb, 0) == skb)) {
1281 pci_unmap_single(pdev, frag->dma, frag->length,
1282 PCI_DMA_TODEVICE);
1283 frag->dma = 0ULL;
1284 for (i = 1; i < buffer->frag_count; i++) {
1285 DPRINTK(INFO, "getting fragment no %d\n", i);
1286 frag++; /* Get the next frag */
1287 pci_unmap_page(pdev, frag->dma, frag->length,
1288 PCI_DMA_TODEVICE);
1289 frag->dma = 0ULL;
1292 adapter->stats.skbfreed++;
1293 dev_kfree_skb_any(skb);
1294 skb = NULL;
1295 } else if (adapter->proc_cmd_buf_counter == 1) {
1296 adapter->stats.txnullskb++;
1298 if (unlikely(netif_queue_stopped(adapter->netdev)
1299 && netif_carrier_ok(adapter->netdev))
1300 && ((jiffies - adapter->netdev->trans_start) >
1301 adapter->netdev->watchdog_timeo)) {
1302 SCHEDULE_WORK(&adapter->tx_timeout_task);
1305 last_consumer = get_next_index(last_consumer,
1306 adapter->max_tx_desc_count);
1307 count1++;
1310 count2 = 0;
1311 spin_lock(&adapter->tx_lock);
1312 if ((--adapter->proc_cmd_buf_counter) == 0) {
1313 adapter->last_cmd_consumer = last_consumer;
1314 while ((adapter->last_cmd_consumer != consumer)
1315 && (count2 < MAX_STATUS_HANDLE)) {
1316 buffer =
1317 &adapter->cmd_buf_arr[adapter->last_cmd_consumer];
1318 count2++;
1319 if (buffer->skb)
1320 break;
1321 else
1322 adapter->last_cmd_consumer =
1323 get_next_index(adapter->last_cmd_consumer,
1324 adapter->max_tx_desc_count);
1327 if (count1 || count2) {
1328 if (netif_queue_stopped(adapter->netdev)
1329 && (adapter->flags & NETXEN_NETDEV_STATUS)) {
1330 netif_wake_queue(adapter->netdev);
1331 adapter->flags &= ~NETXEN_NETDEV_STATUS;
1335 * If everything is freed up to consumer then check if the ring is full
1336 * If the ring is full then check if more needs to be freed and
1337 * schedule the call back again.
1339 * This happens when there are 2 CPUs. One could be freeing and the
1340 * other filling it. If the ring is full when we get out of here and
1341 * the card has already interrupted the host then the host can miss the
1342 * interrupt.
1344 * There is still a possible race condition and the host could miss an
1345 * interrupt. The card has to take care of this.
1347 if (adapter->last_cmd_consumer == consumer &&
1348 (((adapter->cmd_producer + 1) %
1349 adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) {
1350 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1352 done = (adapter->last_cmd_consumer == consumer);
1354 spin_unlock(&adapter->tx_lock);
1355 DPRINTK(INFO, "last consumer is %d in %s\n", last_consumer,
1356 __FUNCTION__);
1357 return (done);
1361 * netxen_post_rx_buffers puts buffer in the Phantom memory
1363 void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid)
1365 struct pci_dev *pdev = adapter->ahw.pdev;
1366 struct sk_buff *skb;
1367 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]);
1368 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
1369 uint producer;
1370 struct rcv_desc *pdesc;
1371 struct netxen_rx_buffer *buffer;
1372 int count = 0;
1373 int index = 0;
1374 netxen_ctx_msg msg = 0;
1375 dma_addr_t dma;
1377 rcv_desc = &recv_ctx->rcv_desc[ringid];
1379 producer = rcv_desc->producer;
1380 index = rcv_desc->begin_alloc;
1381 buffer = &rcv_desc->rx_buf_arr[index];
1382 /* We can start writing rx descriptors into the phantom memory. */
1383 while (buffer->state == NETXEN_BUFFER_FREE) {
1384 skb = dev_alloc_skb(rcv_desc->skb_size);
1385 if (unlikely(!skb)) {
1387 * TODO
1388 * We need to schedule the posting of buffers to the pegs.
1390 rcv_desc->begin_alloc = index;
1391 DPRINTK(ERR, "netxen_post_rx_buffers: "
1392 " allocated only %d buffers\n", count);
1393 break;
1396 count++; /* now there should be no failure */
1397 pdesc = &rcv_desc->desc_head[producer];
1399 #if defined(XGB_DEBUG)
1400 *(unsigned long *)(skb->head) = 0xc0debabe;
1401 if (skb_is_nonlinear(skb)) {
1402 printk("Allocated SKB @%p is nonlinear\n");
1404 #endif
1405 skb_reserve(skb, 2);
1406 /* This will be setup when we receive the
1407 * buffer after it has been filled FSL TBD TBD
1408 * skb->dev = netdev;
1410 dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size,
1411 PCI_DMA_FROMDEVICE);
1412 pdesc->addr_buffer = cpu_to_le64(dma);
1413 buffer->skb = skb;
1414 buffer->state = NETXEN_BUFFER_BUSY;
1415 buffer->dma = dma;
1416 /* make a rcv descriptor */
1417 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1418 pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size);
1419 DPRINTK(INFO, "done writing descripter\n");
1420 producer =
1421 get_next_index(producer, rcv_desc->max_rx_desc_count);
1422 index = get_next_index(index, rcv_desc->max_rx_desc_count);
1423 buffer = &rcv_desc->rx_buf_arr[index];
1425 /* if we did allocate buffers, then write the count to Phantom */
1426 if (count) {
1427 rcv_desc->begin_alloc = index;
1428 rcv_desc->rcv_pending += count;
1429 rcv_desc->producer = producer;
1430 if (rcv_desc->rcv_free >= 32) {
1431 rcv_desc->rcv_free = 0;
1432 /* Window = 1 */
1433 writel((producer - 1) &
1434 (rcv_desc->max_rx_desc_count - 1),
1435 NETXEN_CRB_NORMALIZE(adapter,
1436 recv_crb_registers[
1437 adapter->portnum].
1438 rcv_desc_crb[ringid].
1439 crb_rcv_producer_offset));
1441 * Write a doorbell msg to tell phanmon of change in
1442 * receive ring producer
1444 netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID);
1445 netxen_set_msg_privid(msg);
1446 netxen_set_msg_count(msg,
1447 ((producer -
1448 1) & (rcv_desc->
1449 max_rx_desc_count - 1)));
1450 netxen_set_msg_ctxid(msg, adapter->portnum);
1451 netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid));
1452 writel(msg,
1453 DB_NORMALIZE(adapter,
1454 NETXEN_RCV_PRODUCER_OFFSET));
1455 wmb();
1460 void netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, uint32_t ctx,
1461 uint32_t ringid)
1463 struct pci_dev *pdev = adapter->ahw.pdev;
1464 struct sk_buff *skb;
1465 struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]);
1466 struct netxen_rcv_desc_ctx *rcv_desc = NULL;
1467 u32 producer;
1468 struct rcv_desc *pdesc;
1469 struct netxen_rx_buffer *buffer;
1470 int count = 0;
1471 int index = 0;
1473 rcv_desc = &recv_ctx->rcv_desc[ringid];
1475 producer = rcv_desc->producer;
1476 index = rcv_desc->begin_alloc;
1477 buffer = &rcv_desc->rx_buf_arr[index];
1478 /* We can start writing rx descriptors into the phantom memory. */
1479 while (buffer->state == NETXEN_BUFFER_FREE) {
1480 skb = dev_alloc_skb(rcv_desc->skb_size);
1481 if (unlikely(!skb)) {
1483 * We need to schedule the posting of buffers to the pegs.
1485 rcv_desc->begin_alloc = index;
1486 DPRINTK(ERR, "netxen_post_rx_buffers_nodb: "
1487 " allocated only %d buffers\n", count);
1488 break;
1490 count++; /* now there should be no failure */
1491 pdesc = &rcv_desc->desc_head[producer];
1492 skb_reserve(skb, 2);
1494 * This will be setup when we receive the
1495 * buffer after it has been filled
1496 * skb->dev = netdev;
1498 buffer->skb = skb;
1499 buffer->state = NETXEN_BUFFER_BUSY;
1500 buffer->dma = pci_map_single(pdev, skb->data,
1501 rcv_desc->dma_size,
1502 PCI_DMA_FROMDEVICE);
1504 /* make a rcv descriptor */
1505 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1506 pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size);
1507 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
1508 DPRINTK(INFO, "done writing descripter\n");
1509 producer =
1510 get_next_index(producer, rcv_desc->max_rx_desc_count);
1511 index = get_next_index(index, rcv_desc->max_rx_desc_count);
1512 buffer = &rcv_desc->rx_buf_arr[index];
1515 /* if we did allocate buffers, then write the count to Phantom */
1516 if (count) {
1517 rcv_desc->begin_alloc = index;
1518 rcv_desc->rcv_pending += count;
1519 rcv_desc->producer = producer;
1520 if (rcv_desc->rcv_free >= 32) {
1521 rcv_desc->rcv_free = 0;
1522 /* Window = 1 */
1523 writel((producer - 1) &
1524 (rcv_desc->max_rx_desc_count - 1),
1525 NETXEN_CRB_NORMALIZE(adapter,
1526 recv_crb_registers[
1527 adapter->portnum].
1528 rcv_desc_crb[ringid].
1529 crb_rcv_producer_offset));
1530 wmb();
1535 int netxen_nic_tx_has_work(struct netxen_adapter *adapter)
1537 if (find_diff_among(adapter->last_cmd_consumer,
1538 adapter->cmd_producer,
1539 adapter->max_tx_desc_count) > 0)
1540 return 1;
1542 return 0;
1546 void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1548 memset(&adapter->stats, 0, sizeof(adapter->stats));
1549 return;