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; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 128 | phba->ctrl.mcc_tag_status[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 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 143 | * beiscsi_mccq_compl_wait()- Process completion in MCC CQ |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 155 | int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba, |
| 156 | uint32_t tag, struct be_mcc_wrb **wrb, |
| 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; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 160 | uint32_t mcc_tag_status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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], |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 175 | phba->ctrl.mcc_tag_status[tag], |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 212 | mcc_tag_status = phba->ctrl.mcc_tag_status[tag]; |
| 213 | status = (mcc_tag_status & CQE_STATUS_MASK); |
| 214 | addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >> |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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 { |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 220 | wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >> |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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); |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 260 | tag = tag & MCC_Q_CMD_TAG_MASK; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 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 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 286 | * beiscsi_process_mbox_compl()- Check the MBX completion status |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 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 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 296 | static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl, |
| 297 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 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 | 9343be7 | 2014-01-29 02:16:43 -0500 | [diff] [blame] | 331 | /** |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 332 | * beiscsi_fail_session(): Closing session with appropriate error |
Jayamohan Kallickal | 9343be7 | 2014-01-29 02:16:43 -0500 | [diff] [blame] | 333 | * @cls_session: ptr to session |
Jayamohan Kallickal | 9343be7 | 2014-01-29 02:16:43 -0500 | [diff] [blame] | 334 | **/ |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 335 | void beiscsi_fail_session(struct iscsi_cls_session *cls_session) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 336 | { |
| 337 | iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); |
| 338 | } |
| 339 | |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 340 | static void beiscsi_process_async_link(struct beiscsi_hba *phba, |
| 341 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 342 | { |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 343 | struct be_async_event_link_state *evt; |
| 344 | |
| 345 | evt = (struct be_async_event_link_state *)compl; |
| 346 | |
Jitendra Bhivare | 048084c | 2016-01-20 14:10:58 +0530 | [diff] [blame] | 347 | phba->port_speed = evt->port_speed; |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 348 | /** |
| 349 | * Check logical link status in ASYNC event. |
| 350 | * This has been newly introduced in SKH-R Firmware 10.0.338.45. |
| 351 | **/ |
| 352 | if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) { |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 353 | phba->state = BE_ADAPTER_LINK_UP | BE_ADAPTER_CHECK_BOOT; |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 354 | phba->get_boot = BE_GET_BOOT_RETRIES; |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 355 | __beiscsi_log(phba, KERN_ERR, |
| 356 | "BC_%d : Link Up on Port %d tag 0x%x\n", |
| 357 | evt->physical_port, evt->event_tag); |
| 358 | } else { |
| 359 | phba->state = BE_ADAPTER_LINK_DOWN; |
| 360 | __beiscsi_log(phba, KERN_ERR, |
| 361 | "BC_%d : Link Down on Port %d tag 0x%x\n", |
| 362 | evt->physical_port, evt->event_tag); |
| 363 | iscsi_host_for_each_session(phba->shost, |
| 364 | beiscsi_fail_session); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 368 | static char *beiscsi_port_misconf_event_msg[] = { |
| 369 | "Physical Link is functional.", |
| 370 | "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.", |
| 371 | "Optics of two types installed - Remove one optic or install matching pair of optics.", |
| 372 | "Incompatible optics - Replace with compatible optics for card to function.", |
| 373 | "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.", |
| 374 | "Uncertified optics - Replace with Avago Certified optics to enable link operation." |
| 375 | }; |
| 376 | |
| 377 | static void beiscsi_process_async_sli(struct beiscsi_hba *phba, |
| 378 | struct be_mcc_compl *compl) |
| 379 | { |
| 380 | struct be_async_event_sli *async_sli; |
| 381 | u8 evt_type, state, old_state, le; |
| 382 | char *sev = KERN_WARNING; |
| 383 | char *msg = NULL; |
| 384 | |
| 385 | evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT; |
| 386 | evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK; |
| 387 | |
| 388 | /* processing only MISCONFIGURED physical port event */ |
| 389 | if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED) |
| 390 | return; |
| 391 | |
| 392 | async_sli = (struct be_async_event_sli *)compl; |
| 393 | state = async_sli->event_data1 >> |
| 394 | (phba->fw_config.phys_port * 8) & 0xff; |
| 395 | le = async_sli->event_data2 >> |
| 396 | (phba->fw_config.phys_port * 8) & 0xff; |
| 397 | |
| 398 | old_state = phba->optic_state; |
| 399 | phba->optic_state = state; |
| 400 | |
| 401 | if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) { |
| 402 | /* fw is reporting a state we don't know, log and return */ |
| 403 | __beiscsi_log(phba, KERN_ERR, |
| 404 | "BC_%d : Port %c: Unrecognized optic state 0x%x\n", |
| 405 | phba->port_name, async_sli->event_data1); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | if (ASYNC_SLI_LINK_EFFECT_VALID(le)) { |
| 410 | /* log link effect for unqualified-4, uncertified-5 optics */ |
| 411 | if (state > 3) |
| 412 | msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ? |
| 413 | " Link is non-operational." : |
| 414 | " Link is operational."; |
| 415 | /* 1 - info */ |
| 416 | if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1) |
| 417 | sev = KERN_INFO; |
| 418 | /* 2 - error */ |
| 419 | if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2) |
| 420 | sev = KERN_ERR; |
| 421 | } |
| 422 | |
| 423 | if (old_state != phba->optic_state) |
| 424 | __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n", |
| 425 | phba->port_name, |
| 426 | beiscsi_port_misconf_event_msg[state], |
| 427 | !msg ? "" : msg); |
| 428 | } |
| 429 | |
| 430 | void beiscsi_process_async_event(struct beiscsi_hba *phba, |
| 431 | struct be_mcc_compl *compl) |
| 432 | { |
| 433 | char *sev = KERN_INFO; |
| 434 | u8 evt_code; |
| 435 | |
| 436 | /* interpret flags as an async trailer */ |
| 437 | evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT; |
| 438 | evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK; |
| 439 | switch (evt_code) { |
| 440 | case ASYNC_EVENT_CODE_LINK_STATE: |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 441 | beiscsi_process_async_link(phba, compl); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 442 | break; |
| 443 | case ASYNC_EVENT_CODE_ISCSI: |
| 444 | phba->state |= BE_ADAPTER_CHECK_BOOT; |
| 445 | phba->get_boot = BE_GET_BOOT_RETRIES; |
| 446 | sev = KERN_ERR; |
| 447 | break; |
| 448 | case ASYNC_EVENT_CODE_SLI: |
| 449 | beiscsi_process_async_sli(phba, compl); |
| 450 | break; |
| 451 | default: |
| 452 | /* event not registered */ |
| 453 | sev = KERN_ERR; |
| 454 | } |
| 455 | |
| 456 | beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
Jitendra Bhivare | 9c4f8b0 | 2016-01-20 14:10:59 +0530 | [diff] [blame] | 457 | "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n", |
| 458 | evt_code, compl->status, compl->flags); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 459 | } |
| 460 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 461 | int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl, |
| 462 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 463 | { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 464 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
| 465 | u16 compl_status, extd_status; |
| 466 | struct be_dma_mem *tag_mem; |
| 467 | unsigned int tag, wrb_idx; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 468 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 469 | /** |
| 470 | * Just swap the status to host endian; mcc tag is opaquely copied |
| 471 | * from mcc_wrb |
| 472 | */ |
| 473 | be_dws_le_to_cpu(compl, 4); |
| 474 | tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK); |
| 475 | wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT; |
| 476 | |
| 477 | if (!test_bit(MCC_TAG_STATE_RUNNING, |
| 478 | &ctrl->ptag_state[tag].tag_state)) { |
| 479 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX | |
| 480 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 481 | "BC_%d : MBX cmd completed but not posted\n"); |
| 482 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 483 | } |
| 484 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 485 | if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) { |
| 486 | beiscsi_log(phba, KERN_WARNING, |
| 487 | BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT | |
| 488 | BEISCSI_LOG_CONFIG, |
| 489 | "BC_%d : MBX Completion for timeout Command from FW\n"); |
| 490 | /** |
| 491 | * Check for the size before freeing resource. |
| 492 | * Only for non-embedded cmd, PCI resource is allocated. |
| 493 | **/ |
| 494 | tag_mem = &ctrl->ptag_state[tag].tag_mem_state; |
| 495 | if (tag_mem->size) |
| 496 | pci_free_consistent(ctrl->pdev, tag_mem->size, |
| 497 | tag_mem->va, tag_mem->dma); |
| 498 | free_mcc_tag(ctrl, tag); |
| 499 | return 0; |
| 500 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 501 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 502 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 503 | CQE_STATUS_COMPL_MASK; |
| 504 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 505 | CQE_STATUS_EXTD_MASK; |
| 506 | /* The ctrl.mcc_tag_status[tag] is filled with |
| 507 | * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status, |
| 508 | * [7:0] = compl_status |
| 509 | */ |
| 510 | ctrl->mcc_tag_status[tag] = CQE_VALID_MASK; |
| 511 | ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT); |
| 512 | ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) & |
| 513 | CQE_STATUS_ADDL_MASK; |
| 514 | ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK); |
| 515 | |
| 516 | /* write ordering forced in wake_up_interruptible */ |
| 517 | clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state); |
| 518 | wake_up_interruptible(&ctrl->mcc_wait[tag]); |
| 519 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 520 | } |
| 521 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 522 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 523 | * be_mcc_compl_poll()- Wait for MBX completion |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 524 | * @phba: driver private structure |
| 525 | * |
| 526 | * Wait till no more pending mcc requests are present |
| 527 | * |
| 528 | * return |
| 529 | * Success: 0 |
| 530 | * Failure: Non-Zero |
| 531 | * |
| 532 | **/ |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 533 | int be_mcc_compl_poll(struct beiscsi_hba *phba, unsigned int tag) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 534 | { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 535 | int i; |
| 536 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 537 | for (i = 0; i < mcc_timeout; i++) { |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 538 | if (beiscsi_error(phba)) |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 539 | return -EIO; |
| 540 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 541 | beiscsi_process_mcc_cq(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 542 | |
| 543 | if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0) |
| 544 | break; |
| 545 | udelay(100); |
| 546 | } |
| 547 | if (i == mcc_timeout) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 548 | beiscsi_log(phba, KERN_ERR, |
| 549 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 550 | "BC_%d : FW Timed Out\n"); |
| 551 | phba->fw_timeout = true; |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 552 | beiscsi_ue_detect(phba); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 553 | return -EBUSY; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 554 | } |
| 555 | return 0; |
| 556 | } |
| 557 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 558 | /* |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 559 | * be_mbox_db_ready_poll()- Check ready status |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 560 | * @ctrl: Function specific MBX data structure |
| 561 | * |
| 562 | * Check for the ready status of FW to send BMBX |
| 563 | * commands to adapter. |
| 564 | * |
| 565 | * return |
| 566 | * Success: 0 |
| 567 | * Failure: Non-Zero |
| 568 | **/ |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 569 | static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 570 | { |
Jitendra Bhivare | 9ec6f6b | 2016-01-20 14:10:49 +0530 | [diff] [blame] | 571 | /* wait 30s for generic non-flash MBOX operation */ |
| 572 | #define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 573 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 574 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 575 | unsigned long timeout; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 576 | u32 ready; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 577 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 578 | /* |
| 579 | * This BMBX busy wait path is used during init only. |
| 580 | * For the commands executed during init, 5s should suffice. |
| 581 | */ |
| 582 | timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 583 | do { |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 584 | if (beiscsi_error(phba)) |
| 585 | return -EIO; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 586 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 587 | ready = ioread32(db); |
| 588 | if (ready == 0xffffffff) |
| 589 | return -EIO; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 590 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 591 | ready &= MPU_MAILBOX_DB_RDY_MASK; |
| 592 | if (ready) |
| 593 | return 0; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 594 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 595 | if (time_after(jiffies, timeout)) |
| 596 | break; |
Jitendra Bhivare | 9ec6f6b | 2016-01-20 14:10:49 +0530 | [diff] [blame] | 597 | msleep(20); |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 598 | } while (!ready); |
| 599 | |
| 600 | beiscsi_log(phba, KERN_ERR, |
| 601 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 602 | "BC_%d : FW Timed Out\n"); |
| 603 | |
| 604 | phba->fw_timeout = true; |
| 605 | beiscsi_ue_detect(phba); |
| 606 | |
| 607 | return -EBUSY; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 608 | } |
| 609 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 610 | /* |
| 611 | * be_mbox_notify: Notify adapter of new BMBX command |
| 612 | * @ctrl: Function specific MBX data structure |
| 613 | * |
| 614 | * Ring doorbell to inform adapter of a BMBX command |
| 615 | * to process |
| 616 | * |
| 617 | * return |
| 618 | * Success: 0 |
| 619 | * Failure: Non-Zero |
| 620 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 621 | int be_mbox_notify(struct be_ctrl_info *ctrl) |
| 622 | { |
| 623 | int status; |
| 624 | u32 val = 0; |
| 625 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
| 626 | struct be_dma_mem *mbox_mem = &ctrl->mbox_mem; |
| 627 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 628 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 629 | status = be_mbox_db_ready_poll(ctrl); |
Jayamohan Kallickal | 1e234bb | 2013-04-05 20:38:23 -0700 | [diff] [blame] | 630 | if (status) |
| 631 | return status; |
| 632 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 633 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 634 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 635 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 636 | iowrite32(val, db); |
| 637 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 638 | status = be_mbox_db_ready_poll(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 639 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 640 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 641 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 642 | val = 0; |
| 643 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 644 | val &= ~MPU_MAILBOX_DB_HI_MASK; |
| 645 | val |= (u32) (mbox_mem->dma >> 4) << 2; |
| 646 | iowrite32(val, db); |
| 647 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 648 | status = be_mbox_db_ready_poll(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 649 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 650 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 651 | |
Jitendra Bhivare | 6ac999e | 2016-01-20 14:10:45 +0530 | [diff] [blame] | 652 | /* RDY is set; small delay before CQE read. */ |
| 653 | udelay(1); |
| 654 | |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame^] | 655 | status = beiscsi_process_mbox_compl(ctrl, &mbox->compl); |
| 656 | return status; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 657 | } |
| 658 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 659 | void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len, |
| 660 | bool embedded, u8 sge_cnt) |
| 661 | { |
| 662 | if (embedded) |
| 663 | wrb->embedded |= MCC_WRB_EMBEDDED_MASK; |
| 664 | else |
| 665 | wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) << |
| 666 | MCC_WRB_SGE_CNT_SHIFT; |
| 667 | wrb->payload_length = payload_len; |
| 668 | be_dws_cpu_to_le(wrb, 8); |
| 669 | } |
| 670 | |
| 671 | void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
| 672 | u8 subsystem, u8 opcode, int cmd_len) |
| 673 | { |
| 674 | req_hdr->opcode = opcode; |
| 675 | req_hdr->subsystem = subsystem; |
| 676 | 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] | 677 | req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
| 681 | struct be_dma_mem *mem) |
| 682 | { |
| 683 | int i, buf_pages; |
| 684 | u64 dma = (u64) mem->dma; |
| 685 | |
| 686 | buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages); |
| 687 | for (i = 0; i < buf_pages; i++) { |
| 688 | pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF); |
| 689 | pages[i].hi = cpu_to_le32(upper_32_bits(dma)); |
| 690 | dma += PAGE_SIZE_4K; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | static u32 eq_delay_to_mult(u32 usec_delay) |
| 695 | { |
| 696 | #define MAX_INTR_RATE 651042 |
| 697 | const u32 round = 10; |
| 698 | u32 multiplier; |
| 699 | |
| 700 | if (usec_delay == 0) |
| 701 | multiplier = 0; |
| 702 | else { |
| 703 | u32 interrupt_rate = 1000000 / usec_delay; |
| 704 | if (interrupt_rate == 0) |
| 705 | multiplier = 1023; |
| 706 | else { |
| 707 | multiplier = (MAX_INTR_RATE - interrupt_rate) * round; |
| 708 | multiplier /= interrupt_rate; |
| 709 | multiplier = (multiplier + round / 2) / round; |
| 710 | multiplier = min(multiplier, (u32) 1023); |
| 711 | } |
| 712 | } |
| 713 | return multiplier; |
| 714 | } |
| 715 | |
| 716 | struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem) |
| 717 | { |
| 718 | return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb; |
| 719 | } |
| 720 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 721 | struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba) |
| 722 | { |
| 723 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 724 | struct be_mcc_wrb *wrb; |
| 725 | |
Jayamohan Kallickal | e074d20 | 2013-09-28 15:35:39 -0700 | [diff] [blame] | 726 | WARN_ON(atomic_read(&mccq->used) >= mccq->len); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 727 | wrb = queue_head_node(mccq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 728 | memset(wrb, 0, sizeof(*wrb)); |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 729 | 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] | 730 | queue_head_inc(mccq); |
| 731 | atomic_inc(&mccq->used); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 732 | return wrb; |
| 733 | } |
| 734 | |
| 735 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 736 | int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl, |
| 737 | struct be_queue_info *eq, int eq_delay) |
| 738 | { |
| 739 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 740 | struct be_cmd_req_eq_create *req = embedded_payload(wrb); |
| 741 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
| 742 | struct be_dma_mem *q_mem = &eq->dma_mem; |
| 743 | int status; |
| 744 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 745 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 746 | memset(wrb, 0, sizeof(*wrb)); |
| 747 | |
| 748 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 749 | |
| 750 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 751 | OPCODE_COMMON_EQ_CREATE, sizeof(*req)); |
| 752 | |
| 753 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 754 | |
| 755 | AMAP_SET_BITS(struct amap_eq_context, func, req->context, |
| 756 | PCI_FUNC(ctrl->pdev->devfn)); |
| 757 | AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1); |
| 758 | AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0); |
| 759 | AMAP_SET_BITS(struct amap_eq_context, count, req->context, |
| 760 | __ilog2_u32(eq->len / 256)); |
| 761 | AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context, |
| 762 | eq_delay_to_mult(eq_delay)); |
| 763 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 764 | |
| 765 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 766 | |
| 767 | status = be_mbox_notify(ctrl); |
| 768 | if (!status) { |
| 769 | eq->id = le16_to_cpu(resp->eq_id); |
| 770 | eq->created = true; |
| 771 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 772 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 773 | return status; |
| 774 | } |
| 775 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 776 | /** |
| 777 | * be_cmd_fw_initialize()- Initialize FW |
| 778 | * @ctrl: Pointer to function control structure |
| 779 | * |
| 780 | * Send FW initialize pattern for the function. |
| 781 | * |
| 782 | * return |
| 783 | * Success: 0 |
| 784 | * Failure: Non-Zero value |
| 785 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 786 | int be_cmd_fw_initialize(struct be_ctrl_info *ctrl) |
| 787 | { |
| 788 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 789 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 790 | int status; |
| 791 | u8 *endian_check; |
| 792 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 793 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 794 | memset(wrb, 0, sizeof(*wrb)); |
| 795 | |
| 796 | endian_check = (u8 *) wrb; |
| 797 | *endian_check++ = 0xFF; |
| 798 | *endian_check++ = 0x12; |
| 799 | *endian_check++ = 0x34; |
| 800 | *endian_check++ = 0xFF; |
| 801 | *endian_check++ = 0xFF; |
| 802 | *endian_check++ = 0x56; |
| 803 | *endian_check++ = 0x78; |
| 804 | *endian_check++ = 0xFF; |
| 805 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 806 | |
| 807 | status = be_mbox_notify(ctrl); |
| 808 | if (status) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 809 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 810 | "BC_%d : be_cmd_fw_initialize Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 811 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 812 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 813 | return status; |
| 814 | } |
| 815 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 816 | /** |
| 817 | * be_cmd_fw_uninit()- Uinitialize FW |
| 818 | * @ctrl: Pointer to function control structure |
| 819 | * |
| 820 | * Send FW uninitialize pattern for the function |
| 821 | * |
| 822 | * return |
| 823 | * Success: 0 |
| 824 | * Failure: Non-Zero value |
| 825 | **/ |
| 826 | int be_cmd_fw_uninit(struct be_ctrl_info *ctrl) |
| 827 | { |
| 828 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 829 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
| 830 | int status; |
| 831 | u8 *endian_check; |
| 832 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 833 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 834 | memset(wrb, 0, sizeof(*wrb)); |
| 835 | |
| 836 | endian_check = (u8 *) wrb; |
| 837 | *endian_check++ = 0xFF; |
| 838 | *endian_check++ = 0xAA; |
| 839 | *endian_check++ = 0xBB; |
| 840 | *endian_check++ = 0xFF; |
| 841 | *endian_check++ = 0xFF; |
| 842 | *endian_check++ = 0xCC; |
| 843 | *endian_check++ = 0xDD; |
| 844 | *endian_check = 0xFF; |
| 845 | |
| 846 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 847 | |
| 848 | status = be_mbox_notify(ctrl); |
| 849 | if (status) |
| 850 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 851 | "BC_%d : be_cmd_fw_uninit Failed\n"); |
| 852 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 853 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 854 | return status; |
| 855 | } |
| 856 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 857 | int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl, |
| 858 | struct be_queue_info *cq, struct be_queue_info *eq, |
| 859 | bool sol_evts, bool no_delay, int coalesce_wm) |
| 860 | { |
| 861 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 862 | struct be_cmd_req_cq_create *req = embedded_payload(wrb); |
| 863 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 864 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 865 | struct be_dma_mem *q_mem = &cq->dma_mem; |
| 866 | void *ctxt = &req->context; |
| 867 | int status; |
| 868 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 869 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 870 | memset(wrb, 0, sizeof(*wrb)); |
| 871 | |
| 872 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 873 | |
| 874 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 875 | OPCODE_COMMON_CQ_CREATE, sizeof(*req)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 876 | |
| 877 | 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] | 878 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 879 | AMAP_SET_BITS(struct amap_cq_context, coalescwm, |
| 880 | ctxt, coalesce_wm); |
| 881 | AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay); |
| 882 | AMAP_SET_BITS(struct amap_cq_context, count, ctxt, |
| 883 | __ilog2_u32(cq->len / 256)); |
| 884 | AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1); |
| 885 | AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts); |
| 886 | AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1); |
| 887 | AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id); |
| 888 | AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1); |
| 889 | AMAP_SET_BITS(struct amap_cq_context, func, ctxt, |
| 890 | PCI_FUNC(ctrl->pdev->devfn)); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 891 | } else { |
| 892 | req->hdr.version = MBX_CMD_VER2; |
| 893 | req->page_size = 1; |
| 894 | AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm, |
| 895 | ctxt, coalesce_wm); |
| 896 | AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, |
| 897 | ctxt, no_delay); |
| 898 | AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt, |
| 899 | __ilog2_u32(cq->len / 256)); |
| 900 | AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1); |
| 901 | AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1); |
| 902 | AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id); |
| 903 | AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1); |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 904 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 905 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 906 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 907 | |
| 908 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 909 | |
| 910 | status = be_mbox_notify(ctrl); |
| 911 | if (!status) { |
| 912 | cq->id = le16_to_cpu(resp->cq_id); |
| 913 | cq->created = true; |
| 914 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 915 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 916 | "BC_%d : In be_cmd_cq_create, status=ox%08x\n", |
| 917 | status); |
| 918 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 919 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 920 | |
| 921 | return status; |
| 922 | } |
| 923 | |
| 924 | static u32 be_encoded_q_len(int q_len) |
| 925 | { |
| 926 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
| 927 | if (len_encoded == 16) |
| 928 | len_encoded = 0; |
| 929 | return len_encoded; |
| 930 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 931 | |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 932 | int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 933 | struct be_queue_info *mccq, |
| 934 | struct be_queue_info *cq) |
| 935 | { |
| 936 | struct be_mcc_wrb *wrb; |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 937 | struct be_cmd_req_mcc_create_ext *req; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 938 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
| 939 | struct be_ctrl_info *ctrl; |
| 940 | void *ctxt; |
| 941 | int status; |
| 942 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 943 | mutex_lock(&phba->ctrl.mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 944 | ctrl = &phba->ctrl; |
| 945 | wrb = wrb_from_mbox(&ctrl->mbox_mem); |
Jayamohan Kallickal | 3760976 | 2011-10-07 19:31:11 -0500 | [diff] [blame] | 946 | memset(wrb, 0, sizeof(*wrb)); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 947 | req = embedded_payload(wrb); |
| 948 | ctxt = &req->context; |
| 949 | |
| 950 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 951 | |
| 952 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 953 | OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req)); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 954 | |
| 955 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 956 | req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE; |
| 957 | req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI; |
| 958 | req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 959 | |
| 960 | AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt, |
| 961 | PCI_FUNC(phba->pcidev->devfn)); |
| 962 | AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1); |
| 963 | AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt, |
| 964 | be_encoded_q_len(mccq->len)); |
| 965 | AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id); |
| 966 | |
| 967 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 968 | |
| 969 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 970 | |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame^] | 971 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 972 | if (!status) { |
| 973 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 974 | mccq->id = le16_to_cpu(resp->id); |
| 975 | mccq->created = true; |
| 976 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 977 | mutex_unlock(&phba->ctrl.mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 978 | |
| 979 | return status; |
| 980 | } |
| 981 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 982 | int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q, |
| 983 | int queue_type) |
| 984 | { |
| 985 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 986 | struct be_cmd_req_q_destroy *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 987 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 988 | u8 subsys = 0, opcode = 0; |
| 989 | int status; |
| 990 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 991 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 992 | "BC_%d : In beiscsi_cmd_q_destroy " |
| 993 | "queue_type : %d\n", queue_type); |
| 994 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 995 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 996 | memset(wrb, 0, sizeof(*wrb)); |
| 997 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 998 | |
| 999 | switch (queue_type) { |
| 1000 | case QTYPE_EQ: |
| 1001 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1002 | opcode = OPCODE_COMMON_EQ_DESTROY; |
| 1003 | break; |
| 1004 | case QTYPE_CQ: |
| 1005 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1006 | opcode = OPCODE_COMMON_CQ_DESTROY; |
| 1007 | break; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1008 | case QTYPE_MCCQ: |
| 1009 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1010 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 1011 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1012 | case QTYPE_WRBQ: |
| 1013 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1014 | opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY; |
| 1015 | break; |
| 1016 | case QTYPE_DPDUQ: |
| 1017 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1018 | opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY; |
| 1019 | break; |
| 1020 | case QTYPE_SGL: |
| 1021 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1022 | opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES; |
| 1023 | break; |
| 1024 | default: |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1025 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1026 | BUG(); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 1027 | return -ENXIO; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1028 | } |
| 1029 | be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req)); |
| 1030 | if (queue_type != QTYPE_SGL) |
| 1031 | req->id = cpu_to_le16(q->id); |
| 1032 | |
| 1033 | status = be_mbox_notify(ctrl); |
| 1034 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1035 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1036 | return status; |
| 1037 | } |
| 1038 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1039 | /** |
| 1040 | * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter |
| 1041 | * @ctrl: ptr to ctrl_info |
| 1042 | * @cq: Completion Queue |
| 1043 | * @dq: Default Queue |
| 1044 | * @lenght: ring size |
| 1045 | * @entry_size: size of each entry in DEFQ |
| 1046 | * @is_header: Header or Data DEFQ |
| 1047 | * @ulp_num: Bind to which ULP |
| 1048 | * |
| 1049 | * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted |
| 1050 | * on this queue by the FW |
| 1051 | * |
| 1052 | * return |
| 1053 | * Success: 0 |
| 1054 | * Failure: Non-Zero Value |
| 1055 | * |
| 1056 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1057 | int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl, |
| 1058 | struct be_queue_info *cq, |
| 1059 | struct be_queue_info *dq, int length, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1060 | int entry_size, uint8_t is_header, |
| 1061 | uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1062 | { |
| 1063 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1064 | struct be_defq_create_req *req = embedded_payload(wrb); |
| 1065 | struct be_dma_mem *q_mem = &dq->dma_mem; |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1066 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1067 | void *ctxt = &req->context; |
| 1068 | int status; |
| 1069 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1070 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1071 | memset(wrb, 0, sizeof(*wrb)); |
| 1072 | |
| 1073 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1074 | |
| 1075 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1076 | OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req)); |
| 1077 | |
| 1078 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1079 | if (phba->fw_config.dual_ulp_aware) { |
| 1080 | req->ulp_num = ulp_num; |
| 1081 | req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT); |
| 1082 | req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT); |
| 1083 | } |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1084 | |
| 1085 | if (is_chip_be2_be3r(phba)) { |
| 1086 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1087 | rx_pdid, ctxt, 0); |
| 1088 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1089 | rx_pdid_valid, ctxt, 1); |
| 1090 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1091 | pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn)); |
| 1092 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1093 | ring_size, ctxt, |
| 1094 | be_encoded_q_len(length / |
| 1095 | sizeof(struct phys_addr))); |
| 1096 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1097 | default_buffer_size, ctxt, entry_size); |
| 1098 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1099 | cq_id_recv, ctxt, cq->id); |
| 1100 | } else { |
| 1101 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1102 | rx_pdid, ctxt, 0); |
| 1103 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1104 | rx_pdid_valid, ctxt, 1); |
| 1105 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1106 | ring_size, ctxt, |
| 1107 | be_encoded_q_len(length / |
| 1108 | sizeof(struct phys_addr))); |
| 1109 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1110 | default_buffer_size, ctxt, entry_size); |
| 1111 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1112 | cq_id_recv, ctxt, cq->id); |
| 1113 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1114 | |
| 1115 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1116 | |
| 1117 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1118 | |
| 1119 | status = be_mbox_notify(ctrl); |
| 1120 | if (!status) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1121 | struct be_ring *defq_ring; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1122 | struct be_defq_create_resp *resp = embedded_payload(wrb); |
| 1123 | |
| 1124 | dq->id = le16_to_cpu(resp->id); |
| 1125 | dq->created = true; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1126 | if (is_header) |
| 1127 | defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num]; |
| 1128 | else |
| 1129 | defq_ring = &phba->phwi_ctrlr-> |
| 1130 | default_pdu_data[ulp_num]; |
| 1131 | |
| 1132 | defq_ring->id = dq->id; |
| 1133 | |
| 1134 | if (!phba->fw_config.dual_ulp_aware) { |
| 1135 | defq_ring->ulp_num = BEISCSI_ULP0; |
| 1136 | defq_ring->doorbell_offset = DB_RXULP0_OFFSET; |
| 1137 | } else { |
| 1138 | defq_ring->ulp_num = resp->ulp_num; |
| 1139 | defq_ring->doorbell_offset = resp->doorbell_offset; |
| 1140 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1141 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1142 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1143 | |
| 1144 | return status; |
| 1145 | } |
| 1146 | |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1147 | /** |
| 1148 | * be_cmd_wrbq_create()- Create WRBQ |
| 1149 | * @ctrl: ptr to ctrl_info |
| 1150 | * @q_mem: memory details for the queue |
| 1151 | * @wrbq: queue info |
| 1152 | * @pwrb_context: ptr to wrb_context |
| 1153 | * @ulp_num: ULP on which the WRBQ is to be created |
| 1154 | * |
| 1155 | * Create WRBQ on the passed ULP_NUM. |
| 1156 | * |
| 1157 | **/ |
| 1158 | int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, |
| 1159 | struct be_dma_mem *q_mem, |
| 1160 | struct be_queue_info *wrbq, |
| 1161 | struct hwi_wrb_context *pwrb_context, |
| 1162 | uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1163 | { |
| 1164 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1165 | struct be_wrbq_create_req *req = embedded_payload(wrb); |
| 1166 | struct be_wrbq_create_resp *resp = embedded_payload(wrb); |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1167 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1168 | int status; |
| 1169 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1170 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1171 | memset(wrb, 0, sizeof(*wrb)); |
| 1172 | |
| 1173 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1174 | |
| 1175 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1176 | OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req)); |
| 1177 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (phba->fw_config.dual_ulp_aware) { |
| 1180 | req->ulp_num = ulp_num; |
| 1181 | req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT); |
| 1182 | req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT); |
| 1183 | } |
| 1184 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1185 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1186 | |
| 1187 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1188 | if (!status) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1189 | wrbq->id = le16_to_cpu(resp->cid); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1190 | wrbq->created = true; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 1191 | |
| 1192 | pwrb_context->cid = wrbq->id; |
| 1193 | if (!phba->fw_config.dual_ulp_aware) { |
| 1194 | pwrb_context->doorbell_offset = DB_TXULP0_OFFSET; |
| 1195 | pwrb_context->ulp_num = BEISCSI_ULP0; |
| 1196 | } else { |
| 1197 | pwrb_context->ulp_num = resp->ulp_num; |
| 1198 | pwrb_context->doorbell_offset = resp->doorbell_offset; |
| 1199 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1200 | } |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1201 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1202 | return status; |
| 1203 | } |
| 1204 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1205 | int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl, |
| 1206 | struct be_dma_mem *q_mem) |
| 1207 | { |
| 1208 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1209 | struct be_post_template_pages_req *req = embedded_payload(wrb); |
| 1210 | int status; |
| 1211 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1212 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1213 | |
| 1214 | memset(wrb, 0, sizeof(*wrb)); |
| 1215 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1216 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1217 | OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS, |
| 1218 | sizeof(*req)); |
| 1219 | |
| 1220 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 1221 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1222 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1223 | |
| 1224 | status = be_mbox_notify(ctrl); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1225 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1226 | return status; |
| 1227 | } |
| 1228 | |
| 1229 | int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl) |
| 1230 | { |
| 1231 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1232 | struct be_remove_template_pages_req *req = embedded_payload(wrb); |
| 1233 | int status; |
| 1234 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1235 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1236 | |
| 1237 | memset(wrb, 0, sizeof(*wrb)); |
| 1238 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1239 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1240 | OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS, |
| 1241 | sizeof(*req)); |
| 1242 | |
| 1243 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1244 | |
| 1245 | status = be_mbox_notify(ctrl); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1246 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1247 | return status; |
| 1248 | } |
| 1249 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1250 | int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl, |
| 1251 | struct be_dma_mem *q_mem, |
| 1252 | u32 page_offset, u32 num_pages) |
| 1253 | { |
| 1254 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1255 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1256 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1257 | int status; |
| 1258 | unsigned int curr_pages; |
| 1259 | u32 internal_page_offset = 0; |
| 1260 | u32 temp_num_pages = num_pages; |
| 1261 | |
| 1262 | if (num_pages == 0xff) |
| 1263 | num_pages = 1; |
| 1264 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1265 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1266 | do { |
| 1267 | memset(wrb, 0, sizeof(*wrb)); |
| 1268 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1269 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1270 | OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES, |
| 1271 | sizeof(*req)); |
| 1272 | curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req, |
| 1273 | pages); |
| 1274 | req->num_pages = min(num_pages, curr_pages); |
| 1275 | req->page_offset = page_offset; |
| 1276 | be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem); |
| 1277 | q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE); |
| 1278 | internal_page_offset += req->num_pages; |
| 1279 | page_offset += req->num_pages; |
| 1280 | num_pages -= req->num_pages; |
| 1281 | |
| 1282 | if (temp_num_pages == 0xff) |
| 1283 | req->num_pages = temp_num_pages; |
| 1284 | |
| 1285 | status = be_mbox_notify(ctrl); |
| 1286 | if (status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1287 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 1288 | "BC_%d : FW CMD to map iscsi frags failed.\n"); |
| 1289 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1290 | goto error; |
| 1291 | } |
| 1292 | } while (num_pages > 0); |
| 1293 | error: |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1294 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1295 | if (status != 0) |
| 1296 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 1297 | return status; |
| 1298 | } |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1299 | |
| 1300 | int beiscsi_cmd_reset_function(struct beiscsi_hba *phba) |
| 1301 | { |
| 1302 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1303 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1304 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
| 1305 | int status; |
| 1306 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1307 | mutex_lock(&ctrl->mbox_lock); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1308 | |
| 1309 | req = embedded_payload(wrb); |
| 1310 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1311 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1312 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req)); |
Jitendra Bhivare | a264f5e | 2016-02-04 15:49:13 +0530 | [diff] [blame^] | 1313 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1314 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1315 | mutex_unlock(&ctrl->mbox_lock); |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1316 | return status; |
| 1317 | } |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1318 | |
| 1319 | /** |
| 1320 | * be_cmd_set_vlan()- Configure VLAN paramters on the adapter |
| 1321 | * @phba: device priv structure instance |
| 1322 | * @vlan_tag: TAG to be set |
| 1323 | * |
| 1324 | * Set the VLAN_TAG for the adapter or Disable VLAN on adapter |
| 1325 | * |
| 1326 | * returns |
| 1327 | * TAG for the MBX Cmd |
| 1328 | * **/ |
| 1329 | int be_cmd_set_vlan(struct beiscsi_hba *phba, |
| 1330 | uint16_t vlan_tag) |
| 1331 | { |
| 1332 | unsigned int tag = 0; |
| 1333 | struct be_mcc_wrb *wrb; |
| 1334 | struct be_cmd_set_vlan_req *req; |
| 1335 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1336 | |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1337 | if (mutex_lock_interruptible(&ctrl->mbox_lock)) |
| 1338 | return 0; |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1339 | tag = alloc_mcc_tag(phba); |
| 1340 | if (!tag) { |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1341 | mutex_unlock(&ctrl->mbox_lock); |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1342 | return tag; |
| 1343 | } |
| 1344 | |
| 1345 | wrb = wrb_from_mccq(phba); |
| 1346 | req = embedded_payload(wrb); |
| 1347 | wrb->tag0 |= tag; |
| 1348 | be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0); |
| 1349 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1350 | OPCODE_COMMON_ISCSI_NTWK_SET_VLAN, |
| 1351 | sizeof(*req)); |
| 1352 | |
| 1353 | req->interface_hndl = phba->interface_handle; |
| 1354 | req->vlan_priority = vlan_tag; |
| 1355 | |
Jitendra Bhivare | cdde668 | 2016-01-20 14:10:47 +0530 | [diff] [blame] | 1356 | be_mcc_notify(phba, tag); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 1357 | mutex_unlock(&ctrl->mbox_lock); |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1358 | |
| 1359 | return tag; |
| 1360 | } |