Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 4 | * This software is available under the terms of the GNU General Public License |
| 5 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <asm/byteorder.h> |
| 11 | #include <linux/bitops.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/string.h> |
| 15 | #include "qed.h" |
| 16 | #include <linux/qed/qed_chain.h> |
| 17 | #include "qed_cxt.h" |
| 18 | #include "qed_hsi.h" |
| 19 | #include "qed_hw.h" |
| 20 | #include "qed_int.h" |
| 21 | #include "qed_reg_addr.h" |
| 22 | #include "qed_sp.h" |
| 23 | |
| 24 | int qed_sp_init_request(struct qed_hwfn *p_hwfn, |
| 25 | struct qed_spq_entry **pp_ent, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 26 | u8 cmd, |
| 27 | u8 protocol, |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 28 | struct qed_sp_init_data *p_data) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 29 | { |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 30 | u32 opaque_cid = p_data->opaque_fid << 16 | p_data->cid; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 31 | struct qed_spq_entry *p_ent = NULL; |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 32 | int rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 33 | |
| 34 | if (!pp_ent) |
| 35 | return -ENOMEM; |
| 36 | |
| 37 | rc = qed_spq_get_entry(p_hwfn, pp_ent); |
| 38 | |
| 39 | if (rc != 0) |
| 40 | return rc; |
| 41 | |
| 42 | p_ent = *pp_ent; |
| 43 | |
| 44 | p_ent->elem.hdr.cid = cpu_to_le32(opaque_cid); |
| 45 | p_ent->elem.hdr.cmd_id = cmd; |
| 46 | p_ent->elem.hdr.protocol_id = protocol; |
| 47 | |
| 48 | p_ent->priority = QED_SPQ_PRIORITY_NORMAL; |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 49 | p_ent->comp_mode = p_data->comp_mode; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 50 | p_ent->comp_done.done = 0; |
| 51 | |
| 52 | switch (p_ent->comp_mode) { |
| 53 | case QED_SPQ_MODE_EBLOCK: |
| 54 | p_ent->comp_cb.cookie = &p_ent->comp_done; |
| 55 | break; |
| 56 | |
| 57 | case QED_SPQ_MODE_BLOCK: |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 58 | if (!p_data->p_comp_data) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 61 | p_ent->comp_cb.cookie = p_data->p_comp_data->cookie; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 62 | break; |
| 63 | |
| 64 | case QED_SPQ_MODE_CB: |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 65 | if (!p_data->p_comp_data) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 66 | p_ent->comp_cb.function = NULL; |
| 67 | else |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 68 | p_ent->comp_cb = *p_data->p_comp_data; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 69 | break; |
| 70 | |
| 71 | default: |
| 72 | DP_NOTICE(p_hwfn, "Unknown SPQE completion mode %d\n", |
| 73 | p_ent->comp_mode); |
| 74 | return -EINVAL; |
| 75 | } |
| 76 | |
| 77 | DP_VERBOSE(p_hwfn, QED_MSG_SPQ, |
| 78 | "Initialized: CID %08x cmd %02x protocol %02x data_addr %lu comp_mode [%s]\n", |
| 79 | opaque_cid, cmd, protocol, |
| 80 | (unsigned long)&p_ent->ramrod, |
| 81 | D_TRINE(p_ent->comp_mode, QED_SPQ_MODE_EBLOCK, |
| 82 | QED_SPQ_MODE_BLOCK, "MODE_EBLOCK", "MODE_BLOCK", |
| 83 | "MODE_CB")); |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 84 | |
| 85 | memset(&p_ent->ramrod, 0, sizeof(p_ent->ramrod)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | int qed_sp_pf_start(struct qed_hwfn *p_hwfn, |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 91 | enum qed_mf_mode mode) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 92 | { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 93 | struct pf_start_ramrod_data *p_ramrod = NULL; |
| 94 | u16 sb = qed_int_get_sp_sb_id(p_hwfn); |
| 95 | u8 sb_index = p_hwfn->p_eq->eq_sb_index; |
| 96 | struct qed_spq_entry *p_ent = NULL; |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 97 | struct qed_sp_init_data init_data; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 98 | int rc = -EINVAL; |
| 99 | |
| 100 | /* update initial eq producer */ |
| 101 | qed_eq_prod_update(p_hwfn, |
| 102 | qed_chain_get_prod_idx(&p_hwfn->p_eq->chain)); |
| 103 | |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 104 | memset(&init_data, 0, sizeof(init_data)); |
| 105 | init_data.cid = qed_spq_get_cid(p_hwfn); |
| 106 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 107 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 108 | |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 109 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 110 | COMMON_RAMROD_PF_START, |
| 111 | PROTOCOLID_COMMON, |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 112 | &init_data); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 113 | if (rc) |
| 114 | return rc; |
| 115 | |
| 116 | p_ramrod = &p_ent->ramrod.pf_start; |
| 117 | |
| 118 | p_ramrod->event_ring_sb_id = cpu_to_le16(sb); |
| 119 | p_ramrod->event_ring_sb_index = sb_index; |
| 120 | p_ramrod->path_id = QED_PATH_ID(p_hwfn); |
| 121 | p_ramrod->dont_log_ramrods = 0; |
| 122 | p_ramrod->log_type_mask = cpu_to_le16(0xf); |
| 123 | p_ramrod->mf_mode = mode; |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 124 | switch (mode) { |
| 125 | case QED_MF_DEFAULT: |
| 126 | case QED_MF_NPAR: |
| 127 | p_ramrod->mf_mode = MF_NPAR; |
| 128 | break; |
| 129 | case QED_MF_OVLAN: |
| 130 | p_ramrod->mf_mode = MF_OVLAN; |
| 131 | break; |
| 132 | default: |
| 133 | DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n"); |
| 134 | p_ramrod->mf_mode = MF_NPAR; |
| 135 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 136 | p_ramrod->outer_tag = p_hwfn->hw_info.ovlan; |
| 137 | |
| 138 | /* Place EQ address in RAMROD */ |
| 139 | p_ramrod->event_ring_pbl_addr.hi = |
| 140 | DMA_HI_LE(p_hwfn->p_eq->chain.pbl.p_phys_table); |
| 141 | p_ramrod->event_ring_pbl_addr.lo = |
| 142 | DMA_LO_LE(p_hwfn->p_eq->chain.pbl.p_phys_table); |
| 143 | p_ramrod->event_ring_num_pages = (u8)p_hwfn->p_eq->chain.page_cnt; |
| 144 | |
| 145 | p_ramrod->consolid_q_pbl_addr.hi = |
| 146 | DMA_HI_LE(p_hwfn->p_consq->chain.pbl.p_phys_table); |
| 147 | p_ramrod->consolid_q_pbl_addr.lo = |
| 148 | DMA_LO_LE(p_hwfn->p_consq->chain.pbl.p_phys_table); |
| 149 | |
| 150 | p_hwfn->hw_info.personality = PERSONALITY_ETH; |
| 151 | |
| 152 | DP_VERBOSE(p_hwfn, QED_MSG_SPQ, |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 153 | "Setting event_ring_sb [id %04x index %02x], outer_tag [%d]\n", |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 154 | sb, sb_index, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 155 | p_ramrod->outer_tag); |
| 156 | |
| 157 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 158 | } |
| 159 | |
| 160 | int qed_sp_pf_stop(struct qed_hwfn *p_hwfn) |
| 161 | { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 162 | struct qed_spq_entry *p_ent = NULL; |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 163 | struct qed_sp_init_data init_data; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 164 | int rc = -EINVAL; |
| 165 | |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 166 | /* Get SPQ entry */ |
| 167 | memset(&init_data, 0, sizeof(init_data)); |
| 168 | init_data.cid = qed_spq_get_cid(p_hwfn); |
| 169 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 170 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 171 | |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 172 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 173 | COMMON_RAMROD_PF_STOP, PROTOCOLID_COMMON, |
Yuval Mintz | 06f56b8 | 2016-02-21 11:40:09 +0200 | [diff] [blame^] | 174 | &init_data); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 175 | if (rc) |
| 176 | return rc; |
| 177 | |
| 178 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 179 | } |