treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / brocade / bna / bfa_cee.c
blob09fb9315d1ae2de40e7b3797d89afa800d97e322
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 */
5 /*
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
8 * All rights reserved
9 * www.qlogic.com
12 #include "bfa_cee.h"
13 #include "bfi_cna.h"
14 #include "bfa_ioc.h"
16 static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
17 static void bfa_cee_format_cee_cfg(void *buffer);
19 static void
20 bfa_cee_format_cee_cfg(void *buffer)
22 struct bfa_cee_attr *cee_cfg = buffer;
23 bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
26 static void
27 bfa_cee_stats_swap(struct bfa_cee_stats *stats)
29 u32 *buffer = (u32 *)stats;
30 int i;
32 for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
33 i++) {
34 buffer[i] = ntohl(buffer[i]);
38 static void
39 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
41 lldp_cfg->time_to_live =
42 ntohs(lldp_cfg->time_to_live);
43 lldp_cfg->enabled_system_cap =
44 ntohs(lldp_cfg->enabled_system_cap);
47 /**
48 * bfa_cee_attr_meminfo - Returns the size of the DMA memory needed by CEE attributes
50 static u32
51 bfa_cee_attr_meminfo(void)
53 return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
55 /**
56 * bfa_cee_stats_meminfo - Returns the size of the DMA memory needed by CEE stats
58 static u32
59 bfa_cee_stats_meminfo(void)
61 return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
64 /**
65 * bfa_cee_get_attr_isr - CEE ISR for get-attributes responses from f/w
67 * @cee: Pointer to the CEE module
68 * @status: Return status from the f/w
70 static void
71 bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
73 cee->get_attr_status = status;
74 if (status == BFA_STATUS_OK) {
75 memcpy(cee->attr, cee->attr_dma.kva,
76 sizeof(struct bfa_cee_attr));
77 bfa_cee_format_cee_cfg(cee->attr);
79 cee->get_attr_pending = false;
80 if (cee->cbfn.get_attr_cbfn)
81 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
84 /**
85 * bfa_cee_get_attr_isr - CEE ISR for get-stats responses from f/w
87 * @cee: Pointer to the CEE module
88 * @status: Return status from the f/w
90 static void
91 bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
93 cee->get_stats_status = status;
94 if (status == BFA_STATUS_OK) {
95 memcpy(cee->stats, cee->stats_dma.kva,
96 sizeof(struct bfa_cee_stats));
97 bfa_cee_stats_swap(cee->stats);
99 cee->get_stats_pending = false;
100 if (cee->cbfn.get_stats_cbfn)
101 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
105 * bfa_cee_get_attr_isr()
107 * @brief CEE ISR for reset-stats responses from f/w
109 * @param[in] cee - Pointer to the CEE module
110 * status - Return status from the f/w
112 * @return void
114 static void
115 bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
117 cee->reset_stats_status = status;
118 cee->reset_stats_pending = false;
119 if (cee->cbfn.reset_stats_cbfn)
120 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
123 * bfa_nw_cee_meminfo - Returns the size of the DMA memory needed by CEE module
126 bfa_nw_cee_meminfo(void)
128 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
132 * bfa_nw_cee_mem_claim - Initialized CEE DMA Memory
134 * @cee: CEE module pointer
135 * @dma_kva: Kernel Virtual Address of CEE DMA Memory
136 * @dma_pa: Physical Address of CEE DMA Memory
138 void
139 bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
141 cee->attr_dma.kva = dma_kva;
142 cee->attr_dma.pa = dma_pa;
143 cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
144 cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
145 cee->attr = (struct bfa_cee_attr *) dma_kva;
146 cee->stats = (struct bfa_cee_stats *)
147 (dma_kva + bfa_cee_attr_meminfo());
151 * bfa_cee_get_attr - Send the request to the f/w to fetch CEE attributes.
153 * @cee: Pointer to the CEE module data structure.
155 * Return: status
157 enum bfa_status
158 bfa_nw_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
159 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
161 struct bfi_cee_get_req *cmd;
163 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
164 if (!bfa_nw_ioc_is_operational(cee->ioc))
165 return BFA_STATUS_IOC_FAILURE;
167 if (cee->get_attr_pending)
168 return BFA_STATUS_DEVBUSY;
170 cee->get_attr_pending = true;
171 cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
172 cee->attr = attr;
173 cee->cbfn.get_attr_cbfn = cbfn;
174 cee->cbfn.get_attr_cbarg = cbarg;
175 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
176 bfa_ioc_portid(cee->ioc));
177 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
178 bfa_nw_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb, NULL, NULL);
180 return BFA_STATUS_OK;
184 * bfa_cee_isrs - Handles Mail-box interrupts for CEE module.
187 static void
188 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
190 union bfi_cee_i2h_msg_u *msg;
191 struct bfi_cee_get_rsp *get_rsp;
192 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
193 msg = (union bfi_cee_i2h_msg_u *) m;
194 get_rsp = (struct bfi_cee_get_rsp *) m;
195 switch (msg->mh.msg_id) {
196 case BFI_CEE_I2H_GET_CFG_RSP:
197 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
198 break;
199 case BFI_CEE_I2H_GET_STATS_RSP:
200 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
201 break;
202 case BFI_CEE_I2H_RESET_STATS_RSP:
203 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
204 break;
205 default:
206 BUG_ON(1);
211 * bfa_cee_notify - CEE module heart-beat failure handler.
213 * @event: IOC event type
216 static void
217 bfa_cee_notify(void *arg, enum bfa_ioc_event event)
219 struct bfa_cee *cee;
220 cee = (struct bfa_cee *) arg;
222 switch (event) {
223 case BFA_IOC_E_DISABLED:
224 case BFA_IOC_E_FAILED:
225 if (cee->get_attr_pending) {
226 cee->get_attr_status = BFA_STATUS_FAILED;
227 cee->get_attr_pending = false;
228 if (cee->cbfn.get_attr_cbfn) {
229 cee->cbfn.get_attr_cbfn(
230 cee->cbfn.get_attr_cbarg,
231 BFA_STATUS_FAILED);
234 if (cee->get_stats_pending) {
235 cee->get_stats_status = BFA_STATUS_FAILED;
236 cee->get_stats_pending = false;
237 if (cee->cbfn.get_stats_cbfn) {
238 cee->cbfn.get_stats_cbfn(
239 cee->cbfn.get_stats_cbarg,
240 BFA_STATUS_FAILED);
243 if (cee->reset_stats_pending) {
244 cee->reset_stats_status = BFA_STATUS_FAILED;
245 cee->reset_stats_pending = false;
246 if (cee->cbfn.reset_stats_cbfn) {
247 cee->cbfn.reset_stats_cbfn(
248 cee->cbfn.reset_stats_cbarg,
249 BFA_STATUS_FAILED);
252 break;
254 default:
255 break;
260 * bfa_nw_cee_attach - CEE module-attach API
262 * @cee: Pointer to the CEE module data structure
263 * @ioc: Pointer to the ioc module data structure
264 * @dev: Pointer to the device driver module data structure.
265 * The device driver specific mbox ISR functions have
266 * this pointer as one of the parameters.
268 void
269 bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
270 void *dev)
272 BUG_ON(!(cee != NULL));
273 cee->dev = dev;
274 cee->ioc = ioc;
276 bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
277 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
278 bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);