zfcp_erp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. /*
  2. * zfcp device driver
  3. *
  4. * Error Recovery Procedures (ERP).
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. #define ZFCP_MAX_ERPS 3
  10. enum zfcp_erp_act_flags {
  11. ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
  12. ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
  13. ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
  14. ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
  15. ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
  16. };
  17. enum zfcp_erp_steps {
  18. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  19. ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
  20. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  21. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  22. ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
  23. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  24. ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
  25. ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
  26. };
  27. enum zfcp_erp_act_type {
  28. ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
  29. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  30. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  31. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  32. };
  33. enum zfcp_erp_act_state {
  34. ZFCP_ERP_ACTION_RUNNING = 1,
  35. ZFCP_ERP_ACTION_READY = 2,
  36. };
  37. enum zfcp_erp_act_result {
  38. ZFCP_ERP_SUCCEEDED = 0,
  39. ZFCP_ERP_FAILED = 1,
  40. ZFCP_ERP_CONTINUES = 2,
  41. ZFCP_ERP_EXIT = 3,
  42. ZFCP_ERP_DISMISSED = 4,
  43. ZFCP_ERP_NOMEM = 5,
  44. };
  45. static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
  46. {
  47. zfcp_erp_modify_adapter_status(adapter, 15, NULL,
  48. ZFCP_STATUS_COMMON_UNBLOCKED | mask,
  49. ZFCP_CLEAR);
  50. }
  51. static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
  52. {
  53. struct zfcp_erp_action *curr_act;
  54. list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
  55. if (act == curr_act)
  56. return ZFCP_ERP_ACTION_RUNNING;
  57. return 0;
  58. }
  59. static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
  60. {
  61. struct zfcp_adapter *adapter = act->adapter;
  62. list_move(&act->list, &act->adapter->erp_ready_head);
  63. zfcp_rec_dbf_event_action(146, act);
  64. up(&adapter->erp_ready_sem);
  65. zfcp_rec_dbf_event_thread(2, adapter);
  66. }
  67. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
  68. {
  69. act->status |= ZFCP_STATUS_ERP_DISMISSED;
  70. if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
  71. zfcp_erp_action_ready(act);
  72. }
  73. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  74. {
  75. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  76. zfcp_erp_action_dismiss(&unit->erp_action);
  77. }
  78. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  79. {
  80. struct zfcp_unit *unit;
  81. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  82. zfcp_erp_action_dismiss(&port->erp_action);
  83. else
  84. list_for_each_entry(unit, &port->unit_list_head, list)
  85. zfcp_erp_action_dismiss_unit(unit);
  86. }
  87. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  88. {
  89. struct zfcp_port *port;
  90. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  91. zfcp_erp_action_dismiss(&adapter->erp_action);
  92. else
  93. list_for_each_entry(port, &adapter->port_list_head, list)
  94. zfcp_erp_action_dismiss_port(port);
  95. }
  96. static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
  97. struct zfcp_port *port,
  98. struct zfcp_unit *unit)
  99. {
  100. int need = want;
  101. int u_status, p_status, a_status;
  102. switch (want) {
  103. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  104. u_status = atomic_read(&unit->status);
  105. if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  106. return 0;
  107. p_status = atomic_read(&port->status);
  108. if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
  109. p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  110. return 0;
  111. if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  112. need = ZFCP_ERP_ACTION_REOPEN_PORT;
  113. /* fall through */
  114. case ZFCP_ERP_ACTION_REOPEN_PORT:
  115. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  116. p_status = atomic_read(&port->status);
  117. if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  118. return 0;
  119. a_status = atomic_read(&adapter->status);
  120. if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
  121. a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  122. return 0;
  123. if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  124. need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  125. /* fall through */
  126. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  127. a_status = atomic_read(&adapter->status);
  128. if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  129. return 0;
  130. }
  131. return need;
  132. }
  133. static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
  134. struct zfcp_adapter *adapter,
  135. struct zfcp_port *port,
  136. struct zfcp_unit *unit)
  137. {
  138. struct zfcp_erp_action *erp_action;
  139. u32 status = 0;
  140. switch (need) {
  141. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  142. zfcp_unit_get(unit);
  143. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  144. erp_action = &unit->erp_action;
  145. if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
  146. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  147. break;
  148. case ZFCP_ERP_ACTION_REOPEN_PORT:
  149. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  150. zfcp_port_get(port);
  151. zfcp_erp_action_dismiss_port(port);
  152. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  153. erp_action = &port->erp_action;
  154. if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
  155. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  156. break;
  157. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  158. zfcp_adapter_get(adapter);
  159. zfcp_erp_action_dismiss_adapter(adapter);
  160. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  161. erp_action = &adapter->erp_action;
  162. if (!(atomic_read(&adapter->status) &
  163. ZFCP_STATUS_COMMON_RUNNING))
  164. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  165. break;
  166. default:
  167. return NULL;
  168. }
  169. memset(erp_action, 0, sizeof(struct zfcp_erp_action));
  170. erp_action->adapter = adapter;
  171. erp_action->port = port;
  172. erp_action->unit = unit;
  173. erp_action->action = need;
  174. erp_action->status = status;
  175. return erp_action;
  176. }
  177. static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
  178. struct zfcp_port *port,
  179. struct zfcp_unit *unit, u8 id, void *ref)
  180. {
  181. int retval = 1, need;
  182. struct zfcp_erp_action *act = NULL;
  183. if (!(atomic_read(&adapter->status) &
  184. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
  185. return -EIO;
  186. need = zfcp_erp_required_act(want, adapter, port, unit);
  187. if (!need)
  188. goto out;
  189. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  190. act = zfcp_erp_setup_act(need, adapter, port, unit);
  191. if (!act)
  192. goto out;
  193. ++adapter->erp_total_count;
  194. list_add_tail(&act->list, &adapter->erp_ready_head);
  195. up(&adapter->erp_ready_sem);
  196. zfcp_rec_dbf_event_thread(1, adapter);
  197. retval = 0;
  198. out:
  199. zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
  200. adapter, port, unit);
  201. return retval;
  202. }
  203. static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
  204. int clear_mask, u8 id, void *ref)
  205. {
  206. zfcp_erp_adapter_block(adapter, clear_mask);
  207. /* ensure propagation of failed status to new devices */
  208. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  209. zfcp_erp_adapter_failed(adapter, 13, NULL);
  210. return -EIO;
  211. }
  212. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  213. adapter, NULL, NULL, id, ref);
  214. }
  215. /**
  216. * zfcp_erp_adapter_reopen - Reopen adapter.
  217. * @adapter: Adapter to reopen.
  218. * @clear: Status flags to clear.
  219. * @id: Id for debug trace event.
  220. * @ref: Reference for debug trace event.
  221. */
  222. void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
  223. u8 id, void *ref)
  224. {
  225. unsigned long flags;
  226. read_lock_irqsave(&zfcp_data.config_lock, flags);
  227. write_lock(&adapter->erp_lock);
  228. _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
  229. write_unlock(&adapter->erp_lock);
  230. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  231. }
  232. /**
  233. * zfcp_erp_adapter_shutdown - Shutdown adapter.
  234. * @adapter: Adapter to shut down.
  235. * @clear: Status flags to clear.
  236. * @id: Id for debug trace event.
  237. * @ref: Reference for debug trace event.
  238. */
  239. void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
  240. u8 id, void *ref)
  241. {
  242. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  243. zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
  244. }
  245. /**
  246. * zfcp_erp_port_shutdown - Shutdown port
  247. * @port: Port to shut down.
  248. * @clear: Status flags to clear.
  249. * @id: Id for debug trace event.
  250. * @ref: Reference for debug trace event.
  251. */
  252. void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
  253. {
  254. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  255. zfcp_erp_port_reopen(port, clear | flags, id, ref);
  256. }
  257. /**
  258. * zfcp_erp_unit_shutdown - Shutdown unit
  259. * @unit: Unit to shut down.
  260. * @clear: Status flags to clear.
  261. * @id: Id for debug trace event.
  262. * @ref: Reference for debug trace event.
  263. */
  264. void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  265. {
  266. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  267. zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
  268. }
  269. static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
  270. {
  271. zfcp_erp_modify_port_status(port, 17, NULL,
  272. ZFCP_STATUS_COMMON_UNBLOCKED | clear,
  273. ZFCP_CLEAR);
  274. }
  275. static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
  276. int clear, u8 id, void *ref)
  277. {
  278. zfcp_erp_port_block(port, clear);
  279. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  280. return;
  281. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  282. port->adapter, port, NULL, id, ref);
  283. }
  284. /**
  285. * zfcp_erp_port_forced_reopen - Forced close of port and open again
  286. * @port: Port to force close and to reopen.
  287. * @id: Id for debug trace event.
  288. * @ref: Reference for debug trace event.
  289. */
  290. void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
  291. void *ref)
  292. {
  293. unsigned long flags;
  294. struct zfcp_adapter *adapter = port->adapter;
  295. read_lock_irqsave(&zfcp_data.config_lock, flags);
  296. write_lock(&adapter->erp_lock);
  297. _zfcp_erp_port_forced_reopen(port, clear, id, ref);
  298. write_unlock(&adapter->erp_lock);
  299. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  300. }
  301. static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
  302. void *ref)
  303. {
  304. zfcp_erp_port_block(port, clear);
  305. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  306. /* ensure propagation of failed status to new devices */
  307. zfcp_erp_port_failed(port, 14, NULL);
  308. return -EIO;
  309. }
  310. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  311. port->adapter, port, NULL, id, ref);
  312. }
  313. /**
  314. * zfcp_erp_port_reopen - trigger remote port recovery
  315. * @port: port to recover
  316. * @clear_mask: flags in port status to be cleared
  317. *
  318. * Returns 0 if recovery has been triggered, < 0 if not.
  319. */
  320. int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
  321. {
  322. unsigned long flags;
  323. int retval;
  324. struct zfcp_adapter *adapter = port->adapter;
  325. read_lock_irqsave(&zfcp_data.config_lock, flags);
  326. write_lock(&adapter->erp_lock);
  327. retval = _zfcp_erp_port_reopen(port, clear, id, ref);
  328. write_unlock(&adapter->erp_lock);
  329. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  330. return retval;
  331. }
  332. static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  333. {
  334. zfcp_erp_modify_unit_status(unit, 19, NULL,
  335. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  336. ZFCP_CLEAR);
  337. }
  338. static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
  339. void *ref)
  340. {
  341. struct zfcp_adapter *adapter = unit->port->adapter;
  342. zfcp_erp_unit_block(unit, clear);
  343. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  344. return;
  345. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  346. adapter, unit->port, unit, id, ref);
  347. }
  348. /**
  349. * zfcp_erp_unit_reopen - initiate reopen of a unit
  350. * @unit: unit to be reopened
  351. * @clear_mask: specifies flags in unit status to be cleared
  352. * Return: 0 on success, < 0 on error
  353. */
  354. void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  355. {
  356. unsigned long flags;
  357. struct zfcp_port *port = unit->port;
  358. struct zfcp_adapter *adapter = port->adapter;
  359. read_lock_irqsave(&zfcp_data.config_lock, flags);
  360. write_lock(&adapter->erp_lock);
  361. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  362. write_unlock(&adapter->erp_lock);
  363. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  364. }
  365. static int status_change_set(unsigned long mask, atomic_t *status)
  366. {
  367. return (atomic_read(status) ^ mask) & mask;
  368. }
  369. static int status_change_clear(unsigned long mask, atomic_t *status)
  370. {
  371. return atomic_read(status) & mask;
  372. }
  373. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  374. {
  375. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
  376. zfcp_rec_dbf_event_adapter(16, NULL, adapter);
  377. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  378. }
  379. static void zfcp_erp_port_unblock(struct zfcp_port *port)
  380. {
  381. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
  382. zfcp_rec_dbf_event_port(18, NULL, port);
  383. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  384. }
  385. static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  386. {
  387. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
  388. zfcp_rec_dbf_event_unit(20, NULL, unit);
  389. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  390. }
  391. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  392. {
  393. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  394. zfcp_rec_dbf_event_action(145, erp_action);
  395. }
  396. static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
  397. {
  398. struct zfcp_adapter *adapter = act->adapter;
  399. if (!act->fsf_req)
  400. return;
  401. spin_lock(&adapter->req_list_lock);
  402. if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
  403. act->fsf_req->erp_action == act) {
  404. if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
  405. ZFCP_STATUS_ERP_TIMEDOUT)) {
  406. act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  407. zfcp_rec_dbf_event_action(142, act);
  408. act->fsf_req->erp_action = NULL;
  409. }
  410. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  411. zfcp_rec_dbf_event_action(143, act);
  412. if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  413. ZFCP_STATUS_FSFREQ_DISMISSED))
  414. act->fsf_req = NULL;
  415. } else
  416. act->fsf_req = NULL;
  417. spin_unlock(&adapter->req_list_lock);
  418. }
  419. /**
  420. * zfcp_erp_notify - Trigger ERP action.
  421. * @erp_action: ERP action to continue.
  422. * @set_mask: ERP action status flags to set.
  423. */
  424. void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
  425. {
  426. struct zfcp_adapter *adapter = erp_action->adapter;
  427. unsigned long flags;
  428. write_lock_irqsave(&adapter->erp_lock, flags);
  429. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  430. erp_action->status |= set_mask;
  431. zfcp_erp_action_ready(erp_action);
  432. }
  433. write_unlock_irqrestore(&adapter->erp_lock, flags);
  434. }
  435. /**
  436. * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
  437. * @data: ERP action (from timer data)
  438. */
  439. void zfcp_erp_timeout_handler(unsigned long data)
  440. {
  441. struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
  442. zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
  443. }
  444. static void zfcp_erp_memwait_handler(unsigned long data)
  445. {
  446. zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
  447. }
  448. static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  449. {
  450. init_timer(&erp_action->timer);
  451. erp_action->timer.function = zfcp_erp_memwait_handler;
  452. erp_action->timer.data = (unsigned long) erp_action;
  453. erp_action->timer.expires = jiffies + HZ;
  454. add_timer(&erp_action->timer);
  455. }
  456. static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
  457. int clear, u8 id, void *ref)
  458. {
  459. struct zfcp_port *port;
  460. list_for_each_entry(port, &adapter->port_list_head, list)
  461. _zfcp_erp_port_reopen(port, clear, id, ref);
  462. }
  463. static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
  464. void *ref)
  465. {
  466. struct zfcp_unit *unit;
  467. list_for_each_entry(unit, &port->unit_list_head, list)
  468. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  469. }
  470. static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
  471. {
  472. struct zfcp_adapter *adapter = act->adapter;
  473. struct zfcp_port *port = act->port;
  474. struct zfcp_unit *unit = act->unit;
  475. u32 status = act->status;
  476. /* initiate follow-up actions depending on success of finished action */
  477. switch (act->action) {
  478. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  479. if (status == ZFCP_ERP_SUCCEEDED)
  480. _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
  481. else
  482. _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
  483. break;
  484. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  485. if (status == ZFCP_ERP_SUCCEEDED)
  486. _zfcp_erp_port_reopen(port, 0, 72, NULL);
  487. else
  488. _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
  489. break;
  490. case ZFCP_ERP_ACTION_REOPEN_PORT:
  491. if (status == ZFCP_ERP_SUCCEEDED)
  492. _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
  493. else
  494. _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
  495. break;
  496. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  497. if (status != ZFCP_ERP_SUCCEEDED)
  498. _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
  499. break;
  500. }
  501. }
  502. static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
  503. {
  504. unsigned long flags;
  505. read_lock_irqsave(&zfcp_data.config_lock, flags);
  506. read_lock(&adapter->erp_lock);
  507. if (list_empty(&adapter->erp_ready_head) &&
  508. list_empty(&adapter->erp_running_head)) {
  509. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  510. &adapter->status);
  511. wake_up(&adapter->erp_done_wqh);
  512. }
  513. read_unlock(&adapter->erp_lock);
  514. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  515. }
  516. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
  517. {
  518. if (zfcp_qdio_open(act->adapter))
  519. return ZFCP_ERP_FAILED;
  520. init_waitqueue_head(&act->adapter->request_wq);
  521. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
  522. return ZFCP_ERP_SUCCEEDED;
  523. }
  524. static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
  525. {
  526. struct zfcp_port *port;
  527. port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
  528. adapter->peer_d_id);
  529. if (IS_ERR(port)) /* error or port already attached */
  530. return;
  531. _zfcp_erp_port_reopen(port, 0, 150, NULL);
  532. }
  533. static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
  534. {
  535. int retries;
  536. int sleep = 1;
  537. struct zfcp_adapter *adapter = erp_action->adapter;
  538. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  539. for (retries = 7; retries; retries--) {
  540. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  541. &adapter->status);
  542. write_lock_irq(&adapter->erp_lock);
  543. zfcp_erp_action_to_running(erp_action);
  544. write_unlock_irq(&adapter->erp_lock);
  545. if (zfcp_fsf_exchange_config_data(erp_action)) {
  546. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  547. &adapter->status);
  548. return ZFCP_ERP_FAILED;
  549. }
  550. zfcp_rec_dbf_event_thread_lock(6, adapter);
  551. down(&adapter->erp_ready_sem);
  552. zfcp_rec_dbf_event_thread_lock(7, adapter);
  553. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
  554. break;
  555. if (!(atomic_read(&adapter->status) &
  556. ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
  557. break;
  558. ssleep(sleep);
  559. sleep *= 2;
  560. }
  561. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  562. &adapter->status);
  563. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
  564. return ZFCP_ERP_FAILED;
  565. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  566. zfcp_erp_enqueue_ptp_port(adapter);
  567. return ZFCP_ERP_SUCCEEDED;
  568. }
  569. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
  570. {
  571. int ret;
  572. struct zfcp_adapter *adapter = act->adapter;
  573. write_lock_irq(&adapter->erp_lock);
  574. zfcp_erp_action_to_running(act);
  575. write_unlock_irq(&adapter->erp_lock);
  576. ret = zfcp_fsf_exchange_port_data(act);
  577. if (ret == -EOPNOTSUPP)
  578. return ZFCP_ERP_SUCCEEDED;
  579. if (ret)
  580. return ZFCP_ERP_FAILED;
  581. zfcp_rec_dbf_event_thread_lock(8, adapter);
  582. down(&adapter->erp_ready_sem);
  583. zfcp_rec_dbf_event_thread_lock(9, adapter);
  584. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  585. return ZFCP_ERP_FAILED;
  586. return ZFCP_ERP_SUCCEEDED;
  587. }
  588. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
  589. {
  590. if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
  591. return ZFCP_ERP_FAILED;
  592. if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
  593. return ZFCP_ERP_FAILED;
  594. atomic_set(&act->adapter->stat_miss, 16);
  595. if (zfcp_status_read_refill(act->adapter))
  596. return ZFCP_ERP_FAILED;
  597. return ZFCP_ERP_SUCCEEDED;
  598. }
  599. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
  600. int close)
  601. {
  602. int retval = ZFCP_ERP_SUCCEEDED;
  603. struct zfcp_adapter *adapter = act->adapter;
  604. if (close)
  605. goto close_only;
  606. retval = zfcp_erp_adapter_strategy_open_qdio(act);
  607. if (retval != ZFCP_ERP_SUCCEEDED)
  608. goto failed_qdio;
  609. retval = zfcp_erp_adapter_strategy_open_fsf(act);
  610. if (retval != ZFCP_ERP_SUCCEEDED)
  611. goto failed_openfcp;
  612. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
  613. return ZFCP_ERP_SUCCEEDED;
  614. close_only:
  615. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  616. &act->adapter->status);
  617. failed_openfcp:
  618. /* close queues to ensure that buffers are not accessed by adapter */
  619. zfcp_qdio_close(adapter);
  620. zfcp_fsf_req_dismiss_all(adapter);
  621. adapter->fsf_req_seq_no = 0;
  622. /* all ports and units are closed */
  623. zfcp_erp_modify_adapter_status(adapter, 24, NULL,
  624. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  625. failed_qdio:
  626. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  627. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  628. &act->adapter->status);
  629. return retval;
  630. }
  631. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  632. {
  633. int retval;
  634. zfcp_erp_adapter_strategy_generic(act, 1); /* close */
  635. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  636. return ZFCP_ERP_EXIT;
  637. retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
  638. if (retval == ZFCP_ERP_FAILED)
  639. ssleep(8);
  640. return retval;
  641. }
  642. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  643. {
  644. int retval;
  645. retval = zfcp_fsf_close_physical_port(act);
  646. if (retval == -ENOMEM)
  647. return ZFCP_ERP_NOMEM;
  648. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  649. if (retval)
  650. return ZFCP_ERP_FAILED;
  651. return ZFCP_ERP_CONTINUES;
  652. }
  653. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  654. {
  655. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  656. ZFCP_STATUS_PORT_PHYS_CLOSING |
  657. ZFCP_STATUS_PORT_INVALID_WWPN,
  658. &port->status);
  659. }
  660. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  661. {
  662. struct zfcp_port *port = erp_action->port;
  663. int status = atomic_read(&port->status);
  664. switch (erp_action->step) {
  665. case ZFCP_ERP_STEP_UNINITIALIZED:
  666. zfcp_erp_port_strategy_clearstati(port);
  667. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  668. (status & ZFCP_STATUS_COMMON_OPEN))
  669. return zfcp_erp_port_forced_strategy_close(erp_action);
  670. else
  671. return ZFCP_ERP_FAILED;
  672. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  673. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  674. return ZFCP_ERP_SUCCEEDED;
  675. }
  676. return ZFCP_ERP_FAILED;
  677. }
  678. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  679. {
  680. int retval;
  681. retval = zfcp_fsf_close_port(erp_action);
  682. if (retval == -ENOMEM)
  683. return ZFCP_ERP_NOMEM;
  684. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  685. if (retval)
  686. return ZFCP_ERP_FAILED;
  687. return ZFCP_ERP_CONTINUES;
  688. }
  689. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  690. {
  691. int retval;
  692. retval = zfcp_fsf_open_port(erp_action);
  693. if (retval == -ENOMEM)
  694. return ZFCP_ERP_NOMEM;
  695. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  696. if (retval)
  697. return ZFCP_ERP_FAILED;
  698. return ZFCP_ERP_CONTINUES;
  699. }
  700. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  701. {
  702. struct zfcp_adapter *adapter = act->adapter;
  703. struct zfcp_port *port = act->port;
  704. if (port->wwpn != adapter->peer_wwpn) {
  705. zfcp_erp_port_failed(port, 25, NULL);
  706. return ZFCP_ERP_FAILED;
  707. }
  708. port->d_id = adapter->peer_d_id;
  709. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  710. return zfcp_erp_port_strategy_open_port(act);
  711. }
  712. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  713. {
  714. int retval;
  715. struct zfcp_port *port = container_of(work, struct zfcp_port,
  716. gid_pn_work);
  717. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  718. if (retval == -ENOMEM)
  719. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  720. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  721. if (retval)
  722. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  723. }
  724. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  725. {
  726. struct zfcp_adapter *adapter = act->adapter;
  727. struct zfcp_port *port = act->port;
  728. int p_status = atomic_read(&port->status);
  729. switch (act->step) {
  730. case ZFCP_ERP_STEP_UNINITIALIZED:
  731. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  732. case ZFCP_ERP_STEP_PORT_CLOSING:
  733. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  734. return zfcp_erp_open_ptp_port(act);
  735. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  736. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  737. return ZFCP_ERP_CONTINUES;
  738. }
  739. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  740. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  741. if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
  742. zfcp_erp_port_failed(port, 26, NULL);
  743. return ZFCP_ERP_EXIT;
  744. }
  745. return ZFCP_ERP_FAILED;
  746. }
  747. return zfcp_erp_port_strategy_open_port(act);
  748. case ZFCP_ERP_STEP_PORT_OPENING:
  749. /* D_ID might have changed during open */
  750. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  751. if (p_status & ZFCP_STATUS_PORT_DID_DID)
  752. return ZFCP_ERP_SUCCEEDED;
  753. else {
  754. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  755. return ZFCP_ERP_CONTINUES;
  756. }
  757. /* fall through otherwise */
  758. }
  759. }
  760. return ZFCP_ERP_FAILED;
  761. }
  762. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  763. {
  764. struct zfcp_port *port = erp_action->port;
  765. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  766. goto close_init_done;
  767. switch (erp_action->step) {
  768. case ZFCP_ERP_STEP_UNINITIALIZED:
  769. zfcp_erp_port_strategy_clearstati(port);
  770. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  771. return zfcp_erp_port_strategy_close(erp_action);
  772. break;
  773. case ZFCP_ERP_STEP_PORT_CLOSING:
  774. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  775. return ZFCP_ERP_FAILED;
  776. break;
  777. }
  778. close_init_done:
  779. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  780. return ZFCP_ERP_EXIT;
  781. return zfcp_erp_port_strategy_open_common(erp_action);
  782. }
  783. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  784. {
  785. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  786. ZFCP_STATUS_UNIT_SHARED |
  787. ZFCP_STATUS_UNIT_READONLY,
  788. &unit->status);
  789. }
  790. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  791. {
  792. int retval = zfcp_fsf_close_unit(erp_action);
  793. if (retval == -ENOMEM)
  794. return ZFCP_ERP_NOMEM;
  795. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  796. if (retval)
  797. return ZFCP_ERP_FAILED;
  798. return ZFCP_ERP_CONTINUES;
  799. }
  800. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  801. {
  802. int retval = zfcp_fsf_open_unit(erp_action);
  803. if (retval == -ENOMEM)
  804. return ZFCP_ERP_NOMEM;
  805. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  806. if (retval)
  807. return ZFCP_ERP_FAILED;
  808. return ZFCP_ERP_CONTINUES;
  809. }
  810. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  811. {
  812. struct zfcp_unit *unit = erp_action->unit;
  813. switch (erp_action->step) {
  814. case ZFCP_ERP_STEP_UNINITIALIZED:
  815. zfcp_erp_unit_strategy_clearstati(unit);
  816. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  817. return zfcp_erp_unit_strategy_close(erp_action);
  818. /* already closed, fall through */
  819. case ZFCP_ERP_STEP_UNIT_CLOSING:
  820. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  821. return ZFCP_ERP_FAILED;
  822. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  823. return ZFCP_ERP_EXIT;
  824. return zfcp_erp_unit_strategy_open(erp_action);
  825. case ZFCP_ERP_STEP_UNIT_OPENING:
  826. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  827. return ZFCP_ERP_SUCCEEDED;
  828. }
  829. return ZFCP_ERP_FAILED;
  830. }
  831. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  832. {
  833. switch (result) {
  834. case ZFCP_ERP_SUCCEEDED :
  835. atomic_set(&unit->erp_counter, 0);
  836. zfcp_erp_unit_unblock(unit);
  837. break;
  838. case ZFCP_ERP_FAILED :
  839. atomic_inc(&unit->erp_counter);
  840. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  841. dev_err(&unit->port->adapter->ccw_device->dev,
  842. "ERP failed for unit 0x%016Lx on "
  843. "port 0x%016Lx\n",
  844. (unsigned long long)unit->fcp_lun,
  845. (unsigned long long)unit->port->wwpn);
  846. zfcp_erp_unit_failed(unit, 21, NULL);
  847. }
  848. break;
  849. }
  850. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  851. zfcp_erp_unit_block(unit, 0);
  852. result = ZFCP_ERP_EXIT;
  853. }
  854. return result;
  855. }
  856. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  857. {
  858. switch (result) {
  859. case ZFCP_ERP_SUCCEEDED :
  860. atomic_set(&port->erp_counter, 0);
  861. zfcp_erp_port_unblock(port);
  862. break;
  863. case ZFCP_ERP_FAILED :
  864. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  865. zfcp_erp_port_block(port, 0);
  866. result = ZFCP_ERP_EXIT;
  867. }
  868. atomic_inc(&port->erp_counter);
  869. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  870. dev_err(&port->adapter->ccw_device->dev,
  871. "ERP failed for remote port 0x%016Lx\n",
  872. (unsigned long long)port->wwpn);
  873. zfcp_erp_port_failed(port, 22, NULL);
  874. }
  875. break;
  876. }
  877. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  878. zfcp_erp_port_block(port, 0);
  879. result = ZFCP_ERP_EXIT;
  880. }
  881. return result;
  882. }
  883. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  884. int result)
  885. {
  886. switch (result) {
  887. case ZFCP_ERP_SUCCEEDED :
  888. atomic_set(&adapter->erp_counter, 0);
  889. zfcp_erp_adapter_unblock(adapter);
  890. break;
  891. case ZFCP_ERP_FAILED :
  892. atomic_inc(&adapter->erp_counter);
  893. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  894. dev_err(&adapter->ccw_device->dev,
  895. "ERP cannot recover an error "
  896. "on the FCP device\n");
  897. zfcp_erp_adapter_failed(adapter, 23, NULL);
  898. }
  899. break;
  900. }
  901. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  902. zfcp_erp_adapter_block(adapter, 0);
  903. result = ZFCP_ERP_EXIT;
  904. }
  905. return result;
  906. }
  907. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  908. int result)
  909. {
  910. struct zfcp_adapter *adapter = erp_action->adapter;
  911. struct zfcp_port *port = erp_action->port;
  912. struct zfcp_unit *unit = erp_action->unit;
  913. switch (erp_action->action) {
  914. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  915. result = zfcp_erp_strategy_check_unit(unit, result);
  916. break;
  917. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  918. case ZFCP_ERP_ACTION_REOPEN_PORT:
  919. result = zfcp_erp_strategy_check_port(port, result);
  920. break;
  921. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  922. result = zfcp_erp_strategy_check_adapter(adapter, result);
  923. break;
  924. }
  925. return result;
  926. }
  927. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  928. {
  929. int status = atomic_read(target_status);
  930. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  931. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  932. return 1; /* take it online */
  933. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  934. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  935. return 1; /* take it offline */
  936. return 0;
  937. }
  938. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  939. {
  940. int action = act->action;
  941. struct zfcp_adapter *adapter = act->adapter;
  942. struct zfcp_port *port = act->port;
  943. struct zfcp_unit *unit = act->unit;
  944. u32 erp_status = act->status;
  945. switch (action) {
  946. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  947. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  948. _zfcp_erp_adapter_reopen(adapter,
  949. ZFCP_STATUS_COMMON_ERP_FAILED,
  950. 67, NULL);
  951. return ZFCP_ERP_EXIT;
  952. }
  953. break;
  954. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  955. case ZFCP_ERP_ACTION_REOPEN_PORT:
  956. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  957. _zfcp_erp_port_reopen(port,
  958. ZFCP_STATUS_COMMON_ERP_FAILED,
  959. 68, NULL);
  960. return ZFCP_ERP_EXIT;
  961. }
  962. break;
  963. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  964. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  965. _zfcp_erp_unit_reopen(unit,
  966. ZFCP_STATUS_COMMON_ERP_FAILED,
  967. 69, NULL);
  968. return ZFCP_ERP_EXIT;
  969. }
  970. break;
  971. }
  972. return ret;
  973. }
  974. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  975. {
  976. struct zfcp_adapter *adapter = erp_action->adapter;
  977. adapter->erp_total_count--;
  978. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  979. adapter->erp_low_mem_count--;
  980. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  981. }
  982. list_del(&erp_action->list);
  983. zfcp_rec_dbf_event_action(144, erp_action);
  984. switch (erp_action->action) {
  985. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  986. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  987. &erp_action->unit->status);
  988. break;
  989. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  990. case ZFCP_ERP_ACTION_REOPEN_PORT:
  991. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  992. &erp_action->port->status);
  993. break;
  994. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  995. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  996. &erp_action->adapter->status);
  997. break;
  998. }
  999. }
  1000. struct zfcp_erp_add_work {
  1001. struct zfcp_unit *unit;
  1002. struct work_struct work;
  1003. };
  1004. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1005. {
  1006. struct zfcp_erp_add_work *p =
  1007. container_of(work, struct zfcp_erp_add_work, work);
  1008. struct zfcp_unit *unit = p->unit;
  1009. struct fc_rport *rport = unit->port->rport;
  1010. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  1011. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1012. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1013. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1014. zfcp_unit_put(unit);
  1015. wake_up(&unit->port->adapter->erp_done_wqh);
  1016. kfree(p);
  1017. }
  1018. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1019. {
  1020. struct zfcp_erp_add_work *p;
  1021. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1022. if (!p) {
  1023. dev_err(&unit->port->adapter->ccw_device->dev,
  1024. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1025. (unsigned long long)unit->fcp_lun,
  1026. (unsigned long long)unit->port->wwpn);
  1027. return;
  1028. }
  1029. zfcp_unit_get(unit);
  1030. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1031. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1032. p->unit = unit;
  1033. queue_work(zfcp_data.work_queue, &p->work);
  1034. }
  1035. static void zfcp_erp_rport_register(struct zfcp_port *port)
  1036. {
  1037. struct fc_rport_identifiers ids;
  1038. ids.node_name = port->wwnn;
  1039. ids.port_name = port->wwpn;
  1040. ids.port_id = port->d_id;
  1041. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  1042. port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  1043. if (!port->rport) {
  1044. dev_err(&port->adapter->ccw_device->dev,
  1045. "Registering port 0x%016Lx failed\n",
  1046. (unsigned long long)port->wwpn);
  1047. return;
  1048. }
  1049. scsi_target_unblock(&port->rport->dev);
  1050. port->rport->maxframe_size = port->maxframe_size;
  1051. port->rport->supported_classes = port->supported_classes;
  1052. }
  1053. static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
  1054. {
  1055. struct zfcp_port *port;
  1056. list_for_each_entry(port, &adapter->port_list_head, list) {
  1057. if (!port->rport)
  1058. continue;
  1059. fc_remote_port_delete(port->rport);
  1060. port->rport = NULL;
  1061. }
  1062. }
  1063. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1064. {
  1065. struct zfcp_adapter *adapter = act->adapter;
  1066. struct zfcp_port *port = act->port;
  1067. struct zfcp_unit *unit = act->unit;
  1068. switch (act->action) {
  1069. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1070. if ((result == ZFCP_ERP_SUCCEEDED) &&
  1071. !unit->device && port->rport) {
  1072. atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
  1073. &unit->status);
  1074. if (!(atomic_read(&unit->status) &
  1075. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1076. zfcp_erp_schedule_work(unit);
  1077. }
  1078. zfcp_unit_put(unit);
  1079. break;
  1080. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1081. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1082. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
  1083. zfcp_port_put(port);
  1084. return;
  1085. }
  1086. if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
  1087. zfcp_erp_rport_register(port);
  1088. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  1089. fc_remote_port_delete(port->rport);
  1090. port->rport = NULL;
  1091. }
  1092. zfcp_port_put(port);
  1093. break;
  1094. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1095. if (result != ZFCP_ERP_SUCCEEDED) {
  1096. unregister_service_level(&adapter->service_level);
  1097. zfcp_erp_rports_del(adapter);
  1098. } else {
  1099. register_service_level(&adapter->service_level);
  1100. schedule_work(&adapter->scan_work);
  1101. }
  1102. zfcp_adapter_put(adapter);
  1103. break;
  1104. }
  1105. }
  1106. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1107. {
  1108. switch (erp_action->action) {
  1109. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1110. return zfcp_erp_adapter_strategy(erp_action);
  1111. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1112. return zfcp_erp_port_forced_strategy(erp_action);
  1113. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1114. return zfcp_erp_port_strategy(erp_action);
  1115. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1116. return zfcp_erp_unit_strategy(erp_action);
  1117. }
  1118. return ZFCP_ERP_FAILED;
  1119. }
  1120. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1121. {
  1122. int retval;
  1123. struct zfcp_adapter *adapter = erp_action->adapter;
  1124. unsigned long flags;
  1125. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1126. write_lock(&adapter->erp_lock);
  1127. zfcp_erp_strategy_check_fsfreq(erp_action);
  1128. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1129. zfcp_erp_action_dequeue(erp_action);
  1130. retval = ZFCP_ERP_DISMISSED;
  1131. goto unlock;
  1132. }
  1133. zfcp_erp_action_to_running(erp_action);
  1134. /* no lock to allow for blocking operations */
  1135. write_unlock(&adapter->erp_lock);
  1136. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1137. retval = zfcp_erp_strategy_do_action(erp_action);
  1138. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1139. write_lock(&adapter->erp_lock);
  1140. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1141. retval = ZFCP_ERP_CONTINUES;
  1142. switch (retval) {
  1143. case ZFCP_ERP_NOMEM:
  1144. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1145. ++adapter->erp_low_mem_count;
  1146. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1147. }
  1148. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1149. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1150. else {
  1151. zfcp_erp_strategy_memwait(erp_action);
  1152. retval = ZFCP_ERP_CONTINUES;
  1153. }
  1154. goto unlock;
  1155. case ZFCP_ERP_CONTINUES:
  1156. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1157. --adapter->erp_low_mem_count;
  1158. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1159. }
  1160. goto unlock;
  1161. }
  1162. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1163. zfcp_erp_action_dequeue(erp_action);
  1164. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1165. if (retval == ZFCP_ERP_EXIT)
  1166. goto unlock;
  1167. zfcp_erp_strategy_followup_actions(erp_action);
  1168. unlock:
  1169. write_unlock(&adapter->erp_lock);
  1170. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1171. if (retval != ZFCP_ERP_CONTINUES)
  1172. zfcp_erp_action_cleanup(erp_action, retval);
  1173. return retval;
  1174. }
  1175. static int zfcp_erp_thread(void *data)
  1176. {
  1177. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1178. struct list_head *next;
  1179. struct zfcp_erp_action *act;
  1180. unsigned long flags;
  1181. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1182. /* Block all signals */
  1183. siginitsetinv(&current->blocked, 0);
  1184. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1185. wake_up(&adapter->erp_thread_wqh);
  1186. while (!(atomic_read(&adapter->status) &
  1187. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1188. write_lock_irqsave(&adapter->erp_lock, flags);
  1189. next = adapter->erp_ready_head.next;
  1190. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1191. if (next != &adapter->erp_ready_head) {
  1192. act = list_entry(next, struct zfcp_erp_action, list);
  1193. /* there is more to come after dismission, no notify */
  1194. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1195. zfcp_erp_wakeup(adapter);
  1196. }
  1197. zfcp_rec_dbf_event_thread_lock(4, adapter);
  1198. down_interruptible(&adapter->erp_ready_sem);
  1199. zfcp_rec_dbf_event_thread_lock(5, adapter);
  1200. }
  1201. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1202. wake_up(&adapter->erp_thread_wqh);
  1203. return 0;
  1204. }
  1205. /**
  1206. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1207. * @adapter: Adapter to start the ERP thread for
  1208. *
  1209. * Returns 0 on success or error code from kernel_thread()
  1210. */
  1211. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1212. {
  1213. int retval;
  1214. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1215. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1216. if (retval < 0) {
  1217. dev_err(&adapter->ccw_device->dev,
  1218. "Creating an ERP thread for the FCP device failed.\n");
  1219. return retval;
  1220. }
  1221. wait_event(adapter->erp_thread_wqh,
  1222. atomic_read(&adapter->status) &
  1223. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1224. return 0;
  1225. }
  1226. /**
  1227. * zfcp_erp_thread_kill - Stop ERP thread.
  1228. * @adapter: Adapter where the ERP thread should be stopped.
  1229. *
  1230. * The caller of this routine ensures that the specified adapter has
  1231. * been shut down and that this operation has been completed. Thus,
  1232. * there are no pending erp_actions which would need to be handled
  1233. * here.
  1234. */
  1235. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1236. {
  1237. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1238. up(&adapter->erp_ready_sem);
  1239. zfcp_rec_dbf_event_thread_lock(3, adapter);
  1240. wait_event(adapter->erp_thread_wqh,
  1241. !(atomic_read(&adapter->status) &
  1242. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1243. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1244. &adapter->status);
  1245. }
  1246. /**
  1247. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1248. * @adapter: Failed adapter.
  1249. * @id: Event id for debug trace.
  1250. * @ref: Reference for debug trace.
  1251. */
  1252. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1253. {
  1254. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1255. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1256. }
  1257. /**
  1258. * zfcp_erp_port_failed - Set port status to failed.
  1259. * @port: Failed port.
  1260. * @id: Event id for debug trace.
  1261. * @ref: Reference for debug trace.
  1262. */
  1263. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1264. {
  1265. zfcp_erp_modify_port_status(port, id, ref,
  1266. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1267. }
  1268. /**
  1269. * zfcp_erp_unit_failed - Set unit status to failed.
  1270. * @unit: Failed unit.
  1271. * @id: Event id for debug trace.
  1272. * @ref: Reference for debug trace.
  1273. */
  1274. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1275. {
  1276. zfcp_erp_modify_unit_status(unit, id, ref,
  1277. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1278. }
  1279. /**
  1280. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1281. * @adapter: adapter for which to wait for completion of its error recovery
  1282. */
  1283. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1284. {
  1285. wait_event(adapter->erp_done_wqh,
  1286. !(atomic_read(&adapter->status) &
  1287. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1288. }
  1289. /**
  1290. * zfcp_erp_modify_adapter_status - change adapter status bits
  1291. * @adapter: adapter to change the status
  1292. * @id: id for the debug trace
  1293. * @ref: reference for the debug trace
  1294. * @mask: status bits to change
  1295. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1296. *
  1297. * Changes in common status bits are propagated to attached ports and units.
  1298. */
  1299. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1300. void *ref, u32 mask, int set_or_clear)
  1301. {
  1302. struct zfcp_port *port;
  1303. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1304. if (set_or_clear == ZFCP_SET) {
  1305. if (status_change_set(mask, &adapter->status))
  1306. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1307. atomic_set_mask(mask, &adapter->status);
  1308. } else {
  1309. if (status_change_clear(mask, &adapter->status))
  1310. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1311. atomic_clear_mask(mask, &adapter->status);
  1312. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1313. atomic_set(&adapter->erp_counter, 0);
  1314. }
  1315. if (common_mask)
  1316. list_for_each_entry(port, &adapter->port_list_head, list)
  1317. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1318. set_or_clear);
  1319. }
  1320. /**
  1321. * zfcp_erp_modify_port_status - change port status bits
  1322. * @port: port to change the status bits
  1323. * @id: id for the debug trace
  1324. * @ref: reference for the debug trace
  1325. * @mask: status bits to change
  1326. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1327. *
  1328. * Changes in common status bits are propagated to attached units.
  1329. */
  1330. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1331. u32 mask, int set_or_clear)
  1332. {
  1333. struct zfcp_unit *unit;
  1334. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1335. if (set_or_clear == ZFCP_SET) {
  1336. if (status_change_set(mask, &port->status))
  1337. zfcp_rec_dbf_event_port(id, ref, port);
  1338. atomic_set_mask(mask, &port->status);
  1339. } else {
  1340. if (status_change_clear(mask, &port->status))
  1341. zfcp_rec_dbf_event_port(id, ref, port);
  1342. atomic_clear_mask(mask, &port->status);
  1343. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1344. atomic_set(&port->erp_counter, 0);
  1345. }
  1346. if (common_mask)
  1347. list_for_each_entry(unit, &port->unit_list_head, list)
  1348. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1349. set_or_clear);
  1350. }
  1351. /**
  1352. * zfcp_erp_modify_unit_status - change unit status bits
  1353. * @unit: unit to change the status bits
  1354. * @id: id for the debug trace
  1355. * @ref: reference for the debug trace
  1356. * @mask: status bits to change
  1357. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1358. */
  1359. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1360. u32 mask, int set_or_clear)
  1361. {
  1362. if (set_or_clear == ZFCP_SET) {
  1363. if (status_change_set(mask, &unit->status))
  1364. zfcp_rec_dbf_event_unit(id, ref, unit);
  1365. atomic_set_mask(mask, &unit->status);
  1366. } else {
  1367. if (status_change_clear(mask, &unit->status))
  1368. zfcp_rec_dbf_event_unit(id, ref, unit);
  1369. atomic_clear_mask(mask, &unit->status);
  1370. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1371. atomic_set(&unit->erp_counter, 0);
  1372. }
  1373. }
  1374. }
  1375. /**
  1376. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1377. * @port: The "boxed" port.
  1378. * @id: The debug trace id.
  1379. * @id: Reference for the debug trace.
  1380. */
  1381. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1382. {
  1383. unsigned long flags;
  1384. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1385. zfcp_erp_modify_port_status(port, id, ref,
  1386. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1387. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1388. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1389. }
  1390. /**
  1391. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1392. * @port: The "boxed" unit.
  1393. * @id: The debug trace id.
  1394. * @id: Reference for the debug trace.
  1395. */
  1396. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1397. {
  1398. zfcp_erp_modify_unit_status(unit, id, ref,
  1399. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1400. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1401. }
  1402. /**
  1403. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1404. * @port: port where access has been denied
  1405. * @id: id for debug trace
  1406. * @ref: reference for debug trace
  1407. *
  1408. * Since the adapter has denied access, stop using the port and the
  1409. * attached units.
  1410. */
  1411. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1412. {
  1413. unsigned long flags;
  1414. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1415. zfcp_erp_modify_port_status(port, id, ref,
  1416. ZFCP_STATUS_COMMON_ERP_FAILED |
  1417. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1418. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1419. }
  1420. /**
  1421. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1422. * @unit: unit where access has been denied
  1423. * @id: id for debug trace
  1424. * @ref: reference for debug trace
  1425. *
  1426. * Since the adapter has denied access, stop using the unit.
  1427. */
  1428. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1429. {
  1430. zfcp_erp_modify_unit_status(unit, id, ref,
  1431. ZFCP_STATUS_COMMON_ERP_FAILED |
  1432. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1433. }
  1434. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1435. void *ref)
  1436. {
  1437. int status = atomic_read(&unit->status);
  1438. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1439. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1440. return;
  1441. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1442. }
  1443. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1444. void *ref)
  1445. {
  1446. struct zfcp_unit *unit;
  1447. int status = atomic_read(&port->status);
  1448. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1449. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1450. list_for_each_entry(unit, &port->unit_list_head, list)
  1451. zfcp_erp_unit_access_changed(unit, id, ref);
  1452. return;
  1453. }
  1454. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1455. }
  1456. /**
  1457. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1458. * @adapter: Adapter where the Access Control Table (ACT) changed
  1459. * @id: Id for debug trace
  1460. * @ref: Reference for debug trace
  1461. */
  1462. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1463. void *ref)
  1464. {
  1465. struct zfcp_port *port;
  1466. unsigned long flags;
  1467. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1468. return;
  1469. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1470. list_for_each_entry(port, &adapter->port_list_head, list)
  1471. zfcp_erp_port_access_changed(port, id, ref);
  1472. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1473. }