8 #include <linux/netdevice.h>
10 #include <linux/slab.h>
11 #include <linux/if_vlan.h>
19 #define QLCNIC_MAX_CRB_XFORM 60
22 #define crb_addr_transform(name) \
23 (crb_addr_xform[QLCNIC_HW_PX_MAP_CRB_##name] = \
24 QLCNIC_HW_CRB_HUB_AGT_ADR_##name << 20)
26 #define QLCNIC_ADDR_ERROR (0xffffffff)
35 static void crb_addr_transform_setup(
void)
100 for (i = 0; i < rds_ring->
num_desc; ++
i) {
105 pci_unmap_single(adapter->
pdev,
129 for (i = 0; i < rds_ring->
num_desc; i++) {
145 for (i = 0; i < tx_ring->
num_desc; i++) {
148 pci_unmap_single(adapter->
pdev, buffrag->
dma,
155 pci_unmap_page(adapter->
pdev, buffrag->
dma,
213 if (tx_ring ==
NULL) {
214 dev_err(&netdev->
dev,
"failed to allocate tx ring struct\n");
220 tx_ring->
txq = netdev_get_tx_queue(netdev, 0);
223 if (cmd_buf_arr ==
NULL) {
224 dev_err(&netdev->
dev,
"failed to allocate cmd buffer ring\n");
233 if (rds_ring ==
NULL) {
234 dev_err(&netdev->
dev,
"failed to allocate rds ring struct\n");
263 "rx buffer ring %d\n", ring);
272 for (i = 0; i < rds_ring->
num_desc; i++) {
307 crb_addr_transform_setup();
310 base_addr = addr & 0xfff00000;
311 offset = addr & 0x000fffff;
314 if (crb_addr_xform[i] == base_addr) {
325 #define QLCNIC_MAX_ROM_WAIT_USEC 100
339 "Timeout reached waiting for rom done");
354 if (qlcnic_wait_rom_done(adapter)) {
355 dev_err(&adapter->
pdev->dev,
"Error waiting for rom done\n");
367 static int do_rom_fast_read_words(
struct qlcnic_adapter *adapter,
int addr,
373 for (addridx = addr; addridx < (addr +
size); addridx += 4) {
375 ret = do_rom_fast_read(adapter, addridx, &v);
387 u8 *bytes,
size_t size)
395 ret = do_rom_fast_read_words(adapter, addr, bytes, size);
408 ret = do_rom_fast_read(adapter, addr, valp);
416 int i,
n, init_delay;
476 dev_err(&pdev->
dev,
"ERROR Reading crb_init area: val:%x\n", n);
479 offset = n & 0xffff
U;
480 n = (n >> 16) & 0xffffU;
483 dev_err(&pdev->
dev,
"QLOGIC card flash not initialized.\n");
489 dev_err(&pdev->
dev,
"Unable to calloc memory for rom read.\n");
493 for (i = 0; i <
n; i++) {
504 for (i = 0; i <
n; i++) {
506 off = qlcnic_decode_crb_addr(buf[i].addr);
508 dev_err(&pdev->
dev,
"CRB init value out of range %x\n",
601 dev_err(&adapter->
pdev->dev,
"Command Peg initialization not "
602 "complete, state: 0x%x.\n", val);
623 dev_err(&adapter->
pdev->dev,
"Receive Peg initialization not "
624 "complete, state: 0x%x.\n", val);
636 err = qlcnic_cmd_peg_ready(adapter);
640 err = qlcnic_receive_peg_ready(adapter);
659 "Not an Ethernet NIC func=%u\n", val);
690 "error reading flash layout header\n");
696 if (flt_entry ==
NULL) {
697 dev_warn(&adapter->
pdev->dev,
"error allocating memory\n");
703 (
u8 *)flt_entry, entry_size);
706 "error reading flash layout entries\n");
711 if (flt_entry[i].region == region)
717 "region=%x not found in %d regions\n", region, i);
755 "firmware version %d.%d.%d unsupported."
756 "Min supported version %d.%d.%d\n",
785 for (i = 0; i <
entries; i++) {
791 if (tab_type == section)
798 #define FILEHEADER_SIZE (14 * 4)
803 const u8 *unirom = adapter->
fw->data;
805 __le32 fw_file_size = adapter->
fw->size;
817 if (fw_file_size < tab_size)
828 const u8 *unirom = adapter->
fw->data;
843 if (adapter->
fw->size < tab_size)
852 if (adapter->
fw->size < data_size)
863 const u8 *unirom = adapter->
fw->data;
878 if (adapter->
fw->size < tab_size)
886 if (adapter->
fw->size < data_size)
896 const u8 *unirom = adapter->
fw->data;
897 int mn_present = qlcnic_has_mn(adapter);
903 ptab_descr = qlcnic_get_table_desc(unirom,
912 if (adapter->
fw->size < tab_size)
916 for (i = 0; i <
entries; i++) {
919 u8 chiprev = adapter->
ahw->revision_id;
926 file_chiprev =
cpu_to_le32(*((
int *)&unirom[offs] +
929 flagbit = mn_present ? 1 : 2;
931 if ((chiprev == file_chiprev) &&
932 ((1ULL << flagbit) & flags)) {
947 if (qlcnic_validate_header(adapter)) {
949 "unified image: header validation failed\n");
953 if (qlcnic_validate_product_offs(adapter)) {
955 "unified image: product validation failed\n");
959 if (qlcnic_validate_bootld(adapter)) {
961 "unified image: bootld validation failed\n");
965 if (qlcnic_validate_fw(adapter)) {
967 "unified image: firmware validation failed\n");
976 u32 section,
u32 idx_offset)
978 const u8 *unirom = adapter->
fw->data;
984 tab_desc = qlcnic_get_table_desc(unirom, section);
986 if (tab_desc ==
NULL)
1005 return (
u8 *)&adapter->
fw->data[
offs];
1018 return (
u8 *)&adapter->
fw->data[
offs];
1050 for (i = 0; i < 12; i++) {
1051 if (!
strncmp(&ver_str[i],
"REV=", 4)) {
1052 ret =
sscanf(&ver_str[i+4],
"%u.%u.%u ",
1053 &major, &minor, &sub);
1057 return major + (minor << 8) + (sub << 16);
1077 return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + (bios_ver >> 24);
1080 static void qlcnic_rom_lock_recovery(
struct qlcnic_adapter *adapter)
1103 }
while (--retries);
1112 qlcnic_check_fw_hearbeat(adapter)) {
1113 qlcnic_rom_lock_recovery(adapter);
1126 static const char *
fw_name[] = {
1139 dev_info(&pdev->
dev,
"loading firmware from %s\n",
1147 ptr64 = (
u64 *)qlcnic_get_bootld_offs(adapter);
1150 for (i = 0; i <
size; i++) {
1159 size = (
__force u32)qlcnic_get_fw_size(adapter) / 8;
1161 ptr64 = (
u64 *)qlcnic_get_fw_offs(adapter);
1164 for (i = 0; i <
size; i++) {
1174 size = (
__force u32)qlcnic_get_fw_size(adapter) % 8;
1192 size = bootld_entry.
size / 8;
1198 "using legacy method to get flash fw region");
1201 for (i = 0; i <
size; i++) {
1203 flashaddr, (
int *)&lo) != 0)
1206 flashaddr + 4, (
int *)&hi) != 0)
1209 data = (((
u64)hi << 32) | lo);
1235 if (qlcnic_validate_unified_romimage(adapter))
1247 if (fw->
size < min_size)
1250 val = qlcnic_get_fw_version(adapter);
1255 "%s: firmware version %d.%d.%d unsupported\n",
1260 val = qlcnic_get_bios_version(adapter);
1263 dev_err(&pdev->
dev,
"%s: firmware bios is incompatible\n",
1301 qlcnic_get_next_fwtype(adapter);
1311 rc = qlcnic_validate_firmware(adapter);
1341 cable_OUI = msg->
body[1] & 0xffffffff;
1342 cable_len = (msg->
body[1] >> 32) & 0xffff;
1343 link_speed = (msg->
body[1] >> 48) & 0xffff;
1345 link_status = msg->
body[2] & 0xff;
1346 duplex = (msg->
body[2] >> 16) & 0xff;
1347 autoneg = (msg->
body[2] >> 24) & 0xff;
1348 lb_status = (msg->
body[2] >> 32) & 0x3;
1350 module = (msg->
body[2] >> 8) & 0xff;
1352 dev_info(&netdev->
dev,
"unsupported cable: OUI 0x%x, "
1353 "length %d\n", cable_OUI, cable_len);
1355 dev_info(&netdev->
dev,
"unsupported cable length %d\n",
1381 qlcnic_handle_fw_message(
int desc_cnt,
int index,
1390 while (desc_cnt > 0 && i < 8) {
1400 dev = &adapter->
pdev->dev;
1405 qlcnic_handle_linkevent(adapter, &msg);
1414 dev_info(dev,
"loopback already in progress\n");
1418 dev_info(dev,
"loopback cable is not connected\n");
1422 dev_info(dev,
"loopback configure request failed,"
1444 adapter->
stats.skb_alloc_failure++;
1450 dma = pci_map_single(pdev, skb->
data,
1453 if (pci_dma_mapping_error(pdev, dma)) {
1454 adapter->
stats.rx_dma_map_error++;
1485 adapter->
stats.csummed++;
1488 skb_checksum_none_assert(skb);
1502 if (!__vlan_get_tag(skb, vlan_tag)) {
1510 if (*vlan_tag == adapter->
pvid) {
1549 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1561 if (
unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1562 adapter->
stats.rxdropped++;
1570 __vlan_hwaccel_put_tag(skb, vid);
1574 adapter->
stats.rx_pkts++;
1580 #define QLC_TCP_HDR_SIZE 20
1581 #define QLC_TCP_TS_OPTION_SIZE 12
1582 #define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1587 int ring,
u64 sts_data0,
u64 sts_data1)
1597 int l2_hdr_offset, l4_hdr_offset;
1621 skb = qlcnic_process_rxbuf(adapter, rds_ring, index,
STATUS_CKSUM_OK);
1630 skb_put(skb, lro_length + data_offset);
1634 if (
unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1635 adapter->
stats.rxdropped++;
1643 th = (
struct tcphdr *)(skb->
data + (iph->ihl << 2));
1645 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
1658 __vlan_hwaccel_put_tag(skb, vid);
1661 adapter->
stats.lro_pkts++;
1674 u64 sts_data0, sts_data1;
1677 int opcode, ring, desc_cnt;
1680 while (count < max) {
1695 rxbuf = qlcnic_process_rcv(adapter, sds_ring,
1701 rxbuf = qlcnic_process_lro(adapter, sds_ring,
1702 ring, sts_data0, sts_data1);
1705 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1715 adapter->
stats.null_rxbuf++;
1718 for (; desc_cnt > 0; desc_cnt--) {
1729 &adapter->
recv_ctx->rds_rings[ring];
1731 if (!list_empty(&sds_ring->
free_list[ring])) {
1735 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1737 spin_lock(&rds_ring->
lock);
1738 list_splice_tail_init(&sds_ring->
free_list[ring],
1740 spin_unlock(&rds_ring->
lock);
1743 qlcnic_post_rx_buffers_nodb(adapter, rds_ring);
1767 while (!list_empty(head)) {
1772 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1805 if (!spin_trylock(&rds_ring->
lock))
1811 while (!list_empty(head)) {
1816 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1837 spin_unlock(&rds_ring->
lock);
1846 for (i = 0; i < skb->
len; i++) {
1847 QLCDB(adapter, DRV,
"%02x ", data[i]);
1848 if ((i & 0x0f) == 8)
1855 int ring,
u64 sts_data0)
1875 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1890 dump_skb(skb, adapter);
1893 adapter->
stats.rx_pkts++;
1905 int ring,
opcode, desc_cnt;
1919 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1927 for (; desc_cnt > 0; desc_cnt--) {
1941 u32 mac_low, mac_high;
1948 mac_low |= (mac_low >> 16) | (mac_high << 16);
1952 for (i = 0; i < 2; i++)
1953 mac[i] = (
u8)(mac_high >> ((1 -
i) * 8));
1954 for (i = 2; i < 6; i++)
1955 mac[i] = (
u8)(mac_low >> ((5 -
i) * 8));