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