Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1 | /** |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2015 Emulex |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
Minh Tran | 4627de9 | 2015-05-14 23:16:17 -0700 | [diff] [blame] | 11 | * linux-drivers@avagotech.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 12 | * |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 13 | * Emulex |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 16 | */ |
| 17 | |
John Soni Jose | 2177199 | 2012-04-03 23:41:49 -0500 | [diff] [blame] | 18 | #include <scsi/iscsi_proto.h> |
| 19 | |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 20 | #include "be_main.h" |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 21 | #include "be.h" |
| 22 | #include "be_mgmt.h" |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 23 | |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 24 | int beiscsi_pci_soft_reset(struct beiscsi_hba *phba) |
| 25 | { |
| 26 | u32 sreset; |
| 27 | u8 *pci_reset_offset = 0; |
| 28 | u8 *pci_online0_offset = 0; |
| 29 | u8 *pci_online1_offset = 0; |
| 30 | u32 pconline0 = 0; |
| 31 | u32 pconline1 = 0; |
| 32 | u32 i; |
| 33 | |
| 34 | pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET; |
| 35 | pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0; |
| 36 | pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1; |
| 37 | sreset = readl((void *)pci_reset_offset); |
| 38 | sreset |= BE2_SET_RESET; |
| 39 | writel(sreset, (void *)pci_reset_offset); |
| 40 | |
| 41 | i = 0; |
| 42 | while (sreset & BE2_SET_RESET) { |
| 43 | if (i > 64) |
| 44 | break; |
| 45 | msleep(100); |
| 46 | sreset = readl((void *)pci_reset_offset); |
| 47 | i++; |
| 48 | } |
| 49 | |
| 50 | if (sreset & BE2_SET_RESET) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 51 | printk(KERN_ERR DRV_NAME |
| 52 | " Soft Reset did not deassert\n"); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 53 | return -EIO; |
| 54 | } |
| 55 | pconline1 = BE2_MPU_IRAM_ONLINE; |
| 56 | writel(pconline0, (void *)pci_online0_offset); |
| 57 | writel(pconline1, (void *)pci_online1_offset); |
| 58 | |
Minh Tran | 1d8bc70 | 2012-10-20 04:41:24 +0530 | [diff] [blame] | 59 | sreset |= BE2_SET_RESET; |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 60 | writel(sreset, (void *)pci_reset_offset); |
| 61 | |
| 62 | i = 0; |
| 63 | while (sreset & BE2_SET_RESET) { |
| 64 | if (i > 64) |
| 65 | break; |
| 66 | msleep(1); |
| 67 | sreset = readl((void *)pci_reset_offset); |
| 68 | i++; |
| 69 | } |
| 70 | if (sreset & BE2_SET_RESET) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 71 | printk(KERN_ERR DRV_NAME |
| 72 | " MPU Online Soft Reset did not deassert\n"); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 73 | return -EIO; |
| 74 | } |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int be_chk_reset_complete(struct beiscsi_hba *phba) |
| 79 | { |
| 80 | unsigned int num_loop; |
| 81 | u8 *mpu_sem = 0; |
| 82 | u32 status; |
| 83 | |
| 84 | num_loop = 1000; |
| 85 | mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE; |
| 86 | msleep(5000); |
| 87 | |
| 88 | while (num_loop) { |
| 89 | status = readl((void *)mpu_sem); |
| 90 | |
| 91 | if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000) |
| 92 | break; |
| 93 | msleep(60); |
| 94 | num_loop--; |
| 95 | } |
| 96 | |
| 97 | if ((status & 0x80000000) || (!num_loop)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 98 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 99 | "BC_%d : Failed in be_chk_reset_complete" |
| 100 | "status = 0x%x\n", status); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 101 | return -EIO; |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 107 | unsigned int alloc_mcc_tag(struct beiscsi_hba *phba) |
| 108 | { |
| 109 | unsigned int tag = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 110 | |
Jitendra Bhivare | 12843f0 | 2016-01-20 14:10:48 +0530 | [diff] [blame] | 111 | spin_lock(&phba->ctrl.mcc_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 112 | if (phba->ctrl.mcc_tag_available) { |
| 113 | tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index]; |
| 114 | phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 115 | phba->ctrl.mcc_tag_status[tag] = 0; |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 116 | phba->ctrl.ptag_state[tag].tag_state = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 117 | } |
| 118 | if (tag) { |
| 119 | phba->ctrl.mcc_tag_available--; |
| 120 | if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1)) |
| 121 | phba->ctrl.mcc_alloc_index = 0; |
| 122 | else |
| 123 | phba->ctrl.mcc_alloc_index++; |
| 124 | } |
Jitendra Bhivare | 12843f0 | 2016-01-20 14:10:48 +0530 | [diff] [blame] | 125 | spin_unlock(&phba->ctrl.mcc_lock); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 126 | return tag; |
| 127 | } |
| 128 | |
Jitendra Bhivare | 69fd6d7 | 2016-02-04 15:49:14 +0530 | [diff] [blame^] | 129 | void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag) |
| 130 | { |
| 131 | spin_lock_bh(&ctrl->mcc_lock); |
| 132 | tag = tag & MCC_Q_CMD_TAG_MASK; |
| 133 | ctrl->mcc_tag[ctrl->mcc_free_index] = tag; |
| 134 | if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1)) |
| 135 | ctrl->mcc_free_index = 0; |
| 136 | else |
| 137 | ctrl->mcc_free_index++; |
| 138 | ctrl->mcc_tag_available++; |
| 139 | spin_unlock_bh(&ctrl->mcc_lock); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * beiscsi_fail_session(): Closing session with appropriate error |
| 144 | * @cls_session: ptr to session |
| 145 | **/ |
| 146 | void beiscsi_fail_session(struct iscsi_cls_session *cls_session) |
| 147 | { |
| 148 | iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); |
| 149 | } |
| 150 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 151 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 152 | * beiscsi_mccq_compl_wait()- Process completion in MCC CQ |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 153 | * @phba: Driver private structure |
| 154 | * @tag: Tag for the MBX Command |
| 155 | * @wrb: the WRB used for the MBX Command |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 156 | * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 157 | * |
| 158 | * Waits for MBX completion with the passed TAG. |
| 159 | * |
| 160 | * return |
| 161 | * Success: 0 |
| 162 | * Failure: Non-Zero |
| 163 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 164 | int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba, |
| 165 | uint32_t tag, struct be_mcc_wrb **wrb, |
| 166 | struct be_dma_mem *mbx_cmd_mem) |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 167 | { |
| 168 | int rc = 0; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 169 | uint32_t mcc_tag_status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 170 | uint16_t status = 0, addl_status = 0, wrb_num = 0; |
| 171 | struct be_mcc_wrb *temp_wrb; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 172 | struct be_cmd_req_hdr *mbx_hdr; |
| 173 | struct be_cmd_resp_hdr *mbx_resp_hdr; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 174 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 175 | |
Jayamohan Kallickal | 1f536d4 | 2013-09-28 15:35:56 -0700 | [diff] [blame] | 176 | if (beiscsi_error(phba)) { |
| 177 | free_mcc_tag(&phba->ctrl, tag); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 178 | return -EPERM; |
Jayamohan Kallickal | 1f536d4 | 2013-09-28 15:35:56 -0700 | [diff] [blame] | 179 | } |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 180 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 181 | /* wait for the mccq completion */ |
| 182 | rc = wait_event_interruptible_timeout( |
| 183 | phba->ctrl.mcc_wait[tag], |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 184 | phba->ctrl.mcc_tag_status[tag], |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 185 | msecs_to_jiffies( |
| 186 | BEISCSI_HOST_MBX_TIMEOUT)); |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 187 | /** |
| 188 | * If MBOX cmd timeout expired, tag and resource allocated |
| 189 | * for cmd is not freed until FW returns completion. |
| 190 | */ |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 191 | if (rc <= 0) { |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 192 | struct be_dma_mem *tag_mem; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 193 | |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 194 | /** |
| 195 | * PCI/DMA memory allocated and posted in non-embedded mode |
| 196 | * will have mbx_cmd_mem != NULL. |
| 197 | * Save virtual and bus addresses for the command so that it |
| 198 | * can be freed later. |
| 199 | **/ |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 200 | tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state; |
| 201 | if (mbx_cmd_mem) { |
| 202 | tag_mem->size = mbx_cmd_mem->size; |
| 203 | tag_mem->va = mbx_cmd_mem->va; |
| 204 | tag_mem->dma = mbx_cmd_mem->dma; |
| 205 | } else |
| 206 | tag_mem->size = 0; |
| 207 | |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 208 | /* first make tag_mem_state visible to all */ |
| 209 | wmb(); |
| 210 | set_bit(MCC_TAG_STATE_TIMEOUT, |
| 211 | &phba->ctrl.ptag_state[tag].tag_state); |
| 212 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 213 | beiscsi_log(phba, KERN_ERR, |
| 214 | BEISCSI_LOG_INIT | BEISCSI_LOG_EH | |
| 215 | BEISCSI_LOG_CONFIG, |
| 216 | "BC_%d : MBX Cmd Completion timed out\n"); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 217 | return -EBUSY; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 218 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 219 | |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 220 | rc = 0; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 221 | mcc_tag_status = phba->ctrl.mcc_tag_status[tag]; |
| 222 | status = (mcc_tag_status & CQE_STATUS_MASK); |
| 223 | addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >> |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 224 | CQE_STATUS_ADDL_SHIFT); |
| 225 | |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 226 | if (mbx_cmd_mem) { |
| 227 | mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 228 | } else { |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 229 | wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >> |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 230 | CQE_STATUS_WRB_SHIFT; |
| 231 | temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 232 | mbx_hdr = embedded_payload(temp_wrb); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 233 | |
| 234 | if (wrb) |
| 235 | *wrb = temp_wrb; |
| 236 | } |
| 237 | |
| 238 | if (status || addl_status) { |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 239 | beiscsi_log(phba, KERN_WARNING, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 240 | BEISCSI_LOG_INIT | BEISCSI_LOG_EH | |
| 241 | BEISCSI_LOG_CONFIG, |
| 242 | "BC_%d : MBX Cmd Failed for " |
| 243 | "Subsys : %d Opcode : %d with " |
| 244 | "Status : %d and Extd_Status : %d\n", |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 245 | mbx_hdr->subsystem, |
| 246 | mbx_hdr->opcode, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 247 | status, addl_status); |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 248 | rc = -EIO; |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 249 | if (status == MCC_STATUS_INSUFFICIENT_BUFFER) { |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 250 | mbx_resp_hdr = (struct be_cmd_resp_hdr *) mbx_hdr; |
Jayamohan Kallickal | 1f536d4 | 2013-09-28 15:35:56 -0700 | [diff] [blame] | 251 | beiscsi_log(phba, KERN_WARNING, |
| 252 | BEISCSI_LOG_INIT | BEISCSI_LOG_EH | |
| 253 | BEISCSI_LOG_CONFIG, |
Masanari Iida | d939be3 | 2015-02-27 23:52:31 +0900 | [diff] [blame] | 254 | "BC_%d : Insufficient Buffer Error " |
Jayamohan Kallickal | 1f536d4 | 2013-09-28 15:35:56 -0700 | [diff] [blame] | 255 | "Resp_Len : %d Actual_Resp_Len : %d\n", |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 256 | mbx_resp_hdr->response_length, |
| 257 | mbx_resp_hdr->actual_resp_len); |
Jayamohan Kallickal | 1f536d4 | 2013-09-28 15:35:56 -0700 | [diff] [blame] | 258 | rc = -EAGAIN; |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 259 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 260 | } |
| 261 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 262 | free_mcc_tag(&phba->ctrl, tag); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 263 | return rc; |
| 264 | } |
| 265 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 266 | static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl) |
| 267 | { |
| 268 | if (compl->flags != 0) { |
| 269 | compl->flags = le32_to_cpu(compl->flags); |
| 270 | WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0); |
| 271 | return true; |
| 272 | } else |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) |
| 277 | { |
| 278 | compl->flags = 0; |
| 279 | } |
| 280 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 281 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 282 | * beiscsi_process_mbox_compl()- Check the MBX completion status |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 283 | * @ctrl: Function specific MBX data structure |
| 284 | * @compl: Completion status of MBX Command |
| 285 | * |
| 286 | * Check for the MBX completion status when BMBX method used |
| 287 | * |
| 288 | * return |
| 289 | * Success: Zero |
| 290 | * Failure: Non-Zero |
| 291 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 292 | static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl, |
| 293 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 294 | { |
| 295 | u16 compl_status, extd_status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 296 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 297 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 298 | struct be_cmd_req_hdr *hdr = embedded_payload(wrb); |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 299 | struct be_cmd_resp_hdr *resp_hdr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 300 | |
| 301 | be_dws_le_to_cpu(compl, 4); |
| 302 | |
| 303 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 304 | CQE_STATUS_COMPL_MASK; |
| 305 | if (compl_status != MCC_STATUS_SUCCESS) { |
| 306 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 307 | CQE_STATUS_EXTD_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 308 | |
| 309 | beiscsi_log(phba, KERN_ERR, |
| 310 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 311 | "BC_%d : error in cmd completion: " |
| 312 | "Subsystem : %d Opcode : %d " |
| 313 | "status(compl/extd)=%d/%d\n", |
| 314 | hdr->subsystem, hdr->opcode, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 315 | compl_status, extd_status); |
| 316 | |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 317 | if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) { |
| 318 | resp_hdr = (struct be_cmd_resp_hdr *) hdr; |
| 319 | if (resp_hdr->response_length) |
| 320 | return 0; |
| 321 | } |
Jitendra Bhivare | 23d7ccf1 | 2016-01-20 14:10:55 +0530 | [diff] [blame] | 322 | return -EINVAL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 327 | static void beiscsi_process_async_link(struct beiscsi_hba *phba, |
| 328 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 329 | { |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 330 | struct be_async_event_link_state *evt; |
| 331 | |
| 332 | evt = (struct be_async_event_link_state *)compl; |
| 333 | |
Jitendra Bhivare | 048084c | 2016-01-20 14:10:58 +0530 | [diff] [blame] | 334 | phba->port_speed = evt->port_speed; |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 335 | /** |
| 336 | * Check logical link status in ASYNC event. |
| 337 | * This has been newly introduced in SKH-R Firmware 10.0.338.45. |
| 338 | **/ |
| 339 | if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) { |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 340 | phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT; |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 341 | phba->get_boot = BE_GET_BOOT_RETRIES; |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 342 | __beiscsi_log(phba, KERN_ERR, |
| 343 | "BC_%d : Link Up on Port %d tag 0x%x\n", |
| 344 | evt->physical_port, evt->event_tag); |
| 345 | } else { |
| 346 | phba->state = BE_ADAPTER_LINK_DOWN; |
| 347 | __beiscsi_log(phba, KERN_ERR, |
| 348 | "BC_%d : Link Down on Port %d tag 0x%x\n", |
| 349 | evt->physical_port, evt->event_tag); |
| 350 | iscsi_host_for_each_session(phba->shost, |
| 351 | beiscsi_fail_session); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 355 | static char *beiscsi_port_misconf_event_msg[] = { |
| 356 | "Physical Link is functional.", |
| 357 | "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.", |
| 358 | "Optics of two types installed - Remove one optic or install matching pair of optics.", |
| 359 | "Incompatible optics - Replace with compatible optics for card to function.", |
| 360 | "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.", |
| 361 | "Uncertified optics - Replace with Avago Certified optics to enable link operation." |
| 362 | }; |
| 363 | |
| 364 | static void beiscsi_process_async_sli(struct beiscsi_hba *phba, |
| 365 | struct be_mcc_compl *compl) |
| 366 | { |
| 367 | struct be_async_event_sli *async_sli; |
| 368 | u8 evt_type, state, old_state, le; |
| 369 | char *sev = KERN_WARNING; |
| 370 | char *msg = NULL; |
| 371 | |
| 372 | evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT; |
| 373 | evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK; |
| 374 | |
| 375 | /* processing only MISCONFIGURED physical port event */ |
| 376 | if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED) |
| 377 | return; |
| 378 | |
| 379 | async_sli = (struct be_async_event_sli *)compl; |
| 380 | state = async_sli->event_data1 >> |
| 381 | (phba->fw_config.phys_port * 8) & 0xff; |
| 382 | le = async_sli->event_data2 >> |
| 383 | (phba->fw_config.phys_port * 8) & 0xff; |
| 384 | |
| 385 | old_state = phba->optic_state; |
| 386 | phba->optic_state = state; |
| 387 | |
| 388 | if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) { |
| 389 | /* fw is reporting a state we don't know, log and return */ |
| 390 | __beiscsi_log(phba, KERN_ERR, |
| 391 | "BC_%d : Port %c: Unrecognized optic state 0x%x\n", |
| 392 | phba->port_name, async_sli->event_data1); |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | if (ASYNC_SLI_LINK_EFFECT_VALID(le)) { |
| 397 | /* log link effect for unqualified-4, uncertified-5 optics */ |
| 398 | if (state > 3) |
| 399 | msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ? |
| 400 | " Link is non-operational." : |
| 401 | " Link is operational."; |
| 402 | /* 1 - info */ |
| 403 | if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1) |
| 404 | sev = KERN_INFO; |
| 405 | /* 2 - error */ |
| 406 | if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2) |
| 407 | sev = KERN_ERR; |
| 408 | } |
| 409 | |
| 410 | if (old_state != phba->optic_state) |
| 411 | __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n", |
| 412 | phba->port_name, |
| 413 | beiscsi_port_misconf_event_msg[state], |
| 414 | !msg ? "" : msg); |
| 415 | } |
| 416 | |
| 417 | void beiscsi_process_async_event(struct beiscsi_hba *phba, |
| 418 | struct be_mcc_compl *compl) |
| 419 | { |
| 420 | char *sev = KERN_INFO; |
| 421 | u8 evt_code; |
| 422 | |
| 423 | /* interpret flags as an async trailer */ |
| 424 | evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT; |
| 425 | evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK; |
| 426 | switch (evt_code) { |
| 427 | case ASYNC_EVENT_CODE_LINK_STATE: |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 428 | beiscsi_process_async_link(phba, compl); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 429 | break; |
| 430 | case ASYNC_EVENT_CODE_ISCSI: |
| 431 | phba->state |= BE_ADAPTER_CHECK_BOOT; |
| 432 | phba->get_boot = BE_GET_BOOT_RETRIES; |
| 433 | sev = KERN_ERR; |
| 434 | break; |
| 435 | case ASYNC_EVENT_CODE_SLI: |
| 436 | beiscsi_process_async_sli(phba, compl); |
| 437 | break; |
| 438 | default: |
| 439 | /* event not registered */ |
| 440 | sev = KERN_ERR; |
| 441 | } |
| 442 | |
| 443 | beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 444 | "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n", |
| 445 | evt_code, compl->status, compl->flags); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 446 | } |
| 447 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 448 | int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl, |
| 449 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 450 | { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 451 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
| 452 | u16 compl_status, extd_status; |
| 453 | struct be_dma_mem *tag_mem; |
| 454 | unsigned int tag, wrb_idx; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 455 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 456 | /** |
| 457 | * Just swap the status to host endian; mcc tag is opaquely copied |
| 458 | * from mcc_wrb |
| 459 | */ |
| 460 | be_dws_le_to_cpu(compl, 4); |
| 461 | tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK); |
| 462 | wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT; |
| 463 | |
| 464 | if (!test_bit(MCC_TAG_STATE_RUNNING, |
| 465 | &ctrl->ptag_state[tag].tag_state)) { |
| 466 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX | |
| 467 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 468 | "BC_%d : MBX cmd completed but not posted\n"); |
| 469 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 470 | } |
| 471 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 472 | if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) { |
| 473 | beiscsi_log(phba, KERN_WARNING, |
| 474 | BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT | |
| 475 | BEISCSI_LOG_CONFIG, |
| 476 | "BC_%d : MBX Completion for timeout Command from FW\n"); |
| 477 | /** |
| 478 | * Check for the size before freeing resource. |
| 479 | * Only for non-embedded cmd, PCI resource is allocated. |
| 480 | **/ |
| 481 | tag_mem = &ctrl->ptag_state[tag].tag_mem_state; |
| 482 | if (tag_mem->size) |
| 483 | pci_free_consistent(ctrl->pdev, tag_mem->size, |
| 484 | tag_mem->va, tag_mem->dma); |
| 485 | free_mcc_tag(ctrl, tag); |
| 486 | return 0; |
| 487 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 488 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 489 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 490 | CQE_STATUS_COMPL_MASK; |
| 491 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 492 | CQE_STATUS_EXTD_MASK; |
| 493 | /* The ctrl.mcc_tag_status[tag] is filled with |
| 494 | * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status, |
| 495 | * [7:0] = compl_status |
| 496 | */ |
| 497 | ctrl->mcc_tag_status[tag] = CQE_VALID_MASK; |
| 498 | ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT); |
| 499 | ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) & |
| 500 | CQE_STATUS_ADDL_MASK; |
| 501 | ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK); |
| 502 | |
| 503 | /* write ordering forced in wake_up_interruptible */ |
| 504 | clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state); |
| 505 | wake_up_interruptible(&ctrl->mcc_wait[tag]); |
| 506 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 507 | } |
| 508 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 509 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 510 | * be_mcc_compl_poll()- Wait for MBX completion |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 511 | * @phba: driver private structure |
| 512 | * |
| 513 | * Wait till no more pending mcc requests are present |
| 514 | * |
| 515 | * return |
| 516 | * Success: 0 |
| 517 | * Failure: Non-Zero |
| 518 | * |
| 519 | **/ |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 520 | int be_mcc_compl_poll(struct beiscsi_hba *phba, unsigned int tag) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 521 | { |
Jitendra Bhivare | 69fd6d7 | 2016-02-04 15:49:14 +0530 | [diff] [blame^] | 522 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 523 | int i; |
| 524 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 525 | for (i = 0; i < mcc_timeout; i++) { |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 526 | if (beiscsi_error(phba)) |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 527 | return -EIO; |
| 528 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 529 | beiscsi_process_mcc_cq(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 530 | |
Jitendra Bhivare | 69fd6d7 | 2016-02-04 15:49:14 +0530 | [diff] [blame^] | 531 | if (!test_bit(MCC_TAG_STATE_RUNNING, |
| 532 | &ctrl->ptag_state[tag].tag_state)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 533 | break; |
| 534 | udelay(100); |
| 535 | } |
Jitendra Bhivare | 69fd6d7 | 2016-02-04 15:49:14 +0530 | [diff] [blame^] | 536 | |
| 537 | if (i < mcc_timeout) |
| 538 | return 0; |
| 539 | |
| 540 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 541 | "BC_%d : FW Timed Out\n"); |
| 542 | phba->fw_timeout = true; |
| 543 | beiscsi_ue_detect(phba); |
| 544 | return -EBUSY; |
| 545 | } |
| 546 | |
| 547 | void be_mcc_notify(struct beiscsi_hba *phba, unsigned int tag) |
| 548 | { |
| 549 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 550 | u32 val = 0; |
| 551 | |
| 552 | set_bit(MCC_TAG_STATE_RUNNING, &phba->ctrl.ptag_state[tag].tag_state); |
| 553 | val |= mccq->id & DB_MCCQ_RING_ID_MASK; |
| 554 | val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT; |
| 555 | /* make request available for DMA */ |
| 556 | wmb(); |
| 557 | iowrite32(val, phba->db_va + DB_MCCQ_OFFSET); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 558 | } |
| 559 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 560 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 561 | * be_mbox_db_ready_poll()- Check ready status |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 562 | * @ctrl: Function specific MBX data structure |
| 563 | * |
| 564 | * Check for the ready status of FW to send BMBX |
| 565 | * commands to adapter. |
| 566 | * |
| 567 | * return |
| 568 | * Success: 0 |
| 569 | * Failure: Non-Zero |
| 570 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 571 | static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 572 | { |
Jitendra Bhivare | 9ec6f6b | 2016-01-20 14:10:49 +0530 | [diff] [blame] | 573 | /* wait 30s for generic non-flash MBOX operation */ |
| 574 | #define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 575 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 576 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 577 | unsigned long timeout; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 578 | u32 ready; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 579 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 580 | /* |
| 581 | * This BMBX busy wait path is used during init only. |
| 582 | * For the commands executed during init, 5s should suffice. |
| 583 | */ |
| 584 | timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 585 | do { |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 586 | if (beiscsi_error(phba)) |
| 587 | return -EIO; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 588 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 589 | ready = ioread32(db); |
| 590 | if (ready == 0xffffffff) |
| 591 | return -EIO; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 592 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 593 | ready &= MPU_MAILBOX_DB_RDY_MASK; |
| 594 | if (ready) |
| 595 | return 0; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 596 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 597 | if (time_after(jiffies, timeout)) |
| 598 | break; |
Jitendra Bhivare | 9ec6f6b | 2016-01-20 14:10:49 +0530 | [diff] [blame] | 599 | msleep(20); |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 600 | } while (!ready); |
| 601 | |
| 602 | beiscsi_log(phba, KERN_ERR, |
| 603 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 604 | "BC_%d : FW Timed Out\n"); |
| 605 | |
| 606 | phba->fw_timeout = true; |
| 607 | beiscsi_ue_detect(phba); |
| 608 | |
| 609 | return -EBUSY; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 610 | } |
| 611 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 612 | /* |
| 613 | * be_mbox_notify: Notify adapter of new BMBX command |
| 614 | * @ctrl: Function specific MBX data structure |
| 615 | * |
| 616 | * Ring doorbell to inform adapter of a BMBX command |
| 617 | * to process |
| 618 | * |
| 619 | * return |
| 620 | * Success: 0 |
| 621 | * Failure: Non-Zero |
| 622 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 623 | int be_mbox_notify(struct be_ctrl_info *ctrl) |
| 624 | { |
| 625 | int status; |
| 626 | u32 val = 0; |
| 627 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
| 628 | struct be_dma_mem *mbox_mem = &ctrl->mbox_mem; |
| 629 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 630 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 631 | status = be_mbox_db_ready_poll(ctrl); |
Jayamohan Kallickal | 1e234bb | 2013-04-05 20:38:23 -0700 | [diff] [blame] | 632 | if (status) |
| 633 | return status; |
| 634 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 635 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 636 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 637 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 638 | iowrite32(val, db); |
| 639 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 640 | status = be_mbox_db_ready_poll(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 641 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 642 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 643 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 644 | val = 0; |
| 645 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 646 | val &= ~MPU_MAILBOX_DB_HI_MASK; |
| 647 | val |= (u32) (mbox_mem->dma >> 4) << 2; |
| 648 | iowrite32(val, db); |
| 649 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 650 | status = be_mbox_db_ready_poll(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 651 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 652 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 653 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 654 | /* RDY is set; small delay before CQE read. */ |
| 655 | udelay(1); |
| 656 | |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame] | 657 | status = beiscsi_process_mbox_compl(ctrl, &mbox->compl); |
| 658 | return status; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 659 | } |
| 660 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 661 | void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len, |
| 662 | bool embedded, u8 sge_cnt) |
| 663 | { |
| 664 | if (embedded) |
| 665 | wrb->embedded |= MCC_WRB_EMBEDDED_MASK; |
| 666 | else |
| 667 | wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) << |
| 668 | MCC_WRB_SGE_CNT_SHIFT; |
| 669 | wrb->payload_length = payload_len; |
| 670 | be_dws_cpu_to_le(wrb, 8); |
| 671 | } |
| 672 | |
| 673 | void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
| 674 | u8 subsystem, u8 opcode, int cmd_len) |
| 675 | { |
| 676 | req_hdr->opcode = opcode; |
| 677 | req_hdr->subsystem = subsystem; |
| 678 | req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr)); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 679 | req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
| 683 | struct be_dma_mem *mem) |
| 684 | { |
| 685 | int i, buf_pages; |
| 686 | u64 dma = (u64) mem->dma; |
| 687 | |
| 688 | buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages); |
| 689 | for (i = 0; i < buf_pages; i++) { |
| 690 | pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF); |
| 691 | pages[i].hi = cpu_to_le32(upper_32_bits(dma)); |
| 692 | dma += PAGE_SIZE_4K; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | static u32 eq_delay_to_mult(u32 usec_delay) |
| 697 | { |
| 698 | #define MAX_INTR_RATE 651042 |
| 699 | const u32 round = 10; |
| 700 | u32 multiplier; |
| 701 | |
| 702 | if (usec_delay == 0) |
| 703 | multiplier = 0; |
| 704 | else { |
| 705 | u32 interrupt_rate = 1000000 / usec_delay; |
| 706 | if (interrupt_rate == 0) |
| 707 | multiplier = 1023; |
| 708 | else { |
| 709 | multiplier = (MAX_INTR_RATE - interrupt_rate) * round; |
| 710 | multiplier /= interrupt_rate; |
| 711 | multiplier = (multiplier + round / 2) / round; |
| 712 | multiplier = min(multiplier, (u32) 1023); |
| 713 | } |
| 714 | } |
| 715 | return multiplier; |
| 716 | } |
| 717 | |
| 718 | struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem) |
| 719 | { |
| 720 | return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb; |
| 721 | } |
| 722 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 723 | struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba) |
| 724 | { |
| 725 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 726 | struct be_mcc_wrb *wrb; |
| 727 | |
Jayamohan Kallickal | e074d20 | 2013-09-28 15:35:39 -0700 | [diff] [blame] | 728 | WARN_ON(atomic_read(&mccq->used) >= mccq->len); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 729 | wrb = queue_head_node(mccq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 730 | memset(wrb, 0, sizeof(*wrb)); |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 731 | wrb->tag0 = (mccq->head << MCC_Q_WRB_IDX_SHIFT) & MCC_Q_WRB_IDX_MASK; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 732 | queue_head_inc(mccq); |
| 733 | atomic_inc(&mccq->used); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 734 | return wrb; |
| 735 | } |
| 736 | |
| 737 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 738 | int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl, |
| 739 | struct be_queue_info *eq, int eq_delay) |
| 740 | { |
| 741 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 742 | struct be_cmd_req_eq_create *req = embedded_payload(wrb); |
| 743 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
| 744 | struct be_dma_mem *q_mem = &eq->dma_mem; |
| 745 | int status; |
| 746 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 747 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 748 | memset(wrb, 0, sizeof(*wrb)); |
| 749 | |
| 750 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 751 | |
| 752 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 753 | OPCODE_COMMON_EQ_CREATE, sizeof(*req)); |
| 754 | |
| 755 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 756 | |
| 757 | AMAP_SET_BITS(struct amap_eq_context, func, req->context, |
| 758 | PCI_FUNC(ctrl->pdev->devfn)); |
| 759 | AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1); |
| 760 | AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0); |
| 761 | AMAP_SET_BITS(struct amap_eq_context, count, req->context, |
| 762 | __ilog2_u32(eq->len / 256)); |
| 763 | AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context, |
| 764 | eq_delay_to_mult(eq_delay)); |
| 765 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 766 | |
| 767 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 768 | |
| 769 | status = be_mbox_notify(ctrl); |
| 770 | if (!status) { |
| 771 | eq->id = le16_to_cpu(resp->eq_id); |
| 772 | eq->created = true; |
| 773 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 774 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 775 | return status; |
| 776 | } |
| 777 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 778 | /** |
| 779 | * be_cmd_fw_initialize()- Initialize FW |
| 780 | * @ctrl: Pointer to function control structure |
| 781 | * |
| 782 | * Send FW initialize pattern for the function. |
| 783 | * |
| 784 | * return |
| 785 | * Success: 0 |
| 786 | * Failure: Non-Zero value |
| 787 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 788 | int be_cmd_fw_initialize(struct be_ctrl_info *ctrl) |
| 789 | { |
| 790 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 791 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 792 | int status; |
| 793 | u8 *endian_check; |
| 794 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 795 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 796 | memset(wrb, 0, sizeof(*wrb)); |
| 797 | |
| 798 | endian_check = (u8 *) wrb; |
| 799 | *endian_check++ = 0xFF; |
| 800 | *endian_check++ = 0x12; |
| 801 | *endian_check++ = 0x34; |
| 802 | *endian_check++ = 0xFF; |
| 803 | *endian_check++ = 0xFF; |
| 804 | *endian_check++ = 0x56; |
| 805 | *endian_check++ = 0x78; |
| 806 | *endian_check++ = 0xFF; |
| 807 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 808 | |
| 809 | status = be_mbox_notify(ctrl); |
| 810 | if (status) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 811 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 812 | "BC_%d : be_cmd_fw_initialize Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 813 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 814 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 815 | return status; |
| 816 | } |
| 817 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 818 | /** |
| 819 | * be_cmd_fw_uninit()- Uinitialize FW |
| 820 | * @ctrl: Pointer to function control structure |
| 821 | * |
| 822 | * Send FW uninitialize pattern for the function |
| 823 | * |
| 824 | * return |
| 825 | * Success: 0 |
| 826 | * Failure: Non-Zero value |
| 827 | **/ |
| 828 | int be_cmd_fw_uninit(struct be_ctrl_info *ctrl) |
| 829 | { |
| 830 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 831 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
| 832 | int status; |
| 833 | u8 *endian_check; |
| 834 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 835 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 836 | memset(wrb, 0, sizeof(*wrb)); |
| 837 | |
| 838 | endian_check = (u8 *) wrb; |
| 839 | *endian_check++ = 0xFF; |
| 840 | *endian_check++ = 0xAA; |
| 841 | *endian_check++ = 0xBB; |
| 842 | *endian_check++ = 0xFF; |
| 843 | *endian_check++ = 0xFF; |
| 844 | *endian_check++ = 0xCC; |
| 845 | *endian_check++ = 0xDD; |
| 846 | *endian_check = 0xFF; |
| 847 | |
| 848 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 849 | |
| 850 | status = be_mbox_notify(ctrl); |
| 851 | if (status) |
| 852 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 853 | "BC_%d : be_cmd_fw_uninit Failed\n"); |
| 854 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 855 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 856 | return status; |
| 857 | } |
| 858 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 859 | int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl, |
| 860 | struct be_queue_info *cq, struct be_queue_info *eq, |
| 861 | bool sol_evts, bool no_delay, int coalesce_wm) |
| 862 | { |
| 863 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 864 | struct be_cmd_req_cq_create *req = embedded_payload(wrb); |
| 865 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 866 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 867 | struct be_dma_mem *q_mem = &cq->dma_mem; |
| 868 | void *ctxt = &req->context; |
| 869 | int status; |
| 870 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 871 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 872 | memset(wrb, 0, sizeof(*wrb)); |
| 873 | |
| 874 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 875 | |
| 876 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 877 | OPCODE_COMMON_CQ_CREATE, sizeof(*req)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 878 | |
| 879 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 880 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 881 | AMAP_SET_BITS(struct amap_cq_context, coalescwm, |
| 882 | ctxt, coalesce_wm); |
| 883 | AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay); |
| 884 | AMAP_SET_BITS(struct amap_cq_context, count, ctxt, |
| 885 | __ilog2_u32(cq->len / 256)); |
| 886 | AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1); |
| 887 | AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts); |
| 888 | AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1); |
| 889 | AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id); |
| 890 | AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1); |
| 891 | AMAP_SET_BITS(struct amap_cq_context, func, ctxt, |
| 892 | PCI_FUNC(ctrl->pdev->devfn)); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 893 | } else { |
| 894 | req->hdr.version = MBX_CMD_VER2; |
| 895 | req->page_size = 1; |
| 896 | AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm, |
| 897 | ctxt, coalesce_wm); |
| 898 | AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, |
| 899 | ctxt, no_delay); |
| 900 | AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt, |
| 901 | __ilog2_u32(cq->len / 256)); |
| 902 | AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1); |
| 903 | AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1); |
| 904 | AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id); |
| 905 | AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1); |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 906 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 907 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 908 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 909 | |
| 910 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 911 | |
| 912 | status = be_mbox_notify(ctrl); |
| 913 | if (!status) { |
| 914 | cq->id = le16_to_cpu(resp->cq_id); |
| 915 | cq->created = true; |
| 916 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 917 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 918 | "BC_%d : In be_cmd_cq_create, status=ox%08x\n", |
| 919 | status); |
| 920 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 921 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 922 | |
| 923 | return status; |
| 924 | } |
| 925 | |
| 926 | static u32 be_encoded_q_len(int q_len) |
| 927 | { |
| 928 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
| 929 | if (len_encoded == 16) |
| 930 | len_encoded = 0; |
| 931 | return len_encoded; |
| 932 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 933 | |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 934 | int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 935 | struct be_queue_info *mccq, |
| 936 | struct be_queue_info *cq) |
| 937 | { |
| 938 | struct be_mcc_wrb *wrb; |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 939 | struct be_cmd_req_mcc_create_ext *req; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 940 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
| 941 | struct be_ctrl_info *ctrl; |
| 942 | void *ctxt; |
| 943 | int status; |
| 944 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 945 | mutex_lock(&phba->ctrl.mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 946 | ctrl = &phba->ctrl; |
| 947 | wrb = wrb_from_mbox(&ctrl->mbox_mem); |
Jayamohan Kallickal | 3760976 | 2011-10-07 19:31:11 -0500 | [diff] [blame] | 948 | memset(wrb, 0, sizeof(*wrb)); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 949 | req = embedded_payload(wrb); |
| 950 | ctxt = &req->context; |
| 951 | |
| 952 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 953 | |
| 954 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 955 | OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req)); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 956 | |
| 957 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 958 | req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE; |
| 959 | req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI; |
| 960 | req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 961 | |
| 962 | AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt, |
| 963 | PCI_FUNC(phba->pcidev->devfn)); |
| 964 | AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1); |
| 965 | AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt, |
| 966 | be_encoded_q_len(mccq->len)); |
| 967 | AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id); |
| 968 | |
| 969 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 970 | |
| 971 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 972 | |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame] | 973 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 974 | if (!status) { |
| 975 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 976 | mccq->id = le16_to_cpu(resp->id); |
| 977 | mccq->created = true; |
| 978 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 979 | mutex_unlock(&phba->ctrl.mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 980 | |
| 981 | return status; |
| 982 | } |
| 983 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 984 | int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q, |
| 985 | int queue_type) |
| 986 | { |
| 987 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 988 | struct be_cmd_req_q_destroy *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 989 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 990 | u8 subsys = 0, opcode = 0; |
| 991 | int status; |
| 992 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 993 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 994 | "BC_%d : In beiscsi_cmd_q_destroy " |
| 995 | "queue_type : %d\n", queue_type); |
| 996 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 997 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 998 | memset(wrb, 0, sizeof(*wrb)); |
| 999 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1000 | |
| 1001 | switch (queue_type) { |
| 1002 | case QTYPE_EQ: |
| 1003 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1004 | opcode = OPCODE_COMMON_EQ_DESTROY; |
| 1005 | break; |
| 1006 | case QTYPE_CQ: |
| 1007 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1008 | opcode = OPCODE_COMMON_CQ_DESTROY; |
| 1009 | break; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1010 | case QTYPE_MCCQ: |
| 1011 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1012 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 1013 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1014 | case QTYPE_WRBQ: |
| 1015 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1016 | opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY; |
| 1017 | break; |
| 1018 | case QTYPE_DPDUQ: |
| 1019 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1020 | opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY; |
| 1021 | break; |
| 1022 | case QTYPE_SGL: |
| 1023 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1024 | opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES; |
| 1025 | break; |
| 1026 | default: |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1027 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1028 | BUG(); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 1029 | return -ENXIO; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1030 | } |
| 1031 | be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req)); |
| 1032 | if (queue_type != QTYPE_SGL) |
| 1033 | req->id = cpu_to_le16(q->id); |
| 1034 | |
| 1035 | status = be_mbox_notify(ctrl); |
| 1036 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1037 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1038 | return status; |
| 1039 | } |
| 1040 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1041 | /** |
| 1042 | * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter |
| 1043 | * @ctrl: ptr to ctrl_info |
| 1044 | * @cq: Completion Queue |
| 1045 | * @dq: Default Queue |
| 1046 | * @lenght: ring size |
| 1047 | * @entry_size: size of each entry in DEFQ |
| 1048 | * @is_header: Header or Data DEFQ |
| 1049 | * @ulp_num: Bind to which ULP |
| 1050 | * |
| 1051 | * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted |
| 1052 | * on this queue by the FW |
| 1053 | * |
| 1054 | * return |
| 1055 | * Success: 0 |
| 1056 | * Failure: Non-Zero Value |
| 1057 | * |
| 1058 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1059 | int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl, |
| 1060 | struct be_queue_info *cq, |
| 1061 | struct be_queue_info *dq, int length, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1062 | int entry_size, uint8_t is_header, |
| 1063 | uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1064 | { |
| 1065 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1066 | struct be_defq_create_req *req = embedded_payload(wrb); |
| 1067 | struct be_dma_mem *q_mem = &dq->dma_mem; |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1068 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1069 | void *ctxt = &req->context; |
| 1070 | int status; |
| 1071 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1072 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1073 | memset(wrb, 0, sizeof(*wrb)); |
| 1074 | |
| 1075 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1076 | |
| 1077 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1078 | OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req)); |
| 1079 | |
| 1080 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1081 | if (phba->fw_config.dual_ulp_aware) { |
| 1082 | req->ulp_num = ulp_num; |
| 1083 | req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT); |
| 1084 | req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT); |
| 1085 | } |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1086 | |
| 1087 | if (is_chip_be2_be3r(phba)) { |
| 1088 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1089 | rx_pdid, ctxt, 0); |
| 1090 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1091 | rx_pdid_valid, ctxt, 1); |
| 1092 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1093 | pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn)); |
| 1094 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1095 | ring_size, ctxt, |
| 1096 | be_encoded_q_len(length / |
| 1097 | sizeof(struct phys_addr))); |
| 1098 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1099 | default_buffer_size, ctxt, entry_size); |
| 1100 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1101 | cq_id_recv, ctxt, cq->id); |
| 1102 | } else { |
| 1103 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1104 | rx_pdid, ctxt, 0); |
| 1105 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1106 | rx_pdid_valid, ctxt, 1); |
| 1107 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1108 | ring_size, ctxt, |
| 1109 | be_encoded_q_len(length / |
| 1110 | sizeof(struct phys_addr))); |
| 1111 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1112 | default_buffer_size, ctxt, entry_size); |
| 1113 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1114 | cq_id_recv, ctxt, cq->id); |
| 1115 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1116 | |
| 1117 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1118 | |
| 1119 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1120 | |
| 1121 | status = be_mbox_notify(ctrl); |
| 1122 | if (!status) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1123 | struct be_ring *defq_ring; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1124 | struct be_defq_create_resp *resp = embedded_payload(wrb); |
| 1125 | |
| 1126 | dq->id = le16_to_cpu(resp->id); |
| 1127 | dq->created = true; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1128 | if (is_header) |
| 1129 | defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num]; |
| 1130 | else |
| 1131 | defq_ring = &phba->phwi_ctrlr-> |
| 1132 | default_pdu_data[ulp_num]; |
| 1133 | |
| 1134 | defq_ring->id = dq->id; |
| 1135 | |
| 1136 | if (!phba->fw_config.dual_ulp_aware) { |
| 1137 | defq_ring->ulp_num = BEISCSI_ULP0; |
| 1138 | defq_ring->doorbell_offset = DB_RXULP0_OFFSET; |
| 1139 | } else { |
| 1140 | defq_ring->ulp_num = resp->ulp_num; |
| 1141 | defq_ring->doorbell_offset = resp->doorbell_offset; |
| 1142 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1143 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1144 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1145 | |
| 1146 | return status; |
| 1147 | } |
| 1148 | |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1149 | /** |
| 1150 | * be_cmd_wrbq_create()- Create WRBQ |
| 1151 | * @ctrl: ptr to ctrl_info |
| 1152 | * @q_mem: memory details for the queue |
| 1153 | * @wrbq: queue info |
| 1154 | * @pwrb_context: ptr to wrb_context |
| 1155 | * @ulp_num: ULP on which the WRBQ is to be created |
| 1156 | * |
| 1157 | * Create WRBQ on the passed ULP_NUM. |
| 1158 | * |
| 1159 | **/ |
| 1160 | int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, |
| 1161 | struct be_dma_mem *q_mem, |
| 1162 | struct be_queue_info *wrbq, |
| 1163 | struct hwi_wrb_context *pwrb_context, |
| 1164 | uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1165 | { |
| 1166 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1167 | struct be_wrbq_create_req *req = embedded_payload(wrb); |
| 1168 | struct be_wrbq_create_resp *resp = embedded_payload(wrb); |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1169 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1170 | int status; |
| 1171 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1172 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1173 | memset(wrb, 0, sizeof(*wrb)); |
| 1174 | |
| 1175 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1176 | |
| 1177 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1178 | OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req)); |
| 1179 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1180 | |
| 1181 | if (phba->fw_config.dual_ulp_aware) { |
| 1182 | req->ulp_num = ulp_num; |
| 1183 | req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT); |
| 1184 | req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT); |
| 1185 | } |
| 1186 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1187 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1188 | |
| 1189 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1190 | if (!status) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1191 | wrbq->id = le16_to_cpu(resp->cid); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1192 | wrbq->created = true; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1193 | |
| 1194 | pwrb_context->cid = wrbq->id; |
| 1195 | if (!phba->fw_config.dual_ulp_aware) { |
| 1196 | pwrb_context->doorbell_offset = DB_TXULP0_OFFSET; |
| 1197 | pwrb_context->ulp_num = BEISCSI_ULP0; |
| 1198 | } else { |
| 1199 | pwrb_context->ulp_num = resp->ulp_num; |
| 1200 | pwrb_context->doorbell_offset = resp->doorbell_offset; |
| 1201 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1202 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1203 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1204 | return status; |
| 1205 | } |
| 1206 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1207 | int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl, |
| 1208 | struct be_dma_mem *q_mem) |
| 1209 | { |
| 1210 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1211 | struct be_post_template_pages_req *req = embedded_payload(wrb); |
| 1212 | int status; |
| 1213 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1214 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1215 | |
| 1216 | memset(wrb, 0, sizeof(*wrb)); |
| 1217 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1218 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1219 | OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS, |
| 1220 | sizeof(*req)); |
| 1221 | |
| 1222 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 1223 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1224 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1225 | |
| 1226 | status = be_mbox_notify(ctrl); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1227 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1228 | return status; |
| 1229 | } |
| 1230 | |
| 1231 | int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl) |
| 1232 | { |
| 1233 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1234 | struct be_remove_template_pages_req *req = embedded_payload(wrb); |
| 1235 | int status; |
| 1236 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1237 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1238 | |
| 1239 | memset(wrb, 0, sizeof(*wrb)); |
| 1240 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1241 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1242 | OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS, |
| 1243 | sizeof(*req)); |
| 1244 | |
| 1245 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1246 | |
| 1247 | status = be_mbox_notify(ctrl); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1248 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1249 | return status; |
| 1250 | } |
| 1251 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1252 | int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl, |
| 1253 | struct be_dma_mem *q_mem, |
| 1254 | u32 page_offset, u32 num_pages) |
| 1255 | { |
| 1256 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1257 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1258 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1259 | int status; |
| 1260 | unsigned int curr_pages; |
| 1261 | u32 internal_page_offset = 0; |
| 1262 | u32 temp_num_pages = num_pages; |
| 1263 | |
| 1264 | if (num_pages == 0xff) |
| 1265 | num_pages = 1; |
| 1266 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1267 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1268 | do { |
| 1269 | memset(wrb, 0, sizeof(*wrb)); |
| 1270 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1271 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1272 | OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES, |
| 1273 | sizeof(*req)); |
| 1274 | curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req, |
| 1275 | pages); |
| 1276 | req->num_pages = min(num_pages, curr_pages); |
| 1277 | req->page_offset = page_offset; |
| 1278 | be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem); |
| 1279 | q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE); |
| 1280 | internal_page_offset += req->num_pages; |
| 1281 | page_offset += req->num_pages; |
| 1282 | num_pages -= req->num_pages; |
| 1283 | |
| 1284 | if (temp_num_pages == 0xff) |
| 1285 | req->num_pages = temp_num_pages; |
| 1286 | |
| 1287 | status = be_mbox_notify(ctrl); |
| 1288 | if (status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1289 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 1290 | "BC_%d : FW CMD to map iscsi frags failed.\n"); |
| 1291 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1292 | goto error; |
| 1293 | } |
| 1294 | } while (num_pages > 0); |
| 1295 | error: |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1296 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1297 | if (status != 0) |
| 1298 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 1299 | return status; |
| 1300 | } |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1301 | |
| 1302 | int beiscsi_cmd_reset_function(struct beiscsi_hba *phba) |
| 1303 | { |
| 1304 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1305 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1306 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
| 1307 | int status; |
| 1308 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1309 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1310 | |
| 1311 | req = embedded_payload(wrb); |
| 1312 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1313 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1314 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req)); |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame] | 1315 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1316 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1317 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1318 | return status; |
| 1319 | } |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1320 | |
| 1321 | /** |
| 1322 | * be_cmd_set_vlan()- Configure VLAN paramters on the adapter |
| 1323 | * @phba: device priv structure instance |
| 1324 | * @vlan_tag: TAG to be set |
| 1325 | * |
| 1326 | * Set the VLAN_TAG for the adapter or Disable VLAN on adapter |
| 1327 | * |
| 1328 | * returns |
| 1329 | * TAG for the MBX Cmd |
| 1330 | * **/ |
| 1331 | int be_cmd_set_vlan(struct beiscsi_hba *phba, |
| 1332 | uint16_t vlan_tag) |
| 1333 | { |
| 1334 | unsigned int tag = 0; |
| 1335 | struct be_mcc_wrb *wrb; |
| 1336 | struct be_cmd_set_vlan_req *req; |
| 1337 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1338 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1339 | if (mutex_lock_interruptible(&ctrl->mbox_lock)) |
| 1340 | return 0; |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1341 | tag = alloc_mcc_tag(phba); |
| 1342 | if (!tag) { |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1343 | mutex_unlock(&ctrl->mbox_lock); |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1344 | return tag; |
| 1345 | } |
| 1346 | |
| 1347 | wrb = wrb_from_mccq(phba); |
| 1348 | req = embedded_payload(wrb); |
| 1349 | wrb->tag0 |= tag; |
| 1350 | be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0); |
| 1351 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1352 | OPCODE_COMMON_ISCSI_NTWK_SET_VLAN, |
| 1353 | sizeof(*req)); |
| 1354 | |
| 1355 | req->interface_hndl = phba->interface_handle; |
| 1356 | req->vlan_priority = vlan_tag; |
| 1357 | |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 1358 | be_mcc_notify(phba, tag); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1359 | mutex_unlock(&ctrl->mbox_lock); |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1360 | |
| 1361 | return tag; |
| 1362 | } |