26 #include <linux/netdevice.h>
28 #include <linux/slab.h>
29 #include <linux/if_vlan.h>
38 #define NETXEN_MAX_CRB_XFORM 60
40 #define NETXEN_ADDR_ERROR (0xffffffff)
42 #define crb_addr_transform(name) \
43 crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \
44 NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20
46 #define NETXEN_NIC_XDMA_RESET 0x8000ff
53 static void crb_addr_transform_setup(
void)
118 for (i = 0; i < rds_ring->
num_desc; ++
i) {
122 pci_unmap_single(adapter->
pdev,
140 for (i = 0; i < tx_ring->
num_desc; i++) {
143 pci_unmap_single(adapter->
pdev, buffrag->
dma,
150 pci_unmap_page(adapter->
pdev, buffrag->
dma,
208 if (tx_ring ==
NULL) {
209 dev_err(&pdev->
dev,
"%s: failed to allocate tx ring struct\n",
216 tx_ring->
txq = netdev_get_tx_queue(netdev, 0);
219 if (cmd_buf_arr ==
NULL) {
220 dev_err(&pdev->
dev,
"%s: failed to allocate cmd buffer ring\n",
230 if (rds_ring ==
NULL) {
231 dev_err(&pdev->
dev,
"%s: failed to allocate rds ring struct\n",
242 if (adapter->
ahw.cut_through) {
293 for (i = 0; i < rds_ring->
num_desc; i++) {
329 crb_addr_transform_setup();
332 base_addr = addr & 0xfff00000;
333 offset = addr & 0x000fffff;
336 if (crb_addr_xform[i] == base_addr) {
347 #define NETXEN_MAX_ROM_WAIT_USEC 100
361 "Timeout reached waiting for rom done");
376 if (netxen_wait_rom_done(adapter)) {
377 printk(
"Error waiting for rom done\n");
389 static int do_rom_fast_read_words(
struct netxen_adapter *adapter,
int addr,
395 for (addridx = addr; addridx < (addr +
size); addridx += 4) {
397 ret = do_rom_fast_read(adapter, addridx, &v);
409 u8 *bytes,
size_t size)
417 ret = do_rom_fast_read_words(adapter, addr, bytes, size);
430 ret = do_rom_fast_read(adapter, addr, valp);
435 #define NETXEN_BOARDTYPE 0x4008
436 #define NETXEN_BOARDNUM 0x400c
437 #define NETXEN_CHIPNUM 0x4010
442 int i,
n, init_delay = 0;
460 offset = n & 0xffff
U;
461 n = (n >> 16) & 0xffffU;
475 " initialized.\n", __func__, n);
483 for (i = 0; i <
n; i++) {
495 for (i = 0; i <
n; i++) {
497 off = netxen_decode_crb_addr(buf[i].addr);
530 buf[
i].
data = 0x1020;
548 buf[
i].
data = 0x8000ff;
596 for (i = 0; i <
entries; i++) {
602 if (tab_type == section)
609 #define QLCNIC_FILEHEADER_SIZE (14 * 4)
614 const u8 *unirom = adapter->
fw->data;
616 u32 fw_file_size = adapter->
fw->size;
628 if (fw_file_size < tab_size)
639 const u8 *unirom = adapter->
fw->data;
654 if (adapter->
fw->size < tab_size)
663 if (adapter->
fw->size < data_size)
674 const u8 *unirom = adapter->
fw->data;
689 if (adapter->
fw->size < tab_size)
697 if (adapter->
fw->size < data_size)
708 const u8 *unirom = adapter->
fw->data;
710 1 : netxen_p3_has_mn(adapter);
717 if (ptab_descr ==
NULL)
724 if (adapter->
fw->size < tab_size)
728 for (i = 0; i <
entries; i++) {
731 u8 chiprev = adapter->
ahw.revision_id;
737 file_chiprev =
cpu_to_le32(*((
int *)&unirom[offs] +
740 flagbit = mn_present ? 1 : 2;
742 if ((chiprev == file_chiprev) &&
743 ((1ULL << flagbit) & flags)) {
758 netxen_nic_validate_unified_romimage(
struct netxen_adapter *adapter)
760 if (netxen_nic_validate_header(adapter)) {
762 "unified image: header validation failed\n");
766 if (netxen_nic_validate_product_offs(adapter)) {
768 "unified image: product validation failed\n");
772 if (netxen_nic_validate_bootld(adapter)) {
774 "unified image: bootld validation failed\n");
778 if (netxen_nic_validate_fw(adapter)) {
780 "unified image: firmware validation failed\n");
788 u32 section,
u32 idx_offset)
790 const u8 *unirom = adapter->
fw->data;
796 tab_desc = nx_get_table_desc(unirom, section);
798 if (tab_desc ==
NULL)
817 return (
u8 *)&adapter->
fw->data[
offs];
830 return (
u8 *)&adapter->
fw->data[
offs];
856 fw_data_desc = nx_get_data_desc(adapter,
861 for (i = 0; i < 12; i++) {
862 if (!
strncmp(&ver_str[i],
"REV=", 4)) {
863 ret =
sscanf(&ver_str[i+4],
"%u.%u.%u ",
864 &major, &minor, &sub);
872 return major + (minor << 8) + (sub << 16);
887 return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) +
915 for (i = 0; i < 10; i++) {
925 if (count != old_count)
930 if (count == old_count)
936 val = nx_get_fw_version(adapter);
951 fw_type = (val & 0x4) ?
954 if (adapter->
fw_type != fw_type)
962 #define NETXEN_MIN_P3_FW_SUPP NETXEN_VERSION_CODE(4, 0, 505)
967 u32 flash_fw_ver, min_fw_ver;
974 dev_err(&adapter->
pdev->dev,
"Unable to read flash fw"
981 if (flash_fw_ver >= min_fw_ver)
984 dev_info(&adapter->
pdev->dev,
"Flash fw[%d.%d.%d] is < min fw supported"
985 "[4.0.505]. Please update firmware on flash\n",
1007 dev_info(&pdev->
dev,
"loading firmware from %s\n",
1018 ptr64 = (
u64 *)nx_get_bootld_offs(adapter);
1021 for (i = 0; i <
size; i++) {
1030 size = (
__force u32)nx_get_fw_size(adapter) / 8;
1032 ptr64 = (
u64 *)nx_get_fw_offs(adapter);
1035 for (i = 0; i <
size; i++) {
1045 size = (
__force u32)nx_get_fw_size(adapter) % 8;
1061 for (i = 0; i <
size; i++) {
1063 flashaddr, (
int *)&lo) != 0)
1066 flashaddr + 4, (
int *)&hi) != 0)
1070 data = (((
u64)hi << 32) | lo);
1099 u32 file_fw_ver, min_ver,
bios;
1106 if (netxen_nic_validate_unified_romimage(adapter))
1117 val = nx_get_fw_version(adapter);
1127 (file_fw_ver < min_ver)) {
1129 "%s: firmware version %d.%d.%d unsupported\n",
1130 fw_name[fw_type],
_major(file_fw_ver),
_minor(file_fw_ver),
1134 val = nx_get_bios_version(adapter);
1136 if ((
__force u32)val != bios) {
1137 dev_err(&pdev->
dev,
"%s: firmware bios is incompatible\n",
1144 dev_err(&pdev->
dev,
"Unable to read flash fw version\n");
1151 if (file_fw_ver >= crbinit_fix_fw && flash_fw_ver < crbinit_fix_fw &&
1153 dev_err(&pdev->
dev,
"Incompatibility detected between driver "
1154 "and firmware version on flash. This configuration "
1155 "is not recommended. Please update the firmware on "
1156 "flash immediately\n");
1161 if (!netxen_p3_has_mn(adapter) ||
1163 if (flash_fw_ver > file_fw_ver) {
1164 dev_info(&pdev->
dev,
"%s: firmware is older than flash\n",
1189 else if (netxen_p3_has_mn(adapter))
1240 nx_get_next_fwtype(adapter);
1250 rc = netxen_validate_firmware(adapter);
1280 "ERROR: Could not allocate dummy DMA memory\n");
1285 hi = (addr >> 32) & 0xffffffff;
1286 lo = addr & 0xffffffff;
1314 if ((ctrl & 0x1) != 0) {
1317 while ((ctrl & 0x1) != 0) {
1335 dev_err(&adapter->
pdev->dev,
"dma_watchdog_shutdown failed\n");
1360 }
while (--retries);
1365 dev_warn(&adapter->
pdev->dev,
"firmware init failed\n");
1383 }
while (--retries);
1387 "complete, state: 0x%x.\n", val);
1398 err = netxen_receive_peg_ready(adapter);
1423 cable_OUI = msg->
body[1] & 0xffffffff;
1424 cable_len = (msg->
body[1] >> 32) & 0xffff;
1425 link_speed = (msg->
body[1] >> 48) & 0xffff;
1427 link_status = msg->
body[2] & 0xff;
1428 duplex = (msg->
body[2] >> 16) & 0xff;
1429 autoneg = (msg->
body[2] >> 24) & 0xff;
1431 module = (msg->
body[2] >> 8) & 0xff;
1434 netdev->
name, cable_OUI, cable_len);
1437 netdev->
name, cable_len);
1453 netxen_handle_fw_message(
int desc_cnt,
int index,
1460 while (desc_cnt > 0 && i < 8) {
1472 netxen_handle_linkevent(sds_ring->
adapter, &msg);
1494 if (!adapter->
ahw.cut_through)
1495 skb_reserve(skb, 2);
1497 dma = pci_map_single(pdev, skb->
data,
1500 if (pci_dma_mapping_error(pdev, dma)) {
1530 adapter->
stats.csummed++;
1568 skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum);
1585 adapter->
stats.rx_pkts++;
1591 #define TCP_HDR_SIZE 20
1592 #define TCP_TS_OPTION_SIZE 12
1593 #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE)
1598 int ring,
u64 sts_data0,
u64 sts_data1)
1608 int l2_hdr_offset, l4_hdr_offset;
1632 skb = netxen_process_rxbuf(adapter, rds_ring, index,
STATUS_CKSUM_OK);
1641 skb_put(skb, lro_length + data_offset);
1648 iph = (
struct iphdr *)(skb->
data + vhdr_len);
1649 th = (
struct tcphdr *)((skb->
data + vhdr_len) + (iph->ihl << 2));
1651 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
1665 adapter->
stats.lro_pkts++;
1671 #define netxen_merge_rx_buffers(list, head) \
1672 do { list_splice_tail_init(list, head); } while (0);
1687 u64 sts_data0, sts_data1;
1688 int opcode, ring = 0, desc_cnt;
1690 while (count < max) {
1706 rxbuf = netxen_process_rcv(adapter, sds_ring,
1712 rxbuf = netxen_process_lro(adapter, sds_ring,
1713 ring, sts_data0, sts_data1);
1716 netxen_handle_fw_message(desc_cnt, consumer, sds_ring);
1727 for (; desc_cnt > 0; desc_cnt--) {
1738 &adapter->
recv_ctx.rds_rings[ring];
1740 if (!list_empty(&sds_ring->
free_list[ring])) {
1744 netxen_alloc_rx_skb(adapter, rds_ring, rxbuf);
1746 spin_lock(&rds_ring->
lock);
1749 spin_unlock(&rds_ring->
lock);
1752 netxen_post_rx_buffers_nodb(adapter, rds_ring);
1766 u32 sw_consumer, hw_consumer;
1781 while (sw_consumer != hw_consumer) {
1785 pci_unmap_single(pdev, frag->
dma, frag->
length,
1790 pci_unmap_page(pdev, frag->
dma, frag->
length,
1795 adapter->
stats.xmitfinished++;
1805 if (count && netif_running(netdev)) {
1810 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev))
1812 netif_wake_queue(netdev);
1841 int producer,
count = 0;
1848 while (!list_empty(head)) {
1853 if (netxen_alloc_rx_skb(adapter, rds_ring, buffer))
1872 (producer-1) & (rds_ring->
num_desc-1));
1899 int producer,
count = 0;
1902 if (!spin_trylock(&rds_ring->
lock))
1908 while (!list_empty(head)) {
1913 if (netxen_alloc_rx_skb(adapter, rds_ring, buffer))
1932 (producer - 1) & (rds_ring->
num_desc - 1));
1934 spin_unlock(&rds_ring->
lock);