Lines Matching +full:flash +full:- +full:dma
1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt DMA configuration based mailbox support
48 * struct tb_dma_port - DMA control port
49 * @sw: Switch the DMA port belongs to
50 * @port: Switch port number where DMA capability is found
68 u64 route = tb_cfg_get_route(pkg->buffer) & ~BIT_ULL(63); in dma_port_match()
70 if (pkg->frame.eof == TB_CFG_PKG_ERROR) in dma_port_match()
72 if (pkg->frame.eof != req->response_type) in dma_port_match()
74 if (route != tb_cfg_get_route(req->request)) in dma_port_match()
76 if (pkg->frame.size != req->response_size) in dma_port_match()
84 memcpy(req->response, pkg->buffer, req->response_size); in dma_port_copy()
107 return -ENOMEM; in dma_port_read()
109 req->match = dma_port_match; in dma_port_read()
110 req->copy = dma_port_copy; in dma_port_read()
111 req->request = &request; in dma_port_read()
112 req->request_size = sizeof(request); in dma_port_read()
113 req->request_type = TB_CFG_PKG_READ; in dma_port_read()
114 req->response = &reply; in dma_port_read()
115 req->response_size = 12 + 4 * length; in dma_port_read()
116 req->response_type = TB_CFG_PKG_READ; in dma_port_read()
150 return -ENOMEM; in dma_port_write()
152 req->match = dma_port_match; in dma_port_write()
153 req->copy = dma_port_copy; in dma_port_write()
154 req->request = &request; in dma_port_write()
155 req->request_size = 12 + 4 * length; in dma_port_write()
156 req->request_type = TB_CFG_PKG_WRITE; in dma_port_write()
157 req->response = &reply; in dma_port_write()
158 req->response_size = sizeof(reply); in dma_port_write()
159 req->response_type = TB_CFG_PKG_WRITE; in dma_port_write()
174 * The DMA (NHI) port is either 3, 5 or 7 depending on the in dma_find_port()
181 ret = dma_port_read(sw->tb->ctl, &type, tb_route(sw), ports[i], in dma_find_port()
187 return -ENODEV; in dma_find_port()
191 * dma_port_alloc() - Finds DMA control port from a switch pointed by route
192 * @sw: Switch from where find the DMA port
194 * Function checks if the switch NHI port supports DMA configuration
196 * DMA port structure. Returns %NULL if the capabity was not found.
198 * The DMA control port is functional also when the switch is in safe
203 struct tb_dma_port *dma; in dma_port_alloc() local
210 dma = kzalloc(sizeof(*dma), GFP_KERNEL); in dma_port_alloc()
211 if (!dma) in dma_port_alloc()
214 dma->buf = kmalloc_array(MAIL_DATA_DWORDS, sizeof(u32), GFP_KERNEL); in dma_port_alloc()
215 if (!dma->buf) { in dma_port_alloc()
216 kfree(dma); in dma_port_alloc()
220 dma->sw = sw; in dma_port_alloc()
221 dma->port = port; in dma_port_alloc()
222 dma->base = DMA_PORT_CAP; in dma_port_alloc()
224 return dma; in dma_port_alloc()
228 * dma_port_free() - Release DMA control port structure
229 * @dma: DMA control port
231 void dma_port_free(struct tb_dma_port *dma) in dma_port_free() argument
233 if (dma) { in dma_port_free()
234 kfree(dma->buf); in dma_port_free()
235 kfree(dma); in dma_port_free()
239 static int dma_port_wait_for_completion(struct tb_dma_port *dma, in dma_port_wait_for_completion() argument
243 struct tb_switch *sw = dma->sw; in dma_port_wait_for_completion()
249 ret = dma_port_read(sw->tb->ctl, &in, tb_route(sw), dma->port, in dma_port_wait_for_completion()
250 dma->base + MAIL_IN, 1, 50); in dma_port_wait_for_completion()
252 if (ret != -ETIMEDOUT) in dma_port_wait_for_completion()
261 return -ETIMEDOUT; in dma_port_wait_for_completion()
270 return -EINVAL; in status_to_errno()
272 return -EACCES; in status_to_errno()
275 return -EIO; in status_to_errno()
278 static int dma_port_request(struct tb_dma_port *dma, u32 in, in dma_port_request() argument
281 struct tb_switch *sw = dma->sw; in dma_port_request()
285 ret = dma_port_write(sw->tb->ctl, &in, tb_route(sw), dma->port, in dma_port_request()
286 dma->base + MAIL_IN, 1, DMA_PORT_TIMEOUT); in dma_port_request()
290 ret = dma_port_wait_for_completion(dma, timeout); in dma_port_request()
294 ret = dma_port_read(sw->tb->ctl, &out, tb_route(sw), dma->port, in dma_port_request()
295 dma->base + MAIL_OUT, 1, DMA_PORT_TIMEOUT); in dma_port_request()
305 struct tb_dma_port *dma = data; in dma_port_flash_read_block() local
306 struct tb_switch *sw = dma->sw; in dma_port_flash_read_block()
316 ret = dma_port_request(dma, in, DMA_PORT_TIMEOUT); in dma_port_flash_read_block()
320 return dma_port_read(sw->tb->ctl, buf, tb_route(sw), dma->port, in dma_port_flash_read_block()
321 dma->base + MAIL_DATA, dwords, DMA_PORT_TIMEOUT); in dma_port_flash_read_block()
327 struct tb_dma_port *dma = data; in dma_port_flash_write_block() local
328 struct tb_switch *sw = dma->sw; in dma_port_flash_write_block()
333 ret = dma_port_write(sw->tb->ctl, buf, tb_route(sw), dma->port, in dma_port_flash_write_block()
334 dma->base + MAIL_DATA, dwords, DMA_PORT_TIMEOUT); in dma_port_flash_write_block()
344 in |= ((dwords - 1) << MAIL_IN_DWORDS_SHIFT) & MAIL_IN_DWORDS_MASK; in dma_port_flash_write_block()
348 return dma_port_request(dma, in, DMA_PORT_TIMEOUT); in dma_port_flash_write_block()
352 * dma_port_flash_read() - Read from active flash region
353 * @dma: DMA control port
358 int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address, in dma_port_flash_read() argument
362 dma_port_flash_read_block, dma); in dma_port_flash_read()
366 * dma_port_flash_write() - Write to non-active flash region
367 * @dma: DMA control port
368 * @address: Address relative to the start of non-active region
372 * Writes block of data to the non-active flash region of the switch. If
376 int dma_port_flash_write(struct tb_dma_port *dma, unsigned int address, in dma_port_flash_write() argument
380 return -E2BIG; in dma_port_flash_write()
383 dma_port_flash_write_block, dma); in dma_port_flash_write()
387 * dma_port_flash_update_auth() - Starts flash authenticate cycle
388 * @dma: DMA control port
390 * Starts the flash update authentication cycle. If the image in the
391 * non-active area was valid, the switch starts upgrade process where
392 * active and non-active area get swapped in the end. Caller should call
397 int dma_port_flash_update_auth(struct tb_dma_port *dma) in dma_port_flash_update_auth() argument
404 return dma_port_request(dma, in, 150); in dma_port_flash_update_auth()
408 * dma_port_flash_update_auth_status() - Reads status of update auth command
409 * @dma: DMA control port
420 int dma_port_flash_update_auth_status(struct tb_dma_port *dma, u32 *status) in dma_port_flash_update_auth_status() argument
422 struct tb_switch *sw = dma->sw; in dma_port_flash_update_auth_status()
426 ret = dma_port_read(sw->tb->ctl, &out, tb_route(sw), dma->port, in dma_port_flash_update_auth_status()
427 dma->base + MAIL_OUT, 1, DMA_PORT_TIMEOUT); in dma_port_flash_update_auth_status()
431 /* Check if the status relates to flash update auth */ in dma_port_flash_update_auth_status()
445 * dma_port_power_cycle() - Power cycles the switch
446 * @dma: DMA control port
450 int dma_port_power_cycle(struct tb_dma_port *dma) in dma_port_power_cycle() argument
457 return dma_port_request(dma, in, 150); in dma_port_power_cycle()