zfcp_erp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708
  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. schedule_work(&act->adapter->scan_work);
  614. return ZFCP_ERP_SUCCEEDED;
  615. close_only:
  616. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  617. &act->adapter->status);
  618. failed_openfcp:
  619. /* close queues to ensure that buffers are not accessed by adapter */
  620. zfcp_qdio_close(adapter);
  621. zfcp_fsf_req_dismiss_all(adapter);
  622. adapter->fsf_req_seq_no = 0;
  623. /* all ports and units are closed */
  624. zfcp_erp_modify_adapter_status(adapter, 24, NULL,
  625. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  626. failed_qdio:
  627. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  628. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  629. &act->adapter->status);
  630. return retval;
  631. }
  632. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  633. {
  634. int retval;
  635. zfcp_erp_adapter_strategy_generic(act, 1); /* close */
  636. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  637. return ZFCP_ERP_EXIT;
  638. retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
  639. if (retval == ZFCP_ERP_FAILED)
  640. ssleep(8);
  641. return retval;
  642. }
  643. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  644. {
  645. int retval;
  646. retval = zfcp_fsf_close_physical_port(act);
  647. if (retval == -ENOMEM)
  648. return ZFCP_ERP_NOMEM;
  649. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  650. if (retval)
  651. return ZFCP_ERP_FAILED;
  652. return ZFCP_ERP_CONTINUES;
  653. }
  654. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  655. {
  656. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  657. ZFCP_STATUS_PORT_PHYS_CLOSING |
  658. ZFCP_STATUS_PORT_INVALID_WWPN,
  659. &port->status);
  660. }
  661. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  662. {
  663. struct zfcp_port *port = erp_action->port;
  664. int status = atomic_read(&port->status);
  665. switch (erp_action->step) {
  666. case ZFCP_ERP_STEP_UNINITIALIZED:
  667. zfcp_erp_port_strategy_clearstati(port);
  668. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  669. (status & ZFCP_STATUS_COMMON_OPEN))
  670. return zfcp_erp_port_forced_strategy_close(erp_action);
  671. else
  672. return ZFCP_ERP_FAILED;
  673. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  674. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  675. return ZFCP_ERP_SUCCEEDED;
  676. }
  677. return ZFCP_ERP_FAILED;
  678. }
  679. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  680. {
  681. int retval;
  682. retval = zfcp_fsf_close_port(erp_action);
  683. if (retval == -ENOMEM)
  684. return ZFCP_ERP_NOMEM;
  685. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  686. if (retval)
  687. return ZFCP_ERP_FAILED;
  688. return ZFCP_ERP_CONTINUES;
  689. }
  690. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  691. {
  692. int retval;
  693. retval = zfcp_fsf_open_port(erp_action);
  694. if (retval == -ENOMEM)
  695. return ZFCP_ERP_NOMEM;
  696. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  697. if (retval)
  698. return ZFCP_ERP_FAILED;
  699. return ZFCP_ERP_CONTINUES;
  700. }
  701. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  702. {
  703. struct zfcp_adapter *adapter = act->adapter;
  704. struct zfcp_port *port = act->port;
  705. if (port->wwpn != adapter->peer_wwpn) {
  706. zfcp_erp_port_failed(port, 25, NULL);
  707. return ZFCP_ERP_FAILED;
  708. }
  709. port->d_id = adapter->peer_d_id;
  710. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  711. return zfcp_erp_port_strategy_open_port(act);
  712. }
  713. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  714. {
  715. int retval;
  716. struct zfcp_port *port = container_of(work, struct zfcp_port,
  717. gid_pn_work);
  718. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  719. if (retval == -ENOMEM)
  720. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  721. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  722. if (retval)
  723. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  724. }
  725. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  726. {
  727. struct zfcp_adapter *adapter = act->adapter;
  728. struct zfcp_port *port = act->port;
  729. int p_status = atomic_read(&port->status);
  730. switch (act->step) {
  731. case ZFCP_ERP_STEP_UNINITIALIZED:
  732. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  733. case ZFCP_ERP_STEP_PORT_CLOSING:
  734. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  735. return zfcp_erp_open_ptp_port(act);
  736. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  737. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  738. return ZFCP_ERP_CONTINUES;
  739. }
  740. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  741. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  742. if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
  743. zfcp_erp_port_failed(port, 26, NULL);
  744. return ZFCP_ERP_EXIT;
  745. }
  746. return ZFCP_ERP_FAILED;
  747. }
  748. return zfcp_erp_port_strategy_open_port(act);
  749. case ZFCP_ERP_STEP_PORT_OPENING:
  750. /* D_ID might have changed during open */
  751. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  752. if (p_status & ZFCP_STATUS_PORT_DID_DID)
  753. return ZFCP_ERP_SUCCEEDED;
  754. else {
  755. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  756. return ZFCP_ERP_CONTINUES;
  757. }
  758. /* fall through otherwise */
  759. }
  760. }
  761. return ZFCP_ERP_FAILED;
  762. }
  763. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  764. {
  765. struct zfcp_port *port = erp_action->port;
  766. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  767. goto close_init_done;
  768. switch (erp_action->step) {
  769. case ZFCP_ERP_STEP_UNINITIALIZED:
  770. zfcp_erp_port_strategy_clearstati(port);
  771. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  772. return zfcp_erp_port_strategy_close(erp_action);
  773. break;
  774. case ZFCP_ERP_STEP_PORT_CLOSING:
  775. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  776. return ZFCP_ERP_FAILED;
  777. break;
  778. }
  779. close_init_done:
  780. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  781. return ZFCP_ERP_EXIT;
  782. return zfcp_erp_port_strategy_open_common(erp_action);
  783. }
  784. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  785. {
  786. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  787. ZFCP_STATUS_UNIT_SHARED |
  788. ZFCP_STATUS_UNIT_READONLY,
  789. &unit->status);
  790. }
  791. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  792. {
  793. int retval = zfcp_fsf_close_unit(erp_action);
  794. if (retval == -ENOMEM)
  795. return ZFCP_ERP_NOMEM;
  796. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  797. if (retval)
  798. return ZFCP_ERP_FAILED;
  799. return ZFCP_ERP_CONTINUES;
  800. }
  801. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  802. {
  803. int retval = zfcp_fsf_open_unit(erp_action);
  804. if (retval == -ENOMEM)
  805. return ZFCP_ERP_NOMEM;
  806. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  807. if (retval)
  808. return ZFCP_ERP_FAILED;
  809. return ZFCP_ERP_CONTINUES;
  810. }
  811. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  812. {
  813. struct zfcp_unit *unit = erp_action->unit;
  814. switch (erp_action->step) {
  815. case ZFCP_ERP_STEP_UNINITIALIZED:
  816. zfcp_erp_unit_strategy_clearstati(unit);
  817. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  818. return zfcp_erp_unit_strategy_close(erp_action);
  819. /* already closed, fall through */
  820. case ZFCP_ERP_STEP_UNIT_CLOSING:
  821. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  822. return ZFCP_ERP_FAILED;
  823. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  824. return ZFCP_ERP_EXIT;
  825. return zfcp_erp_unit_strategy_open(erp_action);
  826. case ZFCP_ERP_STEP_UNIT_OPENING:
  827. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  828. return ZFCP_ERP_SUCCEEDED;
  829. }
  830. return ZFCP_ERP_FAILED;
  831. }
  832. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  833. {
  834. switch (result) {
  835. case ZFCP_ERP_SUCCEEDED :
  836. atomic_set(&unit->erp_counter, 0);
  837. zfcp_erp_unit_unblock(unit);
  838. break;
  839. case ZFCP_ERP_FAILED :
  840. atomic_inc(&unit->erp_counter);
  841. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  842. dev_err(&unit->port->adapter->ccw_device->dev,
  843. "ERP failed for unit 0x%016Lx on "
  844. "port 0x%016Lx\n",
  845. (unsigned long long)unit->fcp_lun,
  846. (unsigned long long)unit->port->wwpn);
  847. zfcp_erp_unit_failed(unit, 21, NULL);
  848. }
  849. break;
  850. }
  851. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  852. zfcp_erp_unit_block(unit, 0);
  853. result = ZFCP_ERP_EXIT;
  854. }
  855. return result;
  856. }
  857. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  858. {
  859. switch (result) {
  860. case ZFCP_ERP_SUCCEEDED :
  861. atomic_set(&port->erp_counter, 0);
  862. zfcp_erp_port_unblock(port);
  863. break;
  864. case ZFCP_ERP_FAILED :
  865. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  866. zfcp_erp_port_block(port, 0);
  867. result = ZFCP_ERP_EXIT;
  868. }
  869. atomic_inc(&port->erp_counter);
  870. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  871. dev_err(&port->adapter->ccw_device->dev,
  872. "ERP failed for remote port 0x%016Lx\n",
  873. (unsigned long long)port->wwpn);
  874. zfcp_erp_port_failed(port, 22, NULL);
  875. }
  876. break;
  877. }
  878. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  879. zfcp_erp_port_block(port, 0);
  880. result = ZFCP_ERP_EXIT;
  881. }
  882. return result;
  883. }
  884. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  885. int result)
  886. {
  887. switch (result) {
  888. case ZFCP_ERP_SUCCEEDED :
  889. atomic_set(&adapter->erp_counter, 0);
  890. zfcp_erp_adapter_unblock(adapter);
  891. break;
  892. case ZFCP_ERP_FAILED :
  893. atomic_inc(&adapter->erp_counter);
  894. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  895. dev_err(&adapter->ccw_device->dev,
  896. "ERP cannot recover an error "
  897. "on the FCP device\n");
  898. zfcp_erp_adapter_failed(adapter, 23, NULL);
  899. }
  900. break;
  901. }
  902. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  903. zfcp_erp_adapter_block(adapter, 0);
  904. result = ZFCP_ERP_EXIT;
  905. }
  906. return result;
  907. }
  908. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  909. int result)
  910. {
  911. struct zfcp_adapter *adapter = erp_action->adapter;
  912. struct zfcp_port *port = erp_action->port;
  913. struct zfcp_unit *unit = erp_action->unit;
  914. switch (erp_action->action) {
  915. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  916. result = zfcp_erp_strategy_check_unit(unit, result);
  917. break;
  918. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  919. case ZFCP_ERP_ACTION_REOPEN_PORT:
  920. result = zfcp_erp_strategy_check_port(port, result);
  921. break;
  922. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  923. result = zfcp_erp_strategy_check_adapter(adapter, result);
  924. break;
  925. }
  926. return result;
  927. }
  928. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  929. {
  930. int status = atomic_read(target_status);
  931. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  932. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  933. return 1; /* take it online */
  934. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  935. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  936. return 1; /* take it offline */
  937. return 0;
  938. }
  939. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  940. {
  941. int action = act->action;
  942. struct zfcp_adapter *adapter = act->adapter;
  943. struct zfcp_port *port = act->port;
  944. struct zfcp_unit *unit = act->unit;
  945. u32 erp_status = act->status;
  946. switch (action) {
  947. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  948. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  949. _zfcp_erp_adapter_reopen(adapter,
  950. ZFCP_STATUS_COMMON_ERP_FAILED,
  951. 67, NULL);
  952. return ZFCP_ERP_EXIT;
  953. }
  954. break;
  955. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  956. case ZFCP_ERP_ACTION_REOPEN_PORT:
  957. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  958. _zfcp_erp_port_reopen(port,
  959. ZFCP_STATUS_COMMON_ERP_FAILED,
  960. 68, NULL);
  961. return ZFCP_ERP_EXIT;
  962. }
  963. break;
  964. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  965. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  966. _zfcp_erp_unit_reopen(unit,
  967. ZFCP_STATUS_COMMON_ERP_FAILED,
  968. 69, NULL);
  969. return ZFCP_ERP_EXIT;
  970. }
  971. break;
  972. }
  973. return ret;
  974. }
  975. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  976. {
  977. struct zfcp_adapter *adapter = erp_action->adapter;
  978. adapter->erp_total_count--;
  979. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  980. adapter->erp_low_mem_count--;
  981. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  982. }
  983. list_del(&erp_action->list);
  984. zfcp_rec_dbf_event_action(144, erp_action);
  985. switch (erp_action->action) {
  986. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  987. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  988. &erp_action->unit->status);
  989. break;
  990. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  991. case ZFCP_ERP_ACTION_REOPEN_PORT:
  992. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  993. &erp_action->port->status);
  994. break;
  995. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  996. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  997. &erp_action->adapter->status);
  998. break;
  999. }
  1000. }
  1001. struct zfcp_erp_add_work {
  1002. struct zfcp_unit *unit;
  1003. struct work_struct work;
  1004. };
  1005. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1006. {
  1007. struct zfcp_erp_add_work *p =
  1008. container_of(work, struct zfcp_erp_add_work, work);
  1009. struct zfcp_unit *unit = p->unit;
  1010. struct fc_rport *rport = unit->port->rport;
  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. zfcp_erp_rports_del(adapter);
  1097. zfcp_adapter_put(adapter);
  1098. break;
  1099. }
  1100. }
  1101. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1102. {
  1103. switch (erp_action->action) {
  1104. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1105. return zfcp_erp_adapter_strategy(erp_action);
  1106. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1107. return zfcp_erp_port_forced_strategy(erp_action);
  1108. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1109. return zfcp_erp_port_strategy(erp_action);
  1110. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1111. return zfcp_erp_unit_strategy(erp_action);
  1112. }
  1113. return ZFCP_ERP_FAILED;
  1114. }
  1115. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1116. {
  1117. int retval;
  1118. struct zfcp_adapter *adapter = erp_action->adapter;
  1119. unsigned long flags;
  1120. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1121. write_lock(&adapter->erp_lock);
  1122. zfcp_erp_strategy_check_fsfreq(erp_action);
  1123. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1124. zfcp_erp_action_dequeue(erp_action);
  1125. retval = ZFCP_ERP_DISMISSED;
  1126. goto unlock;
  1127. }
  1128. zfcp_erp_action_to_running(erp_action);
  1129. /* no lock to allow for blocking operations */
  1130. write_unlock(&adapter->erp_lock);
  1131. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1132. retval = zfcp_erp_strategy_do_action(erp_action);
  1133. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1134. write_lock(&adapter->erp_lock);
  1135. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1136. retval = ZFCP_ERP_CONTINUES;
  1137. switch (retval) {
  1138. case ZFCP_ERP_NOMEM:
  1139. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1140. ++adapter->erp_low_mem_count;
  1141. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1142. }
  1143. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1144. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1145. else {
  1146. zfcp_erp_strategy_memwait(erp_action);
  1147. retval = ZFCP_ERP_CONTINUES;
  1148. }
  1149. goto unlock;
  1150. case ZFCP_ERP_CONTINUES:
  1151. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1152. --adapter->erp_low_mem_count;
  1153. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1154. }
  1155. goto unlock;
  1156. }
  1157. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1158. zfcp_erp_action_dequeue(erp_action);
  1159. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1160. if (retval == ZFCP_ERP_EXIT)
  1161. goto unlock;
  1162. zfcp_erp_strategy_followup_actions(erp_action);
  1163. unlock:
  1164. write_unlock(&adapter->erp_lock);
  1165. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1166. if (retval != ZFCP_ERP_CONTINUES)
  1167. zfcp_erp_action_cleanup(erp_action, retval);
  1168. return retval;
  1169. }
  1170. static int zfcp_erp_thread(void *data)
  1171. {
  1172. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1173. struct list_head *next;
  1174. struct zfcp_erp_action *act;
  1175. unsigned long flags;
  1176. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1177. /* Block all signals */
  1178. siginitsetinv(&current->blocked, 0);
  1179. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1180. wake_up(&adapter->erp_thread_wqh);
  1181. while (!(atomic_read(&adapter->status) &
  1182. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1183. write_lock_irqsave(&adapter->erp_lock, flags);
  1184. next = adapter->erp_ready_head.next;
  1185. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1186. if (next != &adapter->erp_ready_head) {
  1187. act = list_entry(next, struct zfcp_erp_action, list);
  1188. /* there is more to come after dismission, no notify */
  1189. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1190. zfcp_erp_wakeup(adapter);
  1191. }
  1192. zfcp_rec_dbf_event_thread_lock(4, adapter);
  1193. down_interruptible(&adapter->erp_ready_sem);
  1194. zfcp_rec_dbf_event_thread_lock(5, adapter);
  1195. }
  1196. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1197. wake_up(&adapter->erp_thread_wqh);
  1198. return 0;
  1199. }
  1200. /**
  1201. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1202. * @adapter: Adapter to start the ERP thread for
  1203. *
  1204. * Returns 0 on success or error code from kernel_thread()
  1205. */
  1206. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1207. {
  1208. int retval;
  1209. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1210. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1211. if (retval < 0) {
  1212. dev_err(&adapter->ccw_device->dev,
  1213. "Creating an ERP thread for the FCP device failed.\n");
  1214. return retval;
  1215. }
  1216. wait_event(adapter->erp_thread_wqh,
  1217. atomic_read(&adapter->status) &
  1218. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1219. return 0;
  1220. }
  1221. /**
  1222. * zfcp_erp_thread_kill - Stop ERP thread.
  1223. * @adapter: Adapter where the ERP thread should be stopped.
  1224. *
  1225. * The caller of this routine ensures that the specified adapter has
  1226. * been shut down and that this operation has been completed. Thus,
  1227. * there are no pending erp_actions which would need to be handled
  1228. * here.
  1229. */
  1230. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1231. {
  1232. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1233. up(&adapter->erp_ready_sem);
  1234. zfcp_rec_dbf_event_thread_lock(3, adapter);
  1235. wait_event(adapter->erp_thread_wqh,
  1236. !(atomic_read(&adapter->status) &
  1237. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1238. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1239. &adapter->status);
  1240. }
  1241. /**
  1242. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1243. * @adapter: Failed adapter.
  1244. * @id: Event id for debug trace.
  1245. * @ref: Reference for debug trace.
  1246. */
  1247. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1248. {
  1249. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1250. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1251. }
  1252. /**
  1253. * zfcp_erp_port_failed - Set port status to failed.
  1254. * @port: Failed port.
  1255. * @id: Event id for debug trace.
  1256. * @ref: Reference for debug trace.
  1257. */
  1258. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1259. {
  1260. zfcp_erp_modify_port_status(port, id, ref,
  1261. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1262. }
  1263. /**
  1264. * zfcp_erp_unit_failed - Set unit status to failed.
  1265. * @unit: Failed unit.
  1266. * @id: Event id for debug trace.
  1267. * @ref: Reference for debug trace.
  1268. */
  1269. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1270. {
  1271. zfcp_erp_modify_unit_status(unit, id, ref,
  1272. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1273. }
  1274. /**
  1275. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1276. * @adapter: adapter for which to wait for completion of its error recovery
  1277. */
  1278. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1279. {
  1280. wait_event(adapter->erp_done_wqh,
  1281. !(atomic_read(&adapter->status) &
  1282. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1283. }
  1284. /**
  1285. * zfcp_erp_modify_adapter_status - change adapter status bits
  1286. * @adapter: adapter to change the status
  1287. * @id: id for the debug trace
  1288. * @ref: reference for the debug trace
  1289. * @mask: status bits to change
  1290. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1291. *
  1292. * Changes in common status bits are propagated to attached ports and units.
  1293. */
  1294. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1295. void *ref, u32 mask, int set_or_clear)
  1296. {
  1297. struct zfcp_port *port;
  1298. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1299. if (set_or_clear == ZFCP_SET) {
  1300. if (status_change_set(mask, &adapter->status))
  1301. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1302. atomic_set_mask(mask, &adapter->status);
  1303. } else {
  1304. if (status_change_clear(mask, &adapter->status))
  1305. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1306. atomic_clear_mask(mask, &adapter->status);
  1307. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1308. atomic_set(&adapter->erp_counter, 0);
  1309. }
  1310. if (common_mask)
  1311. list_for_each_entry(port, &adapter->port_list_head, list)
  1312. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1313. set_or_clear);
  1314. }
  1315. /**
  1316. * zfcp_erp_modify_port_status - change port status bits
  1317. * @port: port to change the status bits
  1318. * @id: id for the debug trace
  1319. * @ref: reference for the debug trace
  1320. * @mask: status bits to change
  1321. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1322. *
  1323. * Changes in common status bits are propagated to attached units.
  1324. */
  1325. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1326. u32 mask, int set_or_clear)
  1327. {
  1328. struct zfcp_unit *unit;
  1329. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1330. if (set_or_clear == ZFCP_SET) {
  1331. if (status_change_set(mask, &port->status))
  1332. zfcp_rec_dbf_event_port(id, ref, port);
  1333. atomic_set_mask(mask, &port->status);
  1334. } else {
  1335. if (status_change_clear(mask, &port->status))
  1336. zfcp_rec_dbf_event_port(id, ref, port);
  1337. atomic_clear_mask(mask, &port->status);
  1338. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1339. atomic_set(&port->erp_counter, 0);
  1340. }
  1341. if (common_mask)
  1342. list_for_each_entry(unit, &port->unit_list_head, list)
  1343. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1344. set_or_clear);
  1345. }
  1346. /**
  1347. * zfcp_erp_modify_unit_status - change unit status bits
  1348. * @unit: unit to change the status bits
  1349. * @id: id for the debug trace
  1350. * @ref: reference for the debug trace
  1351. * @mask: status bits to change
  1352. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1353. */
  1354. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1355. u32 mask, int set_or_clear)
  1356. {
  1357. if (set_or_clear == ZFCP_SET) {
  1358. if (status_change_set(mask, &unit->status))
  1359. zfcp_rec_dbf_event_unit(id, ref, unit);
  1360. atomic_set_mask(mask, &unit->status);
  1361. } else {
  1362. if (status_change_clear(mask, &unit->status))
  1363. zfcp_rec_dbf_event_unit(id, ref, unit);
  1364. atomic_clear_mask(mask, &unit->status);
  1365. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1366. atomic_set(&unit->erp_counter, 0);
  1367. }
  1368. }
  1369. }
  1370. /**
  1371. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1372. * @port: The "boxed" port.
  1373. * @id: The debug trace id.
  1374. * @id: Reference for the debug trace.
  1375. */
  1376. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1377. {
  1378. unsigned long flags;
  1379. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1380. zfcp_erp_modify_port_status(port, id, ref,
  1381. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1382. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1383. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1384. }
  1385. /**
  1386. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1387. * @port: The "boxed" unit.
  1388. * @id: The debug trace id.
  1389. * @id: Reference for the debug trace.
  1390. */
  1391. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1392. {
  1393. zfcp_erp_modify_unit_status(unit, id, ref,
  1394. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1395. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1396. }
  1397. /**
  1398. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1399. * @port: port where access has been denied
  1400. * @id: id for debug trace
  1401. * @ref: reference for debug trace
  1402. *
  1403. * Since the adapter has denied access, stop using the port and the
  1404. * attached units.
  1405. */
  1406. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1407. {
  1408. unsigned long flags;
  1409. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1410. zfcp_erp_modify_port_status(port, id, ref,
  1411. ZFCP_STATUS_COMMON_ERP_FAILED |
  1412. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1413. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1414. }
  1415. /**
  1416. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1417. * @unit: unit where access has been denied
  1418. * @id: id for debug trace
  1419. * @ref: reference for debug trace
  1420. *
  1421. * Since the adapter has denied access, stop using the unit.
  1422. */
  1423. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1424. {
  1425. zfcp_erp_modify_unit_status(unit, id, ref,
  1426. ZFCP_STATUS_COMMON_ERP_FAILED |
  1427. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1428. }
  1429. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1430. void *ref)
  1431. {
  1432. int status = atomic_read(&unit->status);
  1433. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1434. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1435. return;
  1436. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1437. }
  1438. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1439. void *ref)
  1440. {
  1441. struct zfcp_unit *unit;
  1442. int status = atomic_read(&port->status);
  1443. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1444. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1445. list_for_each_entry(unit, &port->unit_list_head, list)
  1446. zfcp_erp_unit_access_changed(unit, id, ref);
  1447. return;
  1448. }
  1449. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1450. }
  1451. /**
  1452. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1453. * @adapter: Adapter where the Access Control Table (ACT) changed
  1454. * @id: Id for debug trace
  1455. * @ref: Reference for debug trace
  1456. */
  1457. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1458. void *ref)
  1459. {
  1460. struct zfcp_port *port;
  1461. unsigned long flags;
  1462. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1463. return;
  1464. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1465. list_for_each_entry(port, &adapter->port_list_head, list)
  1466. zfcp_erp_port_access_changed(port, id, ref);
  1467. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1468. }