fnic_fcs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  4. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  5. */
  6. #include <linux/errno.h>
  7. #include <linux/pci.h>
  8. #include <linux/slab.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/if_ether.h>
  13. #include <linux/if_vlan.h>
  14. #include <linux/workqueue.h>
  15. #include <scsi/fc/fc_fip.h>
  16. #include <scsi/fc/fc_els.h>
  17. #include <scsi/fc_frame.h>
  18. #include <linux/etherdevice.h>
  19. #include <scsi/scsi_transport_fc.h>
  20. #include "fnic_io.h"
  21. #include "fnic.h"
  22. #include "fnic_fdls.h"
  23. #include "fdls_fc.h"
  24. #include "cq_enet_desc.h"
  25. #include "cq_exch_desc.h"
  26. #include "fip.h"
  27. #define MAX_RESET_WAIT_COUNT 64
  28. struct workqueue_struct *fnic_event_queue;
  29. static uint8_t FCOE_ALL_FCF_MAC[6] = FC_FCOE_FLOGI_MAC;
  30. /*
  31. * Internal Functions
  32. * This function will initialize the src_mac address to be
  33. * used in outgoing frames
  34. */
  35. static inline void fnic_fdls_set_fcoe_srcmac(struct fnic *fnic,
  36. uint8_t *src_mac)
  37. {
  38. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  39. "Setting src mac: %02x:%02x:%02x:%02x:%02x:%02x",
  40. src_mac[0], src_mac[1], src_mac[2], src_mac[3],
  41. src_mac[4], src_mac[5]);
  42. memcpy(fnic->iport.fpma, src_mac, 6);
  43. }
  44. /*
  45. * This function will initialize the dst_mac address to be
  46. * used in outgoing frames
  47. */
  48. static inline void fnic_fdls_set_fcoe_dstmac(struct fnic *fnic,
  49. uint8_t *dst_mac)
  50. {
  51. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  52. "Setting dst mac: %02x:%02x:%02x:%02x:%02x:%02x",
  53. dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3],
  54. dst_mac[4], dst_mac[5]);
  55. memcpy(fnic->iport.fcfmac, dst_mac, 6);
  56. }
  57. void fnic_get_host_port_state(struct Scsi_Host *shost)
  58. {
  59. struct fnic *fnic = *((struct fnic **) shost_priv(shost));
  60. struct fnic_iport_s *iport = &fnic->iport;
  61. unsigned long flags;
  62. spin_lock_irqsave(&fnic->fnic_lock, flags);
  63. if (!fnic->link_status)
  64. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  65. else if (iport->state == FNIC_IPORT_STATE_READY)
  66. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  67. else
  68. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  69. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  70. }
  71. void fnic_fdls_link_status_change(struct fnic *fnic, int linkup)
  72. {
  73. struct fnic_iport_s *iport = &fnic->iport;
  74. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  75. "link up: %d, usefip: %d", linkup, iport->usefip);
  76. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  77. if (linkup) {
  78. if (iport->usefip) {
  79. iport->state = FNIC_IPORT_STATE_FIP;
  80. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  81. "link up: %d, usefip: %d", linkup, iport->usefip);
  82. fnic_fcoe_send_vlan_req(fnic);
  83. } else {
  84. iport->state = FNIC_IPORT_STATE_FABRIC_DISC;
  85. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  86. "iport->state: %d", iport->state);
  87. fnic_fdls_disc_start(iport);
  88. }
  89. } else {
  90. iport->state = FNIC_IPORT_STATE_LINK_WAIT;
  91. if (!is_zero_ether_addr(iport->fpma))
  92. vnic_dev_del_addr(fnic->vdev, iport->fpma);
  93. fnic_common_fip_cleanup(fnic);
  94. fnic_fdls_link_down(iport);
  95. }
  96. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  97. }
  98. /*
  99. * FPMA can be either taken from ethhdr(dst_mac) or flogi resp
  100. * or derive from FC_MAP and FCID combination. While it should be
  101. * same, revisit this if there is any possibility of not-correct.
  102. */
  103. void fnic_fdls_learn_fcoe_macs(struct fnic_iport_s *iport, void *rx_frame,
  104. uint8_t *fcid)
  105. {
  106. struct fnic *fnic = iport->fnic;
  107. struct ethhdr *ethhdr = (struct ethhdr *) rx_frame;
  108. uint8_t fcmac[6] = { 0x0E, 0xFC, 0x00, 0x00, 0x00, 0x00 };
  109. memcpy(&fcmac[3], fcid, 3);
  110. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  111. "learn fcoe: dst_mac: %02x:%02x:%02x:%02x:%02x:%02x",
  112. ethhdr->h_dest[0], ethhdr->h_dest[1],
  113. ethhdr->h_dest[2], ethhdr->h_dest[3],
  114. ethhdr->h_dest[4], ethhdr->h_dest[5]);
  115. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  116. "learn fcoe: fc_mac: %02x:%02x:%02x:%02x:%02x:%02x",
  117. fcmac[0], fcmac[1], fcmac[2], fcmac[3], fcmac[4],
  118. fcmac[5]);
  119. fnic_fdls_set_fcoe_srcmac(fnic, fcmac);
  120. fnic_fdls_set_fcoe_dstmac(fnic, ethhdr->h_source);
  121. }
  122. void fnic_fdls_init(struct fnic *fnic, int usefip)
  123. {
  124. struct fnic_iport_s *iport = &fnic->iport;
  125. /* Initialize iPort structure */
  126. iport->state = FNIC_IPORT_STATE_INIT;
  127. iport->fnic = fnic;
  128. iport->usefip = usefip;
  129. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  130. "iportsrcmac: %02x:%02x:%02x:%02x:%02x:%02x",
  131. iport->hwmac[0], iport->hwmac[1], iport->hwmac[2],
  132. iport->hwmac[3], iport->hwmac[4], iport->hwmac[5]);
  133. INIT_LIST_HEAD(&iport->tport_list);
  134. INIT_LIST_HEAD(&iport->tport_list_pending_del);
  135. fnic_fdls_disc_init(iport);
  136. }
  137. void fnic_handle_link(struct work_struct *work)
  138. {
  139. struct fnic *fnic = container_of(work, struct fnic, link_work);
  140. int old_link_status;
  141. u32 old_link_down_cnt;
  142. int max_count = 0;
  143. if (vnic_dev_get_intr_mode(fnic->vdev) != VNIC_DEV_INTR_MODE_MSI)
  144. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  145. "Interrupt mode is not MSI\n");
  146. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  147. if (fnic->stop_rx_link_events) {
  148. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  149. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  150. "Stop link rx events\n");
  151. return;
  152. }
  153. /* Do not process if the fnic is already in transitional state */
  154. if ((fnic->state != FNIC_IN_ETH_MODE)
  155. && (fnic->state != FNIC_IN_FC_MODE)) {
  156. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  157. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  158. "fnic in transitional state: %d. link up: %d ignored",
  159. fnic->state, vnic_dev_link_status(fnic->vdev));
  160. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  161. "Current link status: %d iport state: %d\n",
  162. fnic->link_status, fnic->iport.state);
  163. return;
  164. }
  165. old_link_down_cnt = fnic->link_down_cnt;
  166. old_link_status = fnic->link_status;
  167. fnic->link_status = vnic_dev_link_status(fnic->vdev);
  168. fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev);
  169. while (fnic->reset_in_progress == IN_PROGRESS) {
  170. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  171. "fnic reset in progress. Link event needs to wait\n");
  172. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  173. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  174. "waiting for reset completion\n");
  175. wait_for_completion_timeout(&fnic->reset_completion_wait,
  176. msecs_to_jiffies(5000));
  177. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  178. "woken up from reset completion wait\n");
  179. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  180. max_count++;
  181. if (max_count >= MAX_RESET_WAIT_COUNT) {
  182. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  183. "Rstth waited for too long. Skipping handle link event\n");
  184. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  185. return;
  186. }
  187. }
  188. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  189. "Marking fnic reset in progress\n");
  190. fnic->reset_in_progress = IN_PROGRESS;
  191. if ((vnic_dev_get_intr_mode(fnic->vdev) != VNIC_DEV_INTR_MODE_MSI) ||
  192. (fnic->link_status != old_link_status)) {
  193. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  194. "old link status: %d link status: %d\n",
  195. old_link_status, (int) fnic->link_status);
  196. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  197. "old down count %d down count: %d\n",
  198. old_link_down_cnt, (int) fnic->link_down_cnt);
  199. }
  200. if (old_link_status == fnic->link_status) {
  201. if (!fnic->link_status) {
  202. /* DOWN -> DOWN */
  203. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  204. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  205. "down->down\n");
  206. } else {
  207. if (old_link_down_cnt != fnic->link_down_cnt) {
  208. /* UP -> DOWN -> UP */
  209. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  210. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  211. "up->down. Link down\n");
  212. fnic_fdls_link_status_change(fnic, 0);
  213. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  214. "down->up. Link up\n");
  215. fnic_fdls_link_status_change(fnic, 1);
  216. } else {
  217. /* UP -> UP */
  218. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  219. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  220. "up->up\n");
  221. }
  222. }
  223. } else if (fnic->link_status) {
  224. /* DOWN -> UP */
  225. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  226. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  227. "down->up. Link up\n");
  228. fnic_fdls_link_status_change(fnic, 1);
  229. } else {
  230. /* UP -> DOWN */
  231. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  232. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  233. "up->down. Link down\n");
  234. fnic_fdls_link_status_change(fnic, 0);
  235. }
  236. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  237. fnic->reset_in_progress = NOT_IN_PROGRESS;
  238. complete(&fnic->reset_completion_wait);
  239. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  240. "Marking fnic reset completion\n");
  241. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  242. }
  243. void fnic_handle_frame(struct work_struct *work)
  244. {
  245. struct fnic *fnic = container_of(work, struct fnic, frame_work);
  246. struct fnic_frame_list *cur_frame, *next;
  247. int fchdr_offset = 0;
  248. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  249. list_for_each_entry_safe(cur_frame, next, &fnic->frame_queue, links) {
  250. if (fnic->stop_rx_link_events) {
  251. list_del(&cur_frame->links);
  252. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  253. kfree(cur_frame->fp);
  254. mempool_free(cur_frame, fnic->frame_elem_pool);
  255. return;
  256. }
  257. /*
  258. * If we're in a transitional state, just re-queue and return.
  259. * The queue will be serviced when we get to a stable state.
  260. */
  261. if (fnic->state != FNIC_IN_FC_MODE &&
  262. fnic->state != FNIC_IN_ETH_MODE) {
  263. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  264. "Cannot process frame in transitional state\n");
  265. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  266. return;
  267. }
  268. list_del(&cur_frame->links);
  269. /* Frames from FCP_RQ will have ethhdrs stripped off */
  270. fchdr_offset = (cur_frame->rx_ethhdr_stripped) ?
  271. 0 : FNIC_ETH_FCOE_HDRS_OFFSET;
  272. fnic_fdls_recv_frame(&fnic->iport, cur_frame->fp,
  273. cur_frame->frame_len, fchdr_offset);
  274. kfree(cur_frame->fp);
  275. mempool_free(cur_frame, fnic->frame_elem_pool);
  276. }
  277. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  278. }
  279. void fnic_handle_fip_frame(struct work_struct *work)
  280. {
  281. struct fnic_frame_list *cur_frame, *next;
  282. struct fnic *fnic = container_of(work, struct fnic, fip_frame_work);
  283. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  284. "Processing FIP frame\n");
  285. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  286. list_for_each_entry_safe(cur_frame, next, &fnic->fip_frame_queue,
  287. links) {
  288. if (fnic->stop_rx_link_events) {
  289. list_del(&cur_frame->links);
  290. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  291. kfree(cur_frame->fp);
  292. kfree(cur_frame);
  293. return;
  294. }
  295. /*
  296. * If we're in a transitional state, just re-queue and return.
  297. * The queue will be serviced when we get to a stable state.
  298. */
  299. if (fnic->state != FNIC_IN_FC_MODE &&
  300. fnic->state != FNIC_IN_ETH_MODE) {
  301. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  302. return;
  303. }
  304. list_del(&cur_frame->links);
  305. if (fdls_fip_recv_frame(fnic, cur_frame->fp)) {
  306. kfree(cur_frame->fp);
  307. kfree(cur_frame);
  308. }
  309. }
  310. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  311. }
  312. /**
  313. * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
  314. * @fnic: fnic instance.
  315. * @fp: Ethernet Frame.
  316. */
  317. static inline int fnic_import_rq_eth_pkt(struct fnic *fnic, void *fp)
  318. {
  319. struct ethhdr *eh;
  320. struct fnic_frame_list *fip_fr_elem;
  321. unsigned long flags;
  322. eh = (struct ethhdr *) fp;
  323. if ((eh->h_proto == cpu_to_be16(ETH_P_FIP)) && (fnic->iport.usefip)) {
  324. fip_fr_elem = (struct fnic_frame_list *)
  325. kzalloc_obj(struct fnic_frame_list, GFP_ATOMIC);
  326. if (!fip_fr_elem)
  327. return 0;
  328. fip_fr_elem->fp = fp;
  329. spin_lock_irqsave(&fnic->fnic_lock, flags);
  330. list_add_tail(&fip_fr_elem->links, &fnic->fip_frame_queue);
  331. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  332. queue_work(fnic_fip_queue, &fnic->fip_frame_work);
  333. return 1; /* let caller know packet was used */
  334. } else
  335. return 0;
  336. }
  337. /**
  338. * fnic_update_mac_locked() - set data MAC address and filters.
  339. * @fnic: fnic instance.
  340. * @new: newly-assigned FCoE MAC address.
  341. *
  342. * Called with the fnic lock held.
  343. */
  344. void fnic_update_mac_locked(struct fnic *fnic, u8 *new)
  345. {
  346. struct fnic_iport_s *iport = &fnic->iport;
  347. u8 *ctl = iport->hwmac;
  348. u8 *data = fnic->data_src_addr;
  349. if (is_zero_ether_addr(new))
  350. new = ctl;
  351. if (ether_addr_equal(data, new))
  352. return;
  353. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  354. "Update MAC: %u\n", *new);
  355. if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl))
  356. vnic_dev_del_addr(fnic->vdev, data);
  357. memcpy(data, new, ETH_ALEN);
  358. if (!ether_addr_equal(new, ctl))
  359. vnic_dev_add_addr(fnic->vdev, new);
  360. }
  361. static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc
  362. *cq_desc, struct vnic_rq_buf *buf,
  363. int skipped __attribute__((unused)),
  364. void *opaque)
  365. {
  366. struct fnic *fnic = vnic_dev_priv(rq->vdev);
  367. uint8_t *fp;
  368. struct fnic_stats *fnic_stats = &fnic->fnic_stats;
  369. unsigned int ethhdr_stripped;
  370. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  371. u8 fcoe_fnic_crc_ok = 1, fcoe_enc_error = 0;
  372. u8 fcs_ok = 1, packet_error = 0;
  373. u16 q_number, completed_index, vlan;
  374. u32 rss_hash;
  375. u16 checksum;
  376. u8 csum_not_calc, rss_type, ipv4, ipv6, ipv4_fragment;
  377. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  378. u8 fcoe = 0, fcoe_sof, fcoe_eof;
  379. u16 exchange_id, tmpl;
  380. u8 sof = 0;
  381. u8 eof = 0;
  382. u32 fcp_bytes_written = 0;
  383. u16 enet_bytes_written = 0;
  384. u32 bytes_written = 0;
  385. unsigned long flags;
  386. struct fnic_frame_list *frame_elem = NULL;
  387. struct ethhdr *eh;
  388. dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
  389. DMA_FROM_DEVICE);
  390. fp = (uint8_t *) buf->os_buf;
  391. buf->os_buf = NULL;
  392. cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index);
  393. if (type == CQ_DESC_TYPE_RQ_FCP) {
  394. cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *) cq_desc, &type,
  395. &color, &q_number, &completed_index, &eop, &sop,
  396. &fcoe_fnic_crc_ok, &exchange_id, &tmpl,
  397. &fcp_bytes_written, &sof, &eof, &ingress_port,
  398. &packet_error, &fcoe_enc_error, &fcs_ok,
  399. &vlan_stripped, &vlan);
  400. ethhdr_stripped = 1;
  401. bytes_written = fcp_bytes_written;
  402. } else if (type == CQ_DESC_TYPE_RQ_ENET) {
  403. cq_enet_rq_desc_dec((struct cq_enet_rq_desc *) cq_desc, &type,
  404. &color, &q_number, &completed_index,
  405. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  406. &csum_not_calc, &rss_hash, &enet_bytes_written,
  407. &packet_error, &vlan_stripped, &vlan,
  408. &checksum, &fcoe_sof, &fcoe_fnic_crc_ok,
  409. &fcoe_enc_error, &fcoe_eof, &tcp_udp_csum_ok,
  410. &udp, &tcp, &ipv4_csum_ok, &ipv6, &ipv4,
  411. &ipv4_fragment, &fcs_ok);
  412. ethhdr_stripped = 0;
  413. bytes_written = enet_bytes_written;
  414. if (!fcs_ok) {
  415. atomic64_inc(&fnic_stats->misc_stats.frame_errors);
  416. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  417. "fnic 0x%p fcs error. Dropping packet.\n", fnic);
  418. goto drop;
  419. }
  420. eh = (struct ethhdr *) fp;
  421. if (eh->h_proto != cpu_to_be16(ETH_P_FCOE)) {
  422. if (fnic_import_rq_eth_pkt(fnic, fp))
  423. return;
  424. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  425. "Dropping h_proto 0x%x",
  426. be16_to_cpu(eh->h_proto));
  427. goto drop;
  428. }
  429. } else {
  430. /* wrong CQ type */
  431. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  432. "fnic rq_cmpl wrong cq type x%x\n", type);
  433. goto drop;
  434. }
  435. if (!fcs_ok || packet_error || !fcoe_fnic_crc_ok || fcoe_enc_error) {
  436. atomic64_inc(&fnic_stats->misc_stats.frame_errors);
  437. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  438. "fcoe %x fcsok %x pkterr %x ffco %x fee %x\n",
  439. fcoe, fcs_ok, packet_error,
  440. fcoe_fnic_crc_ok, fcoe_enc_error);
  441. goto drop;
  442. }
  443. spin_lock_irqsave(&fnic->fnic_lock, flags);
  444. if (fnic->stop_rx_link_events) {
  445. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  446. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  447. "fnic->stop_rx_link_events: %d\n",
  448. fnic->stop_rx_link_events);
  449. goto drop;
  450. }
  451. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  452. frame_elem = mempool_alloc(fnic->frame_elem_pool,
  453. GFP_ATOMIC | __GFP_ZERO);
  454. if (!frame_elem) {
  455. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  456. "Failed to allocate memory for frame elem");
  457. goto drop;
  458. }
  459. frame_elem->fp = fp;
  460. frame_elem->rx_ethhdr_stripped = ethhdr_stripped;
  461. frame_elem->frame_len = bytes_written;
  462. spin_lock_irqsave(&fnic->fnic_lock, flags);
  463. list_add_tail(&frame_elem->links, &fnic->frame_queue);
  464. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  465. queue_work(fnic_event_queue, &fnic->frame_work);
  466. return;
  467. drop:
  468. kfree(fp);
  469. }
  470. static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev,
  471. struct cq_desc *cq_desc, u8 type,
  472. u16 q_number, u16 completed_index,
  473. void *opaque)
  474. {
  475. struct fnic *fnic = vnic_dev_priv(vdev);
  476. vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index,
  477. VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv,
  478. NULL);
  479. return 0;
  480. }
  481. int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do)
  482. {
  483. unsigned int tot_rq_work_done = 0, cur_work_done;
  484. unsigned int i;
  485. int err;
  486. for (i = 0; i < fnic->rq_count; i++) {
  487. cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do,
  488. fnic_rq_cmpl_handler_cont,
  489. NULL);
  490. if (cur_work_done && fnic->stop_rx_link_events != 1) {
  491. err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
  492. if (err)
  493. shost_printk(KERN_ERR, fnic->host,
  494. "fnic_alloc_rq_frame can't alloc"
  495. " frame\n");
  496. }
  497. tot_rq_work_done += cur_work_done;
  498. }
  499. return tot_rq_work_done;
  500. }
  501. /*
  502. * This function is called once at init time to allocate and fill RQ
  503. * buffers. Subsequently, it is called in the interrupt context after RQ
  504. * buffer processing to replenish the buffers in the RQ
  505. */
  506. int fnic_alloc_rq_frame(struct vnic_rq *rq)
  507. {
  508. struct fnic *fnic = vnic_dev_priv(rq->vdev);
  509. void *buf;
  510. u16 len;
  511. dma_addr_t pa;
  512. int ret;
  513. len = FNIC_FRAME_HT_ROOM;
  514. buf = kmalloc(len, GFP_ATOMIC);
  515. if (!buf) {
  516. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  517. "Unable to allocate RQ buffer of size: %d\n", len);
  518. return -ENOMEM;
  519. }
  520. pa = dma_map_single(&fnic->pdev->dev, buf, len, DMA_FROM_DEVICE);
  521. if (dma_mapping_error(&fnic->pdev->dev, pa)) {
  522. ret = -ENOMEM;
  523. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  524. "PCI mapping failed with error %d\n", ret);
  525. goto free_buf;
  526. }
  527. fnic_queue_rq_desc(rq, buf, pa, len);
  528. return 0;
  529. free_buf:
  530. kfree(buf);
  531. return ret;
  532. }
  533. void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
  534. {
  535. void *rq_buf = buf->os_buf;
  536. struct fnic *fnic = vnic_dev_priv(rq->vdev);
  537. dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
  538. DMA_FROM_DEVICE);
  539. kfree(rq_buf);
  540. buf->os_buf = NULL;
  541. }
  542. /*
  543. * Send FC frame.
  544. */
  545. static int fnic_send_frame(struct fnic *fnic, void *frame, int frame_len)
  546. {
  547. struct vnic_wq *wq = &fnic->wq[0];
  548. dma_addr_t pa;
  549. int ret = 0;
  550. unsigned long flags;
  551. pa = dma_map_single(&fnic->pdev->dev, frame, frame_len, DMA_TO_DEVICE);
  552. if (dma_mapping_error(&fnic->pdev->dev, pa))
  553. return -ENOMEM;
  554. if ((fnic_fc_trace_set_data(fnic->fnic_num,
  555. FNIC_FC_SEND | 0x80, (char *) frame,
  556. frame_len)) != 0) {
  557. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  558. "fnic ctlr frame trace error");
  559. }
  560. spin_lock_irqsave(&fnic->wq_lock[0], flags);
  561. if (!vnic_wq_desc_avail(wq)) {
  562. dma_unmap_single(&fnic->pdev->dev, pa, frame_len, DMA_TO_DEVICE);
  563. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  564. "vnic work queue descriptor is not available");
  565. ret = -1;
  566. goto fnic_send_frame_end;
  567. }
  568. /* hw inserts cos value */
  569. fnic_queue_wq_desc(wq, frame, pa, frame_len, FC_EOF_T,
  570. 0, fnic->vlan_id, 1, 1, 1);
  571. fnic_send_frame_end:
  572. spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
  573. return ret;
  574. }
  575. /**
  576. * fdls_send_fcoe_frame - send a filled-in FC frame, filling in eth and FCoE
  577. * info. This interface is used only in the non fast path. (login, fabric
  578. * registrations etc.)
  579. *
  580. * @fnic: fnic instance
  581. * @frame: frame structure with FC payload filled in
  582. * @frame_size: length of the frame to be sent
  583. * @srcmac: source mac address
  584. * @dstmac: destination mac address
  585. *
  586. * Called with the fnic lock held.
  587. */
  588. static int
  589. fdls_send_fcoe_frame(struct fnic *fnic, void *frame, int frame_size,
  590. uint8_t *srcmac, uint8_t *dstmac)
  591. {
  592. struct ethhdr *pethhdr;
  593. struct fcoe_hdr *pfcoe_hdr;
  594. struct fnic_frame_list *frame_elem;
  595. int len = frame_size;
  596. int ret;
  597. struct fc_frame_header *fchdr = (struct fc_frame_header *) (frame +
  598. FNIC_ETH_FCOE_HDRS_OFFSET);
  599. pethhdr = (struct ethhdr *) frame;
  600. pethhdr->h_proto = cpu_to_be16(ETH_P_FCOE);
  601. memcpy(pethhdr->h_source, srcmac, ETH_ALEN);
  602. memcpy(pethhdr->h_dest, dstmac, ETH_ALEN);
  603. pfcoe_hdr = (struct fcoe_hdr *) (frame + sizeof(struct ethhdr));
  604. pfcoe_hdr->fcoe_sof = FC_SOF_I3;
  605. /*
  606. * Queue frame if in a transitional state.
  607. * This occurs while registering the Port_ID / MAC address after FLOGI.
  608. */
  609. if ((fnic->state != FNIC_IN_FC_MODE)
  610. && (fnic->state != FNIC_IN_ETH_MODE)) {
  611. frame_elem = mempool_alloc(fnic->frame_elem_pool,
  612. GFP_ATOMIC | __GFP_ZERO);
  613. if (!frame_elem) {
  614. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  615. "Failed to allocate memory for frame elem");
  616. return -ENOMEM;
  617. }
  618. FNIC_FCS_DBG(KERN_DEBUG, fnic->host, fnic->fnic_num,
  619. "Queueing FC frame: sid/did/type/oxid = 0x%x/0x%x/0x%x/0x%x\n",
  620. ntoh24(fchdr->fh_s_id), ntoh24(fchdr->fh_d_id),
  621. fchdr->fh_type, FNIC_STD_GET_OX_ID(fchdr));
  622. frame_elem->fp = frame;
  623. frame_elem->frame_len = len;
  624. list_add_tail(&frame_elem->links, &fnic->tx_queue);
  625. return 0;
  626. }
  627. fnic_debug_dump_fc_frame(fnic, fchdr, frame_size, "Outgoing");
  628. ret = fnic_send_frame(fnic, frame, len);
  629. return ret;
  630. }
  631. void fnic_send_fcoe_frame(struct fnic_iport_s *iport, void *frame,
  632. int frame_size)
  633. {
  634. struct fnic *fnic = iport->fnic;
  635. uint8_t *dstmac, *srcmac;
  636. /* If module unload is in-progress, don't send */
  637. if (fnic->in_remove)
  638. return;
  639. if (iport->fabric.flags & FNIC_FDLS_FPMA_LEARNT) {
  640. srcmac = iport->fpma;
  641. dstmac = iport->fcfmac;
  642. } else {
  643. srcmac = iport->hwmac;
  644. dstmac = FCOE_ALL_FCF_MAC;
  645. }
  646. fdls_send_fcoe_frame(fnic, frame, frame_size, srcmac, dstmac);
  647. }
  648. int
  649. fnic_send_fip_frame(struct fnic_iport_s *iport, void *frame,
  650. int frame_size)
  651. {
  652. struct fnic *fnic = iport->fnic;
  653. if (fnic->in_remove)
  654. return -1;
  655. fnic_debug_dump_fip_frame(fnic, frame, frame_size, "Outgoing");
  656. return fnic_send_frame(fnic, frame, frame_size);
  657. }
  658. /**
  659. * fnic_flush_tx() - send queued frames.
  660. * @work: pointer to work element
  661. *
  662. * Send frames that were waiting to go out in FC or Ethernet mode.
  663. * Whenever changing modes we purge queued frames, so these frames should
  664. * be queued for the stable mode that we're in, either FC or Ethernet.
  665. *
  666. * Called without fnic_lock held.
  667. */
  668. void fnic_flush_tx(struct work_struct *work)
  669. {
  670. struct fnic *fnic = container_of(work, struct fnic, flush_work);
  671. struct fc_frame *fp;
  672. struct fnic_frame_list *cur_frame, *next;
  673. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  674. "Flush queued frames");
  675. list_for_each_entry_safe(cur_frame, next, &fnic->tx_queue, links) {
  676. fp = cur_frame->fp;
  677. list_del(&cur_frame->links);
  678. fnic_send_frame(fnic, fp, cur_frame->frame_len);
  679. mempool_free(cur_frame, fnic->frame_elem_pool);
  680. }
  681. }
  682. int
  683. fnic_fdls_register_portid(struct fnic_iport_s *iport, u32 port_id,
  684. void *fp)
  685. {
  686. struct fnic *fnic = iport->fnic;
  687. struct ethhdr *ethhdr;
  688. int ret;
  689. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  690. "Setting port id: 0x%x fp: 0x%p fnic state: %d", port_id,
  691. fp, fnic->state);
  692. if (fp) {
  693. ethhdr = (struct ethhdr *) fp;
  694. vnic_dev_add_addr(fnic->vdev, ethhdr->h_dest);
  695. }
  696. /* Change state to reflect transition to FC mode */
  697. if (fnic->state == FNIC_IN_ETH_MODE || fnic->state == FNIC_IN_FC_MODE)
  698. fnic->state = FNIC_IN_ETH_TRANS_FC_MODE;
  699. else {
  700. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  701. "Unexpected fnic state while processing FLOGI response\n");
  702. return -1;
  703. }
  704. /*
  705. * Send FLOGI registration to firmware to set up FC mode.
  706. * The new address will be set up when registration completes.
  707. */
  708. ret = fnic_flogi_reg_handler(fnic, port_id);
  709. if (ret < 0) {
  710. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  711. "FLOGI registration error ret: %d fnic state: %d\n",
  712. ret, fnic->state);
  713. if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE)
  714. fnic->state = FNIC_IN_ETH_MODE;
  715. return -1;
  716. }
  717. iport->fabric.flags |= FNIC_FDLS_FPMA_LEARNT;
  718. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  719. "FLOGI registration success\n");
  720. return 0;
  721. }
  722. void fnic_free_txq(struct list_head *head)
  723. {
  724. struct fnic_frame_list *cur_frame, *next;
  725. list_for_each_entry_safe(cur_frame, next, head, links) {
  726. list_del(&cur_frame->links);
  727. kfree(cur_frame->fp);
  728. kfree(cur_frame);
  729. }
  730. }
  731. static void fnic_wq_complete_frame_send(struct vnic_wq *wq,
  732. struct cq_desc *cq_desc,
  733. struct vnic_wq_buf *buf, void *opaque)
  734. {
  735. struct fnic *fnic = vnic_dev_priv(wq->vdev);
  736. dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
  737. DMA_TO_DEVICE);
  738. mempool_free(buf->os_buf, fnic->frame_pool);
  739. buf->os_buf = NULL;
  740. }
  741. static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev,
  742. struct cq_desc *cq_desc, u8 type,
  743. u16 q_number, u16 completed_index,
  744. void *opaque)
  745. {
  746. struct fnic *fnic = vnic_dev_priv(vdev);
  747. unsigned long flags;
  748. spin_lock_irqsave(&fnic->wq_lock[q_number], flags);
  749. vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index,
  750. fnic_wq_complete_frame_send, NULL);
  751. spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags);
  752. return 0;
  753. }
  754. int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do)
  755. {
  756. unsigned int wq_work_done = 0;
  757. unsigned int i;
  758. for (i = 0; i < fnic->raw_wq_count; i++) {
  759. wq_work_done += vnic_cq_service(&fnic->cq[fnic->rq_count+i],
  760. work_to_do,
  761. fnic_wq_cmpl_handler_cont,
  762. NULL);
  763. }
  764. return wq_work_done;
  765. }
  766. void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
  767. {
  768. struct fnic *fnic = vnic_dev_priv(wq->vdev);
  769. dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
  770. DMA_TO_DEVICE);
  771. kfree(buf->os_buf);
  772. buf->os_buf = NULL;
  773. }
  774. void
  775. fnic_fdls_add_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport,
  776. unsigned long flags)
  777. {
  778. struct fnic *fnic = iport->fnic;
  779. struct fc_rport *rport;
  780. struct fc_rport_identifiers ids;
  781. struct rport_dd_data_s *rdd_data;
  782. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  783. "Adding rport fcid: 0x%x", tport->fcid);
  784. ids.node_name = tport->wwnn;
  785. ids.port_name = tport->wwpn;
  786. ids.port_id = tport->fcid;
  787. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  788. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  789. rport = fc_remote_port_add(fnic->host, 0, &ids);
  790. spin_lock_irqsave(&fnic->fnic_lock, flags);
  791. if (!rport) {
  792. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  793. "Failed to add rport for tport: 0x%x", tport->fcid);
  794. return;
  795. }
  796. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  797. "Added rport fcid: 0x%x", tport->fcid);
  798. /* Mimic these assignments in queuecommand to avoid timing issues */
  799. rport->maxframe_size = FNIC_FC_MAX_PAYLOAD_LEN;
  800. rport->supported_classes = FC_COS_CLASS3 | FC_RPORT_ROLE_FCP_TARGET;
  801. rdd_data = rport->dd_data;
  802. rdd_data->tport = tport;
  803. rdd_data->iport = iport;
  804. tport->rport = rport;
  805. tport->flags |= FNIC_FDLS_SCSI_REGISTERED;
  806. }
  807. void
  808. fnic_fdls_remove_tport(struct fnic_iport_s *iport,
  809. struct fnic_tport_s *tport, unsigned long flags)
  810. {
  811. struct fnic *fnic = iport->fnic;
  812. struct rport_dd_data_s *rdd_data;
  813. struct fc_rport *rport;
  814. if (!tport)
  815. return;
  816. fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINE);
  817. rport = tport->rport;
  818. if (rport) {
  819. /* tport resource release will be done
  820. * after fnic_terminate_rport_io()
  821. */
  822. tport->flags |= FNIC_FDLS_TPORT_DELETED;
  823. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  824. /* Interface to scsi_fc_transport */
  825. fc_remote_port_delete(rport);
  826. spin_lock_irqsave(&fnic->fnic_lock, flags);
  827. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  828. "Deregistered and freed tport fcid: 0x%x from scsi transport fc",
  829. tport->fcid);
  830. /*
  831. * the dd_data is allocated by fc transport
  832. * of size dd_fcrport_size
  833. */
  834. rdd_data = rport->dd_data;
  835. rdd_data->tport = NULL;
  836. rdd_data->iport = NULL;
  837. list_del(&tport->links);
  838. kfree(tport);
  839. } else {
  840. fnic_del_tport_timer_sync(fnic, tport);
  841. list_del(&tport->links);
  842. kfree(tport);
  843. }
  844. }
  845. void fnic_delete_fcp_tports(struct fnic *fnic)
  846. {
  847. struct fnic_tport_s *tport, *next;
  848. unsigned long flags;
  849. spin_lock_irqsave(&fnic->fnic_lock, flags);
  850. list_for_each_entry_safe(tport, next, &fnic->iport.tport_list, links) {
  851. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  852. "removing fcp rport fcid: 0x%x", tport->fcid);
  853. fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINING);
  854. fnic_del_tport_timer_sync(fnic, tport);
  855. fnic_fdls_remove_tport(&fnic->iport, tport, flags);
  856. }
  857. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  858. }
  859. /**
  860. * fnic_tport_event_handler() - Handler for remote port events
  861. * in the tport_event_queue.
  862. *
  863. * @work: Handle to the remote port being dequeued
  864. */
  865. void fnic_tport_event_handler(struct work_struct *work)
  866. {
  867. struct fnic *fnic = container_of(work, struct fnic, tport_work);
  868. struct fnic_tport_event_s *cur_evt, *next;
  869. unsigned long flags;
  870. struct fnic_tport_s *tport;
  871. spin_lock_irqsave(&fnic->fnic_lock, flags);
  872. list_for_each_entry_safe(cur_evt, next, &fnic->tport_event_list, links) {
  873. tport = cur_evt->arg1;
  874. switch (cur_evt->event) {
  875. case TGT_EV_RPORT_ADD:
  876. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  877. "Add rport event");
  878. if (tport->state == FDLS_TGT_STATE_READY) {
  879. fnic_fdls_add_tport(&fnic->iport,
  880. (struct fnic_tport_s *) cur_evt->arg1, flags);
  881. } else {
  882. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  883. "Target not ready. Add rport event dropped: 0x%x",
  884. tport->fcid);
  885. }
  886. break;
  887. case TGT_EV_RPORT_DEL:
  888. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  889. "Remove rport event");
  890. if (tport->state == FDLS_TGT_STATE_OFFLINING) {
  891. fnic_fdls_remove_tport(&fnic->iport,
  892. (struct fnic_tport_s *) cur_evt->arg1, flags);
  893. } else {
  894. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  895. "remove rport event dropped tport fcid: 0x%x",
  896. tport->fcid);
  897. }
  898. break;
  899. case TGT_EV_TPORT_DELETE:
  900. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  901. "Delete tport event");
  902. fdls_delete_tport(tport->iport, tport);
  903. break;
  904. default:
  905. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  906. "Unknown tport event");
  907. break;
  908. }
  909. list_del(&cur_evt->links);
  910. kfree(cur_evt);
  911. }
  912. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  913. }
  914. void fnic_flush_tport_event_list(struct fnic *fnic)
  915. {
  916. struct fnic_tport_event_s *cur_evt, *next;
  917. unsigned long flags;
  918. spin_lock_irqsave(&fnic->fnic_lock, flags);
  919. list_for_each_entry_safe(cur_evt, next, &fnic->tport_event_list, links) {
  920. list_del(&cur_evt->links);
  921. kfree(cur_evt);
  922. }
  923. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  924. }
  925. void fnic_reset_work_handler(struct work_struct *work)
  926. {
  927. struct fnic *cur_fnic, *next_fnic;
  928. unsigned long reset_fnic_list_lock_flags;
  929. int host_reset_ret_code;
  930. /*
  931. * This is a single thread. It is per fnic module, not per fnic
  932. * All the fnics that need to be reset
  933. * have been serialized via the reset fnic list.
  934. */
  935. spin_lock_irqsave(&reset_fnic_list_lock, reset_fnic_list_lock_flags);
  936. list_for_each_entry_safe(cur_fnic, next_fnic, &reset_fnic_list, links) {
  937. list_del(&cur_fnic->links);
  938. spin_unlock_irqrestore(&reset_fnic_list_lock,
  939. reset_fnic_list_lock_flags);
  940. dev_err(&cur_fnic->pdev->dev, "fnic: <%d>: issuing a host reset\n",
  941. cur_fnic->fnic_num);
  942. host_reset_ret_code = fnic_host_reset(cur_fnic->host);
  943. dev_err(&cur_fnic->pdev->dev,
  944. "fnic: <%d>: returned from host reset with status: %d\n",
  945. cur_fnic->fnic_num, host_reset_ret_code);
  946. spin_lock_irqsave(&cur_fnic->fnic_lock, cur_fnic->lock_flags);
  947. cur_fnic->pc_rscn_handling_status =
  948. PC_RSCN_HANDLING_NOT_IN_PROGRESS;
  949. spin_unlock_irqrestore(&cur_fnic->fnic_lock, cur_fnic->lock_flags);
  950. spin_lock_irqsave(&reset_fnic_list_lock,
  951. reset_fnic_list_lock_flags);
  952. }
  953. spin_unlock_irqrestore(&reset_fnic_list_lock,
  954. reset_fnic_list_lock_flags);
  955. }